下面是利用数码管显示的时钟的代码
#include <reg52.h>
#define SEGPORT P0
sbit seg_sel = P2^1;
sbit bit_sel = P2^0;
unsigned char segdata[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char bitdata[8] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char disdata[8] = {0x3f,0x3f,0x40,0x3f,0x3f,0x40,0x03,0x03};
unsigned char s = 20;
unsigned char m = 21;
unsigned char h = 12;
void display()
{
static unsigned char i = 0;
SEGPORT = 0x0;
seg_sel = 1;
seg_sel = 0;
SEGPORT = 0xff;
bit_sel = 1;
bit_sel = 0;
SEGPORT = disdata[i];
seg_sel = 1;
seg_sel = 0;
SEGPORT = bitdata[i];
bit_sel = 1;
bit_