|
毕业不久的我,分享一个按键实现单击、双击、长按
单片机源程序如下:
- #include <define.h>
- bit b_1ms_t;
- void PWM_led(void);
- void deplay(void);
- void key_on(void);
- void PWM_Int(void);
- void ad_int(void);
- void ad_on(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 = 0xce;
-
- 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 ad_int(void)
- {
- P1CON = 0x08;
- VREFH = 0x03;
- ADR = 0x50;
- ADM |= 0x03;
- }
- void main(void)
- {
- Init_System();
- Time_int();
- PWM_Int();
- ad_int();
- while(1)
- {
- if(b_1ms_t)
- {
- b_1ms_t = 0;
- WDTR = 0x5A;
- deplay();
- key_on();
- PWM_led();
- ad_on();
- }
- }
- }
- void Time0_Init() interrupt ISRTimer0
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
|
展开
- 商品类型:
-
全新商品
- 剩余时间:
-
1.00 元
附加 3 黑币
1.00 元
附加 5 黑币
评分
-
查看全部评分
|