The words you are searching are inside this book. To get more targeted content, please make full-text search by clicking here.

The Embedded Book Fundamentals of Using PIC 18 F covers the basic concept of a microcontroller system based on the Peripheral Interface Controller ( In lesson 1 students will learn the concept of an embedded system, the structure of C programming for the PIC 18 F, recognize digital input and output, write time delays and i /o
operations Lesson 2 will discuss the concept of a timer, the register used for a timer, and the C program for a timer Then, in Lesson 3 we will focus on the concepts of interrupt and PIC interrupt programming in C The exercises for every lesson are provided to help students quickly understand the concept covered by each lesson

Discover the best professional documents and content resources in AnyFlip Document Base.
Search
Published by Penerbit PSIS, 2023-12-05 21:40:19

THE EMBEDDED BOOK : FUNDAMENTALS OF USING PIC18F

The Embedded Book Fundamentals of Using PIC 18 F covers the basic concept of a microcontroller system based on the Peripheral Interface Controller ( In lesson 1 students will learn the concept of an embedded system, the structure of C programming for the PIC 18 F, recognize digital input and output, write time delays and i /o
operations Lesson 2 will discuss the concept of a timer, the register used for a timer, and the C program for a timer Then, in Lesson 3 we will focus on the concepts of interrupt and PIC interrupt programming in C The exercises for every lesson are provided to help students quickly understand the concept covered by each lesson

Register in interrupts Interrupt source bits control • Flag bit – to indicate that an interrupt event occurred • Enable bit – that allows program execution to branch to the interrupt vector address when the flag bit is set • Priority bit – to select high priority or low priority • RCON (Priority Enable) • INTCON • INTCON2 • INTCON3 • PIR, PIR2 • PIE1, PIE2 • IPR1, IPR2 External Interrupt Sources Internal Peripheral Interrupts 42


Programming EXTERNAL HARDWARE Interrupt Interrupt Flag Bit Register Enable Bit Register INT0 (RB0) INT0IF INTCON INT0IE INTCON INT1 (RB1) INT1IF INTCON3 INT1IE INTCON3 INT2 (RB2) INT2IF INTCON3 INT2IE INTCON3 Flag bit = to indicate whether an interrupt has occurred Enable bit = to enable or disable the interrupt source INTCONbits.INT0IF = INTCONbits.INT0IE = INTCON3bits.INT1IF = INTCON3bits.INT1IE = INTCON3bits.INT2IF = INTCON3bits.INT2IE = INT0 (RB0) INT1 (RB1) INT2 (RB2) Syntax writing to call interrupt flag and Interrupt Enable Table 3.3 : External Interrupt 43


Interrupt Flag Bit Register Enable Bit Register Timer0 TMR0IF INTCON TMR0IE INTCON Timer1 TMR1IF PIR1 TMR1IE PIE1 Timer2 TMR2IF PIR1 TMR2IE PIE1 Timer3 TMR3IF PIR3 TMR3IE PIE2 Programming TIMER Interrupt PortB-Change Interrupt • The four pins of the PORTB (RB4-RB7) can cause an interrupt when any changes are detected on nay one of them. • They are referred to PortB-Change Interrupt to distinguish them from the INT0-INT2 interrupts, which are located on PORTB. • The register involved in this interrupt is INTCON register. D7 D0 GIE RBIE RBIF >>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<< End 44 Table 3.4 : Timer Interrupt


Exercise 4 45


EXERCISE 4 : Interrupt 1. Construct a single instruction to enable and disable the Timer 0 and Timer 1 interrupt, enable external hardware interrupt at RB0 (INT0), RB1 (INTI1), RB2 (INT2) and lastly disable all the interrupt. [8 marks] 2. Describe the interrupt and polling methods in a microcontroller. [4 marks] 3. Explain the differences between Enable Bit and Flag Bit. Give ONE(1) example for each bit. [6 marks] 4. You are given a project to connect a door sensor to pin RB0 and a buzzer to pin RC7. Using INT0 external hardware interrupt, write a program using C language when every time the door is opened, the buzzer activates. Refer Appendix 3c. [10 marks] 5. A postman has put a letter in the mailbox. If the letter falls, the buzzer will notify the owner that he/she has received a letter. An LDR sensor is attached at RB0 at the microcontroller and a buzzer is connected at RA6. Write a source code that shows only instruction from interrupt vector table until interrupt service routine for the process. [8 marks] 46


SOLUTION EXERCISE 4 : Interrupt 1. 47


SOLUTION EXERCISE 4 : Interrupt 2. Interrupt is the signal send to the microcontroller to mark the event that requires immediate attention. Polling is a situation where microcontroller accesses at the exact time interval the external devices and gets the require information. 3. Enable Bit & Flag Bit Enable Bit- it can be used to enable/disable the related interrupt. When set to ‘1’- it is enable the interrupt. When set to 0-it is disable the interrupt. Example- GIE, INTOIE, PEIE . Flag Bit- It is set automatically by the related hardware when the interrupt condition occurs. When set to ‘1’- the interrupt occurs. When set to ‘0’- the interrupt do not occurs. 48


SOLUTION EXERCISE 4 : Interrupt 4. Coding: #include <p18f4580> #define BZ PORTCbits.RC7 void chk_isr (void); void INTO_ISR(void); #pragma interrupt chk_isr void chk_isr (void) { if (INTCONbits.INTOIF==1) INTO_ISR (); } #PRAGMA CODE My_Hiprio_Int=0x08 void My_HiPrio_Int (void) {_asm GOTO chk_isr _endasm } #pragma code void main (void) { TRISCbits.TRISRC7=0; TRISBbits.TRISRB0=1; INTCONbits.INT0IF=0; INTCONbits.GIE=1; while(1) { {void INTO_ISR (void) { BZ=1; INTCONbits.INTOIF=0; } } 49


SOLUTION EXERCISE 4 : Interrupt 5. Coding: #pragma interrupt chk_isr void chk_isr (void) { if (INTCONbits.INTOIF==1) INTO_ISR (); } #PRAGMA code My_Hiprio_Int=0x08 void My_HiPrio_Int (void) { _asm GOTO chk_isr _endasm } #pragma code Void INT0_ISR (void) { Buzzer=1; INTCONbits.INTOIF=0; } 50


Tutorial 3 51


Let’s try Tutorial 3 52 SCAN ME “Just believe in yourself. Even if you don’t, just pretend that you do and at some point, you will.” – Venus Williams


REFERENCES 53 Barry B. Brey (2008). Applying PIC18 Microcontrollers: Architecture, Programming, and Interfacing using C and Assembly. Pearson Prentice Hall Bates, M. (2013). Interfacing PIC Microcontrollers Embedded Design by Interactive Simulation. 2nd Edition. Newnes. Bates, M. (2008). Programming 8-bit PIC Microcontroller In C: With Interactive Hardware Simulation.Newnes. Muhammad Ali Mazidi, Rolin D. McKinlay & Danny Causey (2008); Embedded Systems Using Assembly and C for PIC18; Pearson Education International PIC18 Configuration Setting Addendum; MPLAB 2009 Microchip Technology Inc PIC18F2480/2580/4480/4580 Data Sheet; Microchip Technology Inc Koleksi Soalan Peperiksaan Jabatan Kejuruteraan Elektrik Politeknik Sultan Idris Shah, Sabak Bernam.


Bibliography 54 Ts. KALAIVANI A/P RAMACHANDRAN JABATANKEJURUTERAAN ELEKTRIK (JKE)/DIPLOMA IN ELECTRONIC (COMMUNICATION-DEP) [email protected] Teaching experience for 10 years and familiar with subjects Microprocessor Fundamentals, Electronic Circuits, Embedded System, Electrical Circuits, Semiconductor Devices, Digital Circuit, Power Electronics and AC Motor. Achievement: 1. Best Presenter, 2nd International Conference on Green Technology (ICGT), 2016 (International) 2. Recipient of The Innovation Award, 2nd National Conference on Wood Based Technology, Engineering and Innovation (NCWEI’17), 2016 (National) ZAINORA BINTI KAMAL LUDIN JABATAN KEJURUTERAAN ELEKTRIK (JKE)/DIPLOMA IN ELECTRONIC (COMPUTER-DTK), [email protected] Teaching experience for 18 years and familiar with subjects Embedded System Applications, C Programming, Fundamental Computer Networking, Database System, Entrepreneurship, CMOS Design and AUTOCAD. Achievement: 1. Anugerah Perkhidmatan Cemerlang 2009 2. Anugerah Pekerja Contoh 2020 3. Researcher for Public Private Research Network (PPRN) 2016 - Lemon Grass Blender Machine 4. Researcher for Public Private Research Network (PPRN) 2018 - Spring Roll Rolling Machine NURAIN B T MOHD IZZUAN WONG JABATAN KEJURUTERAAN ELEKTRIK (JKE)/DIPLOMA IN ELECTRONIC (COMMUNICATION-DEP) nurainwong 44 @psis.edu.my Teaching experience for 10 years and familiar with subjects Embedded System Applications, Measurement Devices, Digital Electronics and Electronic Computer Aided Design. Achievement: Best Presenter – Intelligence Traffic Light For Emergency Vehicles at The 2nd National Conference on Wood Based Technology Engineering and Innovation 2017 (NCWEI’17)


Do you know behind the scene of every working electronic devices? You might want to further explore this book to understand the beginning process. It all start with the tiny IC inside all the electronic devices. This book will show you the comprehensive notes to easy understand and many exercises and tutorials to enhance your knowledge.


Click to View FlipBook Version