|
15单片机led闪烁设计- /*#include "STC15F2K60S2.h"
- #include "intrins.h"
-
- void Delay200ms() //@11.0592MHz
- {
- unsigned char i, j, k;
- _nop_();
- _nop_();
- i = 9;
- j = 104;
- k = 139;
- do
- {
- do
- {
- while (--k);
- } while (--j);
- } while (--i);
- }
- void main()
- {
- {
- P2 = ((P2&0x1f|0xa0));
- P0 = 0x10;
- P2 &=0x1f;
- }
- while(1)
- {
- P2 = ((P2&0x1f)|0x80);
- P0 =0x00;
- P2 &= 0x1f;
- Delay200ms();
-
- P2 = ((P2&0x1f|0x80));
- P0 =0xff;
- P2 &= 0x1f;
-
- Delay200ms();
- }
- }
- */
- #include "STC15F2K60S2.h"
- #include "intrins.h"
- #define uchar unsigned char
- void Timer0Init(void);
- uchar cj;
- bit f=0;
- void main()
- {
- Timer0Init();
- P2 = ((P2&0x1f|0xa0));
- P0 = 0x10;
- P2 &=0x1f;
-
- while(1)
- {
- }
- }
- void Timer0Init(void) //5毫秒@11.0592MHz
- {
- AUXR |= 0x80; //定时器时钟1T模式
- TMOD &= 0xF0; //设置定时器模式
- TL0 = 0x00; //设置定时初值
- TH0 = 0x28; //设置定时初值
- TF0 = 0; //清除TF0标志
- TR0 = 1; //定时器0开始计时
- EA = 1;
- ET0 = 1;
- }
- void time0() interrupt 1
- {
- cj++;
- if(cj==200)
- {
- cj=0;
- if(f==0)
- {f=1;P2 = ((P2&0x1f)|0x80);P0 =0x00;P2 &= 0x1f;}
- else
- if(f==1)
- {f=0;P2 = ((P2&0x1f)|0x80);P0 =0xff;P2 &= 0x1f;}
-
- }
- }
复制代码
|
|