大佬们,我是想让数码管显示2018,点阵显示0--9,请大佬们指教我该怎么改正
#include<reg51.h> #include<intrins.h> #define uchar unsigned char #define uint unsigned int
//uchar code DSY_CODE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; uchar code DSY_CODE[]={0xa4,0xc0,0xf9,0x80}; uchar code wei[]={0x80,0x40,0x20,0x10}; unsigned char const xuehao[]={ 0x00,0x00,0xFE,0x82,0x82,0x82,0xFE,0x00, //0 0x00,0x00,0x84,0x82,0xFF,0x80,0x80,0x00, //1 0x00,0x00,0xF2,0x92,0x92,0x92,0x9E,0x00, //2 0x00,0x00,0x92,0x92,0x92,0xFE,0x00,0x00, //3 0x00,0x20,0x30,0x28,0x24,0xFE,0x20,0x00, //4 0x00,0x00,0x9E,0x92,0x92,0x92,0xF2,0x00, //5 0x00,0x00,0xFE,0x92,0x92,0x92,0xF2,0x00, //6 0x00,0x00,0x00,0x02,0x02,0x02,0xFE,0x00, //7 0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00, //8 0x00,0x32,0x49,0x49,0x49,0x3e,0x00,0x00 //9 }; unsigned char code lie[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; void DelayMS(uint x) { uchar t; while(x--) for(t=0;t<120;t++); }
void Timer1Init() { TMOD|=0X10;//选择为定时器1模式,工作方式1,仅用TR1打开启动。
TH1=0XFC; //给定时器赋初值,定时1ms TL1=0X18; ET1=1;//打开定时器1中断允许 EA=1;//打开总中断 TR1=1;//打开定时器 } void main() {
uchar i; while(1) { for(i=0;i<4;i++) { P3=0x00; //关闭显示 P1=DSY_CODE[ i]; //发送数字段码 P3=wei[ i]; DelayMS(10); } Timer1Init(); //定时器1初始化 }
} void Timer1() interrupt 3 { uchar t,j,k; TH1=0XFC; //给定时器赋初值,定时1ms TL1=0X18; for(t=0;t<10;t++) { for(j=0;j<30;j++) { for(k=0;k<8;k++) { P2=lie[k]; P0=~xuehao[t*8+k]; DelayMS(2); } } }
}
|