立即注册 登录
返回首页

uid:261274的个人空间

日志

交通灯程序

已有 391 次阅读2017-12-17 15:13

#include<reg52.h>

#define uchar unsigned char   //¶¨òåÎaucharààDí
#define uint unsigned int   //¶¨òåÎauintààDí


uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //êyÂë1üÏÔê¾0~9 
uchar t=3;
uchar time_Count;  //½øDD¼Æê±
uchar ge,shi;  //òaÏÔê¾μĸöλoíê®Î»

void delay(uchar z)  //ò»¸öÑóê±oˉêy
{
uchar a,b;
for(a=0;a<150;a++)
{
for(b=0;b<z;b++);
}
}


void Init_Timer() //¶¨ê±Æ÷μÄ3õê¼»ˉ
{
TMOD=0x01;
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
ET0=1;
TR0=1;
EA=1;
}

void Seg_Disp() //½«¸öλê®Î»·Ö±eÏÔê¾ÔúêyÂë1üéÏÃæ
{
P2=0xfe;
P0=table[ge];
delay(1);
P2=0xfd;
P0=table[shi];
delay(1);
}

void main() //3ìDòÔËDDμÄÖ÷oˉêy
{   
    SP=0x6f;
P0=0xff;
P2=0xff;
P1=0x00;
Init_Timer();
while(1)
{
 
          Seg_Disp();
          
         if(time_Count==200)
     {
    time_Count=0;
     ge++;
             if(t==3)
              { 
P1=0x01;
       if(ge==10)
         {
       ge=0;
       shi++;
       if(shi==1)
          {
       shi=0;
       t=2;
    
      }
 

      }
  }
if(t==2)
{
 P1=0x02;
             if(ge==6)
     {
   ge=0;
t=1;
   
 

  }
}
          if(t==1)
           { 
    P1=0x04;
    if(ge==10)
     {
   ge=0;
   shi++;
   if(shi==1)
    {
   shi=0;
   t=0;
    
 }
 

  }
}
           if(t==0)
{
 P1=0x02;
             if(ge==6)
     {
   ge=0;
t=3;
   
 

  }
}  
}   
}
}

void timer0() interrupt 1 using 1  //¶¨ê±Æ÷0μÄ2ù×÷¼Æê±
{
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
      time_Count++;

}   



路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

返回顶部