#include#include#define uchar unsigned char#define uint unsigned int//--------------------------------------------uchar code Table_of_Digits[40][8]={ {0x1C,0x22,0x22,0x22,0x22,0x22,0x22,0x1C},//0 {0x08,0x18,0x08,0x08,0x08,0x08,0x08,0x1C},//1 {0x1C,0x22,0x02,0x02,0x1C,0x20,0x20,0x3E},//2 {0x1C,0x22,0x02,0x1C,0x02,0x02,0x22,0x1C},//3 {0x08,0x18,0x28,0x48,0x7C,0x08,0x08,0x08},//4 {0x3E,0x20,0x20,0x3E,0x02,0x02,0x22,0x1C},//5 {0x1C,0x22,0x20,0x3C,0x22,0x22,0x22,0x1C},//6 {0x3E,0x02,0x04,0x08,0x10,0x10,0x10,0x10},//7 {0x1C,0x22,0x22,0x1C,0x22,0x22,0x22,0x1C},//8 {0x1C,0x22,0x22,0x22,0x1E,0x02,0x22,0x1C},//9 {0x00,0x1C,0x22,0x22,0x22,0x3E,0x22,0x22},//A {0x00,0x3C,0x22,0x22,0x3E,0x22,0x22,0x3C},//B {0x00,0x1C,0x22,0x20,0x20,0x20,0x22,0x1C},//C {0x00,0x3C,0x22,0x22,0x22,0x22,0x22,0x3C},//D {0x00,0x3E,0x20,0x20,0x3E,0x20,0x20,0x3E},//E {0x00,0x3E,0x20,0x20,0x3E,0x20,0x20,0x20},//F {0x00,0x1C,0x22,0x20,0x3E,0x22,0x22,0x1C},//G {0x00,0x22,0x22,0x22,0x3E,0x22,0x22,0x22},//H {0x00,0x1C,0x08,0x08,0x08,0x08,0x08,0x1C},//I {0x00,0x3E,0x08,0x08,0x08,0x08,0x28,0x18},//J {0x00,0x20,0x2C,0x30,0x20,0x30,0x2C,0x20},//K {0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x3E},//L {0x00,0x42,0x66,0x5A,0x42,0x42,0x42,0x42},//M {0x00,0x00,0x2C,0x32,0x22,0x22,0x22,0x22},//n {0x00,0x1C,0x22,0x22,0x22,0x22,0x22,0x1C},//O {0x00,0x3C,0x22,0x22,0x3C,0x20,0x20,0x20},//P {0x00,0x1C,0x22,0x22,0x22,0x2A,0x26,0x1F},//Q {0x00,0x38,0x24,0x24,0x38,0x30,0x28,0x24},//R {0x00,0x1C,0x22,0x20,0x1C,0x02,0x22,0x1C},//S {0x00,0x3E,0x08,0x08,0x08,0x08,0x08,0x08},//T {0x00,0x42,0x42,0x42,0x42,0x42,0x42,0x3C},//U {0x00,0x22,0x22,0x22,0x14,0x14,0x08,0x00},//V {0x00,0x41,0x41,0x49,0x55,0x55,0x63,0x41},//W {0x00,0x00,0x42,0x24,0x18,0x18,0x24,0x42},//X {0x00,0x22,0x22,0x14,0x08,0x10,0x20,0x00},//Y {0x00,0x3E,0x02,0x04,0x08,0x10,0x20,0x3E},//Z};//---------------------------------------uchar code xdat[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};uchar code ydat[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};//---------------------------------------uchar i=0;uchar j=0;uchar t=0;uchar Num_Index,disnum;uchar key;uchar xi;uchar yi;//---------------------------------------uchar code disstr[]="C201600102020";//显示内容可以自己定义//---------------------------------------sbit we1=P1^1;sbit we2=P1^3;//---------------------------------------//主程序//---------------------------------------void main(){//P1=0x80;Num_Index=0; //从0 开始显示TMOD=0x01; //T0 方式0TH0=(65536-2000)/256; //2ms 定时TL0=(65536-2000)%256;IE=0x82;key=0;xi=0;yi=0;EX0=1;IT0=1;TR0=1; //启动T0while(1);}//---------------------------------------//外部中断0 中断函数//按键处理//---------------------------------------void ext_int0() interrupt 0{ key++; key&=0x03;}//---------------------------------------//定时器0 中断函数//显示控制//---------------------------------------void LED_Screen_Display() interrupt 1{TH0=(65536-2000)/256; //2ms 定时TL0=(65536-2000)%256;switch(key){//显示点阵图形case 0: P0=0xff; if(disstr[Num_Index]>='A')disnum=disstr[Num_Index]-'A'+10; else disnum=disstr[Num_Index]-'0'; we1=1; P0=~Table_of_Digits[disnum][i]; we1=0; P0=0xff; //输出位码和段码 we2=1; P0=ydat[i]; we2=0; if(++i==8) i=0; //每屏一个数字由8 个字节构成 if(++t==250) //每个数字刷新显示一段时间 { t=0; if(++Num_Index==13) Num_Index=0; //显示下一个数字 } break;//流水灯“点”模式case 1: we1=1; P0=~xdat[xi]; we1=0; we2=1; P0=ydat[yi]; we2=0; if(++t==250) //每个数字刷新显示一段时间 { t=0; yi++; if(yi>7){yi=0;xi++;} if(xi>7)xi=0; } break;//流水灯“行列”模式case 2: we1=1; P0=0x00; we1=0; P0=0xff; //输出位码和段码 we2=1; P0=xdat[i]; we2=0; if(++t==250) //每个数字刷新显示一段时间 { if(++i==8) i=0; //每屏一个数字由8 个字节构成 t=0; } break;default: key=0; i=0; j=0; t=0; xi=0; yi=0; Num_Index=0; we1=1; P0=0xff; we1=0; we2=1; P1=0x80; we2=0; break;}}