单片机SOS闪灯源程序如下:
- #include"STC15.H"
- sbit LED=P3^2;
- unsigned char sos[34]={0,1,0,1,0,1,0,0,0,1,1,1,0,1,1,1,0,1,1,1,0,0,0,1,0,1,0,1,0,0,0,0,0,0};
- void Timer0Init(void) //30毫秒@11.0592MHz
- {
- AUXR &= 0x7F; //定时器时钟12T模式
- TMOD &= 0xF0; //设置定时器模式
- TL0 = 0x00; //设置定时初值
- TH0 = 0x94; //设置定时初值
- TF0 = 0; //清除TF0标志
- TR0 = 1; //定时器0开始计时
- }
- void led_sos(void)
- {
- unsigned char a;
- unsigned char b;
- if(TF0==1)
- {
- TF0=0;
- a++;
- if(a==10)
- {
- a=0;
- b++;
- if(b>33)
- {
- b=0;
- }
- LED=sos[b];
- }
- }
- }
- void main(void)
- {
- P3M1=0X00;
- P3M0=0X04;
- LED=0;
- Timer0Init();
- WDT_CONTR=0x37; //设置看门狗分频,并启动
- while(1)
- {
- led_sos();
- WDT_CONTR |=0x10; //清零看门狗
- }
- }
复制代码
所有资料51hei提供下载:
main.rar
(532 Bytes, 下载次数: 21)
|