PORTC=SEG_CODE[IR_D12 >> 0&0XOOOF];
#define K1_DOWN() (PING&_BV(PD7))==0x00#define K2_DOWN() (PING&_BV(PD5))==0x00
#define K3_DOWN() (PING&_BV(PD3))==0x00
#define K4_DOWN() (PING&_BV(PD1))==0x00
#define K5_DOWN() (PING&_BV(PD0))==0x00
#define K6_DOWN() (PING&_BV(PD4))==0x00
#define K7_DOWN() (PING&_BV(PD2))==0x00
#define K8_DOWN() (PING&_BV(PD0))==0x00
#define IRLED_BLINK() PORTB^= _BV(PB0)
#define IRLED_1() PORTB|= _BV(PB0)
#define IRLED_0() PORTB&=~ _BV(PB0)
void Emit_IR_Carrier_Nx600us(INT8U N)
{
INT8U i;
{ for (i=0;i<N*50;i++)
{ _delay_us(12);IRLED_BLINK(); }
}
void Emit_D12(INT16U D12)
{
INT16U i;
Emit_IR_Carrier_Nx600us(4);
IRLED_0(); _delay_us(600);
for (i=0x0001;i<0x1000;i<<=1)
{
if(D12&i)
Emit_IR_Carrier_Nx600us(2);
else
Emit_IR_Carrier_Nx600us(1);
//
IRLED_0();_delay_us(600);
}
}
#define F_CPU 2000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#define INT8U unsigned char
#define INT16U unsigned int
#define BEEP() PORTD^=_BV(PD7)
#define Read_IR()(PIND&_BV(PD2))
const INT8U SEG_CODE_[]=
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f
,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
INT16U IR_D12=0x0000,Old_IR_D12=0x0000;
INT8U Digit_Buffer[]={0,0,0};
void Sounder()
{
INT8U i;
for(i=0;i<200;i++)
{
BEEP();_delay_us(280);
}
}
int main()
{
DDRD=~_BV(PD2); PORTC()=0XFF;
DDRA=0XFF; PORTA()=0X40;
DDRB=0XFF; PORTB()=0X40;
DDRC=0XFF; PORTC()=0X40;
MCUCR=0X02;
GICR|=_BV(INT0);
SREG =0X80;
while(1);
}
ISR(INT0_vect)
{
INT8U i;
INT16U IR_us=0 ;
GICR & =~_BV(INT0);
_delay_ms(2);
if(Read_IR()!=0X00) goto end;
while(Read_IR()==0X00)
{
_delay_us(1);
if(++IR_us>2400) goto end;
}
for(i=0;i<12;i++)
{
while(Read_IR()!=0X00)
{
_delay_us(1);
if(++IR_us>600) goto end;
}
IR_us=0;
while(Read_IR()==0X00)
{
_delay_us(1);
if(++IR_us>300) goto end;
}
IR_D12>>=1;
if(IR_us>150) IR_D12|=0x0800;
}
if(Old_IR_D12!=IR_D12)
{ Old_IR_D12=IR_D12;
PORTC=SEG_CODE[IR_D12 >> 0&0XOOOF];
PORTA=SEG_CODE[IR_D12 >> 4&0XOOOF];
PORTB=SEG_CODE[IR_D12 >> 8&0XOOOF];
Sounder();
}
end:GICR|=_BV(INT0);
}