微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 我的电子钟c程序完整代码

我的电子钟c程序完整代码

时间:11-29 来源:互联网 点击:
真的很感谢问问的朋友帮我解决了定时器的问题。

今天是拿到单片机的第五天了,经过五天的挑灯学习,单片机的基础也算了解的三三两两了。

解决了定时器问题,早上逃课,趁热打铁,把电子钟的程序写完。有一年没有写复杂的程序了,今天的过程也是磕磕碰碰,问题颇多。废话不说了,想玩wow了。有图有真相。

#include#define  unchar unsigned char//sbit beep=P1^5;unchar temp=0;unsigned char code shuzi[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};unsigned char  count[]={0,0,10,5,5,10,3,2};void delay(void){int i=100;while(--i);}unchar time(unchar j){if (temp==20){ temp=0 ;++count[0];if (count[0]==10){ count[0]=0;++count[1];}if(count[1]==6){count[1]=0;++count[3];}  if (count[3]==10){count[3]=0;++count[4];}if (count[4]==6){count[4]=0;++count[6];}if (count[6]==10){count[6]=0;++count[7];}if (count[7]==3)count[7]=0;if (count[7]==2&&count[6]==4)count[7]=count[6]=0;}return count[j];}void main(){unchar num,i,j;EA=1;ET0=1;TMOD=0x01;TL0=15535%256;TH0=15535/256;TR0=1;while(1){P2=0xff;i=1;for (j=0;j<8;++j){num=time(j);P2=P2-i;P0=shuzi[num];i=i*2;delay();}}}void  duan() interrupt 1{TL0=15535%256;TH0=15535/256;++temp;}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top