1、基于51单片机共阳极数码管显示0000到9999!注意布线#include #define uchar unsigned char#define uint unsigned intuchar code DSY_CODE= 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90;void delayms(uint);void display(uchar,uchar,uchar,uchar);uint num,num1,num2,num3,num4,qian,bai,shi,ge;void main() TMOD=0X01; TH0=(65536-458
2、72)/256; TL0=(65536-45872)%256; EA=1; ET0=1; TR0=1; while(1) display(qian,bai,shi,ge); void display(uchar qian,uchar bai,uchar shi,uchar ge) P2=0xfe; P0=DSY_CODEge; delayms(1); P2=0xfd; P0=DSY_CODEshi; delayms(1); P2=0xfb; P0=DSY_CODEbai; delayms(1); P2=0xf7; P0=DSY_CODEqian; delayms(1);void delayms(uint xms)uint i,j;for(i=xms;i0;i-) for(j=110;j0;j-);void T0_time()interrupt 1 TH0=(65536-45872)/256; TL0=(65536-45872)%256; num1+; if(num1=2) num1=0; num+; qian=num/1000; bai=num%1000/100; shi=num%100/10; ge=num%10;