Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(16 points) Read about the PORTB Interrupt-on-change Interrupt in the PIC16F887 data sheet (Section 3.4.3 and study the PORTB block diagram in Fig. 3-9). Write

image text in transcribed

(16 points) Read about the PORTB Interrupt-on-change Interrupt in the PIC16F887 data sheet (Section 3.4.3 and study the PORTB block diagram in Fig. 3-9). Write a program in C that will keep a count of the occurrences of the RB Change Interrupt on RB4 only that result in RB4-1 (thus we will count occurrences of rising edges on RB4 only). Your main program should configure the bottom half of PORT D (RD) as outputs, set up RB4 as an input, disable the analog input on RB4, enable the internal pull ups for PORTB (nRBPU- 0), set up the PORTB Interrupt-on-change interrupt for RB4 (set IOCB4-1, read RB4, even though nothing is done with the value read, this causes the present state of RB4 to be latched in the bottom-most flip-flop in Fig. 3-9, set RBIF-0RBIE-1, and GE-1) Your interrupt service routine should service the interrupt by reading RB4, if RB 1 you should increment RD in order to count rising edges only, and finally relaxing the appropriate interrupt flag (RBIF 0). Note from Section 3.4.3 that the interrupt flag must be cleared using a two-step procedure: (a) read RB4 (this eliminates the mismatch condition discussed in Section 3.4.3), and then clear the PORTB change interrupt flag RBIF 0. If you do not first read RB4 to eliminate the mismatch condition, RBIF cannot be cleared by writing 0 to it. Note that the PORTB Interrupt-on-change interrupt is enabled locally by setting RBIE bit in the INTCON register-1. It is enabled globally by setting GIE1 4. Test your code using either the simulator or your lab breadboard. If using the breadboard, use one push button connected between RB4 and ground (no external pull up is necessary) to generate the interrupt and display the count on four LEDs connected to RD3:0>. In order to guarantee that there will not be multiple transitions on RB4 as the switch is pressed due to mechanical contact bounce, put a 0.1 uF capacitor across the pushbutton switch (between RB4 and ground). This capacitor will absorb any unwanted multiple transitions caused by mechanical contact bounce. In the simulator, you can generate the pushbutton input using the IOPin window, and observe the value on RD with a variable or watch window. Conduct a test procedure which shows your program works reliably. For example, you might decide to hold 10 trials, where in each trial the button is pressed and then released 4 times in a row. Hopefully you will be able to report that in each of the 10 trials, the LEDs displayed 1 or 1->0)? (16 points) Read about the PORTB Interrupt-on-change Interrupt in the PIC16F887 data sheet (Section 3.4.3 and study the PORTB block diagram in Fig. 3-9). Write a program in C that will keep a count of the occurrences of the RB Change Interrupt on RB4 only that result in RB4-1 (thus we will count occurrences of rising edges on RB4 only). Your main program should configure the bottom half of PORT D (RD) as outputs, set up RB4 as an input, disable the analog input on RB4, enable the internal pull ups for PORTB (nRBPU- 0), set up the PORTB Interrupt-on-change interrupt for RB4 (set IOCB4-1, read RB4, even though nothing is done with the value read, this causes the present state of RB4 to be latched in the bottom-most flip-flop in Fig. 3-9, set RBIF-0RBIE-1, and GE-1) Your interrupt service routine should service the interrupt by reading RB4, if RB 1 you should increment RD in order to count rising edges only, and finally relaxing the appropriate interrupt flag (RBIF 0). Note from Section 3.4.3 that the interrupt flag must be cleared using a two-step procedure: (a) read RB4 (this eliminates the mismatch condition discussed in Section 3.4.3), and then clear the PORTB change interrupt flag RBIF 0. If you do not first read RB4 to eliminate the mismatch condition, RBIF cannot be cleared by writing 0 to it. Note that the PORTB Interrupt-on-change interrupt is enabled locally by setting RBIE bit in the INTCON register-1. It is enabled globally by setting GIE1 4. Test your code using either the simulator or your lab breadboard. If using the breadboard, use one push button connected between RB4 and ground (no external pull up is necessary) to generate the interrupt and display the count on four LEDs connected to RD3:0>. In order to guarantee that there will not be multiple transitions on RB4 as the switch is pressed due to mechanical contact bounce, put a 0.1 uF capacitor across the pushbutton switch (between RB4 and ground). This capacitor will absorb any unwanted multiple transitions caused by mechanical contact bounce. In the simulator, you can generate the pushbutton input using the IOPin window, and observe the value on RD with a variable or watch window. Conduct a test procedure which shows your program works reliably. For example, you might decide to hold 10 trials, where in each trial the button is pressed and then released 4 times in a row. Hopefully you will be able to report that in each of the 10 trials, the LEDs displayed 1 or 1->0)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899

Students also viewed these Databases questions