显示屏幕说明图:
仿真电路图:
仿真结果展示:
汉字取模软件设置:
(取模软件下载链接在文章结尾)
C语言程序代码:
#include #define LCDLCDDisp_Off 0x3e// 程序中 的 LCD_OFF (LCD 断开/不亮) 的值 是 16进制 0x3E #define LCDLCDDisp_On 0x3f// 程序中 的 LCD_ON (LCD 合上/亮) 的值 是 16进制 0x3F #define Page_Add 0xb8// 页地址 #define LCDCol_Add 0x40// 列地址 #define Start_Line 0xC0// 行地址 /*****液晶显示器的端口定义*****/ #define data_ora P0 /*液晶数据总线*/ sbit LCD_CS1=P2^4 ; /*CS1为1时选择右半屏*/ sbit LCD_CS2=P2^3 ; /*CS2为1时选择左半屏*/ sbit RESET=P2^3 ; /*复位信号*/ sbit LCDDi=P2^2 ; /*数据/指令 选择*/ sbit LCDRW=P2^1 ; /*读/写 选择*/ sbit LCDEnable=P2^0 ; /*读/写 使能*/ char code Hz_yang[]= { 0x00,0xFE,0x02,0x22,0xDA,0x06,0x00,0xFE,0x82,0x82,0x82,0x82,0x82,0xFE,0x00,0x00, 0x00,0xFF,0x08,0x10,0x08,0x07,0x00,0xFF,0x40,0x40,0x40,0x40,0x40,0xFF,0x00,0x00 }; char code Hz_guang[]= { 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 }; char code Hz_zheng[]= { 0x00,0x02,0x02,0xC2,0x02,0x02,0x02,0xFE,0x82,0x82,0x82,0xC2,0x83,0x02,0x00,0x00, 0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x40,0x40,0x60,0x40,0x00 }; char code Hz_hao[]= { 0x10,0x10,0xF0,0x1F,0x10,0xF0,0x80,0x82,0x82,0x82,0xE2,0x92,0x8A,0xC6,0x80,0x00, 0x40,0x22,0x15,0x08,0x14,0x63,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00 }; char code Hz_wei[]= { 0x10,0x88,0xC4,0xA3,0xBC,0xA0,0xBF,0xA0,0xBC,0x20,0xD8,0x17,0x90,0x78,0x10,0x00, 0x01,0x00,0xFF,0x40,0x3E,0x02,0x02,0x3E,0x90,0x48,0x33,0x0C,0x33,0xC0,0x40,0x00 }; char code Hz_feng[]= { 0x00,0x00,0xFE,0x02,0x0A,0x12,0x62,0x82,0x62,0x1A,0x02,0xFF,0x02,0x00,0x00,0x00, 0x80,0x40,0x3F,0x20,0x10,0x08,0x06,0x01,0x06,0x18,0x00,0x3F,0x40,0x80,0xE0,0x00 }; char code Hz_bu[]= { 0x02,0x02,0x02,0x02,0x02,0x82,0x42,0xF2,0x0E,0x42,0x82,0x02,0x02,0x03,0x02,0x00, 0x00,0x08,0x04,0x02,0x01,0x00,0x00,0xFF,0x00,0x00,0x00,0x01,0x03,0x06,0x00,0x00 }; char code Hz_zao[]= { 0x80,0x70,0x00,0xFF,0x20,0x10,0x08,0xE0,0x2F,0xE9,0x09,0xE9,0x2F,0xE0,0x00,0x00, 0x40,0x20,0x18,0x07,0x08,0x30,0x44,0x25,0x15,0x0D,0xFE,0x0D,0x35,0x65,0x24,0x00 }; /**************************************************************************** 函数功能:LCD延时程序 入口参数:t 出口参数: ****************************************************************************/ void LCDdelay(unsigned int t) { unsigned int i,j; for(i=0;i } /**************************************************************************** 状态检查,LCD是否忙 *****************************************************************************/ void CheckState() { unsigned char dat,DATA;//状态信息(判断是否忙) LCDDi=0; // 数据指令选择,D/I(RS)="L" ,表示 DB7∽DB0 为显示指令数据 LCDRW=1; //R/W="H" ,E="H"数据被读到DB7∽DB0 do { DATA=0x00; LCDEnable=1; //EN下降源 LCDdelay(2);//延时 dat=DATA; LCDEnable=0; dat=0x80 & dat; //仅当第7位为0时才可操作(判别busy信号) } while(dat!=0x00); } /***************************************************************************** 函数功能:写命令到LCD程序,RS(DI)=L,RW=L,EN=H,即来一个脉冲写一次 入口参数:cmdcode 出口参数: *****************************************************************************/ void write_com(unsigned char cmdcode) { CheckState();//检测LCD是否忙 LCDDi=0; LCDRW=0; P1=cmdcode; LCDdelay(2); LCDEnable=1; LCDdelay(2); LCDEnable=0;//E下降沿将命令锁存到DB0-DB7 } /***************************************************************************** 函数功能:写数据到LCD程序,RS(DI)=H,RW=L,EN=H,即来一个脉冲写一次 入口参数:LCDDispdata 出口参数: *****************************************************************************/ void write_data(unsigned char LCDDispdata) { CheckState();//检测LCD是否忙 LCDDi=1; LCDRW=0; P1=LCDDispdata; LCDdelay(2); LCDEnable=1; LCDdelay(2); LCDEnable=0; } /***************************************************************************** 函数功能:清除LCD内存程序 入口参数:pag,col,hzk 出口参数: *****************************************************************************/ void Clr_Scr() { unsigned char j,k; LCD_CS1=0; //左、右屏均开显示 LCD_CS2=0; write_com(Page_Add+0); write_com(LCDCol_Add+0); for(k=0;k<8;k++)//控制页数0-7,共8页 { write_com(Page_Add+k); //每页每页进行写 for(j=0;j<64;j++) //每页最多可写32个中文文字或64个ASCII字符 { write_com(LCDCol_Add+j); write_data(0x00);//控制列数0-63,共64列,写点内容,列地址自动加1 } } } /***************************************************************************** 函数功能:指定位置显示汉字16*16程序 入口参数:page,column,hzk 出口参数: *****************************************************************************/ void hz_LCDDisp16(unsigned char page,unsigned char column, unsigned char code *hzk) { unsigned char j=0,i=0; for(j=0;j<2;j++) { write_com(Page_Add+page+j); write_com(LCDCol_Add+column); for(i=0;i<16;i++) write_data(hzk[16*j+i]); } } /***************************************************************************** 函数功能:LCD初始化程序 入口参数: 出口参数: *****************************************************************************/ void init_lcd() { LCDdelay(100); LCD_CS1=1;//刚开始关闭两屏 LCD_CS2=1; LCDdelay(100); write_com(LCDLCDDisp_Off); //写初始化命令 write_com(Page_Add+0); write_com(Start_Line+0); write_com(LCDCol_Add+0); write_com(LCDLCDDisp_On); } /*****************************************************************************/ void main() { init_lcd(); Clr_Scr(); LCD_CS1=0; //左屏开显示 LCD_CS2=1; hz_LCDDisp16(0,0,Hz_yang); hz_LCDDisp16(0,16,Hz_guang); hz_LCDDisp16(0,32,Hz_zheng); hz_LCDDisp16(0,48,Hz_hao); LCD_CS1=1; //右屏开显示 LCD_CS2=0; hz_LCDDisp16(0,0,Hz_wei); hz_LCDDisp16(0,16,Hz_feng); hz_LCDDisp16(0,32,Hz_bu); hz_LCDDisp16(0,48,Hz_zao); while(1) { } }
上一篇:单片机控制12864显示多行汉字
下一篇:单片机控制LCD1602显示屏动态显示字符串
推荐阅读最新更新时间:2024-11-17 16:52