- /*T6963C 液晶驱动Keil C源代码
- 线路图
- 89C51 T6963C
- --------
- | 8
- P1.0-1.7|=========== D0-7
- |
- P3.0|----------- /RD
- P3.1|----------- /WR
- P3.2|----------- C/D
- | -- /CE
- | |
- | ---
- P3.3|----------- /RESET
- | VCC--- /HALT
- --------
- */
- #include <reg8751.h>
- #include <math.h>
- #include <intrins.h>
- sbit cd=P3^2;
- sbit wr=P3^1;
- sbit rd=P3^0;
- sbit reset=P3^3;
- sbit vee=P3^7;
- sbit scl=P3^2;
- sbit sda=P3^3;
- unsigned int time;
- unsigned char x,y;
- /* 忙标志 */
- #pragma disable
- unsigned char busy(void) {
- unsigned char dat;
- cd=1;rd=1;wr=1;
- P0=0xff;
- rd=0;
- dat=P0;
- rd=1;
- return(dat);
- }
- /* 数据,指令读写判别 */
- #pragma disable
- void p1(void) {
- while ((busy()&3)!=3) {}
- }
- /* 数据自动读判别 */
- #pragma disable
- void p2(void) {
- while ((busy()&4)!=4) {}
- }
- /* 数据自动写判别 */
- #pragma disable
- void p3(void) {
- while ((busy()&8)!=8) {}
- }
- /* 控制指令 */
- #pragma disable
- void ctrl(unsigned char dat) {
- p1();
- cd=1;
- wr=0;
- P0=dat;
- wr=1;
- }
- /* 写数据 */
- #pragma disable
- void write(unsigned char dat) {
- p1();
- cd=0;
- wr=0;
- P0=dat;
- wr=1;
- cd=1;
- }
- /* 自动写 */
- #pragma disable
- void autowrite(unsigned char dat) {
- p3();
- cd=0;
- wr=0;
- P0=dat;
- wr=1;
- cd=1;
- }
- /* 读数据 */
- #pragma disable
- unsigned char read(void) {
- unsigned char dat;
- p1();
- cd=0;
- P0=0xff;
- rd=0;
- dat=P0;
- rd=1;
- cd=1;
- return(dat);
- }
- /* 自动读数据 */
- #pragma disable
- unsigned char autoread(void) {
- unsigned char dat;
- p2();
- cd=0;
- P0=0xff;
- rd=0;
- dat=P0;
- rd=1;
- cd=1;
- return(dat);
- }
- /* 显示图形和文本 */
- #pragma disable
- void disp(unsigned char d) { /*显示*/
- write(d);ctrl(0xc0);
- }
- /* 设定图形x,y值*/
- #pragma disable
- void ag(unsigned char x,unsigned char y) { /*地址*/
- unsigned int xy;
- xy=y;
- xy=xy*16+x+256;
- write(xy&0xff);write(xy/256);ctrl(0x24);
- }
- /* 设定文本x,y值 */
- #pragma disable
- void at(unsigned char x,unsigned char y) { /*地址*/
- write(y*16+x);write(0);ctrl(0x24);
- }
- /* 点亮一点 */
- #pragma disable
- void setb(unsigned char d) {
- ctrl(0xf8|d);
- }
- /* 清除一点*/
- #pragma disable
- void clrb(unsigned char d) {
- ctrl(0xf0|d);
- }
- /* x,y处显示光标 */
- #pragma disable
- void ab(unsigned char x,unsigned char y) { /*光标*/
- ctrl(0x97); /*光标开*/
- write(x);write(y);ctrl(0x21);
- }
- /* 取消光标 */
- #pragma disable
- void noab(void) {
- ctrl(0x9c);
- }
- /* lcd初始化 */
- void init(void) {
- unsigned int i;
- reset=0;
- reset=1;
- write(0x0);write(0);ctrl(0x40); /*文本首址*/
- write(0x10);write(0x0);ctrl(0x41); /*文本区域*/
- write(0x0);write(0x1);ctrl(0x42); /*图形首址*/
- write(0x10);write(0x0);ctrl(0x43); /*图形区域*/
- ctrl(0x81); /*显示方式*/
- ctrl(0x90); /*显示开关*/
- ctrl(0xa0); /*光标形状*/
- at(0,0);
- ctrl(0xb0); /*自动写方式*/
- for (i=0;i<1280;i++) {
- autowrite(0x0);
- }
- ctrl(0xb2);/*结束自动写方式 */
- ctrl(0x9c);
- }
- void wait10(void) {
- time=0;
- while (time<10) {}
- }
- unsigned char temp;
- unsigned char code asc16[]={
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,126,129,165,129,129,189,153,129,129,126,0,0,0,0,
- 0,0,126,255,219,255,255,195,231,255,255,126,0,0,0,0,
- 0,0,0,0,108,254,254,254,254,124,56,16,0,0,0,0,
- 0,0,0,0,16,56,124,254,124,56,16,0,0,0,0,0,
- 0,0,0,24,60,60,231,231,231,24,24,60,0,0,0,0,
- 0,0,0,24,60,126,255,255,126,24,24,60,0,0,0,0,
- 0,0,0,0,0,0,24,60,60,24,0,0,0,0,0,0,
- 255,255,255,255,255,255,231,195,195,231,255,255,255,255,255,255,
- 0,0,0,0,0,60,102,66,66,102,60,0,0,0,0,0,
- 255,255,255,255,255,195,153,189,189,153,195,255,255,255,255,255,
- 0,0,30,14,26,50,120,204,204,204,204,120,0,0,0,0,
- 0,0,60,102,102,102,102,60,24,126,24,24,0,0,0,0,
- 0,0,63,51,63,48,48,48,48,112,240,224,0,0,0,0,
- 0,0,127,99,127,99,99,99,99,103,231,230,192,0,0,0,
- 0,0,0,24,24,219,60,231,60,219,24,24,0,0,0,0,
- 0,128,192,224,240,248,254,248,240,224,192,128,0,0,0,0,
- 0,2,6,14,30,62,254,62,30,14,6,2,0,0,0,0,
- 0,0,24,60,126,24,24,24,126,60,24,0,0,0,0,0,
- 0,0,102,102,102,102,102,102,102,0,102,102,0,0,0,0,
- 0,0,127,219,219,219,123,27,27,27,27,27,0,0,0,0,
- 0,124,198,96,56,108,198,198,108,56,12,198,124,0,0,0,
- 0,0,0,0,0,0,0,0,254,254,254,254,0,0,0,0,
- 0,0,24,60,126,24,24,24,126,60,24,126,0,0,0,0,
- 0,0,24,60,126,24,24,24,24,24,24,24,0,0,0,0,
- 0,0,24,24,24,24,24,24,24,126,60,24,0,0,0,0,
- 0,0,0,0,0,24,12,254,12,24,0,0,0,0,0,0,
- 0,0,0,0,0,48,96,254,96,48,0,0,0,0,0,0,
- 0,0,0,0,0,0,192,192,192,254,0,0,0,0,0,0,
- 0,0,0,0,0,40,108,254,108,40,0,0,0,0,0,0,
- 0,0,0,0,16,56,56,124,124,254,254,0,0,0,0,0,
- 0,0,0,0,254,254,124,124,56,56,16,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,24,60,60,60,24,24,24,0,24,24,0,0,0,0,
- 0,102,102,102,36,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,108,108,254,108,108,108,254,108,108,0,0,0,0,
- 24,24,124,198,194,192,124,6,6,134,198,124,24,24,0,0,
- 0,0,0,0,194,198,12,24,48,96,198,134,0,0,0,0,
- 0,0,56,108,108,56,118,220,204,204,204,118,0,0,0,0,
- 0,48,48,48,96,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,12,24,48,48,48,48,48,48,24,12,0,0,0,0,
- 0,0,48,24,12,12,12,12,12,12,24,48,0,0,0,0,
- 0,0,0,0,0,102,60,255,60,102,0,0,0,0,0,0,
- 0,0,0,0,0,24,24,126,24,24,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,24,24,24,48,0,0,0,
- 0,0,0,0,0,0,0,254,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,24,24,0,0,0,0,
- 0,0,0,0,2,6,12,24,48,96,192,128,0,0,0,0,
- 0,0,56,108,198,198,214,214,198,198,108,56,0,0,0,0,
- 0,0,24,56,120,24,24,24,24,24,24,126,0,0,0,0,
- 0,0,124,198,6,12,24,48,96,192,198,254,0,0,0,0,
- 0,0,124,198,6,6,60,6,6,6,198,124,0,0,0,0,
- 0,0,12,28,60,108,204,254,12,12,12,30,0,0,0,0,
- 0,0,254,192,192,192,252,6,6,6,198,124,0,0,0,0,
- 0,0,56,96,192,192,252,198,198,198,198,124,0,0,0,0,
- 0,0,254,198,6,6,12,24,48,48,48,48,0,0,0,0,
- 0,0,124,198,198,198,124,198,198,198,198,124,0,0,0,0,
- 0,0,124,198,198,198,126,6,6,6,12,120,0,0,0,0,
- 0,0,0,0,24,24,0,0,0,24,24,0,0,0,0,0,
- 0,0,0,0,24,24,0,0,0,24,24,48,0,0,0,0,
- 0,0,0,6,12,24,48,96,48,24,12,6,0,0,0,0,
- 0,0,0,0,0,126,0,0,126,0,0,0,0,0,0,0,
- 0,0,0,96,48,24,12,6,12,24,48,96,0,0,0,0,
- 0,0,124,198,198,12,24,24,24,0,24,24,0,0,0,0,
- 0,0,0,124,198,198,222,222,222,220,192,124,0,0,0,0,
- 0,0,16,56,108,198,198,254,198,198,198,198,0,0,0,0,
- 0,0,252,102,102,102,124,102,102,102,102,252,0,0,0,0,
- 0,0,60,102,194,192,192,192,192,194,102,60,0,0,0,0,
- 0,0,248,108,102,102,102,102,102,102,108,248,0,0,0,0,
- 0,0,254,102,98,104,120,104,96,98,102,254,0,0,0,0,
- 0,0,254,102,98,104,120,104,96,96,96,240,0,0,0,0,
- 0,0,60,102,194,192,192,222,198,198,102,58,0,0,0,0,
- 0,0,198,198,198,198,254,198,198,198,198,198,0,0,0,0,
- 0,0,60,24,24,24,24,24,24,24,24,60,0,0,0,0,
- 0,0,30,12,12,12,12,12,204,204,204,120,0,0,0,0,
- 0,0,230,102,102,108,120,120,108,102,102,230,0,0,0,0,
- 0,0,240,96,96,96,96,96,96,98,102,254,0,0,0,0,
- 0,0,198,238,254,254,214,198,198,198,198,198,0,0,0,0,
- 0,0,198,230,246,254,222,206,198,198,198,198,0,0,0,0,
- 0,0,124,198,198,198,198,198,198,198,198,124,0,0,0,0,
- 0,0,252,102,102,102,124,96,96,96,96,240,0,0,0,0,
- 0,0,124,198,198,198,198,198,198,214,222,124,12,14,0,0,
- 0,0,252,102,102,102,124,108,102,102,102,230,0,0,0,0,
- 0,0,124,198,198,96,56,12,6,198,198,124,0,0,0,0,
- 0,0,126,126,90,24,24,24,24,24,24,60,0,0,0,0,
- 0,0,198,198,198,198,198,198,198,198,198,124,0,0,0,0,
- 0,0,198,198,198,198,198,198,198,108,56,16,0,0,0,0,
- 0,0,198,198,198,198,214,214,214,254,238,108,0,0,0,0,
- 0,0,198,198,108,124,56,56,124,108,198,198,0,0,0,0,
- 0,0,102,102,102,102,60,24,24,24,24,60,0,0,0,0,
- 0,0,254,198,134,12,24,48,96,194,198,254,0,0,0,0,
- 0,0,60,48,48,48,48,48,48,48,48,60,0,0,0,0,
- 0,0,0,128,192,224,112,56,28,14,6,2,0,0,0,0,
- 0,0,60,12,12,12,12,12,12,12,12,60,0,0,0,0,
- 16,56,108,198,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,
- 48,48,24,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,120,12,124,204,204,204,118,0,0,0,0,
- 0,0,224,96,96,120,108,102,102,102,102,124,0,0,0,0,
- 0,0,0,0,0,124,198,192,192,192,198,124,0,0,0,0,
- 0,0,28,12,12,60,108,204,204,204,204,118,0,0,0,0,
- 0,0,0,0,0,124,198,254,192,192,198,124,0,0,0,0,
- 0,0,56,108,100,96,240,96,96,96,96,240,0,0,0,0,
- 0,0,0,0,0,118,204,204,204,204,204,124,12,204,120,0,
- 0,0,224,96,96,108,118,102,102,102,102,230,0,0,0,0,
- 0,0,24,24,0,56,24,24,24,24,24,60,0,0,0,0,
- 0,0,6,6,0,14,6,6,6,6,6,6,102,102,60,0,
- 0,0,224,96,96,102,108,120,120,108,102,230,0,0,0,0,
- 0,0,56,24,24,24,24,24,24,24,24,60,0,0,0,0,
- 0,0,0,0,0,236,254,214,214,214,214,198,0,0,0,0,
- 0,0,0,0,0,220,102,102,102,102,102,102,0,0,0,0,
- 0,0,0,0,0,124,198,198,198,198,198,124,0,0,0,0,
- 0,0,0,0,0,220,102,102,102,102,102,124,96,96,240,0,
- 0,0,0,0,0,118,204,204,204,204,204,124,12,12,30,0,
- 0,0,0,0,0,220,118,102,96,96,96,240,0,0,0,0,
- 0,0,0,0,0,124,198,96,56,12,198,124,0,0,0,0,
- 0,0,16,48,48,252,48,48,48,48,54,28,0,0,0,0,
- 0,0,0,0,0,204,204,204,204,204,204,118,0,0,0,0,
- 0,0,0,0,0,102,102,102,102,102,60,24,0,0,0,0,
- 0,0,0,0,0,198,198,214,214,214,254,108,0,0,0,0,
- 0,0,0,0,0,198,108,56,56,56,108,198,0,0,0,0,
- 0,0,0,0,0,198,198,198,198,198,198,126,6,12,248,0,
- 0,0,0,0,0,254,204,24,48,96,198,254,0,0,0,0,
- 0,0,14,24,24,24,112,24,24,24,24,14,0,0,0,0,
- 0,0,24,24,24,24,0,24,24,24,24,24,0,0,0,0,
- 0,0,112,24,24,24,14,24,24,24,24,112,0,0,0,0,
- 0,0,118,220,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,16,56,108,198,198,198,254,0,0,0,0,0
- };
- /* 显示8*16点阵英文字母,反白 */
- void da(unsigned char n,bit un) {
- unsigned char i;
- unsigned int k=n;
- for (i=0;i<16;i++) {
- ag(x,y*8+i);
- if (un==0) disp(asc16[k*16+i]); else disp(255-asc16[k*16+i]);
- }
- if ((++x)>=16) {
- x=0;
- y+=2;
- if (y>=8) y=0;
- }
- }
- /* 反白文本/取消 */
- void da8(unsigned char n,bit un) {
- unsigned char i,j;
- for (j=0;j<n;j++) {
- for (i=0;i<8;i++) {
- ag(x,y*8+i);
- if (un==0) disp(0xff); else disp(0x0);
- }
- if ((++x)>=16) {
- x=0;
- y+=1;
- if (y>=8) y=0;
- }
- }
- }
- unsigned char code fot[]={
- /*0时*/0x0,0x8,0x4,0x8,0x7e,0x8,0x44,0x8,0x47,0xfe,0x44,0x8,0x44,0x8,0x7c,0x88,0x44,0x48,
- 0x44,0x48,0x44,0x8,0x44,0x8,0x7c,0x8,0x44,0x48,0x0,0x28,0x0,0x10,
- /*1间*/0x20,0x4,0x1b,0xfe,0x8,0x4,0x40,0x24,0x4f,0xf4,0x48,0x24,0x48,0x24,0x48,0x24,
- 0x4f,0xe4,0x48,0x24,0x48,0x24,0x48,0x24,0x4f,0xe4,0x48,0x24,0x40,0x14,0x40,0x8,
- /*2日*/0x0,0x10,0x1f,0xf8,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1f,0xf0,
- 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1f,0xf0,0x10,0x10,0x0,0x0,
- /*3期*/0x22,0x4,0x22,0x7e,0x22,0x44,0x7f,0x44,0x22,0x44,0x3e,0x7c,0x22,0x44,0x3e,0x44,
- 0x22,0x44,0x22,0x7c,0xff,0xc4,0x0,0x44,0x24,0x44,0x22,0x84,0x41,0x14,0x82,0x8,
- /*4闹*/0x40,0x4,0x37,0xfe,0x10,0x4,0x42,0x4,0x41,0x24,0x5f,0xf4,0x41,0x4,0x41,0x24,
- 0x4f,0xf4,0x49,0x24,0x49,0x24,0x49,0x24,0x49,0x64,0x41,0x4,0x41,0x14,0x40,0x8,
- /*5钟*/0x10,0x20,0x10,0x20,0x10,0x20,0x1c,0x24,0x21,0xfe,0x21,0x24,0x7d,0x24,0x91,0x24,
- 0x11,0x24,0xfd,0xfc,0x11,0x24,0x10,0x20,0x14,0x20,0x18,0x20,0x10,0x20,0x0,0x20,
- /*6设*/0x1,0xf0,0x21,0x10,0x11,0x10,0x11,0x10,0x1,0x10,0x2,0xe,0xf4,0x0,0x13,0xf8,
- 0x11,0x8,0x11,0x10,0x10,0x90,0x10,0xa0,0x14,0x40,0x18,0xb0,0x13,0xe,0xc,0x4,
- /*7定*/0x2,0x0,0x1,0x0,0x7f,0xfe,0x40,0x2,0x80,0x24,0x1f,0xf0,0x1,0x0,0x1,0x0,
- 0x11,0x20,0x11,0xf0,0x11,0x0,0x11,0x0,0x11,0x0,0x29,0x6,0x47,0xfc,0x80,0x0,
- /*8开*/0x0,0x8,0x7f,0xfc,0x8,0x20,0x8,0x20,0x8,0x20,0x8,0x20,0x8,0x24,0xff,0xfe,
- 0x8,0x20,0x8,0x20,0x8,0x20,0x8,0x20,0x10,0x20,0x10,0x20,0x20,0x20,0x40,0x20,
- /*9关*/0x10,0x10,0x8,0x18,0x4,0x20,0x4,0x48,0x7f,0xfc,0x1,0x0,0x1,0x0,0x1,0x4,
- 0xff,0xfe,0x1,0x0,0x2,0x80,0x2,0x80,0x4,0x40,0x8,0x30,0x30,0xe,0xc0,0x4,
- /*10星*/0x0,0x8,0x3f,0xfc,0x20,0x8,0x3f,0xf8,0x20,0x8,0x3f,0xf8,0x1,0x0,0x21,0x8,
- 0x3f,0xfc,0x21,0x0,0x41,0x10,0xbf,0xf8,0x1,0x0,0x1,0x4,0xff,0xfe,0x0,0x0,
- /*11温*/0x0,0x8,0x43,0xfc,0x32,0x8,0x12,0x8,0x83,0xf8,0x62,0x8,0x22,0x8,0xb,0xf8,
- 0x10,0x0,0x27,0xfc,0xe4,0xa4,0x24,0xa4,0x24,0xa4,0x24,0xa4,0x2f,0xfe,0x20,0x0,
- /*12度*/0x1,0x0,0x0,0x84,0x3f,0xfe,0x22,0x20,0x22,0x28,0x3f,0xfc,0x22,0x20,0x23,0xe0,
- 0x20,0x0,0x2f,0xf0,0x22,0x20,0x21,0x40,0x20,0x80,0x43,0x60,0x8c,0x1e,0x30,0x4,
- /*13亮*/0x1,0x8,0x7f,0xfc,0x0,0x10,0x1f,0xf8,0x10,0x10,0x10,0x10,0x1f,0xf0,0x0,0x0,
- 0x7f,0xfe,0x40,0x22,0x8f,0xf4,0x8,0x20,0x8,0x20,0x8,0x22,0x10,0x22,0x60,0x1e,
- /*14湿*/0x0,0x8,0x47,0xfc,0x34,0x8,0x14,0x8,0x87,0xf8,0x64,0x8,0x24,0x8,0xf,0xf8,
- 0x11,0x20,0x21,0x20,0xe9,0x24,0x25,0x28,0x23,0x30,0x21,0x24,0x3f,0xfe,0x20,0x0,
- /*15报*/0x10,0x8,0x11,0xfc,0x11,0x8,0x11,0x8,0xfd,0x28,0x11,0x10,0x15,0x0,0x19,0xf8,
- 0x31,0x8,0xd1,0x90,0x11,0x50,0x11,0x20,0x11,0x50,0x11,0x8e,0x51,0x4,0x21,0x0,
- /*16警*/0x14,0x40,0x7f,0x7c,0x10,0xc8,0x3f,0x28,0x55,0x10,0x1d,0x6e,0x3,0x4,0xff,0xfe,
- 0x0,0x0,0x1f,0xf0,0x0,0x0,0x1f,0xf0,0x0,0x0,0x1f,0xf0,0x10,0x10,0x1f,0xf0,
- /*17火*/0x1,0x0,0x1,0x0,0x1,0x0,0x1,0x0,0x11,0x8,0x11,0x18,0x11,0x20,0x21,0x40,
- 0x42,0x80,0x2,0x80,0x4,0x40,0x4,0x40,0x8,0x20,0x10,0x10,0x20,0xe,0x40,0x4,
- /*18盗*/0x1,0x0,0x41,0x8,0x33,0xfc,0x12,0x48,0x4,0x40,0x10,0xa0,0x21,0x10,0xc6,0xe,
- 0x40,0x4,0x1f,0xf0,0x12,0x90,0x12,0x90,0x12,0x90,0x12,0x94,0xff,0xfe,0x0,0x0,
- /*19煤*/0x21,0x10,0x21,0x10,0x21,0x10,0x27,0xfc,0xf9,0x10,0x49,0xf0,0x49,0x10,0x49,0xf0,
- 0x48,0x44,0x8f,0xfe,0x50,0x40,0x20,0xe0,0x51,0x50,0x4a,0x4e,0x84,0x44,0x0,0x40,
- /*20气*/0x10,0x0,0x10,0x8,0x1f,0xfc,0x20,0x0,0x2f,0xf0,0x40,0x0,0xbf,0xe0,0x0,0x20,
- 0x0,0x20,0x0,0x20,0x0,0x20,0x0,0x20,0x0,0x22,0x0,0x12,0x0,0xa,0x0,0x53,
- /*21紧*/0x4,0x0,0x25,0xf8,0x25,0x10,0x24,0xa0,0x24,0x40,0x24,0xb0,0x7,0xe,0x4,0x24,
- 0x1f,0xc0,0x1,0x0,0x2,0x10,0x7f,0xf8,0x1,0x8,0x9,0x20,0x11,0x18,0x63,0x8,
- /*22急*/0x4,0x0,0x4,0x0,0xf,0xe0,0x8,0x40,0x10,0x88,0x3f,0xfc,0x40,0x8,0x1f,0xf8,
- 0x0,0x8,0x3f,0xf8,0x2,0x0,0x51,0x84,0x50,0x92,0x90,0x12,0xf,0xf0,0x0,0x0,
- /*23电*/0x2,0x0,0x2,0x0,0x2,0x10,0x7f,0xf8,0x42,0x10,0x42,0x10,0x7f,0xf0,0x42,0x10,
- 0x42,0x10,0x7f,0xf0,0x42,0x10,0x2,0x0,0x2,0x4,0x2,0x4,0x1,0xfc,0x0,0x0,
- /*24话*/0x0,0x10,0x40,0x38,0x33,0xc0,0x10,0x40,0x0,0x40,0x0,0x44,0xf7,0xfe,0x10,0x40,
- 0x10,0x48,0x13,0xfc,0x12,0x8,0x12,0x8,0x16,0x8,0x1a,0x8,0x13,0xf8,0x2,0x8
- };
- /* 显示16*16点阵汉字,反白 */
- void dh(unsigned char n,bit un) {
- unsigned char i,j;
- unsigned int k=n;
- for (i=0;i<16;i++) {
- for (j=0;j<2;j++) {
- ag(j+x,y*8+i);
- if (un==0) disp(fot[k*32+i*2+j]); else disp(255-fot[k*32+i*2+j]);
- }
- }
- x+=2;
- if (x>=16) {
- x=0;
- y+=2;
- if (y>=8) y=0;
- }
- }
- /* 划线 */
- void line(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1) {
- unsigned char x=x1-x0,y=y1-y0,xx,temp;
- float yy;
- if (x>y) {
- yy=y0;
- for (xx=x0;xx<x1;xx++) {
- yy+=(float)y/x;
- ag((xx/8),yy);
- setb((7-xx&7));
- }
- } else {
- yy=x0;
- for (xx=y0;xx<y1;xx++) {
- yy+=(float)x/y;
- ag(yy/8,xx);
- setb((7-(char)yy&7));
- }
- }
- }
- //==============================================
- unsigned char kpush;
- unsigned char code key[]={0,237,221,189,125,231,215,183,119,
- 238,222,190,126,235,219,187,123};
- void scankey(void) {
- unsigned char lie,knew=0;
- P1=0xf;
- if ((P1&0xf)!=0xf) {
- wait10();
- if ((lie=P1&0xf)!=0xf) {
- P1=0xf0;
- knew=P1&0xf0|lie;
- }
- }
- for (lie=0;lie<17;lie++) {
- if (knew==key[lie]) break;
- }
- kpush=lie;
- }
- /* 定时器0中断 */
- unsigned char s,m,h;
- unsigned int s001;
- void int_t0(void) interrupt 1 {
- TL0+=48;TH0=0xf8;
- time++;
- if ((++s001)>=1000) {
- s001=0;
- if ((++s)>59) {
- s=0;
- if ((++m)>59) {
- m=0;
- if ((++h)>23) h=0;
- }
- }
- }
- }
- /* 定时器1中断,现用于lcd负压 */
- /* 该部分线路图整理中*/
- void int_t1(void) interrupt 3 {
- P3=P3^0xc0;
- }
- void main(void) {
- unsigned char i,j;
- TMOD=0x21;
- TH1=0;PT0=1;
- P3=0x7f;
- EA=1;
- ET0=1;TR0=1;
- ET1=1;TR1=1;
- init();
- dh(10,0);
- dh(3,0);
- da(' ',0);
- da('1',0);
- at(7,0);
- disp('1'-0x20);
- disp('2'-0x20);
- disp(':'-0x20);
- disp('5'-0x20);
- disp('9'-0x20);
- disp(' '-0x20);
- disp('o'-0x20);
- disp('n'-0x20);
- at(7,1);
- disp('1'-0x20);
- disp('2'-0x20);
- disp(':'-0x20);
- disp('5'-0x20);
- disp('9'-0x20);
- disp(' '-0x20);
- disp('o'-0x20);
- disp('f'-0x20);
- disp('f'-0x20);
- line(53,0,53,18);
- line(0,18,128,18);
- x=0;y=3;
- dh(0,0);
- dh(1,0);
- x=0;y=6;
- dh(2,0);
- dh(3,0);
- da(' ',0);
- da('1',0);
- da('9',0);
- da('9',0);
- da('8',0);
- da('-',0);
- da('1',0);
- da('2',0);
- da('-',0);
- da('2',0);
- da('9',0);
- // for (i=0;i<128;i++) {
- // da(i,i%16,i/16*2);
- // }
- // while (1) {}
- // at(0,2);
- // for (i=0;i<16;i++) disp('='-0x20);
- // for (i=0;i<8;i++) {
- // dh(i,i*2,0);
- // dh(i+8,i*2,2);
- // dh(i+16,i*2,4);
- // dh(i+24,i*2,6);
- // }
- // while (1) {}
- x=13;
- y=1;
- da8(3,0);
- while (1) {
- scankey();
- if (kpush==1) {
- x=0;y=0;
- dh(10,1);
- dh(3,1);
- } else if (kpush==2) {
- x=0;y=3;
- dh(0,1);
- dh(1,1);
- }
- x=6;y=3;
- da(h/10+0x30,0);
- da(h%10+0x30,0);
- da(':',0);
- da(m/10+0x30,0);
- da(m%10+0x30,0);
- da(':',0);
- da(s/10+0x30,0);
- da(s%10+0x30,0);
- }
- }