新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > STC單片機做的電子表C51程序

STC單片機做的電子表C51程序

作者: 時間:2012-08-29 來源:網(wǎng)絡(luò) 收藏

電路很簡單我就不畫了,是stc系列的單片機做的,顯示部分就是2個74hc573芯片連到P1口,然后用p3.0控制段選,按鍵的定義程序里有說明。很容易就能搭出來,下圖是效果圖,自己用萬用板焊的,技術(shù)不行。到處都是飛線呵呵,請大家多多指教
點擊瀏覽下一頁
程序的c51語言完整版本的下載地址:http://www.51hei.com/f/biaoc4.rar

#includestc90.h>#define uchar unsigned char#define uint unsigned intuchar d0,ss,gs,sf,gf,sm,gm;uchar e1,e2,e3,e4,e5,e6;uchar s1,q1;uchar shi,fen,miao;// 8 4 2 1 8 4 2 1  // h g f e d c b a//效正 累加數(shù)98 跑1320秒 實際1316//當(dāng)前已走秒數(shù) 乘以 當(dāng)前累加數(shù) 除以除以實際秒數(shù) 等于 累加數(shù)應(yīng)得值uchar code num[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x80};//0-9 點uchar code wes[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0x7f};//1-8位sbit dua=P3^0;sbit laba=P3^1;sbit a1=P3^2;//時間設(shè)置sbit a2=P3^3;//鬧鐘設(shè)置sbit a3=P3^4;//按鍵+sbit a4=P3^5;//按鍵-sbit a5=P3^7;//返回 啟動鬧鐘void weiduan(uchar z,uchar x); //位段 函數(shù)void chushi();    //初始化函數(shù)void shijian();   //時間顯示函數(shù)void shjianbata();//測試時間函數(shù)void shezhi();    //時間設(shè)置函數(shù)void naozhong();  //鬧鐘這是函數(shù)void shu();       //時間最大值限制函數(shù)void delay(uchar d1);//延時函數(shù)//...................................................................void main(){ chushi(); //初始化時間TH0=(65535-40000)/256;//定時器裝初值TL0=(65535-40000)%256;ET0=1;//開定時器0中斷TR0=1;//啟動定時器0EA=1; //打開總中斷l(xiāng)aba=1;while(1){  shijian(); //調(diào)用時間顯示函數(shù) 顯示時間 if(a1==1){if(a2==1){if(a3==1){if(a4==1)
{ weiduan(1,10);delay(5);weiduan(3,10);delay(5);weiduan(5,10);delay(5); }}}}if(a1==0){delay(100);if(a1==0){shezhi();}}if(a2==0){delay(100);if(a2==0){naozhong();}}//調(diào)用鬧鐘設(shè)置函數(shù)if(a5==0){delay(100);{if(a5==0){while(1)
{if(q1==0){q1=1;break;}else{q1=0;break;}}while(a5==0);delay(100);}}}if(a2==0){delay(100);if(a2==0){naozhong();}    }if(q1==1){weiduan(6,0);delay(20);if(fen==e2)
{if(shi==e1){laba=0;}}if(fen!=e2){laba=1;}  }else{laba=1;}}}//...................................................................void naozhong(){while(1){   ss=e1/10;gs=e1%10;  sf=e2/10;gf=e2%10;   sm=e3/10;gm=e3%10;delay(10);weiduan(0,ss);delay(10);weiduan(1,gs);delay(10);weiduan(2,sf);delay(10);     weiduan(3,gf);delay(10);weiduan(4,sm);delay(10);weiduan(5,gm);delay(10);if(a1==0){delay(100);if(a1==0){while(a1==0);delay(20);break;}}if(a2==0){delay(100);while(a2==0);delay(20);s1++;}if(s1==3){s1=0;}if(s1==1){weiduan(0,10);delay(5);weiduan(1,10);delay(5);if(a3==0){delay(20);if(a3==0){e1++;}while(a3==0);delay(100);}if(a4==0){delay(20);if(a4==0){e1--;}while(a4==0);delay(100);}}if(s1==2){weiduan(2,10);delay(5);weiduan(3,10);delay(5);if(a3==0){delay(20);if(a3==0){e2++;}while(a3==0);delay(100);}if(a4==0){delay(20);if(a4==0){e2--;}while(a4==0);delay(100);}}if(s1==0){weiduan(4,10);delay(5);weiduan(5,10);delay(5);if(a3==0){delay(20);if(a3==0){e3++;}while(a3==0);delay(100);}if(a4==0){delay(20);if(a4==0){e3--;}while(a4==0);delay(100);}}}}//.........................................................void shezhi()//時間設(shè)置函數(shù){while(1){   ss=shi/10;gs=shi%10;  sf=fen/10;gf=fen%10;   sm=miao/10;gm=miao%10;shijian();if(a2==0){delay(100);if(a2==0){while(a2==0);delay(20);break;}}if(a1==0){delay(100);while(a1==0);delay(20);s1++;}if(s1==3){s1=0;}if(s1==1){weiduan(0,10);delay(5);weiduan(1,10);delay(5);if(a3==0){delay(20);if(a3==0){shi++;}while(a3==0);delay(100);}if(a4==0){delay(20);if(a4==0){shi--;}while(a4==0);delay(100);}}if(s1==2){weiduan(2,10);delay(5);weiduan(3,10);delay(5);if(a3==0){delay(20);if(a3==0){fen++;}while(a3==0);delay(100);}if(a4==0){delay(20);if(a4==0){fen--;}while(a4==0);delay(100);}}if(s1==0){weiduan(4,10);delay(5);weiduan(5,10);delay(5);if(a3==0){delay(20);if(a3==0){miao++;}while(a3==0);delay(100);}if(a4==0){delay(20);if(a4==0){miao--;}while(a4==0);delay(100);}}}}//...................................................................void zhongduan() interrupt 1   //定時器中斷函數(shù)體{  TH0=(65535-40400)/256;TL0=(65535-40400)%256;if(e3>=60)//判斷秒等于或超過60{e2++;   //分鐘加1e3=0;}   //秒數(shù)清零if(e2>=60) //判斷分鐘等于或超過60{e1++;   //小時加1e2=0;}   //分鐘數(shù)清零if(e1>=24) //判斷小時等于或大于24{e1=0;}   //小時數(shù) 清零d0++;//累加數(shù)shu(); //調(diào)用時間最大值限制函數(shù)} //...............................................................void delay(uchar d1)//延時函數(shù){uchar t0,t1;for(t0=d1;t0>0;t0--)for(t1=110;t1>0;t1--);}//.................................................................void weiduan(uchar z,uchar x) //位段選擇函數(shù){  P1=num[x];dua=1;dua=0;P1=wes[z];}//.....................................................................................void shijian()//動態(tài)掃描時間顯示函數(shù) 帶延時{chushi();//調(diào)用時間初始化函數(shù)  delay(10);weiduan(0,ss);delay(10);weiduan(1,gs);delay(10);weiduan(2,sf);delay(10);     weiduan(3,gf);delay(10);weiduan(4,sm);delay(10);weiduan(5,gm);delay(10);}//............................................................void shu()   //時間最大限制函數(shù)體{  if(d0>=98)  //判斷定時器進入 多少次{d0=0;    //清除累加數(shù)miao++;}   //秒數(shù)自+if(miao>=60)//判斷秒等于或超過60{fen++;   //分鐘加1miao=0;}   //秒數(shù)清零if(fen>=60) //判斷分鐘等于或超過60{shi++;   //小時加1fen=0;}   //分鐘數(shù)清零if(shi>=24) //判斷小時等于或大于24{shi=0;}   //小時數(shù) 清零}//...................................................................void chushi() //時間初始化{   ss=shi/10;gs=shi%10;  sf=fen/10;gf=fen%10;   sm=miao/10;gm=miao%10;}//.............................................................


關(guān)鍵詞: STC單片 電子表 C51程序

評論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉