买51hei开发板的同学们可以烧到你的单片机里面试试什么效果。 注意:烧之前先校核时间。默认是1点05分开始的。 #include<reg52.h> #define uchar unsigned char #define uint unsigned int sbit dula=P2^6; sbit wela=P2^7; uchar sec,min,hour,secl,sech,minl,minh,hourl,hourh,a; uchar code tab[]= {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; void display(uchar a,uchar b,uchar c,uchar d,uchar e,uchar f); void initial(); void delay(uchar z); void spark(); void main() { initial(); while(1) { if(a==20) { a=0; spark(); ////////////////// sec++; if(sec==60) { sec=0; min++; if(min==60) { min=0; hour++; if(hour==24) { hour=0; } } } ///////////////////////// sech=sec/10; secl=sec%10; minh=min/10; minl=min%10; hourh=hour/10; hourl=hour%10; } display(secl,sech,minl,minh,hourl,hourh); } } void initial() { dula=0; wela=0; TMOD=0x01; TH0=(65536-50000)/256; TL0=(65536-50000)%256; EA=1; ET0=1; TR0=1; hour=1; min=4; sec=56; } void display(uchar a,uchar b,uchar c,uchar d,uchar e,uchar f) { P0=0x00; dula=1; P0=tab[a]; dula=0; delay(1); P0=0xff; wela=1; P0=0xef; wela=0; P0=0; ///////// dula=1; P0=tab[b]; dula=0; delay(1); P0=0xff; wela=1; P0=0xf7; wela=0; P0=0; dula=1; P0=tab[c]; dula=0; delay(1); P0=0xff; wela=1; P0=0xfd; wela=0; P0=0; dula=1; P0=tab[d]; dula=0; delay(1); P0=0xff; wela=1; P0=0xfe; wela=0; P0=0; dula=1; P0=tab[e]; dula=0; delay(1); P0=0xff; wela=1; P0=0x7f; wela=0; P0=0; dula=1; P0=tab[f]; dula=0; delay(1); P0=0xff; wela=1; P0=0xbf; wela=0; } void delay(uchar z) { uchar x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } void timer0()interrupt 1 { TH0=(65536-50000)/256; TL0=(65536-50000)%256; a++; } void spark() { wela=1; P0=0X49; P0=0; dula=1; P0=0XDB; delay(100); wela=0; }