User manual
Robotics experiment with PIC microcontroller l 81
In the Listing A10-1 is C program for reading data from ER-4 remote control and
shows on LCD screen. In addition use this data to compare the reference data for driving
sound to piezo speaker by Sound_Play function of mikroC compiler.
A10.1 Write the Listing A10-1. Compile and download the code to Robo-PICA.
Activity 10
Reading Remote control data
Listing A10-1 : Reading data from ER-4 remote control program (continue)
char *text = "ER-4 Remote"; // Define message
unsigned char ir_cmd=0; // Keep Command button from ER-4 Remote
//------------------ Interrupt service routine INT -----------------//
void interrupt()
{
unsigned char i; // Keep counter
if(INTCON.INTF) // Check interrupt flag RB0 (Falling edge)
{
Delay_us(416); // Delay 1/2 of 1 bit timing
// (baudrate 1200 bps)
for(i=0;i<8;i++) // Loop 8 times for keep data from ER-4
{
Delay_us(833); // Delay of 1 bit timing
// (baudrate 1200 bps)
ir_cmd = ir_cmd>>1; // Shitt bit 1 time
if((PORTB & 0x01)==1) // Get logic @ RB0 = '1'?
ir_cmd = ir_cmd | 0x80; // Inset bit data is '1'
}
Delay_us(833); // Delay of 1 bit timing
// (baudrate 1200 bps)
INTCON.INTF =0; // Clear interrupt flag
}
}
//------------------ Function for get character from Remote ---------//
unsigned char get_remote()
{
unsigned char _key=ir_cmd; // Get character to buffer
ir_cmd=0; // Clear old data
return(_key); // Return character from Remote
}
//------------------ Main Program ----------------------------------//
void main()
{
unsigned char key; // Save Remote Key Press
ANSELH.F4=0; // RB0 ==> Digital IO
OPTION_REG.INTEDG = 0; // INT falling edge
INTCON.INTE =1; // Enable INT/PB0
INTCON.GIE =1; // Enable Global interrupt