去年的硬件,这次趁空重新改了程序,改为向上翻页,由于自己是业余瞎弄的,不足之处请告诉,
单片机源程序如下:
- #include <REGX51.H>
- unsigned char min=0,hou=12,timecount=0,oldP1=0xff,setting=0,day=0;
- bit point=1,K1_old,K2_old;
- char sec=0,err=0,j,l=-1;
- unsigned char code dis_code[]=
- {
- 0x3E,0x41,0x41,0x3E,0x21,0x7F,0x01,0x00,//0与1
- 0x23,0x45,0x49,0x31,0x22,0x41,0x49,0x36, //2与3
- 0x1E,0x22,0x7F,0x02,0x72,0x51,0x51,0x4E, //4与5
- 0x3E,0x49,0x49,0x26,0x60,0x40,0x4F,0x70, //6与7
- 0x36,0x49,0x49,0x36,0x32,0x49,0x49,0x3E, //8与9
- 0x3E,0x49,0x49,0x00,0x3F,0x4C,0x4A,0x31,0x00,0x00,0x18,0x18,0x7E,0x7E,0x18,0x18,//err+
- 0x3E,0x49,0x49,0x00,0x3F,0x4C,0x4A,0x31,0x00,0x00,0x18,0x18,0x18,0x18,0x18,0x18,//err-
- 0x7F,0x08,0x08,0x7F,0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x7E,0x01,0x01,0x01,0x7E,//hou
- 0x3F,0x40,0x7C,0x40,0x3F,0x00,0x41,0x7F,0x41,0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,//min
- 0x31,0x49,0x49,0x49,0x46,0x00,0x3E,0x49,0x49,0x49,0x00,0x3E,0x41,0x41,0x41,0x22, //sec
- 0x00,0x18,0x18,0x7E,0x7E,0x18,0x18,0x00,//+
- 0x00,0x18,0x18,0x18,0x18,0x18,0x18,0x00,//-
- };
- unsigned char code dis_code1[]=
- {
- 0x3E,0x41,0x41,0x3E,
- 0x7C,0x82,0x82,0x7C,0xF8,0x04,0x05,0xF8,
- 0xF0,0x09,0x0B,0xF0,0xE0,0x12,0x17,0xE0, //0-1
- 0xC0,0x24,0x2F,0xC0,0x80,0x48,0x5F,0x80,
- 0x00,0x90,0xBF,0x00,0x00,0x21,0x7F,0x01,
- 0x00,0x42,0xFE,0x02,0x00,0x85,0xFD,0x04,
- 0x01,0x0A,0xFA,0x09,0x02,0x14,0xF4,0x13, //1-2
- 0x04,0x28,0xE9,0x26,0x08,0x51,0xD2,0x4C,
- 0x11,0xA2,0xA4,0x98,0x23,0x45,0x49,0x31,
- 0x46,0x8A,0x92,0x62,0x8C,0x15,0x25,0xC4,
- 0x19,0x2A,0x4A,0x89,0x32,0x54,0x94,0x13,
- 0x64,0xA8,0x29,0x26,0xC8,0x50,0x52,0x4D, //2-3
- 0x91,0xA0,0xA4,0x9B,0x22,0x41,0x49,0x36,
-
- 0x44,0x82,0x92,0x6C,0x88,0x04,0x25,0xD8,
- 0x10,0x09,0x4B,0xB0,0x21,0x12,0x97,0x60,
- 0x43,0x24,0x2F,0xC0,0x87,0x48,0x5F,0x80, //3-4
- 0x0F,0x91,0xBF,0x01,0x1E,0x22,0x7F,0x02,
- 0x3C,0x44,0xFE,0x04,0x79,0x89,0xFD,0x09,
- 0xF3,0x12,0xFA,0x12,0xE7,0x25,0xF5,0x24,
- 0xCE,0x4A,0xEA,0x49,0x9C,0x94,0xD4,0x93, //4-5
- 0x39,0x28,0xA8,0x27,0x72,0x51,0x51,0x4E,
- 0xE4,0xA2,0xA2,0x9C,0xC8,0x45,0x45,0x38,
- 0x91,0x8A,0x8A,0x71,0x23,0x14,0x14,0xE2,
- 0x47,0x29,0x29,0xC4,0x8F,0x52,0x52,0x89, //5-6
- 0x1F,0xA4,0xA4,0x13,0x3E,0x49,0x49,0x26,
- 0x7C,0x92,0x92,0x4C,0xF9,0x25,0x25,0x99,
- 0xF3,0x4A,0x4A,0x33,0xE6,0x94,0x94,0x67,
- 0xCC,0x28,0x29,0xCE,0x98,0x50,0x53,0x9C, //6-7
- 0x30,0xA0,0xA7,0x38,0x60,0x40,0x4F,0x70,
- 0xC0,0x80,0x9E,0xE0,0x80,0x01,0x3D,0xC0,
- 0x01,0x02,0x7A,0x81,0x03,0x04,0xF4,0x03,
- 0x06,0x09,0xE9,0x06,0x0D,0x12,0xD2,0x0D, //7-8
- 0x1B,0x24,0xA4,0x1B,0x36,0x49,0x49,0x36,
- 0x6C,0x92,0x92,0x6C,0xD8,0x25,0x25,0xD8,
- 0xB1,0x4A,0x4A,0xB1,0x63,0x94,0x94,0x63,
- 0xC6,0x29,0x29,0xC6,0x8C,0x52,0x52,0x8F, //8-9
- 0x19,0xA4,0xA4,0x1F,0x32,0x49,0x49,0x3E,
- 0x64,0x92,0x92,0x7C,0xC8,0x25,0x25,0xF8,
- 0x91,0x4A,0x4A,0xF1,0x23,0x94,0x94,0xE3,
- 0x47,0x28,0x28,0xC7,0x8F,0x50,0x50,0x8F, //9-0
- 0x1F,0xA0,0xA0,0x1F,0x3E,0x41,0x41,0x3E,
- 0x7C,0x82,0x82,0x7C,0xF8,0x04,0x05,0xF8,
- 0xF0,0x09,0x0B,0xF0,0xE0,0x12,0x17,0xE0, //0-1
- 0xC0,0x24,0x2F,0xC0,0x80,0x48,0x5F,0x80,
- 0x00,0x90,0xBF,0x00,0x00,0x21,0x7F,0x01,
- 0x00,0x42,0xFE,0x02,0x00,0x85,0xFD,0x04,
- 0x01,0x0A,0xFA,0x09,0x02,0x14,0xF4,0x13, //1-2
- 0x04,0x28,0xE9,0x26,0x08,0x51,0xD2,0x4C,
- 0x11,0xA2,0xA4,0x98,0x23,0x45,0x49,0x31,
- 0x46,0x8A,0x92,0x62,0x8C,0x14,0x25,0xC4,
- 0x18,0x29,0x4B,0x88,0x30,0x52,0x97,0x10,
- 0x60,0xA4,0x2F,0x20,0xC0,0x48,0x5F,0x40,
- 0x80,0x90,0xBF,0x80,0x00,0x21,0x7F,0x01,//2-1
- };
- unsigned char code dis_code2[]=
- {
- 0x3E,0x41,0x41,0x3E,
- 0x7C,0x82,0x82,0x7C,0xF8,0x04,0x05,0xF8,
- 0xF0,0x09,0x0B,0xF0,0xE0,0x12,0x17,0xE0, //0-1
- 0xC0,0x24,0x2F,0xC0,0x80,0x48,0x5F,0x80,
- 0x00,0x90,0xBF,0x00,0x00,0x21,0x7F,0x01,
- 0x00,0x42,0xFE,0x02,0x00,0x85,0xFD,0x04,
- 0x01,0x0A,0xFA,0x09,0x02,0x14,0xF4,0x13, //1-2
- 0x04,0x28,0xE9,0x26,0x08,0x51,0xD2,0x4C,
- 0x11,0xA2,0xA4,0x98,0x23,0x45,0x49,0x31,
- 0x46,0x8A,0x92,0x62,0x8C,0x15,0x25,0xC4,
- 0x19,0x2A,0x4A,0x89,0x32,0x54,0x94,0x13,
- 0x64,0xA8,0x29,0x26,0xC8,0x50,0x52,0x4D, //2-3
- 0x91,0xA0,0xA4,0x9B,0x22,0x41,0x49,0x36,
-
- 0x44,0x82,0x92,0x6C,0x88,0x04,0x25,0xD8,
- 0x10,0x09,0x4B,0xB0,0x21,0x12,0x97,0x60,
- 0x43,0x24,0x2F,0xC0,0x87,0x48,0x5F,0x80, //3-4
- 0x0F,0x91,0xBF,0x01,0x1E,0x22,0x7F,0x02,
- 0x3C,0x44,0xFE,0x04,0x79,0x89,0xFD,0x09,
- 0xF3,0x12,0xFA,0x12,0xE7,0x25,0xF5,0x24,
- 0xCE,0x4A,0xEA,0x49,0x9C,0x94,0xD4,0x93, //4-5
- 0x39,0x28,0xA8,0x27,0x72,0x51,0x51,0x4E,
- 0xE4,0xA2,0xA2,0x9C,0xC8,0x45,0x45,0x38,
- 0x91,0x8A,0x8A,0x71,0x23,0x14,0x14,0xE3,
- 0x47,0x28,0x28,0xC7,0x8F,0x50,0x50,0x8F, //5-0
- 0x1F,0xA0,0xA0,0x1F,0x3E,0x41,0x41,0x3E,
- };
- unsigned char code dis_code3[]=
- {
- 0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,
- 0x00,0x01,0x03,0x00,0x00,0x02,0x07,0x00,
- 0x00,0x04,0x0F,0x00,0x00,0x08,0x1F,0x00,
- 0x00,0x10,0x3F,0x00,0x00,0x21,0x7F,0x01,//1进入
- 0x00,0x42,0xFE,0x02,0x00,0x84,0xFC,0x04,
- 0x00,0x08,0xF8,0x08,0x00,0x10,0xF0,0x10,
- 0x00,0x20,0xE0,0x20,0x00,0x40,0xC0,0x40, //1退出
- 0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,
-
- };
- sbit K1=P1^7;
- sbit K2=P1^6;
- void delay_ms(void);
- void timedeal(void);
- /*******************************************************************/
- void main(void)
- {
- char i,q,disnum;
- unsigned char num,x,y,offset=0,dis_p,scantimes=0;
- IE=0x82; //允许定时器0工作
- TMOD=0x01; //timer0为模式1
- TR0=1; //定时器0可以工作
- TH0 = 0x4c;
- TL0 = 0x1e;
- do
- {
- q=sec;
- if(setting==0)
- {
- if(j<q)
- {
- for(i=0;i<8;i++)
- {
- unsigned char a;
- a=3;
- while(a--)
- {
- for(x=0;x<16;x++)
- {
- dis_p=x;
- if(dis_p==3|| dis_p==8|| dis_p==10|| dis_p==15||dis_p>15)
- {
- y=0;
- }
- else if(dis_p<=2)
- {
- num=hou/10;
- if(hou==10&min==0&sec==0)
- y=dis_code3[(num)+dis_p+i*4];
- else
- y=dis_code3[(num)*32+dis_p+1];
- if(hou==1&min==0&sec==0)
- y=dis_code3[32+dis_p+1+i*4];
- }
- else if(dis_p<=7)
- {
- num=hou%10;
- y=dis_code1[(num)*32+dis_p-4];
- if((min==0)&sec==0)
- y=dis_code1[(num-1)*32+dis_p-4+(i*4)];
- if(hou==10&min==0&sec==0)
- y=dis_code1[288+dis_p-4+(i*4)];
- if(hou==1&min==0&sec==0)
- y=dis_code1[384+dis_p-4+(i*4)];
- }
- else if(dis_p<=9)
- {
- if(point)
- y=0x22;
- else
- y=0;
- }
- else if(dis_p<=14)
- {
- num=min/10;
- y=dis_code2[num*32+dis_p-11];
- if((min==10||min==20||min==30||min==40||min==50)&sec==0)
- y=dis_code2[(num-1)*32+dis_p-11+(i*4)];
- if((min==0)&sec==0)
- y=dis_code2[160+dis_p-11+i*4];
- }
- P3=0;
- P1=x|0xE0;
- P3=y;
- delay_ms();
- }
- for(x=0;x<16;x++)
- {
- dis_p=x;
- if(dis_p==4 || dis_p==6||dis_p==11||dis_p==16||dis_p>16 )
- {
- y=0;
- }
- else if(dis_p<=3)
- {
- num=min%10;
- y=dis_code1[(num)*32+dis_p];
- if(sec==0)
- y=dis_code1[(num-1)*32+dis_p+i*4];
- if((min==0||min==10||min==20||min==30||min==40||min==50)&sec==0)
- y=dis_code1[288+dis_p+i*4];
- }
- else if(dis_p<=5)
- {
- if(point)
- y=0x22;
- else
- y=0;
- }
- else if(dis_p<=10)
- {
- num=sec/10;
- y=dis_code2[(num)*32+dis_p-7];
- if(sec==0)
- y=dis_code2[160+dis_p-7+i*4];
- if(sec==10||sec==20||sec==30||sec==40||sec==50)
- y=dis_code2[(num-1)*32+dis_p-7+i*4];
- }
- else if(dis_p<=15)
- {
- num=sec%10;
- y=dis_code1[(num-1)*32+dis_p-12+i*4];
- if(sec==0||sec==10||sec==20||sec==30||sec==40||sec==50)
- y=dis_code1[288+dis_p-12+i*4];
- }
- P3=0;
- P1=x|0xd0;
- P3=y;
- delay_ms();
- }
- }
- }
- }
- j=q;
- {
- for(x=0;x<16;x++) //
- {
- dis_p=x;
- if(dis_p==3|| dis_p==8|| dis_p==10|| dis_p==15||dis_p>15)
- {
- y=0;
- }
- else if(dis_p<=2)
- {
- num=hou/10;
- y=dis_code3[num*32+dis_p+1];
- }
- else if(dis_p<=7) //4~7为时的个位
- {
- num=hou%10;
- y=dis_code1[num*32+dis_p-4];
- }
- else if(dis_p<=9)
- {
- if(point)
- y=0x22;
- else
- y=0;
- }
- else if(dis_p<=14)
- {
- num=min/10;
- y=dis_code2[num*32+dis_p-11];
- }
- P3=0;
- P1=x|0xE0;
- P3=y;
- delay_ms();
- }
- for(x=0;x<16;x++)
- {
- dis_p=x;
- if(dis_p==4 || dis_p==6||dis_p==11||dis_p==16||dis_p>16 )
- {
- y=0;
- }
- else if(dis_p<=3)
- {
- num=min%10;
- y=dis_code1[num*32+dis_p];
- }
- else if(dis_p<=5)
- {
- if(point)
- y=0x22;
- else
- y=0;
- }
- else if(dis_p<=10)
- {
- num=sec/10;
- y=dis_code2[num*32+dis_p-7];
- }
-
- else if(dis_p<=15)
- {
- num=sec%10;
- y=dis_code1[num*32+dis_p-12];
- }
- P3=0;
- P1=x|0xd0;
- P3=y;
- delay_ms();
- }
- }
- }
- /**************************************************///
- else //当进入调整时间的状态,运行下面的程序段
- {
- for(x=0;x<16;x++)
- {
- if(setting==1)
- if(x<16)
- if(point)
- y=dis_code[40+x];
- else
- y=0;
- if(setting==2)
- if(x<16)
- if(point)
- y=dis_code[56+x];
- else
- y=0;
- if(setting==3||setting==4)
- if(x<16)
- if(point)
- y=dis_code[72+x];
- else
- y=0;
- if(setting==5||setting==6)
- if(x<=16)
- if(point)
- y=dis_code[88+x];
- else
- y=0;
- if(setting==7)
- if(x<=16)
- if(point)
- y=dis_code[104+x];
- else
- y=0;
-
- P3=0;
- P1=x|0xe0;
- P3=y;
- delay_ms();
- }
-
- for(x=0;x<16;x++)
- {
- if(setting==1||setting==2)
- {
- dis_p=x;
- if(err>=0)
- {
- if(dis_p<=7)
- {
- y=dis_code[120+x];
- }
- else if(dis_p<12)
- {
- disnum=err;
- num=disnum/10;
- y=dis_code[num*4+x-8];
- }
- else
- {
- num=disnum%10;
- y=dis_code[num*4+x-12];
- }
- }
- if(err<0)
- {
- if(dis_p<=7 )
- {
- y=dis_code[128+x];
- }
- else if(dis_p<12)
- {
- disnum=err;
- num=l*disnum/10;
- y=dis_code[num*4+x-8];
- }
- else
- {
- num=l*disnum%10;
- y=dis_code[num*4+x-12];
- }
- }
- }
-
- if(setting==3)
- {
- dis_p=x;
- if(dis_p<=7 )
- {
- y=dis_code[120+x];
- }
- else if(x<12)
- {
- disnum=hou;
- num=disnum/10;
- y=dis_code[num*4+x-8];
- }
- else
- {
- num=disnum%10;
- y=dis_code[num*4+x-12];
- }
- }
- if(setting==4)
- {
- dis_p=x;
- if(dis_p<=7 )
- {
- y=dis_code[128+x];
- }
- else if(x<12)
- {
- disnum=hou;
- num=disnum/10;
- y=dis_code[num*4+x-8];
- }
- else
- {
- num=disnum%10;
- y=dis_code[num*4+x-12];
- }
- }
- if(setting==5)
- {
- dis_p=x;
- if(dis_p<=7 )
- {
- y=dis_code[120+x];
- }
- else if(x<12)
- {
- disnum=min;
- num=disnum/10;
- y=dis_code[num*4+x-8];
- }
- else
- {
- num=disnum%10;
- y=dis_code[num*4+x-12];
- }
- }
-
- if(setting==6)
- {
- dis_p=x;
- if(dis_p<=7 )
- {
- y=dis_code[128+x];
- }
- else if(x<12)
- {
- disnum=min;
- num=disnum/10;
- y=dis_code[num*4+x-8];
- }
- else
- {
- num=disnum%10;
- y=dis_code[num*4+x-12];
- }
- }
- if(setting==7)
- {
- dis_p=x;
- if(dis_p<=5||dis_p==7)
- {
- y=0;
- }
- else if(dis_p==6)
- {
- if(point)
- y=0x22;
- else
- y=0;
- }
- else if(x<12)
- {
- disnum=sec;
- num=disnum/10;
- y=dis_code[num*4+x-8];
- }
- else
- {
- num=disnum%10;
- y=dis_code[num*4+x-12];
- }
- }
- P3=0;
- P1=x|0xd0;
- P3=y;
- delay_ms();
- }
- }
- }
- while(1);
- }
- /***************************************************/
- void delay_ms(void)
- {
- unsigned char i,j;
- for(i=0;i<4;i++)
- for(j=0;j<30;j++);
- }
- /****************************************************/
- void time50ms(void) interrupt 1
- {
- TH0 = 0x4c;
- TL0 = 0x1e;
- timecount++;
- if(timecount==10)
- {
- timecount=0;
- point=!point;
- if(point)
- {
- sec++;
- timedeal();
- }
- }
- if(!K1&&K1!=K1_old)
- {
- setting++;
- if(setting==8)
- setting=0;
- }
- if(!K2 && K2!=K2_old)
- {
- if(setting==1)
- {
- err++;
- if(err==60)
-
- err=0;
- timedeal();
- }
- else if(setting==2)
- {
- err--;
- if(err==-60)
- err=0;
- timedeal();
- }
- else if(setting==3)
- {
- hou++;
- if(hou>12)
- hou=1;
- timedeal();
- }
- else if(setting==4)
- {
- hou--;
- if(hou==0)
- hou=12;
- timedeal();
- }
- else if(setting==5)
- {
- if(min==60)
- min=0;
- min++;
- timedeal();
- }
- else if(setting==6)
- {
- if(min==0)
- min=60;
- min--;
- timedeal();
- }
- else if(setting==7)
- sec=0;
-
- }
- K1_old=K1;
- K2_old=K2;
- }
- /****************************************************/
- void timedeal(void)
- {
- if(sec>=60)
- {
- sec=0;
- j=-1;
- min++;
- }
- if(min>=60)
- {
- min=0;
- hou++;
- }
- if(hou>12)
- {
- hou=1;
- day++;
- }
- if(day>=2)
- {
- day=0;
- sec=sec+err;
- }
- }
复制代码
|