📄 lcd.c
字号:
//------------------------------------------------------------------
//
// this program is a simple driver for LCD12864
// functions like display Chinese characters/English characters/dot/images are
// all demonstrated in this file
#include<mc9s12dg128.h>
#include<string.h>
#include "lcd.h"
#include <hidef.h> /* common defines and macros */
uchar const string1[8]={0XBB,0XB6,0XD3,0XAD,0XBD,0XF8,0XC8,0XEB};
uchar const string2[16]={0XD0,0XFC,0XB9,0XD2,0XD4,0XCB,0XB6,0XAF,0XBF,0XD8,0XD6,0XC6,0XCF,0XB5,0XCD,0XB3};
uchar const string3[12]={0XB0,0XB4,0XC8,0XB7,0XC8,0XCF,0XBC,0XFC,0XBD,0XF8,0XC8,0XEB};
uchar const string4[12]={0xd2,0xc6,0xb6,0xaf,0xb9,0xe2,0xb1,0xea,0xd1,0xa1,0xd4,0xf1};
uchar const string5[8]={0xb6,0xa8,0xb5,0xe3,0xd4,0xcb,0xb6,0xaf};
uchar const string6[8]={0xd6,0xb1,0xcf,0xdf,0xd4,0xcb,0xb6,0xaf};
uchar const string7[4]={0xbb,0xad,0xd4,0xb2};
uchar const string8[10]={0xbb,0xad,0xc8,0xce,0xd2,0xe2,0xc7,0xfa,0xcf,0xdf};
uchar const string9[4]={0xd1,0xb0,0xbc,0xa3};
uchar const string10[8]={0xb7,0xb5,0xbb,0xd8,0xd4,0xad,0xb5,0xe3};
uchar const string11[12]={0XB0,0XB4,0XC8,0XB7,0XC8,0XCF,0XBC,0XFC,0XD1,0XA1,0XB6,0XA8};
uchar const ilove[16]={"i love you ever!"};
uchar const image[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x04,0x00,0x40,0x00,0x00,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x04,0x00,0x40,0x00,0x00,
0x83,0x97,0x81,0xC7,0x03,0x8E,0x55,0x44,0x39,0xCA,0x11,0x15,0x8E,0xE0,0x00,0x00,
0x84,0x5A,0x42,0x28,0x84,0x51,0x66,0x44,0x12,0x2C,0x12,0x96,0x51,0x40,0x00,0x00,
0x83,0xD2,0x41,0x88,0x83,0x11,0x44,0x28,0x12,0x28,0x0A,0xA4,0x4F,0x40,0x00,0x00,
0x84,0x52,0x40,0x48,0x80,0x91,0x44,0x28,0x12,0x28,0x0A,0xA4,0x51,0x40,0x00,0x00,
0x84,0xD2,0x42,0x28,0x84,0x51,0x44,0x10,0x12,0x28,0x04,0x44,0x53,0x40,0x00,0x00,
0x83,0x52,0x41,0xC7,0x03,0x8E,0x44,0x10,0x11,0xC8,0x04,0x44,0x4D,0x60,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xA0,0x00,0x01,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x10,0x00,0x04,0x00,0x00,0x00,
0xA0,0x00,0x01,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,
0xA8,0x9C,0x0D,0x39,0xE3,0x82,0xC9,0xC7,0x1C,0x70,0x73,0x94,0xD5,0x13,0x82,0xF1,
0x88,0xA2,0x13,0x45,0x14,0x43,0x2A,0x28,0xA2,0x88,0x24,0x59,0x35,0x14,0x43,0x4A,
0x85,0x3E,0x11,0x45,0x17,0xC2,0x2B,0xE7,0x98,0xF8,0x24,0x51,0x14,0xA7,0xC2,0x4B,
0x85,0x20,0x11,0x45,0x14,0x02,0x2A,0x08,0x84,0x80,0x24,0x51,0x14,0xA4,0x02,0x4A,
0x82,0x22,0x13,0x45,0x14,0x43,0x2A,0x29,0xA2,0x88,0x24,0x51,0x34,0x44,0x42,0x4A,
0x82,0x1C,0x0D,0x39,0x13,0x8A,0xC9,0xC6,0x9C,0x70,0x23,0x90,0xD4,0x43,0x82,0x49,
0x00,0x00,0x00,0x00,0x00,0x0A,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x0A,0x00,0x00,0x00,0x00,0x00,0x01,0xE0,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x10,0x80,0x00,0x00,0x00,0x00,0x01,0x40,0x00,0x00,0x00,0x40,0x00,0x02,0x00,0x00,
0x28,0x80,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x40,0x00,0x04,0x00,0x00,
0x28,0xA2,0x27,0x22,0x70,0x39,0x79,0x4E,0x38,0x1C,0xF0,0x58,0xE5,0x0E,0x71,0xC7,
0x28,0xA5,0x28,0xA2,0x88,0x45,0xA5,0x51,0x44,0x22,0x88,0x65,0x16,0x04,0x8A,0x28,
0x44,0x95,0x47,0x94,0x60,0x31,0x25,0x5F,0x30,0x22,0x88,0x45,0xF4,0x04,0x7A,0x0F,
0x7C,0x95,0x48,0x94,0x10,0x09,0x25,0x50,0x08,0x22,0x88,0x45,0x04,0x04,0x8A,0x08,
0x82,0x88,0x89,0x88,0x88,0x45,0x25,0x51,0x44,0x22,0x88,0x45,0x14,0x04,0x9A,0x28,
0x82,0x88,0x86,0x88,0x70,0x39,0x25,0x4E,0x38,0x1C,0x88,0x44,0xE4,0x04,0x69,0xC7,
0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xF8,0x04,0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0xE0,0xE0,0x00,0x00,0x00,0x00,
0x84,0x04,0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x01,0x11,0x10,0x00,0x00,0x00,0x00,
0x85,0x1E,0x16,0x38,0x1C,0x71,0xC8,0x00,0x1A,0x72,0x0A,0x08,0x00,0x00,0x00,0x00,
0xFD,0x14,0x19,0x44,0x22,0x8A,0x28,0x00,0x26,0x8A,0x02,0x08,0x00,0x00,0x00,0x00,
0x85,0x14,0x11,0x7C,0x20,0x8A,0x28,0x00,0x22,0x8A,0x3A,0x08,0x00,0x00,0x00,0x00,
0x85,0x14,0x11,0x40,0x20,0x8A,0x28,0x00,0x22,0x8A,0x0A,0x08,0x00,0x00,0x00,0x00,
0x85,0x34,0x19,0x44,0x22,0x8A,0x28,0x00,0x26,0x89,0x11,0x10,0x00,0x00,0x00,0x00,
0xF8,0xD6,0x16,0x38,0x1C,0x71,0xC9,0x24,0x1A,0x70,0xE0,0xE0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00} ;
void sleep_ms(unsigned int count) //延时1MS
{
unsigned int i,j;
for(i=0;i<count;i++)
{
for(j=0;j<2000;j++)
;
}
}
void send(uchar dat) //写命令和数据
{
while(busy==1);
DATA=dat;
REQ=1;
while(busy==0);
REQ=0;
}
void wr_comm (uchar comm,uchar addr_x,uchar addr_y)
{
send(comm);
send(addr_x);
send(addr_y);
}
//sub_routine for displaying Chinese characters
//从第二个位置开始显示汉字
//chn为传入的已经定义的汉字字符串,length为显示的汉字的个数
//line为显示在LCD的行。display_chn中的i为LCD显示的列值.
void display_chn(uchar const *chn, uchar length, uchar line)
{
uchar i;
for(i=start_x;i<length+start_x;i++)
{
wr_comm(0xf0,i,line);
send(chn[(i-start_x)*2]-0xa0);
send(chn[(i-start_x)*2+1]-0xa0);
}
}
//sub_routine for displaying ASCII characters
//THE X axis range is 0x04~0x13(16 characters)
//THE Y axis range is 0x00~0x3f(64 lines)
//start_x is the beginning position OF X of each line表示第一个字符与边延空格数
void display_ASCII(uchar const *chn, uchar length, uchar line)
{
uchar i;
start_x=start_x+4;
for(i=start_x;i<length+start_x;i++)
{
wr_comm(0xf1,i,line);
send(chn[i-start_x]);
}
}
//sub_routine for displaying A dot
//the the top-left position is (0,0)
void display_dot(uchar x, uchar y)
{
wr_comm(0xf2,x+32,y);
}
//sub_routine for dispalying an image
//notes:
//image:is the image code of the image to be displayed, it can be extract by tools
// the format of the code is n*(1*8)pix. up->down and left->right
//position:(x,y)is the top-left corner the image, coordinate of the top-left of LCD is (0,0)
// x=0..16 y=0..64
//size of image(dx,dy): dx must be n*8, n is an integer
void diplay_image(uchar const *image,uchar x,uchar y,uchar dx,uchar dy)
{uchar i,j;
x=x+4;
dx=dx/8;
for(j=0;j<dy;j++)
for(i=0;i<dx;i++)
{
wr_comm(0xf3,x+i,y+j);
send(image[j*dx+i]);}
}
//demo display
void jiemian1(void)
{
send(0xf4);
start_x=4;
display_chn(string1,4,0); //在第一行显示
start_x=2;
display_chn(string2,8,1); //在第二行显示
start_x=3;
display_chn(string3,6,3); //在第四行显示
}
void jiemian2(void)
{
send(0xf4);
start_x=0;
display_ASCII(ilove,16,3);
}
void jiemian3(void)
{
send(0xf4);
diplay_image(image,0,0,128,64);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -