电子大神的日记本,供应链专家的功夫茶盘,在这里记录、分享与共鸣。

登录以开始

JE-AN12864驱动

attachment download  接口说明

在一乐买了个拆机的12864,便宜吐舌头,15块钱。是ks0108的控制器,比st7920的性价比高不少。

=702) window.open('http://bbs.mydigit.cn/attachment/Mon\_1007/108\_7452\_7dd2a4bbfdfb144.jpg');" src="http://bbs.mydigit.cn/attachment/Mon\_1007/108\_7452\_7dd2a4bbfdfb144.jpg" border=0>

=702) window.open('http://bbs.mydigit.cn/attachment/Mon\_1007/108\_7452\_664e026a58cf97f.jpg');" src="http://bbs.mydigit.cn/attachment/Mon\_1007/108\_7452\_664e026a58cf97f.jpg" border=0>

//液晶屏是JEAN12864,左右屏片选是低电平有效

//列行式取模,即先逐列取每个字符的上一半,在逐列取每个字符的下一半

//By Paul

//2011.3.31

#include<reg52.h>
#include<intrins.h>

typedef unsigned int uint;
typedef unsigned char uchar;

#define  NOP()    _nop_()

typedef struct GB12
{
 char GB_Index[2];
 char GB_Msk[24];
};

#define HZKCD 13   //汉字库长度为11,汉字库长度改变时这里也需要改变
code struct GB12 GB_code[HZKCD];  //12*12中文数组
code uchar ascii_code[128][12];//6*12字符数组

/****************端口定义*************************/

#define LCD_DIO P0
sbit LCD_EN = P1^5;
sbit LCD_RW = P1^3;
sbit LCD_RS = P1^4;
sbit LCD_CS2 = P1^1;
sbit LCD_CS1 = P1^0;
sbit LCD_RST = P1^2;
sbit BUSY = P0^7;

/*******************内部函数**********************************/

void LCD_SEL_Left(); //选择左屏  ,Proteus里有两种ks0108的LCD,JEAN12864是低选通那种
void LCD_SEL_Right();//选择右屏
void LCD_SEL_NON();  //两个屏都不选择
void LCD_BUSY();   //液晶判忙
void LCD_Write_COM(uchar cmd);   //写入一个字节命令数据
void LCD_Write_BYTE(uchar byte);  //写入一个字节数据
void LCD_write_char(uchar x,uchar y,uchar index,uchar fanbai);//在x(0~19)列y(0~3)行显示一个6*12的西文字符 
void LCD_Write_CH(uchar x,uchar y,uchar *chh,uchar fanbai);//在x(0~9)列y(0~3)行写入一个12*12的中文字符,列数据仍然是送16位的,所以还是显示四行,一行可以显示10个中文

/************************************************************/

/*******************外部函数**********************************/

void LCD_write_str(uchar x,uchar y,uchar *str,uchar fanbai);  //显示连续的英文字符串
void LCD_write_chinese(uchar x,uchar y,uchar *che,uchar fanbai);//显示中文字符串,fanbai为255时反白显示
void LCD_clear();  //半屏写入0x00
void LCD_cls();    //清屏
void LCD_PORT_init();  //液晶端口初始化
void LCD_init();   //液晶初始化
 
/************************************************************/

void delay_nms(uint t);  //延时nms
void delay_nus(uchar tt);

void main()
{
  delay_nms(100);
  LCD_init();  //液晶初始化
  LCD_write_chinese(0,2,"中华人民",255);
  LCD_write_str(8,2,"123456",255);
  LCD_write_str(0,0,"abcdefghijklmnopqrst",0);
  LCD_write_str(0,1,"uvwxyz0123456789",255);
  delay_nms(1000);
  delay_nus(1);
  //LCD_cls();
  while(1);

}

void delay_nms(uint t)
{
 uchar m,n;
 uint t1;
 for(t1=t;t1>0;t1--)
   for(m=0;m<3;m++)
     for(n=0;n<108;n++)
       ;
}

void delay_nus(uchar tt)   //us???
{
 uchar t2=tt;
 while(t2--);
}

void LCD_SEL_Left() //选择左屏  ,Proteus里有两种LCD,JEAN12864是低选通那种
{
 LCD_CS1=0;
 LCD_CS2=1;
 NOP();
}

void LCD_SEL_Right()//选择右屏
{
 LCD_CS1=1;
 LCD_CS2=0;
 NOP();
}

void LCD_SEL_NON()  //两个屏都不选择
{
 LCD_CS1=1;
 LCD_CS2=1;
 NOP();
}

void LCD_BUSY() //LCD判忙子程序
{              
 uchar i;
 LCD_DIO=0xff; //输入
 LCD_RS=0;    //状态
 LCD_RW=1;    //读
 NOP();
 LCD_EN=1;  //空读操作
 NOP();
 LCD_EN=0;
 NOP();
 
 for(i=0;i<20;i++)  //循环读状态
 {
  LCD_EN=1;
  NOP();
  if(BUSY==0)break;
  LCD_EN=0;
  NOP();
 }
 
 LCD_EN=0;
 NOP();
}

void LCD_Write_COM(uchar cmd)  //写命令
{
 LCD_BUSY(); //判忙
 LCD_RW=0;   //写
 LCD_RS=0;   //命令
 LCD_DIO=cmd;
 LCD_EN=1;
 LCD_EN=0;
}

void LCD_Write_BYTE(uchar byte)  //写一个字节数据
{
 LCD_BUSY();//判忙
 LCD_RW=0;  //写
 LCD_RS=1;  //数据
 LCD_DIO=byte;
 LCD_EN=1;
 LCD_EN=0;
}

void LCD_write_char(uchar x,uchar y,uchar index,uchar fanbai)  //在x列y行显示一个6*12的西文字符,fanbai为255时显示反白
{                                                 //左屏的前四列和右屏的最后四列不用,这样一行就能显示20个西文了(128-8)/6=20                                      
 uchar i,xx;                                      //即左右屏每行分别可显示10个西文字符
 if(x<10)                       //要显示的字符在左屏?(列小于10则说明在左屏),当需要修改字符尺寸时,比较的数(这里是10)亦需修改
 {LCD_SEL_Left();  xx=x*6+4;}   //选中左屏,并使列地址指向左屏
 else                           //要显示的字符在右屏?(列大于等于10则说明在右屏)
 {LCD_SEL_Right(); xx=(x-10)*6;} //选中右屏,并使列地址指向右屏
 
 LCD_Write_COM(0xb8+2*y);   //写入行地址
 LCD_Write_COM(0x40+xx);    //写入列地址
 for(i=0;i<6;i++)
 {
  if(fanbai==255)             //是否反白?
  {LCD_Write_BYTE(0xFE&(255-ascii_code[index][i]));}  //是反白,写入反白数据至LCD的显示RAM(注:用255减去原来的显示码即为反白后的显示码)
  else
  {LCD_Write_BYTE(ascii_code[index][i]);}  //不反白,写入数据至LCD的显示RAM
  }
 
 LCD_Write_COM(0xb8+2*y+1); //写入下一行地址
 LCD_Write_COM(0x40+xx);    //写入列地址
 for(i=0;i<6;i++)
 {
  if(fanbai==255)            //是否反白?
  {LCD_Write_BYTE(0x7F&(255-ascii_code[index][i+6]));}  //是反白,写入反白数据至LCD的显示RAM(注:用255减去原来的显示码即为反白后的显示码)
  else
  {LCD_Write_BYTE(ascii_code[index][i+6]);}  //不反白,写入数据至LCD的显示RAM
  }
 
 LCD_SEL_NON();   //取消对LCD的选择
}

void LCD_Write_CH(uchar x,uchar y,uchar *chh,uchar fanbai)   //在x列y行显示一个12*12中文字符
{                            //左屏的前四列和右屏的最后四列不用,这样一行就能显示10个中文了(128-8)/12=10
 uchar i,xx,j,c1,c2;                 //即左右屏每行分别可显示5个中文字符
 c1=*chh++; c2=*chh++;
 if(x<5)                     //要显示的字符在左屏?(列小于5则说明在左屏),当需要修改字符尺寸时,比较的数(这里是5)亦需修改
 {LCD_SEL_Left();  xx=x*12+4;}   //选中左屏,并使列地址指向左屏
 else                            //要显示的字符在右屏?(列大于等于5则说明在右屏)
 {LCD_SEL_Right(); xx=(x-5)*12;} //选中右屏,并使列地址指向右屏
 
 for(j=0;j",62*/

{0x60,0x10,0x10,0x90,0x60,0x00,0x00,0x00,0x0B,0x00,0x00,0x00},/*"?",63*/

{0xE0,0x10,0x90,0x50,0xE0,0x00,0x07,0x08,0x0B,0x0A,0x0B,0x00},/*"@",64*/

{0x00,0x80,0x70,0xC0,0x00,0x00,0x08,0x0F,0x02,0x03,0x0E,0x08},/*"A",65*/

{0x10,0xF0,0x90,0x90,0x60,0x00,0x08,0x0F,0x08,0x08,0x07,0x00},/*"B",66*/

{0xE0,0x10,0x10,0x10,0x30,0x00,0x07,0x08,0x08,0x08,0x04,0x00},/*"C",67*/

{0x10,0xF0,0x10,0x10,0xE0,0x00,0x08,0x0F,0x08,0x08,0x07,0x00},/*"D",68*/

{0x10,0xF0,0x90,0xD0,0x30,0x00,0x08,0x0F,0x08,0x09,0x0C,0x00},/*"E",69*/

{0x10,0xF0,0x90,0xD0,0x30,0x00,0x08,0x0F,0x08,0x01,0x00,0x00},/*"F",70*/

{0xC0,0x20,0x10,0x10,0x30,0x00,0x03,0x04,0x08,0x09,0x07,0x01},/*"G",71*/

{0x10,0xF0,0x80,0x80,0xF0,0x10,0x08,0x0F,0x00,0x00,0x0F,0x08},/*"H",72*/

{0x10,0x10,0xF0,0x10,0x10,0x00,0x08,0x08,0x0F,0x08,0x08,0x00},/*"I",73*/

{0x00,0x10,0x10,0xF0,0x10,0x10,0x18,0x10,0x10,0x0F,0x00,0x00},/*"J",74*/

{0x10,0xF0,0x90,0x40,0x30,0x10,0x08,0x0F,0x08,0x03,0x0C,0x08},/*"K",75*/

{0x10,0xF0,0x10,0x00,0x00,0x00,0x08,0x0F,0x08,0x08,0x08,0x0C},/*"L",76*/

{0xF0,0xF0,0x00,0xF0,0xF0,0x00,0x0F,0x00,0x0F,0x00,0x0F,0x00},/*"M",77*/

{0x10,0xF0,0xC0,0x10,0xF0,0x10,0x08,0x0F,0x08,0x03,0x0F,0x00},/*"N",78*/

{0xE0,0x10,0x10,0x10,0xE0,0x00,0x07,0x08,0x08,0x08,0x07,0x00},/*"O",79*/

{0x10,0xF0,0x90,0x90,0x60,0x00,0x08,0x0F,0x08,0x00,0x00,0x00},/*"P",80*/

{0xE0,0x10,0x10,0x10,0xE0,0x00,0x07,0x0A,0x0A,0x1C,0x17,0x00},/*"Q",81*/

{0x10,0xF0,0x90,0x90,0x60,0x00,0x08,0x0F,0x08,0x01,0x0E,0x08},/*"R",82*/

{0x60,0x90,0x90,0x10,0x30,0x00,0x0C,0x08,0x08,0x09,0x06,0x00},/*"S",83*/

{0x30,0x10,0xF0,0x10,0x30,0x00,0x00,0x08,0x0F,0x08,0x00,0x00},/*"T",84*/

{0x10,0xF0,0x00,0x00,0xF0,0x10,0x00,0x07,0x08,0x08,0x07,0x00},/*"U",85*/

{0x10,0xF0,0x00,0x80,0x70,0x10,0x00,0x01,0x0E,0x03,0x00,0x00},/*"V",86*/

{0x70,0x80,0xF0,0x80,0x70,0x00,0x00,0x0F,0x00,0x0F,0x00,0x00},/*"W",87*/

{0x10,0x70,0x80,0x70,0x10,0x00,0x08,0x0E,0x01,0x0E,0x08,0x00},/*"X",88*/

{0x10,0x70,0x80,0x70,0x10,0x00,0x00,0x08,0x0F,0x08,0x00,0x00},/*"Y",89*/

{0x30,0x10,0x90,0x70,0x10,0x00,0x08,0x0E,0x09,0x08,0x0C,0x00},/*"Z",90*/

{0x00,0x00,0xF8,0x08,0x08,0x00,0x00,0x00,0x1F,0x10,0x10,0x00},/*"[",91*/

{0x00,0x38,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x08,0x00},/*"\",92*/

{0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x10,0x10,0x1F,0x00,0x00},/*"]",93*/

{0x00,0x10,0x08,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"^",94*/

{0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x20,0x20,0x20,0x20},/*"_",95*/

{0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"`",96*/

{0x00,0x00,0x80,0x80,0x00,0x00,0x00,0x05,0x0A,0x0A,0x0F,0x08},/*"a",97*/

{0x10,0xF0,0x80,0x80,0x00,0x00,0x00,0x0F,0x08,0x08,0x07,0x00},/*"b",98*/

{0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x07,0x08,0x08,0x09,0x00},/*"c",99*/

{0x00,0x00,0x80,0x90,0xF0,0x00,0x00,0x07,0x08,0x08,0x0F,0x08},/*"d",100*/

{0x00,0x00,0x80,0x80,0x00,0x00,0x00,0x07,0x0A,0x0A,0x0B,0x00},/*"e",101*/

{0x00,0x80,0xE0,0x90,0x90,0x10,0x00,0x08,0x0F,0x08,0x08,0x00},/*"f",102*/

{0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x1D,0x2A,0x2A,0x29,0x10},/*"g",103*/

{0x10,0xF0,0x80,0x80,0x00,0x00,0x08,0x0F,0x08,0x00,0x0F,0x08},/*"h",104*/

{0x00,0x80,0x90,0x00,0x00,0x00,0x00,0x08,0x0F,0x08,0x00,0x00},/*"i",105*/

{0x00,0x00,0x80,0x90,0x00,0x00,0x20,0x20,0x20,0x1F,0x00,0x00},/*"j",106*/

{0x10,0xF0,0x00,0x80,0x80,0x80,0x08,0x0F,0x0A,0x03,0x0C,0x08},/*"k",107*/

{0x10,0x10,0xF0,0x00,0x00,0x00,0x08,0x08,0x0F,0x08,0x08,0x00},/*"l",108*/

{0x80,0x80,0x80,0x80,0x00,0x00,0x0F,0x00,0x0F,0x00,0x0F,0x00},/*"m",109*/

{0x80,0x80,0x80,0x80,0x00,0x00,0x08,0x0F,0x08,0x00,0x0F,0x08},/*"n",110*/

{0x00,0x00,0x80,0x80,0x00,0x00,0x00,0x07,0x08,0x08,0x07,0x00},/*"o",111*/

{0x80,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x28,0x08,0x07,0x00},/*"p",112*/

{0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x07,0x08,0x28,0x3F,0x20},/*"q",113*/

{0x80,0x80,0x00,0x80,0x80,0x00,0x08,0x0F,0x09,0x00,0x00,0x00},/*"r",114*/

{0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x09,0x0A,0x0A,0x0C,0x00},/*"s",115*/

{0x00,0x80,0xE0,0x80,0x00,0x00,0x00,0x00,0x07,0x08,0x08,0x00},/*"t",116*/

{0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x07,0x08,0x08,0x0F,0x08},/*"u",117*/

{0x80,0x80,0x80,0x00,0x80,0x80,0x00,0x03,0x0C,0x06,0x01,0x00},/*"v",118*/

{0x80,0x00,0x80,0x00,0x80,0x00,0x01,0x0E,0x03,0x0E,0x01,0x00},/*"w",119*/

{0x80,0x80,0x00,0x80,0x80,0x00,0x08,0x0D,0x02,0x0D,0x08,0x00},/*"x",120*/

{0x80,0x80,0x80,0x00,0x80,0x80,0x20,0x23,0x1C,0x06,0x01,0x00},/*"y",121*/

{0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x08,0x0E,0x09,0x08,0x00},/*"z",122*/

{0x00,0x00,0x80,0x78,0x08,0x00,0x00,0x00,0x00,0x1F,0x10,0x00},/*"{",123*/

{0x00,0x00,0x00,0xFC,0x00,0x00,0x00,0x00,0x00,0x3F,0x00,0x00},/*"|",124*/

{0x00,0x08,0x78,0x80,0x00,0x00,0x00,0x10,0x1F,0x00,0x00,0x00},/*"}",125*/

{0x08,0x04,0x08,0x10,0x10,0x08,0x00,0x00,0x00,0x00,0x00,0x00},/*"~",126*/

{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00} /*"",127*/

};

 

code struct GB12 GB_code[HZKCD]={
 //中(0) 华(1) 人(2) 民(3) 共(4) 和(5) 国(6) 主(7) 席(8) 是(9) 胡(10) 锦(11) 涛(12)

{"中",
 0x00,0xF0,0x10,0x10,0x10,0xFC,0x10,0x10,0x10,0xF0,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x01,0x00,0x00},/*"中",0*/

{"华",
 0x20,0x10,0xF8,0x44,0x40,0x20,0xFC,0xA0,0x90,0x88,0xE0,0x00,0x02,0x02,0x02,0x02,0x02,0x1F,0x02,0x02,0x02,0x02,0x02,0x00},/*"华",1*/

{"人",
 0x00,0x00,0x00,0x00,0x80,0x7C,0x80,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x08,0x06,0x01,0x00,0x01,0x06,0x08,0x10,0x10,0x00},/*"人",2*/

{"民",
 0x00,0xFC,0xA4,0xA4,0xA4,0xE4,0xA4,0xA4,0xA4,0xBC,0x80,0x00,0x00,0x1F,0x10,0x08,0x04,0x01,0x06,0x08,0x10,0x10,0x1C,0x00},/*"民",3*/

{"共",
 0x10,0x10,0x10,0xFC,0x10,0x10,0x10,0xFC,0x10,0x10,0x10,0x00,0x11,0x11,0x09,0x05,0x01,0x01,0x01,0x05,0x05,0x09,0x11,0x00},/*"共",4*/

{"和",
 0x28,0x28,0x28,0xF8,0xA4,0x24,0xF8,0x08,0x08,0x08,0xF8,0x00,0x04,0x02,0x01,0x1F,0x00,0x01,0x0F,0x04,0x04,0x04,0x0F,0x00},/*"和",5*/

{"国",
 0x00,0xFC,0x04,0x54,0x54,0xF4,0x54,0x54,0x54,0x04,0xFC,0x00,0x00,0x1F,0x14,0x14,0x14,0x17,0x14,0x15,0x16,0x14,0x1F,0x00},/*"国",6*/

{"主",
 0x10,0x10,0x10,0x10,0x14,0xF8,0x10,0x10,0x10,0x18,0x10,0x00,0x10,0x11,0x11,0x11,0x11,0x1F,0x11,0x11,0x11,0x11,0x10,0x00},/*"主",7*/

{"席",
 0x00,0xF8,0x28,0x28,0xF8,0xAC,0xA8,0xF8,0x28,0x28,0x28,0x00,0x18,0x07,0x00,0x0E,0x02,0x02,0x1F,0x02,0x0A,0x0E,0x00,0x00},/*"席",8*/

{"是",
 0x00,0x00,0x00,0x7C,0x54,0x54,0x54,0x54,0x7C,0x00,0x00,0x00,0x11,0x09,0x07,0x05,0x09,0x1F,0x15,0x15,0x15,0x15,0x11,0x00},/*"是",9*/

{"胡",
 0x10,0x90,0xFC,0x90,0x90,0x10,0xFC,0x24,0x24,0x24,0xFC,0x00,0x00,0x0F,0x04,0x04,0x17,0x08,0x07,0x01,0x11,0x11,0x1F,0x00},/*"胡",10*/

{"锦",
 0x60,0xDC,0x50,0x50,0x00,0xF8,0xA8,0xAC,0xA8,0xF8,0x00,0x00,0x01,0x1F,0x09,0x05,0x0E,0x02,0x02,0x1F,0x02,0x0A,0x0E,0x00},/*"锦",11*/

{"涛",
 0x20,0x44,0x98,0x80,0xA8,0xA8,0xFC,0xA8,0xA8,0xA8,0x88,0x00,0x04,0x1E,0x09,0x04,0x02,0x07,0x0A,0x12,0x12,0x1F,0x02,0x00}/*"涛",12*/

};

博主
sgpf@live.cn
betbet's Blog
betbet
点击跳转