表示错误有点多 我只是想让它运行起来
- #include <reg51.h>
- #ifndef _12864ZIFU_H_
- #define _12864ZIFU_H_
- unchar code
- shu0[]={0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00};/*"0",0*/
- unchar code
- shu1[]={0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00};/*"1",0*/
- unchar code
- shu2[]={0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00};/*"2",0*/
- unchar code
- shu3[]={0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00};/*"3",0*/
- unchar code
- shu4[]={0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00};/*"4",0*/
- unchar code
- shu5[]={0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00};/*"5",0*/
- unchar code
- shu6[]={0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00};/*"6",0*/
- unchar code
- shu7[]={0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00};/*"7",0*/
- unchar code
- shu8[]={0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00};/*"8",0*/
- unchar code
- shu9[]={0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00};/*"9",0*/
- unchar code
- dian[]={0x00,0x38,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/*"°",0*/
- unchar code
- C[]={0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00};/*"C",0*/
- unchar code
- xiao[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00};/*".",0*/
- unchar code
- jian[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01};
- unchar code
- jia[]={0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00};/*"+",0*/
- unchar code
- maohao[]={0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00};/*":",0*/
- uchar code nian[]=
- {0x40,0x20,0x10,0x0C,0xE3,0x22,0x22,0x22,0xFE,0x22,0x22,0x22,0x22,0x02,0x00,0x00,
- 0x04,0x04,0x04,0x04,0x07,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x04,0x04,0x00};/*"年",0*/
- uchar code yue[]=
- {0x00,0x00,0x00,0x00,0x00,0xFF,0x11,0x11,0x11,0x11,0x11,0xFF,0x00,0x00,0x00,0x00,
- 0x00,0x40,0x20,0x10,0x0C,0x03,0x01,0x01,0x01,0x21,0x41,0x3F,0x00,0x00,0x00,0x00};/*"月",0*/
- uchar code shi[]=
- {0x00,0xFC,0x44,0x44,0x44,0xFC,0x10,0x90,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x00,
- 0x00,0x07,0x04,0x04,0x04,0x07,0x00,0x00,0x03,0x40,0x80,0x7F,0x00,0x00,0x00,0x00};/*"时",0*/
- uchar code fen[]=
- {0x80,0x40,0x20,0x98,0x87,0x82,0x80,0x80,0x83,0x84,0x98,0x30,0x60,0xC0,0x40,0x00,0x00,0x80,0x40,0x20,0x10,0x0F,0x00,0x00,0x20,0x40,0x3F,0x00,0x00,0x00,0x00,0x00};/*"分",0*/
- uchar code miao[]=
- {0x12,0x12,0xD2,0xFE,0x91,0x11,0xC0,0x38,0x10,0x00,0xFF,0x00,0x08,0x10,0x60,0x00,
- 0x04,0x03,0x00,0xFF,0x00,0x83,0x80,0x40,0x40,0x20,0x23,0x10,0x08,0x04,0x03,0x00};/*"秒",0*/
- uchar code ri[]=
- {0x00,0x00,0x00,0xFE,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0xFE,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x3F,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x3F,0x00,0x00,0x00,0x00};/*"日",0*/
- uchar code zj_dong[]=
- {/*-- 文字: 东 --*/
- /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
- 0x00,0x04,0x04,0xC4,0xB4,0x8C,0x87,0x84,0xF4,0x84,0x84,0x84,0x84,0x04,0x00,0x00,
- 0x00,0x00,0x20,0x18,0x0E,0x04,0x20,0x40,0xFF,0x00,0x02,0x04,0x18,0x30,0x00,0x00};
- uchar code zj_bei[]=
- {/*-- 文字: 北 --*/
- /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
- 0x00,0x20,0x20,0x20,0x20,0xFF,0x00,0x00,0x00,0xFF,0x40,0x20,0x30,0x18,0x10,0x00,
- 0x10,0x30,0x18,0x08,0x04,0x7F,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x40,0x78,0x00};
- uchar code zj_shi[]=
- {/*-- 文字: 石 --*/
- /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
- 0x02,0x02,0x02,0x02,0x82,0xF2,0x4E,0x42,0x42,0x42,0x42,0x42,0xC2,0x02,0x02,0x00,
- 0x10,0x08,0x04,0x02,0x01,0x7F,0x20,0x20,0x20,0x20,0x20,0x20,0x7F,0x00,0x00,0x00
- };
- uchar code zj_you[]=
- {/*-- 文字: 油 --*/
- /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
- 0x10,0x61,0x06,0xF0,0x00,0xF0,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0xF0,0x00,0x00,
- 0x04,0x04,0xFF,0x00,0x00,0xFF,0x42,0x42,0x42,0x7F,0x42,0x42,0x42,0xFF,0x00,0x00};
- uchar code zj_da[]=
- {/*-- 文字: 大 --*/
- /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
- 0x20,0x20,0x20,0x20,0x20,0x20,0xA0,0x7F,0xA0,0x20,0x20,0x20,0x20,0x20,0x20,0x00,
- 0x00,0x80,0x40,0x20,0x10,0x0C,0x03,0x00,0x01,0x06,0x08,0x30,0x60,0xC0,0x40,0x00};
- uchar code zj_xue[]=
- {/*-- 文字: 学 --*/
- /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
- 0x40,0x30,0x10,0x12,0x5C,0x54,0x50,0x51,0x5E,0xD4,0x50,0x18,0x57,0x32,0x10,0x00,
- 0x00,0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x02,0x02,0x02,0x00};
- uchar code zj_dian[]=
- {/*-- 文字: 电 --*/
- /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
- 0x00,0x00,0xF8,0x48,0x48,0x48,0x48,0xFF,0x48,0x48,0x48,0x48,0xF8,0x00,0x00,0x00,
- 0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0x3F,0x44,0x44,0x44,0x44,0x4F,0x40,0x70,0x00,};
- uchar code zj_qi[]=
- {/*-- 文字: 气 --*/
- /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
- 0x00,0x20,0x10,0x8C,0xA7,0xA4,0xA4,0xA4,0xA4,0xA4,0xA4,0xA4,0x24,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x30,0x40,0xF0,0x00};
- uchar code zj_yuan[]=
- {/*-- 文字: 院 --*/
- /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
- 0xFE,0x02,0x32,0x4A,0x86,0x0C,0x24,0x24,0x25,0x26,0x24,0x24,0x24,0x0C,0x04,0x00,
- 0xFF,0x00,0x02,0x04,0x83,0x41,0x31,0x0F,0x01,0x01,0x7F,0x81,0x81,0x81,0xF1,0x00};
- uchar code xiaoren[]=
- {0x00,0x00,0x80,0x88,0x9C,0xA2,0x45,0xD1,0xD1,0x45,0xA2,0x9C,0x88,0x80,0x00,0x00,
- 0x07,0x01,0x03,0x04,0x0C,0x98,0xF9,0x0A,0x0A,0xF9,0x98,0x0C,0x04,0x03,0x01,0x07};/*"小人",0*/
- uchar code zj_xingxing[]=
- {0x40,0x40,0xC0,0xC0,0xC0,0xE0,0xFC,0xFF,0xFC,0xE0,0xC0,0xC0,0xC0,0x40,0x40,0x00,
- 0x00,0x00,0x40,0x39,0x3F,0x1F,0x1F,0x0F,0x1F,0x1F,0x3F,0x39,0x40,0x00,0x00,0x00};/*"★",0*/
- #endif
- #ifndef _KEYSCNA_H_
- #define _KEYSCNA_H_/*#define dataport P3 uchar sum; */
- uchar read_keyscan()
- { uchar col,flagg,line,num,temp;
- P3=0xf0;
- delay_us();
- delay_us();
- delay_us(); //等待按键按下
- flagg=P3&0xf0;
- if(flagg!=0xf0) // 检测是否有按键按下
- { for(line=0;line<3;line++)
- { P3=tab[line];
- temp=P3&0xf0;
- delay(5); //判断行
- if(temp!=0xf0)
- { switch(temp)
- {case 0xe0:col=0;break; //判断列
- case 0xd0:col=1;break;
- case 0xb0:col=2;break;
- default: break;}
- break;}}}
- P3=0xf0;
- while(P3!=0xf0); //检测是否松手
- num=line*3+col;
- return num; //返回值为0,1,2,3,4,5,6,7,8
- }/*
- uchar scan(uchar k)
- { uchar re;
- switch (k)
- { case 1:re=0;break;
- case 2:re=1;break;
- case 4:re=2;break;
- default:break; }
- return re;}
- void read_keyscan()
- { uchar m,n;
- dataport=0x07;
- delay_us();
- if(dataport!=0x07)
- { dataport=0x07;
- delay(5);
- m=dataport&0x07;
- if(m!=0x07)
- { m=m^0x07;
- m=scan(m);
- dataport=0x70;
- delay_us();
- n=dataport&0x70;
- if(n!=0x70)
- { n=n>>4;
- n=n^0x07;
- n=scan(n);
- sum=3*m+n;}}
- dataport=0x07;
- while(dataport!=0x07);} }*/ //输出012345678
- void keyscan_manage()
- { count=read_keyscan();
- switch(count)
- { case 0:setflag=1;flag0=1;break; //设置
- case 1:add=0x88;flag0=1;break; //月
- case 2:add=0x86;flag0=1;break; //日
- case 3:add=0x84;flag0=1;break; //时
- case 4:add=0x82;flag0=1;break; //分
- case 5:setflag=0;flag0=1;break; //退出设置
- default: break;}
- if(flag0==1&&setflag==1)
- { count=read_keyscan();
- if(count==1)
- { count=0xff;
- DS_set_time(add,1);}
- if(count==2)
- { count=0xff;
- DS_set_time(add,1);}
- if(count==3)
- { count=0xff;
- DS_set_time(add,1);}
- if(count==4)
- { count=0xff;
- DS_set_time(add,1);}
- if(count==5)
- { count=0xff;
- setflag=0;}}
- #endif
- #ifndef _LCD12864_H_
- #define _LCD12864_H_
- /************选屏*****************/
- void LCD_choose(uchar cs)
- { switch(cs)
- { case 0:cs1=0;cs2=1; break;
- case 1:cs1=1;cs2=0; break;
- case 2:cs1=0;cs2=0; break;
- default: break;}}
- /**************忙检查***************************/
- void LCD_check_busy()
- { uchar state;
- rs=0;
- rw=1;
- do
- { P0=0x00;
- en=1;
- state=P0&0x80;
- en=0;}
- while(state==0x80);
- }
- /****************写命令********************/
- void LCD_write_cmd(uchar cmd)
- { LCD_check_busy();
- rs=0;
- rw=0;
- en=1;
- P0=cmd;
- delay(2);
- en=0;
- }
- /*******写数据**********************/
- void LCD_write_data(uchar dat)
- { LCD_check_busy();
- rs=1;
- rw=0;
- en=1;
- P0=dat;
- delay(2);
- en=0;}
- /************读数据****************/
- /*uchar LCD_read_data(uchar cs,uchar page,uchar row)
- { uchar dat;
- LCD_check_busy();
- LCD_write_cmd(0xb8+page);
- LCD_write_cmd(0x40+row);
- P0=0xff;
- rs=0;
- rw=1;
- en=1;
- en=0;
- en=1;
- dat=P0;
- en=0;
- delay_us();
- return dat;} */
- /*********写小数点*******************/
- /*void LCD_display_dot(uchar cs,uchar page,uchar row)
- { LCD_choose(cs);
- page=page/8;
- LCD_write_cmd(0xb8+page);
- LCD_write_cmd(0x40+row);
- LCD_write_data(0x01);
- }*/
- /*****清屏*****************/
- void LCD_clear()
- { uchar i,j;
- LCD_choose(2);
- LCD_write_cmd(0xb8);
- LCD_write_cmd(0x40);
- for(i=0;i<8;i++)
- { LCD_write_cmd(i+0xb8);
- for(j=0;j<64;j++)
- { LCD_write_cmd(0x40+j);
- LCD_write_data(0x00);}}}
- /*8x8 点阵显示*/
- void LCD_display8(uchar cs,uchar page,uchar row,uchar *s)
- { uchar i;
- LCD_choose(cs);
- page<<=1;
- row=row*8;
- LCD_write_cmd(0xb8+page);
- LCD_write_cmd(0x40+row);
- for(i=0;i<8;i++)
- LCD_write_data(s[i]);
- LCD_write_cmd(0xb9+page);
- LCD_write_cmd(0x40+row);
- for(i=8;i<16;i++)
- LCD_write_data(s[i]);}
- /***16X16点阵显示***/
- void LCD_display16(uchar cs,uchar page,uchar row,uchar *s)
- { uchar i;
- LCD_choose(cs);
- page<<=1;
- row=row*8;
- LCD_write_cmd(0xb8+page);
- LCD_write_cmd(0x40+row);
- for(i=0;i<16;i++)
- LCD_write_data(s[i]);
- LCD_write_cmd(0xb9+page);
- LCD_write_cmd(0x40+row);
- for(i=16;i<32;i++)
- LCD_write_data(s[i]);}
- /************初始化*****************************/
- void LCD_init()
- { LCD_choose(2);
- LCD_write_cmd(0x3e);
- LCD_write_cmd(0x30);
- LCD_write_cmd(0x30);
- LCD_write_cmd(0xc0);
- LCD_write_cmd(0xb8);
- LCD_write_cmd(0x40);
- LCD_write_cmd(0x3f);
- delay(1);}
- /********显示时间**************************/
- void LCD_display_time()
- { LCD_display8(0,2,6,(shu0+16*(second/10)));
- LCD_display8(0,2,7,(shu0+16*(second%10)));
- LCD_display8(0,2,3,(shu0+16*(minute/10)));
- LCD_display8(0,2,4,(shu0+16*(minute%10)));
- LCD_display8(0,2,0,(shu0+16*(hour/10)));
- LCD_display8(0,2,1,(shu0+16*(hour%10)));
- LCD_display8(1,1,3,(shu0+16*(date/10)));
- LCD_display8(1,1,4,(shu0+16*(date%10)));
- LCD_display8(0,1,7,(shu0+16*(month/10)));
- LCD_display8(1,1,0,(shu0+16*(month%10)));
- LCD_display8(0,1,3,(shu0+16*(year/10)));
- LCD_display8(0,1,4,(shu0+16*(year%10)));
- LCD_display16(1,2,6,(yi+32*(day-2)));}
- #endif
- #ifndef _DELAY_H_
- #define _DELAY_H_
- void delay(uint z)
- {uint x,y;
- for(y=z;y>0;y--)
- for(x=10;x>0;x--);}
- void delay_us()
- {_nop_();_nop_();}
- #endif
- #ifndef _DEFINE_H_
- #define _DEFINE_H_
- #define uchar unsigned char
- #define uint unsigned int
- sbit rst=P1^5;
- sbit io=P1^7;
- sbit sclk=P1^6;
- sbit rs=P2^0;
- sbit rw=P2^1;
- sbit en=P2^2;
- sbit cs1=P2^3;
- sbit cs2=P2^4;
- sbit led=P1^4;
- sbit led1=P1^3;
- charhour,minute,second,year,month,date,day;
- uchartemp,flag0,flag1,cs,page,row,count,add,setflag;
- uchar tab[4]={0xfe,0xfd,0xfb};
- #endif
- 头文件
- #ifndef __INTRINS_H__
- #define __INTRINS_H__
- externvoid_nop_ (void);
- externbit_testbit_(bit);externunsignedchar_cror_(unsignedchar, unsigned char);
- extern unsigned int_iror_(unsigned int, unsigned char);
- externunsignedlong_lror_(unsignedlong, unsigned char);
- externunsignedchar_crol_(unsigned char, unsigned char);
- externunsignedint_irol_(unsigned int, unsigned char);
- externunsignedlong_lrol_(unsigned long, unsigned char);
- extern unsigned char _chkfloat_(float);
- extern void_push_ (unsigned char _sfr);
- extern void_pop_(unsigned char _sfr);
- #endif
- #ifndef __REG52_H__
- #define __REG52_H__
- /* BYTE Registers */
- sfr P0 = 0x80;
- sfr P1 = 0x90;
- sfr P2 = 0xA0;
- sfr P3 = 0xB0;
- sfr PSW = 0xD0;
- sfr ACC = 0xE0;
- sfr B = 0xF0;
- sfr SP = 0x81;
- sfr DPL = 0x82;
- sfr DPH = 0x83;
- sfr PCON = 0x87;
- sfr TCON = 0x88;
- sfr TMOD = 0x89;
- sfr TL0 = 0x8A;
- sfr TL1 = 0x8B;
- sfr TH0 = 0x8C;
- sfr TH1 = 0x8D;
- sfr IE = 0xA8;
- sfr IP = 0xB8;
- sfr SCON = 0x98;
- sfr SBUF = 0x99;
- /* 8051Extensions */
- sfr T2CON = 0xC8;
- sfr RCAP2L = 0xCA;
- sfr RCAP2H = 0xCB;
- sfr TL2 = 0xCC;
- sfr TH2 = 0xCD;
- /* BIT Registers */
- /* PSW */
- sbit CY = PSW^7;
- sbit AC = PSW^6;
- sbit F0 = PSW^5;
- sbit RS1 = PSW^4;
- sbit RS0 = PSW^3;
- sbit OV = PSW^2;
- sbit P = PSW^0; //8051 only
- /* TCON */
- sbit TF1 = TCON^7;
- sbit TR1 = TCON^6;
- sbit TF0 = TCON^5;
- sbit TR0 = TCON^4;
- sbit IE1 = TCON^3;
- sbit IT1 = TCON^2;
- sbit IE0 = TCON^1;
- sbit IT0 = TCON^0;
- /* IE */
- sbit EA = IE^7;
- sbit ET2 = IE^5; //8051 only
- sbit ES = IE^4;
- sbit ET1 = IE^3;
- sbit EX1 = IE^2;
- sbit ET0 = IE^1;
- sbit EX0 = IE^0;
- /* IP */
- sbit PT2 = IP^5;
- sbit PS = IP^4;
- sbit PT1 = IP^3;
- sbit PX1 = IP^2;
- sbit PT0 = IP^1;
- sbit PX0 = IP^0;
- /* P3 */
- sbit RD = P3^7;
- sbit WR = P3^6;
- sbit T1 = P3^5;
- sbit T0 = P3^4;
- sbit INT1 = P3^3;
- sbit INT0 = P3^2;
- sbit TXD = P3^1;
- sbit RXD = P3^0;
- /* SCON */
- sbit SM0 = SCON^7;
- sbit SM1 = SCON^6;
- sbit SM2 = SCON^5;
- sbit REN = SCON^4;
- sbit TB8 = SCON^3;
- sbit RB8 = SCON^2;
- sbit TI = SCON^1;
- sbit RI = SCON^0;
- /* P1 */
- sbit T2EX = P1^1; // 8052 only
- sbit T2 = P1^0; // 8052 only
- /* T2CON */
- sbit TF2 = T2CON^7;
- sbit EXF2 = T2CON^6;
- sbit RCLK = T2CON^5;
- sbit TCLK = T2CON^4;
- sbit EXEN2 = T2CON^3;
- sbit TR2 = T2CON^2;
- sbit C_T2 = T2CON^1;
- sbit CP_RL2 = T2CON^0;
- #endif
- #include<reg52.h>
- #include<intrins.h>
- #include"define.h"
- #include"delay.h"
- #include"12864zifu.h"
- #include"DS1302.h"
- #include"LCD12864.h"
- #include"keyscan.h"
- void main()
- { LCD_init();
- LCD_clear();
- DS_init();
- DS_set_type(1);//有错
- time_init(); //初始化设置时间
- LCD_display8(0,1,1,shu2);
- LCD_display8(0,1,2,shu0);
- LCD_display16(0,1,5,nian);
- LCD_display16(1,1,1,yue);
- LCD_display16(1,1,5,ri);
- LCD_display8(0,2,2,maohao);
- LCD_display8(0,2,5,maohao);
- LCD_display16(1,2,2,xing);
- LCD_display16(1,2,4,qi);
- LCD_display16(0,0,0,zj_xingxing);
- LCD_display16(0,0,2,zj_chang);
- LCD_display16(0,0,4,zj_shu);
- LCD_display16(0,0,6,zj_li);
- LCD_display16(1,0,0,zj_gong);
- LCD_display16(1,0,2,zj_xue);
- LCD_display16(1,0,4,zj_yuan);
- LCD_display16(1,0,6,zj_xingxing);
- LCD_display16(1,3,4,xiaoren);
- LCD_display16(1,3,6,xiaoren);
- while(1)
- { keyscan_manage();
- DS_gettime();
- LCD_display_time();
- }
- }
复制代码
|