快捷搜索:

数码管显示时间整点报时C语言实例

数码管显示时间整点报时C语言实例

电路很简单就不画图了,数码管的段是p0口,2个数码管位选分别是p2.5,p2.6#includesbit cs1=P2^5;sbit cs2=P2^6;sbit e=P2^7;sbit beep=P0^4;#define uchar unsigned charuchar display_code[11]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x7f};uchar display_data[8]={0,0,0x0a,0,0,0x0a,0,0};uchar time[3]={0,0,0};void delay(){uchar i;for(i=250;i>0;i--);}void js(){time[2]++;if(time[2]>59){time[2]=0;time[1]++;if(time[1]>59){time[1]=0;time[0]++;if(time[0]>23)time[0]=0;}}}void zh(){display_data[6]=time[2]/10;display_data[7]=time[2]%10;display_data[3]=time[1]/10;display_data[4]=time[1]%10;display_data[0]=time[0]/10;display_data[1]=time[0]%10;}void display(){uchar i,k;k=0x80;for(i=8;i>0;i--){P0=0xff;P0=display_code[display_data[i]];e=0;cs1=0;e=1;cs1=1;P0=~k;k=k>>1;e=0;cs2=0;e=1;cs2=1;delay();}}void shenying(){beep=0;if(time[0]>0){beep=1;if(time[1]

您可能还会对下面的文章感兴趣: