文号
t52558
阅读
7092
回复
1
收藏
1
定时程序
2012/11/27
IP:广东
    刚学单片机做了定时.用按键定时方式. 也就是定时的时间和按键时间有关.
我设定的是按键1秒定时1分钟. 也可以改为别的比例,改下I值就行.
#include <reg52.h>
unsigned int i;
unsigned int a;
unsigned int b;
sbit key=P3^2;
void main ()
{
    key=1;
    a=0;
    i=0;
    b=0;
    while(1){

    
    if(!key&&(a<65534)){
        i=500;
        while(i--);
        P0=0xcf;
    
        i=500;
        while(i--);
        P0=0xff;
        a++;
        }
    
    else if(!key&&(a>65533))
        a--;
    else if((key==1)&&(a>0)){
        P0=0;
        i=30000;
        while(i--);
        i=30000;
        while(i--);
        a--;
        if(!key)
        a=0;
        }
    else
    P0=0xfe;
          }
}
笔记
{{note.content}}
{{n.user.username}}
{{fromNow(n.toc)}} {{n.status === noteStatus.disabled ? "已屏蔽" : ""}} {{n.status === noteStatus.unknown ? "正在审核" : ""}} {{n.status === noteStatus.deleted ? '已删除' : ''}}
  • 编辑
  • 删除
  • {{n.status === 'disabled' ? "解除屏蔽" : "屏蔽" }}
我也是有底线的