dasar teori
- Logical ‘0’ – a 562.5µs pulse burst followed by a 562.5µs space, with a total transmit time of 1.125ms
- Logical ‘1’ – a 562.5µs pulse burst followed by a 1.6875ms space, with a total transmit time of 2.25ms
protocol NEC terdiri dari
- 9ms leading pulse burst (16 times the pulse burst length used for a logical data bit)
- the 8-bit address for the receiving device
- the 8-bit logical inverse of the address
- the 8-bit logical inverse of the command
- a final 562.5µs pulse burst to signify the end of message transmission
remote yang dibeli dari orang bandung pa noor
berikur source code sederhana terhubung ke modul avr trainer 2.0, xtal 11.059200
#include <mega16.h>
#include <stdio.h>
#include <delay.h>
// Declare your global variables here
#define LCD_RS_HI PORTC|=(1<<7) //LCD
#define LCD_RS_LO PORTC&=~(1<<7)
#define LCD_EN_HI PORTC|=(1<<6)
#define LCD_EN_LO PORTC&=~(1<<6)
#define LCD_D4_HI PORTC|=(1<<5)
#define LCD_D4_LO PORTC&=~(1<<5)
#define LCD_D5_HI PORTC|=(1<<4)
#define LCD_D5_LO PORTC&=~(1<<4)
#define LCD_D6_HI PORTC|=(1<<3)
#define LCD_D6_LO PORTC&=~(1<<3)
#define LCD_D7_HI PORTC|=(1<<2)
#define LCD_D7_LO PORTC&=~(1<<2)
#define line1 0x00
#define line2 0x40
#define _ALTERNATE_PUTCHAR_
unsigned int data_ir,datatimer;
unsigned char cnt_ir;
unsigned char flag_ir_start;
unsigned char flag_ir_ok;
unsigned char counter_dummy;
unsigned char poutput;
#define LCD 0
#define SERIAL 1
//=================================================================
void enableint0()
{GICR|=(1<<INT0);}
void disableint0()
{GICR&=~(1<<INT0);}
//===============================================
//=====================================================
void LCD_STROBE()
{
LCD_EN_HI;
LCD_EN_LO;
}
void lcd_write(unsigned char datalcd)
{
if(datalcd & 0x80) {LCD_D7_HI;} else {LCD_D7_LO;}
if(datalcd & 0x40) {LCD_D6_HI;} else {LCD_D6_LO;}
if(datalcd & 0x20) {LCD_D5_HI;} else {LCD_D5_LO;}
if(datalcd & 0x10) {LCD_D4_HI;} else {LCD_D4_LO;}
LCD_STROBE();
if(datalcd & 0x08) {LCD_D7_HI;} else {LCD_D7_LO;}
if(datalcd & 0x04) {LCD_D6_HI;} else {LCD_D6_LO;}
if(datalcd & 0x02) {LCD_D5_HI;} else {LCD_D5_LO;}
if(datalcd & 0x01) {LCD_D4_HI;} else {LCD_D4_LO;}
LCD_STROBE();
delay_ms(5);
}
void lcd_clrscr()
{
LCD_RS_LO;
lcd_write(0x1);
delay_ms(2);
}
void lcd_putc(unsigned char c)
{
LCD_RS_HI;
lcd_write(c);
}
void lcd_goto(unsigned char poslcd)
{
LCD_RS_LO;
lcd_write(0x80 + poslcd);
}
void init_lcd()
{
LCD_RS_LO;
delay_ms(15);
LCD_D4_HI;
LCD_D5_HI;
LCD_STROBE();
delay_ms(5);
LCD_STROBE();
delay_us(100);
LCD_STROBE();
delay_ms(5);
LCD_D4_LO;
LCD_STROBE();
delay_us(40);
lcd_write(0x28);
lcd_write(0x0C);
lcd_write(0x06);
lcd_write(0x01);
delay_ms(10);
}
//===============================================
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
disableint0();
TCCR1B=0B00000000;
datatimer=TCNT1;
TCNT1 = 0;
TCCR1B=0B00000101;
if(cnt_ir==0)
{
if((datatimer>130)&&(datatimer<150))
{
flag_ir_start=1;
cnt_ir=1;
}
}
if((flag_ir_start==1)&&(cnt_ir>0))
{
counter_dummy++;
if(counter_dummy>16)
{
flag_ir_start=2;
cnt_ir=1;
}
}
if((flag_ir_start==2)&&(cnt_ir>0))
{
cnt_ir–;
if(datatimer>15)
{
data_ir|=(1<<cnt_ir);
}
else
{
data_ir&=~(1<<cnt_ir);
}
cnt_ir = cnt_ir + 2;
if (cnt_ir > 8)
{
data_ir=data_ir;
flag_ir_start=0;
flag_ir_ok=1;
cnt_ir = 0;
}
}
enableint0();
}
//================================================
void putchar(char c)
{
switch (poutput)
{
case SERIAL: // the output will be directed to USART0
while ((UCSRA & (1<<5))==0);
UDR=c;
break;
case LCD: // the output will be directed to USART1
lcd_putc(c);
break;
};
}
// Declare your global variables here
void main(void)
{
delay_ms(100);
// External Interrupt(s) initialization
DDRD&=~(1<<2); //inisialisai pin int0
PORTD|=(1<<2);
MCUCR=0b00000010; //interupt int0 rising
// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 115200
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x05;
DDRC=255;
init_lcd();
enableint0();
// Global enable interrupts
#asm(“sei”)
lcd_clrscr();
flag_ir_start=0;
cnt_ir=0;
counter_dummy=0;
while (1)
{
if(flag_ir_ok==1)
{
disableint0();
flag_ir_start=0;
flag_ir_ok=0;
cnt_ir = 0;
counter_dummy=0;
poutput=SERIAL;
printf(“%u \r\n”,data_ir);
poutput=LCD;
lcd_clrscr();
lcd_goto(line1);
printf(“%u”,data_ir);
enableint0();
}
}
}