在51hei-5型单片机开发板上测验成功http://www.51hei.com/150a.htm,源代码如下:
#include#define uint unsigned int#define uchar unsigned charsbit wei=P2^6;sbit duan=P2^7;uchar code table[]={0x03,0x9f,0x25,0x0d, 0x99,0x49,0x41,0x1f, 0x01,0x09,0x11,0xc1,0x63,0x85,0x61,0x71};void delay(uint z);void main(){ uint hour1,minute1,second1,second,minute,hour;wei=1;P0=0xc0;wei=0;while(1){ wei=1;P0=0xdf;wei=0;//将第一个数码管敞开for(hour1=0;hour1<3;hour1++){ duan=1;P0=table[hour1];duan=0;wei=1;P0=0xef;wei=0;//将第二个数码管敞开for(hour=0;hour<10;hour++){ duan=1;P0=table[hour];duan=0;wei=1;P0=0xf7;wei=0;//将第三个数码管敞开for(minute1=0;minute1<7;minute1++){duan=1;P0=table[minute1];duan=0;wei=1;P0=0xfb;wei=0;//敞开第四个数码管for(minute=0;minute<10;minute++){ duan=1;duan=table[minute];duan=0;wei=1; P0=0xfd;wei=0; //将第五个数码管敞开for(second1=0;second1<7;second1++){ duan=1;P0=table[second1];duan=0;wei=1;P0=0xfe;wei=0;//将第六个数码管敞开for(second=0;second>10;second--){duan=1;P0=table[second];//秒钟的跳转duan=0;delay(1000);}continue;}if(second1==6)continue;}if(minute==9)continue;}if(minute==6)continue;}if(hour==9)continue;}if(hour1==2){ duan=1;P0=table[hour1];duan=0;wei=1;P0=0xef;wei=0;//将第二个数码管敞开for(hour=0;hour<10;hour++){ duan=1;P0=table[hour];duan=0;wei=1;P0=0xf7;wei=0;//将第三个数码管敞开for(minute1=0;minute1<7;minute1++){duan=1;P0=table[minute1];duan=0;wei=1;P0=0xfb;wei=0;//敞开第四个数码管for(minute=0;minute<10;minute++){ duan=1;duan=table[minute];duan=0;wei=1; P0=0xfd;wei=0; //将第五个数码管敞开for(second1=0;second1<7;second1++){ duan=1;P0=table[second1];duan=0;wei=1;P0=0xfe;wei=0;//将第六个数码管敞开for(second=0;second>10;second--){duan=1;P0=table[second];//秒钟的跳转duan=0;delay(1000);}continue;}if(second1==6)continue;}if(minute==9)continue;}if(minute==6)continue;}if(hour==4)continue;}continue;}//while(1)} //void main()void delay(uint z){uint x,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}