|
avr單片機(jī)源程序如下:
- //ICC-AVR application builder : 2018/1/11 10:02:04
- // Target : M16
- // Crystal: 8.0000Mhz
- #include <iom16v.h>
- #include <macros.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define pind2 PIND&0x04
- uchar shujuma[2]={0,0},IrValue[4]={0,0,0,0};
- uchar Time;
- void delay_us(unsigned char nus)
- {
- unsigned char i;
- while(nus--)
- {for(i=12;i>0;i--);}
- }
- void xs(void)
- {
- uchar k[17]={0x03,0x9f,0x25,0x0d,0x99,0x49,0x41,0x1f,0x01,0x09,0x11,0xc1,0x63,0x85,0x61,0x71,0x91};
- uchar j[8]={0x7f,0xbf,0xdf,0xef,0xfe,0xfd,0xfb,0xf7};
- PORTB=0xff;
- PORTA=k[16];
- PORTB=j[2];
- delay_us(1);
- PORTB=0x00;
- PORTA=k[shujuma[1]];
- PORTB=j[1];
- delay_us(1);
- PORTB=0x00;
- PORTA=k[shujuma[0]];
- PORTB=j[0];
- }
- void main(void)
- {
- DDRA=0xff;
- DDRB=0xff;
- DDRD&=0xfb;
- GICR|=0x40;//開啟INT0中斷
- MCUCR|=0x02;
- MCUCR&=0xfe;//設(shè)為下降沿觸發(fā)
- SEI();//開啟總中斷
- while(1)
- {
- shujuma[0]=IrValue[2]/16;
- shujuma[1]=IrValue[2]%16;
- xs();
- if(IrValue[2]==0x0c)
- {DDRC=0xff;PORTC=0xff;}
- else if(IrValue[2]==0x16)
- {DDRC=0xff;PORTC=0x00;}
- }
- }
- #pragma interrupt_handler INT0_zd:2
- void INT0_zd(void)
- {
- uchar j,k;
- int err;
- Time=0;
- if((pind2)==0)
- {
- err=1000;
- while(((pind2)==0)&&(err>0))
- {
- delay_us(1);
- err--;
- }
- if((pind2))
- {
- err=500;
- while(((pind2))&&(err>0))
- {
- delay_us(1);
- err--;
- }
- for(k=0;k<4;k++)
- {
- for(j=0;j<8;j++)
- {
- err=60;
- while(((pind2)==0)&&(err>0))
- {
- delay_us(1);
- err--;
- }
- err=500;
- while((pind2)&&(err>0))
- {
- delay_us(10);//0.1ms
- Time++;
- err--;
- if(Time>30)
- return;
- }
- IrValue[k]>>=1;
- if(Time>=8)
- IrValue[k]|=0x80;
- Time=0;
- }
- }
- }
- if(IrValue[2]!=~IrValue[3])
- return;
- }
- }
復(fù)制代碼
所有資料51hei提供下載:
紅外線.rar
(16.42 KB, 下載次數(shù): 30)
2018-9-3 22:39 上傳
點(diǎn)擊文件名下載附件
icc
|
評分
-
查看全部評分
|