1024手机基地看电影,午夜福利视频导航,国产精品福利在线一区,亚洲欧美日韩另类成人,在线观看午夜日本理论片,成年超爽免费网站,国产精品成人免费,精品动作一级毛片,成人免费观看网站,97精品伊人久久大香蕉

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1954|回復: 0
打印 上一主題 下一主題
收起左側

數(shù)碼管顯示交通燈

[復制鏈接]
跳轉到指定樓層
樓主
ID:315589 發(fā)表于 2018-5-31 08:56 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
#include<reg52.h>  

sbit LACTCH1=P2^2;   
sbit LACTCH2=P2^3;

bit red,green,yellow,turnred;//定義紅綠黃燈標志位



code unsigned char tab[]=
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
                            //共陰數(shù)碼管 0-9

unsigned char Dis_Shiwei;//定義十位
unsigned char Dis_Gewei; //定義個位
/*------------------------------------------------
              
------------------------------------------------*/
void delay(unsigned int cnt)
{
while(--cnt);
}
/*------------------------------------------------
              主程序
------------------------------------------------*/
main()
{
TMOD |=0x01;//定時器設置 10ms in 12M crystal
TH0=0xd8;
TL0=0xf0;
IE= 0x82;   //打開中斷
TR0=1;

P1=0xfc;    //紅燈亮
red =1;
while(1)
  {
  P0=Dis_Shiwei;//顯示十位
  LACTCH1=1;    //鎖存
  LACTCH1=0;
  P0=0xfe;
  LACTCH2=1;    // 鎖存
  LACTCH2=0;
  delay(300);   //短暫延時
  P0=Dis_Gewei; //顯示個位
  LACTCH1=1;    //鎖存
  LACTCH1=0;
  P0=0xfd;
  LACTCH2=1;    // 鎖存
  LACTCH2=0;
  delay(300);
  }

}



void tim(void) interrupt 1
{
static unsigned char second=60,count; //初值99

TH0=0xd8;//重新賦值
TL0=0xf0;
count++;
if (count==100)
    {
    count=0;
    second--;//秒減1
    if(second==0)
       {
       if(red)
         {
          red=0;yellow=1;
          second=5;
          P1=0xF3;//黃燈亮5秒
         }
       else if(yellow && !turnred)
         {
          yellow=0;green=1;
          second=50;
          P1=0xCF;//綠燈亮50秒
         }
       else if(green)
         {
         yellow=1;green=0;
         second=5;
         P1=0xF3;//黃燈亮5秒
         turnred=1;
         }
       else if(yellow && turnred)
         {
         red=1;yellow=0;
         P1=0xFC;//紅燈亮60秒
         second=60;
         turnred=0;
         }

       }
    Dis_Shiwei=tab[second/10];//十位顯示值處理
    Dis_Gewei=tab[second%10]; //個位顯示處理
   
    }
}


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表