Remot Infra Merah Sony (SIRC) dan LCD grafik 48×84

Bismillahirrohmaanirrohiim…

cource code nya :

#define F_CPU 8000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <util/delay.h>

#include “pcd8544.h”
#include “main.h”

#define ENABLE_INT0 GICR |= 0x40
#define DISABLE_INT0 GICR &= ~0x40

#define T_pulse 28    //14
#define T_header 60    //30

void compare();

void port_init(void);
void timer0_init(void);
unsigned int read_IR (void);
void init_devices(void);

volatile unsigned char number,CODE,DEVICE;
unsigned int IR_input;

void port_init(void)
{
DDRB = 0x0f;
PORTB = 0x00;
DDRD |= (1<<5);
DDRD |= (1<<6);
DDRD |= (1<<7);
}

void timer0_init(void)
{
TCCR0 = 0x04; //CLK / 64
TCNT0 = 0; //reset the timer
}

ISR(INT1_vect)
{
unsigned char count;
TCNT0 = 0;
while(!(PIND & 0x08));
count = TCNT0;
if(count < T_header)
// START pulse detected
{
return;
}
IR_input = read_IR ();
CODE=(unsigned char) ((IR_input & 0xff00) >> 8);
LcdHex(FONT_1X,6,1,CODE);
DEVICE=(unsigned char) (IR_input & 0x00ff);
LcdHex(FONT_1X,8,1,DEVICE);
compare();
LcdUpdate();
}

unsigned int read_IR (void)
{
unsigned char pulseCount=0, code = 0, address = 0, timerCount;
unsigned int IR_input;

while(pulseCount < 7)
{
while(PIND & 0x08);
TCNT0 = 0;
while(!(PIND & 0x08));
pulseCount++;

timerCount = TCNT0;

if(timerCount > T_pulse)
code = code | (1 << (pulseCount-1));
else
code = code & ~(1 << (pulseCount-1));
}
pulseCount = 0;
while(pulseCount < 5)
{
while(PIND & 0x08);
TCNT0 = 0;
while(!(PIND & 0x08));
pulseCount++;
timerCount = TCNT0;
if(timerCount > T_pulse)
address = address | (1 << (pulseCount-1));
else
address = address & ~(1 << (pulseCount-1));
}
IR_input = (((unsigned int)code) << 8) | address;
return(IR_input);
}

**********************************************************
void RemoteInit(void)
{
cli();
port_init();
timer0_init();

MCUCR = 0b00001010;
GICR|=(1<<INT0);
GICR|=(1<<INT1);
TIMSK |= (1<<TOIE1); //timer interrupt sources
sei();
}

void compare()
{
LcdGotoXYFont(1,4);LcdFStr(FONT_1X,(unsigned char*)PSTR(”              “));
LcdGotoXYFont(1,4);
if(CODE==0x00){LcdFStr(FONT_1X,(unsigned char*)PSTR(“Channel 1”));}
if(CODE==0x01){LcdFStr(FONT_1X,(unsigned char*)PSTR(“Channel 2”));}
if(CODE==0x02){LcdFStr(FONT_1X,(unsigned char*)PSTR(“Channel 3”));}
if(CODE==0x03){LcdFStr(FONT_1X,(unsigned char*)PSTR(“Channel 4”));}
if(CODE==0x04){LcdFStr(FONT_1X,(unsigned char*)PSTR(“Channel 5”));}
if(CODE==0x05){LcdFStr(FONT_1X,(unsigned char*)PSTR(“Channel 6”));}
if(CODE==0x06){LcdFStr(FONT_1X,(unsigned char*)PSTR(“Channel 7”));}
if(CODE==0x07){LcdFStr(FONT_1X,(unsigned char*)PSTR(“Channel 8”));}
if(CODE==0x08){LcdFStr(FONT_1X,(unsigned char*)PSTR(“Channel 9”));}
if(CODE==0x09){LcdFStr(FONT_1X,(unsigned char*)PSTR(“Channel 0”));}

if(CODE==0x10){LcdFStr(FONT_1X,(unsigned char*)PSTR(“Channel Up”));}
if(CODE==0x11){LcdFStr(FONT_1X,(unsigned char*)PSTR(“Channel Down”));}
if(CODE==0x12){LcdFStr(FONT_1X,(unsigned char*)PSTR(“Volume Up”));}
if(CODE==0x13){LcdFStr(FONT_1X,(unsigned char*)PSTR(“Volume Down”));}
if(CODE==0x14){LcdFStr(FONT_1X,(unsigned char*)PSTR(“Mute”));}
if(CODE==0x15){LcdFStr(FONT_1X,(unsigned char*)PSTR(“POWER”));}
if(CODE==0x17){LcdFStr(FONT_1X,(unsigned char*)PSTR(“NICAM”));}
if(CODE==0x1d){LcdFStr(FONT_1X,(unsigned char*)PSTR(“–/-“));}
if(CODE==0x25){LcdFStr(FONT_1X,(unsigned char*)PSTR(“TV/AV”));}
if(CODE==0x36){LcdFStr(FONT_1X,(unsigned char*)PSTR(“Sleep”));}
if(CODE==0x3a){LcdFStr(FONT_1X,(unsigned char*)PSTR(“Display”));}
if(CODE==0x3B){LcdFStr(FONT_1X,(unsigned char*)PSTR(“Return”));}
if(CODE==0x5a){LcdFStr(FONT_1X,(unsigned char*)PSTR(“System”));}
LcdUpdate();
}

int main()
{
LcdInit();
RemoteInit();
LcdClear();
LcdGotoXYFont(1,1);LcdFStr(FONT_1X,(unsigned char*)PSTR(“CODE:”));
LcdGotoXYFont(1,2);LcdFStr(FONT_1X,(unsigned char*)PSTR(“Infra Red”));
LcdGotoXYFont(1,3);LcdFStr(FONT_1X,(unsigned char*)PSTR(“Remote Control”));
LcdUpdate();
while(1)
{
}
}

download file lengkap nya di http://www.indowebster.com/remot_lcd.html

bersambung…

~ by den-wam on August 27, 2010.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: