gokulnathk
Newbie level 2
- Joined
- May 31, 2013
- Messages
- 2
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,330
hello,
i have a program of IR remote control for pic 16f887.
Anybody please help me to convert it so that i can use it in pic 18f4520.
// Lcd pinout settings
sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D4 at RD4_bit;
// Pin direction
sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D7_Direction at TRISD7_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D4_Direction at TRISd4_bit;
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; // **** 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
Lcd_Init(&PORTD); // Initialize LCD connected to PORTD
Lcd_Cmd(Lcd_CLEAR); // Clear display
Lcd_Cmd(Lcd_CURSOR_OFF); // Turn cursor off
Lcd_Out(1, 1, text); // Print text to LCD,2nd row,1st column
Sound_Init(&PORTC,0);
while(1) // Infinite loop
{
key = get_remote(); // Get Remote
if(key=='a' || key=='A') // Button A press?
{
Lcd_Out(2, 1, "Button A Press "); // Display message Button A press
Sound_Play(100,500);
}
else if(key=='b' || key=='B') // Button B press?
{
Lcd_Out(2, 1, "Button B Press "); // Display message Button B press
Sound_Play(110,500);
}
else if(key=='c' || key=='C') // Button C press?
{
Lcd_Out(2, 1, "Button C Press "); // Display message Button C press
Sound_Play(120,500);
}
else if(key=='d' || key=='D') // Button D press?
{
Lcd_Out(2, 1, "Button D Press "); // Display message Button D press
Sound_Play(130,500);
}
}
}
i have a program of IR remote control for pic 16f887.
Anybody please help me to convert it so that i can use it in pic 18f4520.
// Lcd pinout settings
sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D4 at RD4_bit;
// Pin direction
sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D7_Direction at TRISD7_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D4_Direction at TRISd4_bit;
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; // **** 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
Lcd_Init(&PORTD); // Initialize LCD connected to PORTD
Lcd_Cmd(Lcd_CLEAR); // Clear display
Lcd_Cmd(Lcd_CURSOR_OFF); // Turn cursor off
Lcd_Out(1, 1, text); // Print text to LCD,2nd row,1st column
Sound_Init(&PORTC,0);
while(1) // Infinite loop
{
key = get_remote(); // Get Remote
if(key=='a' || key=='A') // Button A press?
{
Lcd_Out(2, 1, "Button A Press "); // Display message Button A press
Sound_Play(100,500);
}
else if(key=='b' || key=='B') // Button B press?
{
Lcd_Out(2, 1, "Button B Press "); // Display message Button B press
Sound_Play(110,500);
}
else if(key=='c' || key=='C') // Button C press?
{
Lcd_Out(2, 1, "Button C Press "); // Display message Button C press
Sound_Play(120,500);
}
else if(key=='d' || key=='D') // Button D press?
{
Lcd_Out(2, 1, "Button D Press "); // Display message Button D press
Sound_Play(130,500);
}
}
}