The output of a motor encoder is connected to RB1 INT1 of th

The output of a motor encoder is connected to RB1 (INT1) of the PIC18F4321. The encoder pulse frequency is about 10 Hz. The pin RB7 is connected to an LED. The program will toggle the LED on the falling edge of the pulse generated by the encoder. This means that the LED is turned on and off at the same rate as the output of the motor encoder. Write a C-program using interrupts to perform this task.

Solution

#define _XTAL_FREQ 10

#include <xc.h>

// BEGIN CONFIG
#pragma config FOSC = HS // HS oscillator Enable
#pragma config WDTE = ON // WDT enabled
#pragma config PWRTE = OFF // PWRT disabled
#pragma config BOREN = ON // BOR enabled
#pragma config LVP = OFF // Low-Voltage (Single-Supply)
#pragma config CPD = OFF // Data EEPROM code protection off
#pragma config WRT = OFF // Write Enable bits
#pragma config CP = OFF // Code Protection bit

//END CONFIG

int main()
{
TRISB7 = 0; //RB7 as Output PIN
while(1)
{
RB1 = 1; // LED ON
__delay_ms(2000); // 2 Second Delay
RB1 = 0; // LED OFF
__delay_ms(2000); // 2 Second Delay
}
return 0;
}

 The output of a motor encoder is connected to RB1 (INT1) of the PIC18F4321. The encoder pulse frequency is about 10 Hz. The pin RB7 is connected to an LED. The

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site