鄙人不才,分享一个红外接收模块,普通IO口就可以实现,不需要外部中断,浪费CPU资源
单片机源程序如下:
- #include <define.h>
- bit b_1ms_t;
- bit b_250us_t;
- void PWM_led(void);
- void deplay(void);
- void PWM_Int(void);
- void IR_on(void);
- void ad_on(void);
- void key(void);
- void Init_System(void)
- {
- WDTR = 0x5A;
- CLKSEL = 0x06;
- CLKCMD = 0x69;
- CKCON = 0x10;
-
- P0M = 0xd0;
- P0UR = 0x00;
-
- P1M = 0xe0;
- P1UR = 0x05;
-
- P2M = 0x03;
- P2UR = 0x00;
-
- led = 0;
- }
- void Time_int(void)
- {
- TMOD = 0x55;
- TCON0 = 0x22;
-
- TH0 = 0xff;
- TL0 = 0x9c;
-
- TH1 = 0xfc;
- TL1 = 0x18;
-
- EAL = 1;
- ET0 = 1;
- TR0 = 1;
- ET1 = 1;
- TR1 = 1;
- }
- void PWM_Int(void)
- {
- PW1M |= 0x20;
- //PW1CH = 0x20;
-
- PW1YH = 0x1f; //T
- PW1YL = 0x40;
-
- PW1DH = 0x00; //duty
- PW1DL = 0x00;
-
- PW1BH = PW1DH;
- PW1BL = PW1DL;
- }
- void main(void)
- {
- Init_System();
- Time_int();
- PWM_Int();
- P04 = 1;
- while(1)
- {
- if(b_1ms_t)
- {
- b_1ms_t = 0;
- WDTR = 0x5A;
- deplay();
- PWM_led();
- ad_on();
- key();
- }
- }
- }
- void Time0_Init() interrupt ISRTimer0
- {
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
IR.zip
(75.52 KB, 下载次数: 193)
|