|
这个程序非常简单,用这个来发帖试试,如果有错误的话请指正- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar code segcode []={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90} ; //定义段码
- uchar code bitcode []={0xf7,0xfb};//定义位码
- uchar dispbuf[2];
- uint count;
- void DelayMs (uint n)
- {
- uchar j;
- while (n--)
- {
- for (j=0;j<113;j++);
- }
- } //延时0.5秒
- void numtobuf(void)
- {
- dispbuf[1]=count/10%10;
- dispbuf[0]=count%10;
- }
- void buftoseg(void)
- {
- uchar i;
- for(i=0;i<2;i++)
- {
- P0=segcode[dispbuf[i]];
- P2=bitcode[i];
- DelayMs(1);
- }
- }
- void main (void)
- {
- uint k;
- while(1)
- {
- if(++k==220)
- {
- k=0;
- if(++count==100)count=0;
- }
- numtobuf();
- buftoseg();
- }
- }
复制代码
|
|