unsigned char code changled[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x27,0x7f,0x6f}; unsigned char led[6];
unsigned char present_time[3]; unsigned char flash=0;
unsigned char timemeasure=0; unsigned char flash_cs=0; unsigned char tiaozheng=0; bit enablebit=0;
unsigned int enabletime=0; sbit P1_0=P1^0; sbit P1_1=P1^1; sbit P1_2=P1^2; sbit P1_3=P1^3;
void change_data()
//调整时间
{
unsigned char x,change; x=present_time[0]; change=x/100;
x=present_time[0];
led[0]=x/10-change*10; x=present_time[0];
led[1]=(unsigned char)(x-change*100-led[0]*10);
x=present_time[1]; change=x/100; x=present_time[1];
led[2]=x/10-change*10; x=present_time[1];
led[3]=(unsigned char)(x-change*100-led[2]*10); x=present_time[2]; change=x/100; x=present_time[2]; led[4]=x/10-change*10; x=present_time[2];
led[5]=(unsigned char)(x-change*100-led[4]*10); }
void init()
{
present_time[0]=12; present_time[1]=00;
//默认时间
present_time[2]=00; xiao[0]=23; xiao[1]=00; xiao[2]=00; }
T0_in() interrupt 1 using 3 {
unsigned char bb; flash++;
enabletime++; if(flash==15) {
flash=0;
if(flash_cs==0) P2=254;
if(flash_cs==1) P2=253; if(flash_cs==2) P2=251;
if(flash_cs==3) P2=247;
if(flash_cs==4) P2=239;
//亮一半时间
if(flash_cs==5) P2=223; bb=led[flash_cs]; P0=changled[bb]; if(flash_cs!=5) flash_cs++; else flash_cs=0; }
if(enabletime==555) {
enabletime=0; enablebit=1; } }
T1_in() interrupt 3 using 3
{
TH1=(65535-40000)/256; TL1=(65536-40000)%256; TR1=1;
timemeasure++;
if(timemeasure==25) {
timemeasure=0; if(present_time[2]<59) {
present_time[2]++; } else
{
present_time[2]=0; if(present_time[1]<59) present_time[1]++; else {
present_time[1]=0; if(present_time[0]<23) present_time[0]++; else
present_time[0]=0; }
}
if(tiaozheng<=3) {
change_data(); } } }
main() {
unsigned char dengstate=0; P3=0;
ET0=1;
ET1=1; TMOD=0x12; TH0=0; TL0=0; TR0=1;
TH1=(65535-40000)/256; TL1=(65536-40000)%256; TR1=1; EA=1; while(1) {
if(P1_0==0) if(enablebit==1) {
enablebit=0; enabletime=0; tiaozheng++; if(tiaozheng>0) if(tiaozheng<=3) change_data();
if(tiaozheng==10) {
tiaozheng=0; P3=0; }
if(P1_2==0) if(enablebit==1) {
enablebit=0; enabletime=0; if(tiaozheng==1) {
if(present_time[0]<23) present_time[0]++; else
present_time[0]=0; change_data(); }
if(tiaozheng==2) {
if(present_time[1]<59) present_time[1]++; else
present_time[1]=0; change_data(); }
if(tiaozheng==3) {
if(present_time[2]<59) present_time[2]++; else
present_time[2]=0; change_data(); }
if(P1_1==0) if(enablebit==1) {
enablebit=0; enabletime=0; if(tiaozheng==1) {
if(present_time[0]>=1) present_time[0]--; else
present_time[0]=23; change_data(); }
if(tiaozheng==2) {
if(present_time[1]>=1) present_time[1]--; else
present_time[1]=59; change_data(); }
if(tiaozheng==3) {
if(present_time[2]>=1) present_time[2]--; else
present_time[2]=59; change_data(); } } }}}
}
因篇幅问题不能全部显示,请点此查看更多更全内容