HG192646测试程序,KS0108控制器
#include <reg52.h>
#include <stdio.h>
#include <intrins.h>
#include <math.h>
#define uchar unsigned char
#define uint unsigned int
#define buslcd P1
sbit E=P3^0;
sbit RW=P3^1;
sbit RS=P3^3;
sbit CS1=P3^4;
sbit CS2=P3^5;
sbit REST=P3^6;
uchar code tab1[][8]={
0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00, /*"H"=28h*/
0x00,0x3E,0x41,0x41,0x49,0x7A,0x00,0x00, /*"G"=27h*/
0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00, /*"1"=11h*/
0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00, /*"9"=19h*/
0x00,0x42,0x61,0x51,0x49,0x46,0x00,0x00, /*"2"=12h*/
0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00, /*"6"=16h*/
0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00, /*"4"=14h*/
0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00, /*"6"=16h*/
0x00,0x7F,0x49,0x49,0x49,0x49,0x00,0x00, /*"E"=25h*/
0x00,0x41,0x7F,0x41,0x41,0x3E,0x00,0x00, /*"D"=24h*/
0x00,0x00,0x41,0x7F,0x41,0x00,0x00,0x00, /*"I"=29h*/
0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00, /*"T"=34h*/
0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00, /*"O"=2Fh*/
0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00, /*"R"=32h*/
0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00, /*":"=1Ah*/
0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00, /*"M"=2Dh*/
0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00, /*"R"=32h*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*" "=32h*/
0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00, /*"Q"=31h*/
0x00,0x00,0x41,0x7F,0x41,0x00,0x00,0x00, /*"I"=29h*/
0x00,0x7F,0x06,0x08,0x30,0x7F,0x00,0x00, /*"N"=2Eh*/
0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00, /*"Q"=31h*/
0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00, /*"Q"=31h*/
0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00, /*":"=1Ah*/
0x00,0x21,0x41,0x45,0x4B,0x31,0x00,0x00, /*"3"=13h*/
0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00, /*"8"=18h*/
0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00, /*"1"=11h*/
0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00, /*"1"=11h*/
0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00, /*"9"=19h*/
0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00, /*"8"=18h*/
0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00, /*"4"=14h*/
0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00, /*"6"=16h*/
0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00, /*"4"=14h*/
};
uchar code tab[][32]={
/* 点阵:16x16
提取点阵方向:纵向
字节掉转:是
字节方式:C语言 */
0x10,0x10,0xD0,0xFF,0x90,0x10,0x08,0xC8, // 杭
0x49,0x4E,0x48,0xE8,0x4C,0x08,0x00,0x00,
0x04,0x03,0x00,0xFF,0x80,0x41,0x20,0x1F,
0x00,0x00,0x00,0x3F,0x40,0x40,0x70,0x00,
0x80,0x70,0x00,0xFF,0x00,0x10,0x60,0x00, // 州
0xFE,0x00,0x10,0x60,0x00,0xFF,0x00,0x00,
0x00,0x40,0x30,0x0F,0x00,0x00,0x00,0x00,
0x3F,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,
0x10,0x22,0x64,0x0C,0xC0,0x44,0x54,0x54, // 清
0x54,0x7F,0x54,0x54,0xD6,0x44,0x40,0x00,
0x04,0x04,0xFE,0x01,0x00,0x00,0xFF,0x15,
0x15,0x15,0x55,0x95,0x7F,0x01,0x00,0x00,
0x40,0x42,0xCC,0x00,0x20,0x20,0x20,0xA0, // 达
0x7F,0x20,0x20,0x20,0x30,0x20,0x00,0x00,
0x40,0x20,0x1F,0x20,0x50,0x48,0x46,0x41,
0x40,0x41,0x42,0x4C,0x58,0x60,0x20,0x00,
0x40,0x40,0x42,0x44,0x58,0xC0,0x40,0x7F, // 光
0x40,0xC0,0x50,0x48,0x46,0x64,0x40,0x00,
0x00,0x80,0x40,0x20,0x18,0x07,0x00,0x00,
0x00,0x3F,0x40,0x40,0x40,0x40,0x70,0x00,
0x00,0xF8,0x48,0x48,0x48,0x48,0xFF,0x48, // 电
0x48,0x48,0x48,0xFC,0x08,0x00,0x00,0x00,
0x00,0x07,0x02,0x02,0x02,0x02,0x3F,0x42,
0x42,0x42,0x42,0x47,0x40,0x70,0x00,0x00,
0x10,0x22,0x64,0x0C,0x80,0x04,0xC4,0x34, // 液
0x05,0xC6,0xBC,0x24,0x24,0xE6,0x04,0x00,
0x04,0x04,0xFE,0x01,0x02,0x01,0xFF,0x42,
0x21,0x16,0x08,0x15,0x23,0x60,0x20,0x00,
0x00,0x00,0x00,0x00,0xFF,0x49,0x49,0x49, // 晶
0x49,0x49,0xFF,0x00,0x00,0x80,0x00,0x00,
0x00,0xFF,0x49,0x49,0x49,0x49,0xFF,0x00,
0xFF,0x49,0x49,0x49,0x49,0xFF,0x01,0x00,
0x00,0x00,0x00,0xFE,0x92,0x92,0x92,0x92, // 显
0x92,0x92,0x92,0xFF,0x02,0x00,0x00,0x00,
0x40,0x42,0x44,0x4D,0x40,0x7F,0x40,0x40,
0x40,0x7F,0x40,0x49,0x44,0x66,0x40,0x00,
0x40,0x40,0x42,0x42,0x42,0x42,0x42,0xC2, // 示
0x42,0x42,0x42,0x43,0x42,0x60,0x40,0x00,
0x00,0x10,0x08,0x04,0x06,0x40,0x80,0x7F,
0x00,0x00,0x02,0x04,0x0C,0x18,0x00,0x00,
0x10,0x10,0xD0,0xFF,0x94,0x14,0xE4,0xBF, // 模
0xA4,0xA4,0xA4,0xBF,0xF4,0x26,0x04,0x00,
0x04,0x03,0x00,0xFF,0x08,0x89,0x8B,0x4A,
0x2A,0x1E,0x2A,0x2A,0x4B,0xC8,0x48,0x00,
0x20,0x20,0x20,0xFF,0x20,0x20,0x10,0x10, // 块
0xFF,0x10,0x10,0x10,0xF8,0x10,0x00,0x00,
0x08,0x18,0x08,0x0F,0x84,0x46,0x22,0x1A,
0x07,0x0A,0x12,0x22,0x43,0xC2,0x42,0x00,
};
/**** 延时子程序****/
void delay(uint t)
{uint i,j;
for(i=0;i<t;i++)
for(j=0;j<305;j++)
_nop_();_nop_();_nop_();_nop_();
}
/**忙判断****/
void Busy()
{
RS=0;
RW=1;
buslcd=0xff;
E=1;
_nop_();
while(buslcd&0x80);
E=0;
_nop_();
}
/**指令写入 wcom为指令代码 n,m为IC选择位**/
void Writecom(uchar wcom,uchar n,uchar m)
{
if((n==0)&&(m==0))
{CS1=0;CS2=0;}
else if((n==0)&&(m==1))
{CS1=1;CS2=0;}
else
{CS1=0;CS2=1;}
Busy();
buslcd=wcom;
RS=0;
RW=0;
E=1;
_nop_(); _nop_();
E=0;
_nop_();
}
/**数据写入 wdata为数据代码 n,m为IC选择位**/
void Writedata(uchar wdata,uchar n,uchar m)
{
if((n==0)&&(m==0))
{CS1=0;CS2=0;}
else if((n==0)&&(m==1))
{CS1=1;CS2=0;}
else
{CS1=0;CS2=1;}
Busy();
buslcd=wdata;
RS=1;
RW=0;
E=1;
_nop_();_nop_();
E=0;
_nop_();}
/**数据读出 wdata为数据代码 n,m为IC选择位**/
uchar Readdata(uchar n,uchar m)
{
uchar rdata;
if((n==0)&&(m==0))
{CS1=0;CS2=0;}
else if((n==0)&&(m==1))
{CS1=1;CS2=0;}
else
{CS1=0;CS2=1;}
Busy();
buslcd=rdata;
RS=1;
RW=1;
E=1;
_nop_();_nop_();_nop_();
E=0;
_nop_();
return rdata;
}
/**** 清除 ****/
void clear(void)
{uchar i,j;
for(i=0;i<8;i++)
{Writecom(0xb8+i,0,0);Writecom(0x40,0,0);
Writecom(0xb8+i,0,1);Writecom(0x40,0,1);
Writecom(0xb8+i,1,0);Writecom(0x40,1,0);
for(j=0;j<64;j++)
{Writedata(0x00,0,0);
Writedata(0x00,0,1);
Writedata(0x00,1,0);}}}
/** 初始化**/
void INT()
{
delay(3);
Writecom(0x3f,0,0);Writecom(0x3f,0,1);Writecom(0x3f,1,0);
Writecom(0xc0,0,0);Writecom(0xc0,0,1);Writecom(0xc0,1,0);
clear();}
/****************写入16*16汉字*********/
void hz16(uchar x,uchar y,uchar coder)
{ uchar i,n,m;
uchar j=1;
n=x;m=y;
for(i=0;i<16;i++)
{ if(x>127)
{Writecom(0xb8+y,1,0);
Writecom((x-128)|0x40,1,0);
Writedata(tab[coder][i],1,0);}
else if(x>63)
{Writecom(0xb8+y,0,1);
Writecom((x-64)|0x40,0,1);
Writedata(tab[coder][i],0,1);}
else
{Writecom(0xb8+y,0,0);
Writecom(x|0x40,0,0);
Writedata(tab[coder][i],0,0);}
x++;}
x=n;y=m+1;
_nop_();
for(i=0;i<16;i++)
{if(x>127)
{Writecom(0xb8+y,1,0);
Writecom((x-128)|0x40,1,0);
Writedata(tab[coder][i+(j<<4)],1,0);}
else if(x>63)
{Writecom(0xb8+y,0,1);
Writecom((x-64)|0x40,0,1);
Writedata(tab[coder][i+(j<<4)],0,1);}
else
{Writecom(0xb8+y,0,0);
Writecom(x|0x40,0,0);
Writedata(tab[coder][i+(j<<4)],0,0);}
x++;}}
/**********写入 一串16*16汉字*******************/
void hz1616(uchar x,uchar y,uchar m,uchar mend)
{
uchar i;
for(i=m;i<mend;i++)
{hz16(x,y,i);x=x+16;}}
/*************写入 8*8字母************/
void hz8(uchar x,uchar y,uchar coder)
{
uchar i;
for(i=0;i<8;i++)
{ if(x>127)
{ Writecom(0xb8+y,1,0);
Writecom((x-128)|0x40,1,0);
Writedata(tab1[coder][i],1,0);}
else if(x>63)
{Writecom(0xb8+y,0,1);
Writecom((x-64)|0x40,0,1);
Writedata(tab1[coder][i],0,1);}
else
{Writecom(0xb8+y,0,0);
Writecom(x|0x40,0,0);
Writedata(tab1[coder][i],0,0);}
x++;}}
/******************写入 一串 8*8字母**********/
void hz88(uchar x,uchar y,uchar m,uchar mend)
{ uchar i;
for(i=m;i<mend;i++)
{hz8(x,y,i);x=x+8;}}
/**主函数**/
void main()
{
REST=0;
delay(1);
REST=1;
_nop_();
_nop_();
INT();
hz1616(0,0,0,12);
hz1616(0,6,0,12);
hz88(10,3,0,8);
hz88(96,3,21,33);
hz88(120,5,0,8);
hz88(0,5,8,21);
while(1);
}