单片机

我闲着没事又编了个交通灯的程序。

#include<reg52.h>
#include<intrins.h>
#define uint  unsigned int
#define uchar unsigned char
sbit we = P2^7;
sbit du = P2^6;
sbit S3 = P3^1;
uint counter;
void delay(uint z)
{
  uint x,y;
  for(x = z;x > 0; x--)
    for(y = 120;y > 0; y--);
}
uchar code leddata[]={
                       0x3F,  //"0"
                       0x06,  //"1"
                       0x5B,  //"2"
                       0x4F,  //"3"
                       0x66,  //"4"
                       0x6D,  //"5"
                       0x7D,  //"6"
                       0x07,  //"7"
                       0x7F,  //"8"
                       0x6F,  //"9"
                       0x77,  //"A"
                       0x7C,  //"B"
                       0x39,  //"C"
                       0x5E,  //"D"
                       0x79,  //"E"
                       0x71,  //"F"
                       0x76,  //"H"
                       0x38,  //"L"
                       0x37,  //"n"
                       0x3E,  //"u"
                       0x73,  //"P"
                       0x5C,  //"o"
                       0x40,  //"-"
                       0x00,  //熄灭
                       0x00  //自定义
                          };
void main()
{
uint a = 0;
     TMOD = 0x10;
TH1  = 0x4b;
     TL1  = 0xfe;
while(1)
 {
   if(S3 != 0)
{
 delay(5);
 if(S3 != 0)
 {
  TR1 = 1;
 }
}
if(TF1 == 1)
   {
    TF1 = 0;
    TH1 = 0x4b;
         TL1 = 0xfe;
    counter++;
    }


du = 1;
   P0 = leddata[a];
   du = 0;


   we = 1;
   P0 = 0xf0;
   we = 0;
delay(1);
        if(counter == 20)
   {
 a++;
 counter = 0;
}
   if(a == 16)
  a = 0;
   if(S3 == 0)
{
  delay(5);
  if(S3 == 0)
  TR1 = 0;
}

}  

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值