LCD12864驱动程序(STM32F103RCT6)
- 格式:pdf
- 大小:100.71 KB
- 文档页数:7
STM32 LCD12864驱动程序(头文件)(2012-05-29 21:25:08)转载▼标签:杂谈#ifndef LCD12864_H#define LCD12864_H#define LCD_CONTROL GPIOD //默认LCD12864的控制口在PD口#define LCD_DATAPORT GPIOD //默认LCD12864的数据口在PD口#define LCD_RESET_Pin GPIO_Pin_12 //默认LCD12864的复位引脚连接到PD.12 也可不用#define LCD_RS_Pin GPIO_Pin_13 //默认LCD12864 RS -- PD.13#define LCD_RW_Pin GPIO_Pin_14 //默认LCD12864 RW -- PD.14#define LCD_EN_Pin GPIO_Pin_15 //默认LCD12864 E -- PD.15#define LCD_CONTROL_CLOCK RCC_APB2Periph_GPIOD //默认LCD12864的控制口时钟#define LCD_DATAPORT_CLOCK RCC_APB2Periph_GPIOD //默认LCD12864的数据口时钟#define LCD_RS_1 LCD_CONTROL->BSRR &=~LCD_RS_Pin;LCD_CONTROL->BSRR |=LCD_RS_Pin //RS置高电平#define LCD_RS_0 LCD_CONTROL->BRR &=~LCD_RS_Pin;LCD_CONTROL->BRR |=LCD_RS_Pin //RS置低电平#define LCD_RW_1 LCD_CONTROL->BSRR &=~LCD_RW_Pin;LCD_CONTROL->BSRR |=LCD_RW_Pin //RW置高电平#define LCD_RW_0 LCD_CONTROL->BRR &=~LCD_RW_Pin;LCD_CONTROL->BRR |=LCD_RW_Pin //RW置低电平#define LCD_EN_1 LCD_CONTROL->BSRR &=~LCD_EN_Pin;LCD_CONTROL->BSRR |=LCD_EN_Pin //EN置高电平#define LCD_EN_0 LCD_CONTROL->BRR &=~LCD_EN_Pin;LCD_CONTROL->BRR |=LCD_EN_Pin //EN置低电平#define LCD_RESET_0 LCD_CONTROL->BRR = LCD_RESET_Pin // 复位#define LCD_RESET_1 LCD_CONTROL->BSRR = LCD_RESET_Pin // 复位脚拉高#define DATAOUT LCD_DATAPORT->ODR &=0xff00;LCD_DATAPORT->ODR // 数据输出寄存器#define DATAIN LCD_DATAPORT->IDR // 数据输入寄存器#define LCD_BF ((DATAIN)& 0x0080) // 忙状态void LCD_delayus(unsigned long n); //延时n(us)void LCD_delayms(unsigned long n); //延时n(ms)void LCD_WriteInitcmd(uint8_t initcmd); //写初始化命令void LCD_WaitLaisure(void); //一直等待到LCD内部操作完成,变为空闲状态void LCD_Writecmd(uint8_t cmd); //写命令到LCD12864void LCD_WriteByte(uint8_t byte); //写一字节数据到LCD12864void LCD_pos(uint16_t pos); //LCD显示位置设置void LCD_Setpos(uint16_t row,uint16_t col);//设定LCD12864的显示地址,根据习惯void LCD_DispChar(char ch); //显示一个字符void LCD_Setpos_DispChar(uint16_t row,uint16_t col,char ch);//在指定位置显示一个字符void LCD_DispString(char str[]); //显示一个字符串,显示位置需提前设定//在指定位置显示一个字符串void LCD_Setpos_DispString(uint16_t row,uint16_t col,char str[]);void LCD_Dispnum(uint32_t num); //显示一个不超过8位的整数,显示位置需提前设置//在指定位置显示一个不超过8位的整数void LCD_Setpos_Dispnum(uint16_t row,uint16_t col,uint32_t num);void LCD_DispDecimal(uint32_t num,uint16_t dot);//显示一个有效位不超过8位的浮点数,显示位置需要提前设定//在指定位置显示一个有效位不超过8位的浮点数void LCD_Setpos_DispDecimal(uint16_t row,uint16_t col,uint32_t num,uint16_t dot);//显示日历,显示日期与时间void LCD_DispDateTime(uint32_t year,uint16_t month,uint16_t day,uint16_t hour,uint16_t min,uint16_t sec);void LCD_DispPicture(const unsigned char picture[]); //显示一幅图像128*64//屏幕整体左移一格,用于滚动显示void LCD_ShiftLeft(void);//屏幕整体右移一格,用于滚动显示void LCD_ShiftRight(void);//清屏,清除显示void LCD_Clear(void);//使光标还回原点位置void LCD_Return(void);//关显示void LCD_Close(void);//开显示void LCD_Open(void);void LCD_FlickerChar(uint16_t row,uint16_t col);//关闭字符闪烁void LCD_CloseFlicker(void);//屏幕秒闪烁一次void LCD_FlickerScreen(void);void LCD_PORT_Init(void); //LCD连接端口初始化void LCD_Init(void); //LCD配置初始化#endif#include "stm32f10x.h"#include "stm32f10x_gpio.h"#include "LCD12864.h"#include "picture.h"//延时n(us)void LCD_delayus(unsigned long n){unsigned long j;while(n--){ j=8;while(j--);}}//延时n(ms)void LCD_delayms(unsigned long n){while(n--)LCD_delayus(1100);}//写初始化命令void LCD_WriteInitcmd(uint8_t initcmd){LCD_RS_0;LCD_RW_0;LCD_EN_1;DATAOUT |= initcmd;LCD_delayus(600);LCD_EN_0;LCD_RW_1;}//一直等待到LCD内部操作完成,变为空闲状态void LCD_WaitLaisure(void){uint16_t flag=0x00;LCD_RS_0;LCD_RW_1;do{LCD_EN_0;LCD_delayus(5);LCD_EN_1;LCD_delayus(5);flag=(uint16_t)LCD_BF;}while(flag);}//写命令到LCD12864void LCD_Writecmd(uint8_t cmd){LCD_WaitLaisure();LCD_RS_0;LCD_RW_0;LCD_EN_1;DATAOUT |= cmd;LCD_delayus(600); //经过测试,取600。
stm32f103rct6程序例子以stm32f103rct6程序例子为题,我们来介绍一些关于该例子的内容。
1. 引言在这个例子中,我们将使用stm32f103rct6微控制器来实现一个简单的LED闪烁程序。
该程序将通过设置GPIO引脚状态来控制LED的亮灭。
2. 初始化设置我们需要进行初始化设置。
我们将使用stm32的库函数来配置GPIO 引脚和时钟。
代码如下:```c#include "stm32f10x.h"void GPIO_Init(void){GPIO_InitTypeDef GPIO_InitStructure;RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(GPIOC, &GPIO_InitStructure);}```在上述代码中,我们使用GPIOC的第13号引脚作为输出引脚,并将其配置为推挽输出模式。
3. 主函数接下来,我们将在主函数中实现LED闪烁的逻辑。
代码如下:```cint main(void){GPIO_Init();while(1){GPIO_SetBits(GPIOC, GPIO_Pin_13);Delay(1000000);GPIO_ResetBits(GPIOC, GPIO_Pin_13);Delay(1000000);}}```在上述代码中,我们使用GPIO_SetBits()函数将GPIOC的第13号引脚设置为高电平,从而点亮LED。
然后,我们使用Delay()函数进行延时,以保持LED亮的时间。
STM32驱动12864液晶屏#include "stm32f10x_lib.h"#define uint unsigned int#define uchar unsigned char#define RSH GPIO_SetBits(GPIOA,GPIO_Pin_0)#define RSL GPIO_ResetBits(GPIOA,GPIO_Pin_0)#define RWH GPIO_SetBits(GPIOA,GPIO_Pin_1)#define RWL GPIO_ResetBits(GPIOA,GPIO_Pin_1)#define ENH GPIO_SetBits(GPIOA,GPIO_Pin_2)#define ENL GPIO_ResetBits(GPIOA,GPIO_Pin_2)#define CS1H GPIO_SetBits(GPIOA,GPIO_Pin_3)#define CS1L GPIO_ResetBits(GPIOA,GPIO_Pin_3)#define CS2H GPIO_SetBits(GPIOA,GPIO_Pin_4)#define CS2L GPIO_ResetBits(GPIOA,GPIO_Pin_4)void RCC_Configuration(void);void NVIC_Configuration(void);void GPIO_Configuration(void);void Delay();uchar table[][16]={/*-- 文字: 我 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x20,0x20,0x22,0x22,0xFE,0x21,0x21,0x20,0x20,0xFF,0x20,0x22,0xAC,0x20,0x20,0x00 ,0x04,0x04,0x42,0x82,0x7F,0x01,0x01,0x10,0x10,0x08,0x07,0x1A,0x21,0x40,0xF0,0x00 ,/*-- 文字: 爸 --*//*-- 文字: 一 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xC0,0x80,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,/*-- 文字: 天 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x40,0x42,0x42,0x42,0x42,0x42,0xFE,0x42,0x42,0x42,0x42,0x42,0x42,0x40,0x00 ,0x00,0x80,0x40,0x20,0x10,0x08,0x06,0x01,0x02,0x04,0x08,0x10,0x30,0x60,0x20,0x00 ,/*-- 文字: 的 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0xF8,0x8C,0x8B,0x88,0xF8,0x40,0x30,0x8F,0x08,0x08,0x08,0x08,0xF8,0x00,0x00 ,0x00,0x7F,0x10,0x10,0x10,0x3F,0x00,0x00,0x00,0x03,0x26,0x40,0x20,0x1F,0x00,0x00 ,/*-- 文字: 成 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0xF8,0x48,0x48,0x48,0xC8,0x08,0xFF,0x08,0x09,0x0A,0xC8,0x88,0x08,0x00 ,0x40,0x30,0x0F,0x00,0x08,0x50,0x4F,0x20,0x10,0x0B,0x0C,0x12,0x21,0x40,0xF0,0x00 ,/*-- 文字: 果 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0x00,0x3E,0x2A,0x2A,0x2A,0xFE,0x2A,0x2A,0x2A,0x3E,0x00,0x00,0x00,0x00 ,0x21,0x21,0x11,0x11,0x09,0x05,0x03,0xFF,0x03,0x05,0x09,0x09,0x11,0x31,0x11,0x00 ,};void Write_cmd_left(uchar cmd) {RSL;RWL;CS1H;GPIO_Write(GPIOF,cmd);ENL;Delay(50);ENH;Delay(50);ENL;Delay(50);CS1L;}void Write_cmd_right(uchar cmd) {RSL;RWL;CS2H;GPIO_Write(GPIOF,cmd);ENL;Delay(50);ENH;Delay(50);ENL;Delay(50);CS2L;}void Write_data_left(uchar data) {RSH;RWL;CS2L;CS1H;GPIO_Write(GPIOF,data);ENL;Delay(50);ENH;Delay(50);ENL;Delay(50);CS1L;}void Write_data_right(uchar data) {RSH;RWL;CS1L;CS2H;GPIO_Write(GPIOF,data);ENL;Delay(50);ENH;Delay(50);ENL;Delay(50);CS2L;}void led_disp(uchar *p,uchar lr) {uchar i,cl,cr;if(lr=='L'){for(i=0;i<16;i++){cl=*p;p++;Write_data_left(cl);}}if(lr=='R'){for(i=0;i<16;i++){cr=*p;p++;Write_data_right(cr);}}}void clear(){uchar i,j,disp_page;for(i=0;i<8;i++){disp_page=0xb8+i;Write_cmd_left(disp_page);Write_cmd_left(0x40);for(j=0;j<64;j++)Write_data_left(0x00);}for(i=0;i<8;i++){disp_page=0xb8+i;Write_cmd_right(disp_page);Write_cmd_right(0x40);for(j=0;j<64;j++)Write_data_right(0x00);}}void init(){Write_cmd_left(0x30);Delay(10);Write_cmd_right(0x30);Delay(10);Write_cmd_left(0x3f);Delay(10);Write_cmd_right(0x3f);Delay(10);Write_cmd_left(0xc0);Delay(10);Write_cmd_right(0xc0);}int main(void){/* Infinite loop */RCC_Configuration();NVIC_Configuration();GPIO_Configuration();clear();Delay(10);init();Delay(10);uchar i;while(1){Write_cmd_left(0xb8);Write_cmd_left(0x40);for(i=0;i<4;i++)led_disp(table[2*i],'L');Write_cmd_left(0xb8+1);Write_cmd_left(0x40);for(i=0;i<4;i++)led_disp(table[2*i+1],'L');Write_cmd_right(0xb8);Write_cmd_right(0x40);for(i=0;i<2;i++)led_disp(table[2*i+8],'R');Write_cmd_right(0xb8+1);Write_cmd_right(0x40);for(i=0;i<2;i++)led_disp(table[2*i+9],'R');}}/*******************************************************************************Function Name :RCC_Configuration.*Descriprion :configures the different system clocks.*Input :None*Output :None*Return :None******************************************************************************* /void RCC_Configuration(void){ErrorStatus HSEStartUpStatus;/*RCC system reset(for debug purpose)*/RCC_DeInit();/*Enable HSE 打开外部时钟*/RCC_HSEConfig(RCC_HSE_ON);/*Wait till HSE is read */HSEStartUpStatus = RCC_WaitForHSEStartUp();if(HSEStartUpStatus==SUCCESS)//起振成功{/*Enable PrefetchBuffer 打开flash的预存储功能*/FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);FLASH_SetLatency(FLASH_Latency_2);//设置代码延时值/*HCLK=syclk*/RCC_HCLKConfig(RCC_SYSCLK_Div1);/*PCLK2=HCLK*/RCC_PCLK2Config(RCC_HCLK_Div1);/*RCLK1=HCLK*/RCC_PCLK1Config(RCC_HCLK_Div2);/*PLLCLK=8MHZ*9=72MHZ*/RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);/*Enable PLL*/RCC_PLLCmd(ENABLE);/*Wait till PLL is ready*/while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)==RESET){}/*Select PLL as system clock source*/RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);/*Wait till pll used as system clock source*/while(RCC_GetSYSCLKSource() !=0x80){}/*打开相应的外部时钟:GPIOF*/RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); }else{}}/*******************************************************************************Function Name :NVIC_Configuration.*Descriprion :configures Vector Table base location.*Input :None*Output :None*Return :None******************************************************************************* /void NVIC_Configuration(void){#ifdef VECT_TAB_RAM/*Set the vector table base location at 0x20000000*/NVIC_SetVectorTable(NVIC_VectTab_RAM,0X0);#else/*Set the vector table base location at 0x20000000*/NVIC_SetVectorTable(NVIC_VectTab_FLASH,0x0);#endif}void GPIO_Configuration(void){GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.GPIO_Pin=GPIO_Pin_All;GPIO_InitStructure.GPIO_Mode =GPIO_Mode_Out_PP;//设置GPIO的工作状态GPIO_InitStructure.GPIO_Speed =GPIO_Speed_50MHz; / /设置GPIO的速度GPIO_Init(GPIOF,&GPIO_InitStructure);GPIO_Init(GPIOA, &GPIO_InitStructure);}/******************************************************************************延时函数******************************************************************************/void Delay(uint z){uint x,y;for(x=z;x>0;x--)for(y=100;y>0;y--);}以上是鑫洪泰的小编为你带来的液晶屏ST7565R IC驱动程序演示代码介绍,如果你想有更进一步的了解,请您关注我们微信,或者点击我们官网了解我们,也可以在线咨询或者拨打我们的热线电话与我们联系!我们会有专业的工作人员为你实时解答。
lcd12864 程序流程图
我们常用的人机交互显示界面中,除了数码管,LED,以及我们之前已经提到的LCD1602 之外,还有一种液晶屏用的比较多。
相信接触过单片机的朋友都知道了,那就是12864 液晶。
顾名思义,12864 表示其横向可以显示128 个点,纵向可以显示64 个点。
我们常用的12864 液晶模块中有带字库的,也有不带字库的,其控制芯片也有很多种,如KS0108 、T6963,ST7920 等等。
在这里我们以ST7920 为主控芯片的12864 液晶屏来学习如何去驱动它。
(液晶屏采用金鹏的OCMJ4X8C)。
lcd12864 液晶说明:
我们先来了解一下它的并行连接情况。
下面是电路连接图:
上面的图可以看出,液晶模块和单片机的连接除了P0 口的8 位并行数据线之外,还有RS,RW,E 等几根线。
其中R/S 是指令和数据寄存器的选择控制线(串行模式下为片选),R/W 是读写控制线(串行模式下是数据线),E 是使能线(串行模式下为时钟线)。
通过这几根控制线和数据线,再结合它的时序图,我们就可以编写出相应的驱动程序啦。
看看并行模式下的写时序图:。
12864液晶屏串口驱动程序代码12864液晶屏驱动采用4_Wire-SPI串口驱动方式,可有效的减少IO口的占用,方便使用调试,本程序的代码驱动IC为ST7565R,是基于STC89C53RC的12864串行模式的程序,硬件电路连接只需要5根线:RS、 SDA、 SCLK、RES、CS 。
程序已经调试通过,很好用。
代码如下://----------------------------------------------------------------------/*hotdisplay CO,.LTD.*/// Module : HTG12864// Lanuage : C51 Code// Create :// Version : 1.0// Date : OCT-21-2016// LCM Drive IC : ST7565R// INTERFACE : 4_Wire-SPI// MCU : STC89C53RC// VDD : 3.3V//********************************************************* ******************#include<reg51.h>#define uchar unsigned char#define uint unsigned intuchar bdata transdata;sbit R_S= P3^5;sbit RES= P3^4;sbit SCK= P1^6;sbit SDA= P1^7;sbit CS1= P3^7;sbit transbit = transdata^7 ;#define Page 0xb0//##########################################//void Comwrite(unsigned char com); //D′??á?3ìDò//void Datawrite(unsigned char dat);void Delay(unsigned int time); //?óê±×ó3ìDò//char code Hanzi[]={0xFF,0x01,0x01,0x09,0xF9,0x09,0x01,0x01,0x09,0xF9,0x09,0xE1 ,0x11,0x09,0x09,0x09,0x11,0xE1,0x01,0x19,0x09,0x09,0xF9,0x09,0x09,0x19,0x01,0x01 ,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x09,0xF9,0x09,0x09,0x09,0x11,0xE1,0x01,0x01 ,0x09,0x09,0xF9,0x09,0x09,0x01,0x01,0x01,0x71,0x89,0x09,0x09,0x09,0x39,0x01,0x09 ,0xF9,0x09,0x09,0x09,0x09,0xF1,0x01,0x01,0x01,0xC1,0x39,0xE1,0x01,0x01,0x01,0x09 ,0xF9,0x09,0x01,0x01,0x01,0x01,0x01,0x09,0x39,0xC9,0x01,0xC9,0x39,0x09,0x01,0x01 ,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x09,0xF9,0x09,0x01,0x01,0x01,0x01,0x01,0xC1 ,0x31,0x09,0x09,0x09,0x09,0x39,0x01,0x09,0xF9,0x09,0x09,0x09,0x11,0xE1,0x01,0x01 ,0x01,0x01,0x01,0xFF,0xFF,0x00,0x00,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,0x0F ,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,0x00 ,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,0x20 ,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,0x20 ,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,0x07 ,0x18,0x20,0x20,0x20,0x10,0x08,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,0x00 ,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xF8,0x08,0x00 ,0x00,0x08,0xF8,0x08,0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x08,0xF8,0xF8,0x00 ,0xF8,0xF8,0x08,0x00,0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x70,0x08,0x08 ,0x08,0x88,0x70,0x00,0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0xE0,0x10,0x88 ,0x88,0x18,0x00,0x00,0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x21,0x01 ,0x01,0x21,0x3F,0x20,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,0x20,0x3F,0x00,0x3F ,0x00,0x3F,0x20,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,0x00,0x30,0x28,0x24 ,0x22,0x21,0x30,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,0x00,0x0F,0x11,0x20 ,0x20,0x11,0x0E,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0xE0,0x10,0x08,0x08 ,0x08,0x10,0xE0,0x00,0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x70,0x88,0x08 ,0x08,0x08,0x38,0x00,0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x10,0x10,0xF8 ,0x00,0x00,0x00,0x00,0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x70,0x88,0x08 ,0x08,0x88,0x70,0x00,0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0xE0,0x10,0x88 ,0x88,0x18,0x00,0x00,0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,0x0F,0x10,0x20,0x20 ,0x20,0x10,0x0F,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,0x00,0x38,0x20,0x21 ,0x21,0x22,0x1C,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x20,0x20,0x3F ,0x20,0x20,0x00,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,0x00,0x1C,0x22,0x21 ,0x21,0x22,0x1C,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,0x00,0x0F,0x11,0x20 ,0x20,0x11,0x0E,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0xFF,0xFF,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x10,0x10,0xF8 ,0x00,0x00,0x00,0x00,0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x08,0x88 ,0x88,0x48,0x30,0x00,0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0xF8,0x08,0x88 ,0x88,0x08,0x08,0x00,0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x38,0x08,0x08 ,0xC8,0x38,0x08,0x00,0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0xE0,0x10,0x08 ,0x08,0x10,0xE0,0x00,0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x10,0x10,0xF8 ,0x00,0x00,0x00,0x00,0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x08,0x88 ,0x88,0x48,0x30,0x00,0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0xF8,0x08,0x88 ,0x88,0x08,0x08,0xFF,0xFF,0x8F,0x90,0xA0,0xA0,0x90,0x8F,0x80,0x80,0xA0,0xA0,0xBF ,0xA0,0xA0,0x80,0x80,0x80,0xB0,0xA8,0xA4,0xA2,0xA1,0xB0,0x80,0x80,0x98,0xA0,0xA0 ,0xA0,0x91,0x8E,0x80,0x80,0x87,0x84,0xA4,0xA4,0xBF,0xA4,0x80,0x80,0x99,0xA1,0xA0 ,0xA0,0x91,0x8E,0x80,0x80,0x8F,0x91,0xA0,0xA0,0x91,0x8E,0x80,0x80,0x80,0x80,0xBF ,0x80,0x80,0x80,0x80,0x80,0x9C,0xA2,0xA1,0xA1,0xA2,0x9C,0x80,0x80,0x80,0xB1,0xA2 ,0xA2,0x91,0x8F,0x80,0x80,0x8F,0x90,0xA0,0xA0,0x90,0x8F,0x80,0x80,0xA0,0xA0,0xBF ,0xA0,0xA0,0x80,0x80,0x80,0xB0,0xA8,0xA4,0xA2,0xA1,0xB0,0x80,0x80,0x98,0xA0,0xA0 ,0xA0,0x91,0x8E,0x80,0x80,0x87,0x84,0xA4,0xA4,0xBF,0xA4,0x80,0x80,0x99,0xA1,0xA0 ,0xA0,0x91,0x8E,0xFF};//###############################################//char code Hanzi1[]={0x00,0x04,0xFC,0x84,0x84,0x84,0x84,0x78,0x00,0x00,0x00,0xA0 ,0xA0,0xA0,0xA0,0xC0,0x00,0x00,0x00,0xC0,0x40,0x20,0x20,0x44,0xFC,0x00,0x00,0x00 ,0x00,0x20,0x20,0xE4,0x00,0x00,0x00,0x00,0x00,0xC0,0x40,0x20,0x20,0x20,0x40,0xC0 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x84,0x84,0x84 ,0x44,0xF8,0x00,0x00,0x00,0x08,0x04,0x04,0x84,0x44,0x38,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0x88,0x44,0x44,0x44,0x80,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0xFC,0x30,0xC0,0x00,0xC0,0x30,0xFC,0x04 ,0x04,0xFC,0x44,0x40,0x40,0x40,0x44,0xFC,0x04,0x00,0x60,0x20,0x20,0x20,0xA0,0x60 ,0x20,0x00,0x00,0x00,0x40,0x48,0x4F,0x48,0x40,0x41,0x42,0x4C,0x48,0x40,0x47,0x48 ,0x48,0x48,0x48,0x47,0x48,0x40,0x40,0x47,0x44,0x48,0x48,0x44,0x4F,0x48,0x40,0x40 ,0x40,0x48,0x48,0x4F,0x48,0x48,0x40,0x40,0x40,0x47,0x44,0x48,0x48,0x48,0x44,0x47 ,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x48,0x48,0x48 ,0x44,0x43,0x40,0x40,0x40,0x4C,0x4A,0x49,0x48,0x48,0x48,0x40,0x40,0x40,0x40,0x40 ,0x4C,0x4C,0x40,0x40,0x40,0x40,0x40,0x47,0x48,0x48,0x48,0x48,0x47,0x40,0x40,0x40 ,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x48,0x4F,0x48,0x40,0x43,0x40,0x48,0x4F,0x48 ,0x48,0x4F,0x48,0x40,0x40,0x40,0x48,0x4F,0x48,0x40,0x48,0x4C,0x4A,0x49,0x48,0x48 ,0x4C,0x40,0x40,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0xE0,0xE0,0xE0,0xFC,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C ,0x1C,0xFC,0xE0,0xE0,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xE0,0xE0,0xFC ,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0xFC,0xE0,0xE0,0xE0,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xE0,0xE0,0xFC,0x1C,0x1C,0x1C,0x1C ,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0xFC,0xE0,0xE0,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,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00 ,0x00,0xF0,0x00,0x00,0x00,0x00,0x80,0x40,0x20,0x10,0x00,0x00,0x80,0x00,0x80,0x80 ,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0xC0,0x30,0x00,0xF0,0x00,0x80 ,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x1F,0x1F,0x1F,0xFF,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0 ,0xE0,0xFF,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F,0xFF ,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xFF,0x1F,0x1F,0x1F,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F,0xFF,0xE0,0xE0,0xE0,0xE0 ,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xFF,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00 ,0x00,0xFF,0x08,0x04,0x02,0x07,0x08,0x30,0x40,0x80,0x00,0x00,0xFF,0x01,0x00,0x00 ,0x00,0xFF,0x01,0x00,0x00,0x00,0xFF,0x00,0xC0,0x3C,0x03,0x00,0x00,0xFF,0x01,0x00 ,0x00,0x00,0xFF,0x00,0x04,0x04,0x84,0x44,0x44,0x44,0x84,0x04,0x04,0x04,0x84,0x44 ,0x44,0x44,0x84,0x04,0x04,0x04,0x84,0x84,0xC4,0x04,0x04,0x04,0x04,0x04,0x84,0x44 ,0x44,0x44,0x84,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x84,0x84 ,0xC4,0x04,0x04,0x04,0x04,0x04,0x84,0x44,0x44,0x44,0x84,0x04,0x04,0x04,0x04,0x04 ,0x04,0x04,0x04,0x04,0x04,0x04,0x84,0x44,0x44,0x44,0x84,0x04,0x04,0x04,0x84,0x44 ,0x44,0x44,0x84,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x84,0x84 ,0xC4,0x04,0x04,0x04,0x04,0x04,0xC4,0x44,0x44,0x44,0x44,0x04,0x04,0x04,0x04,0x04 ,0x04,0x04,0x04,0x04,0x04,0x84,0x44,0x44,0x44,0x84,0x04,0x04,0x04,0xC4,0x44,0x44 ,0x44,0x44,0x04,0x04,0x00,0x00,0x60,0x50,0x48,0x44,0x43,0x00,0x00,0x00,0x3F,0x40 ,0x40,0x40,0x3F,0x00,0x00,0x00,0x40,0x40,0x7F,0x40,0x40,0x00,0x00,0x00,0x3F,0x40 ,0x40,0x40,0x3F,0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,0x40,0x40 ,0x7F,0x40,0x40,0x00,0x00,0x00,0x60,0x50,0x48,0x44,0x43,0x00,0x00,0x08,0x08,0x08 ,0x08,0x08,0x08,0x08,0x00,0x00,0x20,0x40,0x44,0x44,0x3B,0x00,0x00,0x00,0x3F,0x40 ,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x40 ,0x7F,0x40,0x40,0x00,0x00,0x00,0x27,0x44,0x44,0x44,0x38,0x00,0x00,0x00,0x00,0x00 ,0x21,0x00,0x00,0x00,0x00,0x60,0x50,0x48,0x44,0x43,0x00,0x00,0x00,0x27,0x44,0x44 ,0x44,0x38,0x00,0x00,};void Delay(unsigned int time){unsigned char j;while(time--){for(j=0;j<=50;j++){}}}/******************************************************/ void Display(unsigned char sda,unsigned char sda1){unsigned char i,j,k=0;Comwrite(0x40);for(i=0;i<8;i++){Comwrite(Page+k);Comwrite(0x10);Comwrite(0x00);for(j=0;j<66;j++){Datawrite(sda);Datawrite(sda1);}k++;}}/*****************************************************/void Hanzi_Disp(void){unsigned char i,j,k=0;Comwrite(0x40);for(i=0;i<8;i++){Comwrite(Page+k);Comwrite(0x10);Comwrite(0x00);for(j=0;j<128;j++){Datawrite(Hanzi[i*128+j]);}k++;}Delay(5000);}void Hanzi_Disp1(void){unsigned char i,j,k=0;Comwrite(0x40);for(i=0;i<8;i++){Comwrite(Page+k);Comwrite(0x10);Comwrite(0x00);for(j=0;j<128;j++){Datawrite(Hanzi1[i*128+j]);}k++;}Delay(5000);}//######################################################### void Intial(void){Delay(100);Comwrite(0xe3);Comwrite(0xA2);Comwrite(0xA0); //A0为正显示,A1为镜像显示Comwrite(0xc9);Comwrite(0x2c);Comwrite(0x2e);Comwrite(0x2F);Comwrite(0xf8);Comwrite(0x00);Comwrite(0x81);Comwrite(0x10);Comwrite(0x25);Comwrite(0xAF);Comwrite(0x40);Delay(20);}/********************************************************** /int main(){/*PINSEL0=0x00000000; IO0DIR=SPIIOCON;RES=0;Delay(20);RES=1;Delay(20);while(1){Intial();Delay(20);Display(0xFF,0xFF);Delay(1000);Display(0x00,0x00);Delay(1000);Display(0xFF,0x00);Delay(1000);Display(0x00,0xff);Delay(1000);Display(0x55,0xAA);Delay(1000);Display(0xAA,0x55);Delay(1000);Hanzi_Disp(); Delay(1000);Hanzi_Disp1();Delay(1000);}}//###############################################// void Comwrite(char com){unsigned char data i;transdata=com;CS1=0;R_S=0;SCK=1;for(i=0;i<8;i++){SDA=transbit;SCK=0;SCK=1;transdata=transdata<<1;}CS1=1;R_S=0;}//######################################################### ##//void Datawrite(char dat){unsigned char data i;transdata=dat;CS1=0;R_S=1;SCK=1;for(i=0;i<8;i++){SDA=transbit;SCK=0;SCK=1;transdata=transdata<<1;}CS1=1;R_S=0;}以上是鑫洪泰的小编为你带来的12864液晶屏驱动程序编写示例,如果你想有更进一步的了解,请您关注我们微信,或者点击我们官网了解我们,也可以在线咨询或者拨打我们的热线电话与我们联系!我们会有专业的工作人员为你实时解答。
#include "LCD12864.h"/*原程序参考于网络,原作者不明,liangjin2807修改适用于MSP430单片机,驱动MGLS12864液晶屏,HD61202芯片*/typedef unsigned char uchar;typedef unsigned int uint;uchardigital[21][16]={{0x00,0xE0,0xF0,0x18,0x08,0x18,0xF0,0xE0,0x00,0x0F,0x1F,0x30,0x20,0x30,0x1F, 0x0F},/*"0",0*/{0x00,0x10,0x10,0xF8,0xF8,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x3F,0x20,0x20,0x00},/*"1",1*/ {0x00,0x70,0x78,0x08,0x08,0x88,0xF8,0x70,0x00,0x30,0x38,0x2C,0x26,0x23,0x31,0x30},/*"2",2* /{0x00,0x30,0x38,0x88,0x88,0xC8,0x78,0x30,0x00,0x18,0x38,0x20,0x20,0x31,0x1F,0x0E},/*"3",3* /{0x00,0x00,0xC0,0xE0,0x30,0xF8,0xF8,0x00,0x00,0x07,0x07,0x24,0x24,0x3F,0x3F,0x24},/*"4",4*/ {0x00,0xF8,0xF8,0x88,0x88,0x88,0x08,0x08,0x00,0x19,0x39,0x21,0x20,0x31,0x1F,0x0E},/*"5",5*/ {0x00,0xE0,0xF0,0x98,0x88,0x98,0x18,0x00,0x00,0x0F,0x1F,0x31,0x20,0x31,0x1F,0x0E},/*"6",6*/ {0x00,0x38,0x38,0x08,0xC8,0xF8,0x38,0x08,0x00,0x00,0x00,0x3F,0x3F,0x00,0x00,0x00},/*"7",7*/ {0x00,0x70,0xF8,0x88,0x08,0x88,0xF8,0x70,0x00,0x1C,0x3E,0x23,0x21,0x23,0x3E,0x1C},/*"8",8* /{0x00,0xE0,0xF0,0x18,0x08,0x18,0xF0,0xE0,0x00,0x00,0x31,0x33,0x22,0x33,0x1F,0x0F},/*"9",9*/ {0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20},/*"A",0* /{0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00},/*"B",1*/ {0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00},/*"C",2* /{0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00},/*"D",3*/ {0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00},/*"E",4*/ {0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00},/*"F",5*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00},/*".",6*/ {0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00},/*":",7*/ {0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00},/*"/",8* /{0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00},/*"*",9*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01},/*"-",10 */};/*"*",12*//**************宏定义***************/#define DataDir P2DIR#define DataPort P2OUT#define Busy 0x80#define CtrlDir P6DIR#define CLR_RS P6OUT&=~BIT3; //RS = P6.3#define SET_RS P6OUT|=BIT3;#define CLR_RW P6OUT&=~BIT4; //RW = P6.4#define SET_RW P6OUT|=BIT4;#define CLR_EN P6OUT&=~BIT5; //EN = P6.5#define SET_EN P6OUT|=BIT5;#define CLR_CS1 P6OUT&=~BIT0; //RW = 6.0#define SET_CS1 P6OUT|=BIT0;#define CLR_CS2 P6OUT&=~BIT1; //EN = 6.1#define SET_CS2 P6OUT|=BIT1;/***********************************************函数名称:DispStr功能:让液晶从某个位置起连续显示一个字符串参数:x--位置的列坐标y--位置的行坐标ptr--指向字符串存放位置的指针返回值:无***********************************************/void DispStr(uchar x,uchar y,uchar *ptr){uchar *temp;uchar i;temp = ptr;//计算字符串有效字符的个数LocateXY( x, y );for (i=0;i<64;i++) //连续显示4个16*16字符{LcdWriteData( temp[i] );}}/***********************************************函数名称:DispDigital功能:让液晶从某个位置显示一个数字,上列数组寻址方式,不建议使用参数:x--位置的列坐标y--位置的行坐标返回值:无***********************************************/void DispDigetal(uchar x,uchar y,uchar n){uchar i;uchar x_1;if(x<64){LcdChoiceL();LocateXY( x, y );for (i=0;i<8;i++)LcdWriteData( digital[n][i] );LocateXY( x, y+1 );for (i=8;i<16;i++)LcdWriteData( digital[n][i] );}else{x_1=x-64;LcdChoiceR();LocateXY( x_1, y );for (i=0;i<8;i++)LcdWriteData( digital[n][i] );LocateXY( x_1, y+1 );for (i=8;i<16;i++)LcdWriteData( digital[n][i] );}}/*********************************************** 函数名称:DispHex功能:让液晶从某个位置显示四个十六进数字参数:x--位置的列坐标y--位置的行坐标ptr--指向字符串存放位置的指针返回值:无***********************************************/ void DispHex(uchar x,uchar y,uint temp){uchar n;n=temp/0x1000;DispDigetal(x,y,n);n=(temp/0x100)%0x10;DispDigetal(x+8,y,n);n=(temp/0x10)%0x10;DispDigetal(x+16,y,n);n=temp%0x10;DispDigetal(x+24,y,n);}/*******************************************函数名称:LocateXY功能:向液晶输入显示字符位置的坐标信息参数:x--位置的列坐标y--位置的行坐标返回值:无********************************************/ void LocateXY(uchar x,uchar y){uchar tempx;uchar tempy;tempx=x|0x40;tempy=y|0xb8;LcdWriteCommand(tempx,1);LcdWriteCommand(tempy,1);}/*******************************************函数名称:DispNChar功能:在某个位置显示一个字符12864参数:x--位置的列坐标y--位置的行坐标n--显示的字个数data--显示的字符数据返回值:无********************************************/void DispNChar(uchar x,uchar y,uchar n,uchar (*ptr)[64]) { uchar i;uchar x_1;for(i=0;i<(16*n);i++)//输入总共的字符数{if(x<64){LcdChoiceL();//指定左屏LocateXY( x, y );//定位地址LcdWriteData( *(*ptr+i) );LocateXY( x, y+1 );LcdWriteData( *(*(ptr+1)+i) );}else {if(x<128)//如果64<X<128,则选择右屏{x_1=x-64;LcdChoiceR();LocateXY( x_1, y );LcdWriteData( *(*ptr+i) );LocateXY( x_1, y+1 );LcdWriteData( *(*(ptr+1)+i) );}else {x=0;y+=2;if(y<8){LcdChoiceL();LocateXY( x, y );LcdWriteData( *(*ptr+i) );LocateXY( x, y+1 );LcdWriteData( *(*(ptr+1)+i) );}else{y=0;LcdChoiceL();LocateXY( x, y );LcdWriteData( *(*ptr+i) );LocateXY( x, y+1 );LcdWriteData( *(*(ptr+1)+i) );}}}x++;}}/******************************************* 函数名称:LcdChoiceL功能:对12864液晶模块左侧参数:无返回值:无********************************************/ void LcdChoiceL(void){SET_CS2;//片选命令,选择左侧CLR_CS1;}/*******************************************函数名称:LcdChoiceR功能:对12864液晶模块右侧参数:无返回值:无********************************************/void LcdChoiceR(void){SET_CS1;//片选命令,选择右侧CLR_CS2;}/*******************************************函数名称:LcdStop功能:对12864液晶模块禁止参数:无返回值:无********************************************/void LcdStop(void){SET_CS1;//片选命令,禁止SET_CS2;}/*******************************************函数名称:LcdReset功能:对12864液晶模块进行复位操作参数:无返回值:无********************************************/void LcdReset(void){CtrlDir |= 0x3B; //控制线端口设为输出状态DataDir = 0xFF; //数据端口设为输出状态LcdChoiceL();//选择右侧LcdWriteCommand(0x3f, 1); //设置显示屏数据开LcdWriteCommand(0xc0, 1);//设置显示屏0行为第一行//LcdWriteCommand(0x40, 1);//设置显示屏0列为第一列/*_NOP();_NOP();_NOP();*/Delay5ms();LcdChoiceR();//选择左侧LcdWriteCommand(0x3f, 1); //设置显示屏数据开LcdWriteCommand(0xc0, 1);//设置显示屏0行为第一行//LcdWriteCommand(0x40, 1);//设置显示屏0列为第一列//显示模式设置}/*******************************************函数名称:LcdLine功能:改变lCD显示的第一行,从而实现滚屏效果参数:Line 取值0-63之间,增大向上滚,减小向下滚返回值:无********************************************/void LcdLine(uchar Line){if(Line<64){Line=Line+0xc0;LcdChoiceL();//选择右侧LcdWriteCommand(Line, 1);//设置显示屏0行为第一行//LcdWriteCommand(0x40, 1);//设置显示屏0列为第一列/*_NOP();_NOP();_NOP();*/Delay5ms();LcdChoiceR();//选择左侧LcdWriteCommand(Line, 1);//设置显示屏0行为第一行//LcdWriteCommand(0x40, 1);//设置显示屏0列为第一列}//显示模式设置}/*******************************************函数名称:LcdClear功能:对12864液晶模块屏幕清屏参数:无返回值:无********************************************/void LcdClear(void){ uchar k;uchar n;for(k=0;k<8;k++){for(n=0;n<64;n++){ LcdChoiceL();//选择左侧LocateXY( n,k );LcdWriteData(0x00);LcdChoiceR();//选择右侧LocateXY( n,k );LcdWriteData(0x00);}}}/*******************************************函数名称:LcdWriteCommand功能:向液晶模块写入命令12864参数:cmd--命令,chk--是否判忙的标志,1:判忙,0:不判返回值:无********************************************/void LcdWriteCommand(uchar cmd,uchar chk){if (chk) WaitForEnable(); // 检测忙信号?CLR_RS;CLR_RW;_NOP();DataPort = cmd; //将命令字写入数据端口_NOP();SET_EN; //产生使能脉冲信号_NOP();_NOP();CLR_EN;}/*******************************************函数名称:LcdWriteData功能:向液晶显示的当前地址写入显示数据参数:data--显示字符数据返回值:无********************************************/void LcdWriteData( uchar data ){WaitForEnable(); //等待液晶不忙SET_RS;CLR_RW;_NOP();_NOP();_NOP();_NOP();DataPort = data; //将显示数据写入数据端口_NOP();_NOP();_NOP();_NOP();SET_EN; //产生使能脉冲信号_NOP();_NOP();CLR_EN;DataPort =0xff;}/*******************************************函数名称:WaitForEnable功能:等待12864液晶完成内部操作参数:无返回值:无********************************************/ void WaitForEnable(void){P2DIR &= 0x00; //将P2口切换为输入状态SET_RW;CLR_RS;_NOP();SET_EN;_NOP();_NOP();while((P2IN & Busy)!=0); //检测忙标志CLR_EN;P2DIR |= 0xFF; //将P2口切换为输出状态}/*******************************************函数名称:Delay5ms功能:延时约5ms参数:无返回值:无********************************************/void Delay5ms(void){uint i=40000;while (i != 0){i--;}}/************************************************************函数名:LCD_Write_16X16Font*功能:写一个16X16的汉字*参数:x , y , c[2] x:0-83 y:0-5*返回值:无*备注:***********************************************************/void LCD_Write_16X16Font(unsigned char x,unsigned char y,unsigned char c[2]) {unsigned char i,k;if(x<64){LcdChoiceL();LocateXY(x,y);}else{LcdChoiceL();x=x-64;LocateXY(x,y);}for(k=0; k<70; k++) //K的值表示汉字库最多存放的字的数量(可改大){if((font16X16[k].Index[0]==c[0])&&(font16X16[k].Index[1]==c[1])){for(i=0; i<32; i++){LcdWriteData(font16X16[k].Msk[i]);if(i==16){y++;LocateXY(x,y);}}}}}/************************************************************函数名:DisplarString*功能:写一行的中文字符*参数:*返回值:无*备注:***********************************************************/void DisplarString(unsigned char x,unsigned char y,unsigned char n,unsigned char *MemuTemp) {uchar a,b,i,x_1,y_1;for(a=0;a<n*2;a+=2) //计数列,每列7个字符{for(b=0;b<70;b++) //50个字符内搜索需要显示的字符{if((font16X16[b].Index[0]==MemuTemp[a])&&(font16X16[b].Index[1]==MemuTemp[a+1])) //找到需要显示的字符,显示{if((a*8+x)<64){LcdChoiceL();x_1=a*8+x;y_1=y;}else{ if((a*8+x)<128){LcdChoiceR();x_1=a*8+x-64;y_1=y;}else{LcdChoiceL();x_1=a*8+x-128;y_1=y+2;}}LocateXY(x_1,y_1);for(i=0; i<32; i++){if(i==16) //如果已经传送16个字节,换行传送字符下半部分{LocateXY(x_1,y_1+1);}LcdWriteData(font16X16[b].Msk[i]);}break;}}}}/*******************************************函数名称:LocateXY功能:向液晶输入显示字符位置的坐标信息,按照像素点定位行参数:x--位置的列坐标y--位置的行坐标返回值:无********************************************/void LocateXY_1(uchar x,uchar y){uchar tempx;uchar tempy;tempx=x|0x40;tempy=y|0xC0;LcdWriteCommand(tempx,1);LcdWriteCommand(tempy,1);}/************************************************************函数名:DisplarString2*功能:写指定个数的汉字,按照像素点定位行*参数:x列数,y行数,n显示汉字个数,MemuTemp汉字字符串*返回值:无*备注:***********************************************************/void DisplarString2(unsigned char x,unsigned char y,unsigned char n,unsigned char *MemuTemp) {uchar a,b,i,x_1,y_1;for(a=0;a<n*2;a+=2) //计数列,每列7个字符{for(b=0;b<70;b++) //50个字符内搜索需要显示的字符{if((font16X16[b].Index[0]==MemuTemp[a])&&(font16X16[b].Index[1]==MemuTemp[a+1])) //找到需要显示的字符,显示{if((a*8+x)<64){LcdChoiceL();x_1=a*8+x;y_1=y;}else{ if((a*8+x)<128){LcdChoiceR();x_1=a*8+x-64;y_1=y;}else{LcdChoiceL();x_1=a*8+x-128;y_1=y+2;}}LocateXY_1(x_1,y_1);for(i=0; i<32; i++){if(i==16) //如果已经传送16个字节,换行传送字符下半部分{LocateXY_1(x_1,y_1+1);}LcdWriteData(font16X16[b].Msk[i]);}break;}}}}/************************************************************函数名:DisplarFont8x16_2*功能:写一行的指定个数的字母*参数:x列数,y行数,n显示汉字个数,MemuTemp汉字字符串*返回值:无*备注:***********************************************************/void DisplarFont8x16_2(unsigned char x,unsigned char y,unsigned char d,unsigned char *MemuTemp){uchar a,b,i,x_1,y_1;uchar n;n=d*8;for(a=0;a<n;a++) //计数列,每列7个字符{if((a*8+x)<64) //判断是否在左侧屏幕{LcdChoiceL(); //选择左侧x_1=a*8+x; //定位坐标y_1=y;}else{ if((a*8+x)<128) //在右侧屏幕{LcdChoiceR();x_1=a*8+x-64;y_1=y;}else //超出右侧屏幕{if(a*8+x-128<64){LcdChoiceL(); //选择左侧屏幕x_1=a*8+x-128;y_1=y+2; //行下移一行}else{if(a*8+x-192<64){LcdChoiceR(); //选择右侧侧屏幕x_1=a*8+x-192;y_1=y+2; //行下移一行}}}}LocateXY(x_1,y_1);for(b=0;b<94;b++) //50个字符内搜索需要显示的字符{if(font8x16[b][0]==MemuTemp[a]) //找到需要显示的字符,显示{for(i=1; i<17; i++){if(i==9) //如果已经传送16个字节,换行传送字符下半部分{LocateXY(x_1,y_1+1);}LcdWriteData(font8x16[b][i]);}break;}}}}/************************************************************函数名:DisplarFont8x16*功能:写一行的字母*参数:*返回值:无*备注:***********************************************************/void DisplarFont8x16(unsigned char x,unsigned char y,unsigned char *MemuTemp) {uchar a,b,i,x_1,y_1;uchar n=0;while(MemuTemp[n]!='\0')n++;for(a=0;a<n;a++) //计数列,每列7个字符{if((a*8+x)<64) //判断是否在左侧屏幕{LcdChoiceL(); //选择左侧x_1=a*8+x; //定位坐标y_1=y;}else{ if((a*8+x)<128) //在右侧屏幕{LcdChoiceR();x_1=a*8+x-64;y_1=y;}else //超出右侧屏幕{if(a*8+x-128<64){LcdChoiceL(); //选择左侧屏幕x_1=a*8+x-128;y_1=y+2; //行下移一行}else{if(a*8+x-192<64){LcdChoiceR(); //选择右侧侧屏幕x_1=a*8+x-192;y_1=y+2; //行下移一行}}}}LocateXY(x_1,y_1);for(b=0;b<94;b++) //50个字符内搜索需要显示的字符{if(font8x16[b][0]==MemuTemp[a]) //找到需要显示的字符,显示{for(i=1; i<17; i++){if(i==9) //如果已经传送16个字节,换行传送字符下半部分{LocateXY(x_1,y_1+1);}LcdWriteData(font8x16[b][i]);}break;}}}}/************************************************************函数名:DisplarFont8x16Left*功能:写左侧一行的字母,y参数为1-4之间数字,字符组MemuTemp包含8个字符*参数:*返回值:无*备注:***********************************************************/void DisplarFont8x16Left(unsigned char y,unsigned char *MemuTemp){uchar a,b,i,x;y=2*y-2;uchar n=0;LcdChoiceL(); // 清除所选择行数据开始LocateXY( 0,y);for(n=0;n<64;n++)LcdWriteData(0x00);LocateXY( 0,y+1);for(n=0;n<64;n++)LcdWriteData(0x00); // 清除所选择行数据结束for(a=0;a<8;a++) //计数每行字节,每行7个字符{for(b=0;b<94;b++) //50个字符内搜索需要显示的字符{if(font8x16[b][0]==MemuTemp[a]) //找到需要显示的字符,显示{x=a*8; //计算LocateXY(x,y); //开始定位y 行0位上半部分for(i=1; i<17; i++){if(i==9) //如果已经传送16个字节,换行传送字符下半部分LocateXY(x,y+1); ////开始定位y 行0位下半部分LcdWriteData(font8x16[b][i]);}break;}}}}/*******************************************函数名称:LcdChoiceLine功能:对12864液晶指定行进行清除参数:无返回值:无********************************************/void LcdClearLine(uchar y){uchar n;LcdChoiceL();//选择左侧LocateXY( 0,y);for(n=0;n<64;n++)LcdWriteData(0x00);LocateXY( 0,y+1);for(n=0;n<64;n++)LcdWriteData(0x00);LcdChoiceR();//选择右侧LocateXY( 0,y);for(n=0;n<64;n++)LcdWriteData(0x00);LocateXY( 0,y+1);for(n=0;n<64;n++)LcdWriteData(0x00);}typedef struct{unsigned char Index[2];unsigned char Msk[32];}TYPE_FONT16X16;const TYPE_FONT16X16 font16X16[]={"宁",0x20,0x18,0x88,0x88,0x88,0x88,0x89,0x8E,0x88,0x88,0x88,0x88,0x88,0x28,0x18,0x00, 0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,"波",0x10,0x60,0x02,0x0C,0xC0,0x00,0xF8,0x88,0x88,0x88,0xFF,0x88,0x88,0xA8,0x18,0x00, 0x04,0x04,0x7C,0x03,0x80,0x60,0x1F,0x80,0x43,0x2C,0x10,0x28,0x46,0x81,0x80,0x00,"钢",0x20,0x10,0x2C,0xE7,0x24,0x24,0x00,0xFE,0x12,0x62,0x82,0x72,0x02,0xFE,0x00,0x00, 0x01,0x01,0x01,0x7F,0x21,0x11,0x00,0xFF,0x08,0x06,0x01,0x4E,0x80,0x7F,0x00,0x00,"铁",0x20,0x10,0x2C,0xE7,0x24,0x24,0x40,0x3C,0x10,0x10,0xFF,0x10,0x10,0x10,0x00,0x00, 0x01,0x01,0x01,0x7F,0x21,0x11,0x80,0x41,0x31,0x0D,0x03,0x0D,0x31,0x41,0x81,0x00,"有",0x04,0x04,0x04,0x84,0xE4,0x3C,0x27,0x24,0x24,0x24,0x24,0xE4,0x04,0x04,0x04,0x00, 0x04,0x02,0x01,0x00,0xFF,0x09,0x09,0x09,0x09,0x49,0x89,0x7F,0x00,0x00,0x00,0x00,"限",0x00,0xFE,0x22,0x5A,0x86,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00, 0x00,0xFF,0x04,0x08,0x07,0x00,0xFF,0x40,0x20,0x03,0x0C,0x14,0x22,0x41,0x40,0x00,"公",0x00,0x80,0x40,0x20,0x18,0x06,0x80,0x00,0x07,0x18,0x20,0x40,0x80,0x00,0x00,0x00, 0x01,0x00,0x20,0x70,0x28,0x26,0x21,0x20,0x20,0x24,0x38,0x60,0x00,0x01,0x01,0x00,"司",0x00,0x10,0x12,0x92,0x92,0x92,0x92,0x92,0x92,0x12,0x12,0x02,0xFE,0x00,0x00,0x00, 0x00,0x00,0x00,0x3F,0x10,0x10,0x10,0x10,0x3F,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,"能",0x08,0xCC,0x4A,0x49,0x48,0x4A,0xCC,0x18,0x00,0x7F,0x88,0x88,0x84,0x82,0xE0,0x00, 0x00,0xFF,0x12,0x12,0x52,0x92,0x7F,0x00,0x00,0x7E,0x88,0x88,0x84,0x82,0xE0,0x00,"环",0x04,0x84,0x84,0xFC,0x84,0x84,0x00,0x04,0x04,0x84,0xE4,0x1C,0x84,0x04,0x04,0x00, 0x20,0x60,0x20,0x1F,0x10,0x10,0x04,0x02,0x01,0x00,0xFF,0x00,0x00,0x01,0x06,0x00,"部",0x40,0x44,0x54,0x65,0x46,0x44,0x64,0x54,0x44,0x40,0xFE,0x02,0x22,0xDA,0x06,0x00, 0x00,0x00,0x7E,0x22,0x22,0x22,0x22,0x7E,0x00,0x00,0xFF,0x08,0x10,0x08,0x07,0x00,"煤",0x80,0x70,0x00,0xFF,0x20,0x10,0x04,0x04,0xFF,0x24,0x24,0x24,0xFF,0x04,0x04,0x00,0x80,0x60,0x18,0x07,0x08,0x30,0x44,0x24,0x15,0x0D,0xFF,0x0D,0x15,0x24,0x44,0x00,"气",0x20,0x10,0x4C,0x47,0x54,0x54,0x54,0x54,0x54,0x54,0x54,0xD4,0x04,0x04,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x30,0x40,0xF0,0x00,"排",0x10,0x10,0x10,0xFF,0x90,0x08,0x88,0x88,0xFF,0x00,0x00,0xFF,0x88,0x88,0x08,0x00,0x02,0x42,0x81,0x7F,0x00,0x08,0x08,0x08,0xFF,0x00,0x00,0xFF,0x08,0x08,0x08,0x00,"水",0x00,0x20,0x20,0x20,0xA0,0x60,0x00,0xFF,0x60,0x80,0x40,0x20,0x18,0x00,0x00,0x00, 0x20,0x10,0x08,0x06,0x01,0x40,0x80,0x7F,0x00,0x01,0x02,0x04,0x08,0x10,0x10,0x00,"器",0x80,0x80,0x9E,0x92,0x92,0x92,0x9E,0xE0,0x80,0x9E,0xB2,0xD2,0x92,0x9E,0x80,0x00, 0x08,0x08,0xF4,0x94,0x92,0x92,0xF1,0x00,0x01,0xF2,0x92,0x94,0x94,0xF8,0x08,0x00,"报",0x10,0x10,0x10,0xFF,0x10,0x90,0x00,0xFE,0x82,0x82,0x82,0x92,0xA2,0x9E,0x00,0x00, 0x04,0x44,0x82,0x7F,0x01,0x00,0x00,0xFF,0x80,0x43,0x2C,0x10,0x2C,0x43,0x80,0x00,"警",0x12,0xEA,0xAF,0xAA,0xEA,0x0F,0xFA,0x02,0x88,0x8C,0x57,0x24,0x54,0x8C,0x84,0x00, 0x02,0x02,0xEA,0xAA,0xAA,0xAB,0xAA,0xAB,0xAA,0xAA,0xAA,0xAA,0xEA,0x02,0x02,0x00,"CO",0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00C, 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,"信",0x00,0x80,0x60,0xF8,0x07,0x00,0x04,0x24,0x24,0x25,0x26,0x24,0x24,0x24,0x04,0x00, 0x01,0x00,0x00,0xFF,0x00,0x00,0x00,0xF9,0x49,0x49,0x49,0x49,0x49,0xF9,0x00,0x00,"号",0x80,0x80,0x80,0xBE,0xA2,0xA2,0xA2,0xA2,0xA2,0xA2,0xA2,0xBE,0x80,0x80,0x80,0x00, 0x00,0x00,0x00,0x06,0x05,0x04,0x04,0x04,0x44,0x84,0x44,0x3C,0x00,0x00,0x00,0x00,"正",0x00,0x02,0x02,0xC2,0x02,0x02,0x02,0xFE,0x82,0x82,0x82,0x82,0x82,0x02,0x00,0x00, 0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,"常",0x20,0x18,0x08,0xEA,0xAC,0xA8,0xA8,0xAF,0xA8,0xA8,0xAC,0xEA,0x08,0x28,0x18,0x00, 0x00,0x00,0x3E,0x02,0x02,0x02,0x02,0xFF,0x02,0x02,0x12,0x22,0x1E,0x00,0x00,0x00,"在",0x08,0x08,0x88,0xC8,0x38,0x0C,0x0B,0x08,0x08,0xE8,0x08,0x08,0x08,0x08,0x08,0x00,0x02,0x01,0x00,0xFF,0x40,0x41,0x41,0x41,0x41,0x7F,0x41,0x41,0x41,0x41,0x40,0x00,"发",0x00,0x00,0x18,0x16,0x10,0xD0,0xB8,0x97,0x90,0x90,0x90,0x92,0x94,0x10,0x00,0x00, 0x00,0x20,0x10,0x8C,0x83,0x80,0x41,0x46,0x28,0x10,0x28,0x44,0x43,0x80,0x80,0x00,"送",0x40,0x40,0x42,0xCC,0x00,0x88,0x89,0x8E,0x88,0xF8,0x88,0x8C,0x8B,0x88,0x80,0x00, 0x00,0x40,0x20,0x1F,0x20,0x40,0x50,0x48,0x46,0x41,0x42,0x44,0x58,0x40,0x40,0x00,"短",0x90,0x88,0x87,0xFC,0x84,0x84,0x80,0x02,0xF2,0x12,0x12,0x12,0x12,0xF2,0x02,0x00, 0x80,0x60,0x18,0x07,0x08,0x30,0x00,0x40,0x45,0x59,0x41,0x41,0x51,0x4D,0x40,0x00,"成",0x00,0x00,0xF8,0x48,0x48,0x48,0xC8,0x08,0xFF,0x08,0x09,0x0A,0xC8,0x88,0x08,0x00, 0x40,0x30,0x0F,0x00,0x08,0x50,0x4F,0x20,0x10,0x0B,0x0C,0x12,0x21,0x40,0xF0,0x00,"功",0x00,0x04,0x04,0x04,0xFC,0x04,0x14,0x14,0x10,0x90,0x7F,0x10,0x10,0xF0,0x00,0x00, 0x04,0x0C,0x04,0x04,0x03,0x42,0x22,0x11,0x0C,0x23,0x20,0x60,0x20,0x1F,0x00,0x00," ",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,"手",0x00,0x24,0x24,0x24,0x24,0x24,0x24,0xFE,0x22,0x22,0x22,0x22,0x22,0x20,0x00,0x00, 0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00,"机",0x08,0x08,0xC8,0xFF,0x48,0x88,0x08,0x00,0xFE,0x02,0x02,0x02,0xFE,0x00,0x00,0x00, 0x04,0x03,0x00,0xFF,0x00,0x41,0x30,0x0C,0x03,0x00,0x00,0x00,0x3F,0x40,0x78,0x00,"卡",0x00,0x40,0x40,0x40,0x40,0x40,0x40,0xFF,0x44,0x44,0x44,0x44,0x44,0x44,0x40,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x02,0x04,0x0C,0x38,0x10,0x00,0x00,"错",0x40,0x30,0x2C,0xE7,0x24,0x24,0x40,0x48,0x7F,0x48,0x48,0x7F,0x48,0x48,0x40,0x00, 0x01,0x01,0x01,0xFF,0x41,0x21,0x00,0xFF,0x49,0x49,0x49,0x49,0x49,0xFF,0x00,0x00,"误",0x40,0x41,0xCE,0x04,0x00,0x40,0x5F,0x51,0x51,0xD1,0x51,0x51,0x5F,0x40,0x00,0x00, 0x00,0x00,0x3F,0x10,0x88,0x42,0x22,0x12,0x0A,0x07,0x0A,0x12,0x22,0xE2,0x42,0x00,/*********************************************/"强",0x02,0xE2,0x22,0x22,0x3E,0x00,0x80,0x9E,0x92,0x92,0xF2,0x92,0x92,0x9E,0x80,0x00, 0x00,0x43,0x82,0x42,0x3E,0x40,0x47,0x44,0x44,0x44,0x7F,0x44,0x44,0x54,0xE7,0x00,"度",0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00, 0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00,"中",0x00,0x00,0xF0,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0xF0,0x00,0x00,0x00, 0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x0F,0x00,0x00,0x00,"国",0x00,0xFE,0x02,0x12,0x92,0x92,0x92,0xF2,0x92,0x92,0x92,0x12,0x02,0xFE,0x00,0x00, 0x00,0xFF,0x40,0x48,0x48,0x48,0x48,0x4F,0x48,0x4A,0x4C,0x48,0x40,0xFF,0x00,0x00,"移",0x24,0x24,0xA4,0xFE,0x23,0x22,0x00,0x10,0x08,0x94,0x67,0x24,0x94,0x0C,0x00,0x00, 0x08,0x06,0x01,0xFF,0x01,0x06,0x00,0x89,0x89,0x44,0x4A,0x33,0x12,0x0A,0x06,0x00,"动",0x40,0x44,0xC4,0x44,0x44,0x44,0x40,0x10,0x10,0xFF,0x10,0x10,0x10,0xF0,0x00,0x00, 0x10,0x3C,0x13,0x10,0x14,0xB8,0x40,0x30,0x0E,0x01,0x40,0x80,0x40,0x3F,0x00,0x00,"联",0x02,0xFE,0x92,0x92,0xFE,0x02,0x00,0x10,0x11,0x16,0xF0,0x14,0x13,0x10,0x00,0x00, 0x10,0x1F,0x08,0x08,0xFF,0x04,0x81,0x41,0x31,0x0D,0x03,0x0D,0x31,0x41,0x81,0x00,"通",0x40,0x42,0xCC,0x00,0x00,0xE2,0x22,0x2A,0x2A,0xF2,0x2A,0x26,0x22,0xE0,0x00,0x00, 0x80,0x40,0x3F,0x40,0x80,0xFF,0x89,0x89,0x89,0xBF,0x89,0xA9,0xC9,0xBF,0x80,0x00,"服",0x00,0x00,0xFE,0x22,0x22,0x22,0xFE,0x00,0xFE,0x82,0x82,0x92,0xA2,0x9E,0x00,0x00, 0x80,0x60,0x1F,0x02,0x42,0x82,0x7F,0x00,0xFF,0x40,0x2F,0x10,0x2C,0x43,0x80,0x00,"务",0x00,0x00,0x90,0x88,0x4C,0x57,0xA4,0x24,0x54,0x54,0x8C,0x84,0x00,0x00,0x00,0x00, 0x01,0x01,0x80,0x42,0x22,0x1A,0x07,0x02,0x42,0x82,0x42,0x3E,0x01,0x01,0x01,0x00,"串",0x00,0x00,0x3C,0x24,0x24,0x24,0x24,0xFF,0x24,0x24,0x24,0x24,0x3C,0x00,0x00,0x00, 0x00,0x1F,0x09,0x09,0x09,0x09,0x09,0xFF,0x09,0x09,0x09,0x09,0x09,0x1F,0x00,0x00,"口",0x00,0x00,0xFC,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0xFC,0x00,0x00,0x00, 0x00,0x00,0x7F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7F,0x00,0x00,0x00,"通",0x40,0x42,0xCC,0x00,0x00,0xE2,0x22,0x2A,0x2A,0xF2,0x2A,0x26,0x22,0xE0,0x00,0x00, 0x80,0x40,0x3F,0x40,0x80,0xFF,0x89,0x89,0x89,0xBF,0x89,0xA9,0xC9,0xBF,0x80,0x00,"讯",0x40,0x40,0x42,0xCC,0x00,0x82,0x82,0xFE,0x82,0x82,0x02,0xFE,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x7F,0x20,0x10,0x00,0xFF,0x00,0x00,0x00,0x0F,0x30,0x40,0xF8,0x00,"异",0x00,0x00,0x7E,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x9E,0x80,0xE0,0x00,0x00, 0x08,0x88,0x48,0x28,0x1E,0x08,0x08,0x08,0x08,0x08,0xFE,0x08,0x08,0x08,0x08,0x00,"修",0x40,0x20,0xF8,0x07,0xF0,0xA0,0x90,0x4C,0x57,0x24,0xA4,0x54,0x4C,0x80,0x80,0x00, 0x00,0x00,0xFF,0x00,0x1F,0x80,0x92,0x52,0x49,0x29,0x24,0x12,0x08,0x00,0x00,0x00,//修0,"改",0x04,0x84,0x84,0x84,0x84,0xFC,0x40,0x30,0xCC,0x0B,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x7F,0x20,0x10,0x10,0x08,0x80,0x40,0x21,0x16,0x08,0x16,0x21,0x40,0x80,0x00,//改1,"码",0x04,0x84,0xE4,0x5C,0x44,0xC4,0x00,0x02,0xF2,0x82,0x82,0x82,0xFE,0x80,0x80,0x00,0x02,0x01,0x7F,0x10,0x10,0x3F,0x00,0x08,0x08,0x08,0x08,0x48,0x88,0x40,0x3F,0x00,//码2,"电",0x00,0x00,0xF8,0x88,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x88,0xF8,0x00,0x00,0x00,0x00,0x00,0x1F,0x08,0x08,0x08,0x08,0x7F,0x88,0x88,0x88,0x88,0x9F,0x80,0xF0,0x00,//电3,"话",0x40,0x40,0x42,0xCC,0x00,0x00,0x20,0x24,0x24,0x24,0xFE,0x22,0x23,0x22,0x20,0x00,0x00,0x00,0x00,0x7F,0x20,0x10,0x00,0xFE,0x42,0x42,0x43,0x42,0x42,0xFE,0x00,0x00,//话4,"接",0x10,0x10,0x10,0xFF,0x10,0x50,0x44,0x54,0x65,0xC6,0x44,0x64,0x54,0x44,0x40,0x00,0x04,0x44,0x82,0x7F,0x01,0x82,0x82,0x4A,0x56,0x23,0x22,0x52,0x4E,0x82,0x02,0x00,//接5,"收",0x00,0xFC,0x00,0x00,0xFF,0x00,0x40,0x20,0xD8,0x17,0x10,0x10,0xF0,0x10,0x10,0x00,0x00,0x0F,0x04,0x02,0xFF,0x00,0x80,0x40,0x21,0x16,0x08,0x16,0x21,0x40,0x80,0x00,//收6,"息",0x00,0x00,0x00,0xFC,0x54,0x54,0x56,0x55,0x54,0x54,0x54,0xFC,0x00,0x00,0x00,0x00,0x40,0x30,0x00,0x03,0x39,0x41,0x41,0x45,0x59,0x41,0x41,0x73,0x00,0x08,0x30,0x00,//息7,"数",0x90,0x52,0x34,0x10,0xFF,0x10,0x34,0x52,0x80,0x70,0x8F,0x08,0x08,0xF8,0x08,0x00,0x82,0x9A,0x56,0x63,0x22,0x52,0x8E,0x00,0x80,0x40,0x33,0x0C,0x33,0x40,0x80,0x00,//数8,"量",0x20,0x20,0x20,0xBE,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xBE,0x20,0x20,0x20,0x00, 0x00,0x80,0x80,0xAF,0xAA,0xAA,0xAA,0xFF,0xAA,0xAA,0xAA,0xAF,0x80,0x80,0x00,0x00,//量9,"存",0x04,0x04,0x84,0xE4,0x1C,0x07,0x24,0x24,0x24,0x24,0xA4,0x64,0x24,0x04,0x04,0x00,0x02,0x01,0x00,0xFF,0x00,0x02,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x02,0x02,0x00,//存10,"储",0x80,0x60,0xF8,0x87,0x84,0x98,0x00,0x20,0x24,0xA4,0x7F,0x24,0x34,0x28,0x24,0x00,0x00,0x00,0xFF,0x00,0x00,0x7F,0x24,0x12,0x01,0xFF,0x49,0x49,0x49,0xFF,0x00,0x00,//储11,"无",0x00,0x40,0x42,0x42,0x42,0xC2,0x7E,0x42,0xC2,0x42,0x42,0x42,0x40,0x40,0x00,0x00,0x80,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x3F,0x40,0x40,0x40,0x40,0x70,0x00,0x00,};/************************************************************说明:该font.h 文件中包含的是5110显示所用的ASCII、部分汉字、及图片字模。
LCD12864驱动程序(无字库)电路图如下,本人亲自调试过,可用!程序如下:*******************************************************************************主程序:#include <reg52.h>#include <LCD_12864.h>main() //主程序{unsigned char i=0;while(1){init_lcd();display_imge1();delay(30000);Msg(0);delay(30000);display_imge2();delay(30000);Disp_H_Line();delay(10000);Disp_V_Line();delay(10000);Msg(1);delay(30000);}}驱动程序//**********************LCD——12864显示程序**************// #include <reg52.h>#include <string.h>#include <math.h>#include <LCD_12864.h>#include <LCD_12864_data.h>#define Disp_On 0x3f //开显示#define Disp_Off 0x3e //关显示#define Col_Add 0x40 //#define Page_Add 0xb8 //页起始地址#define Start_Line 0xc0 //行起始地址#define Lcd_Bus P0 // MCU P0<------> LCMsbit Di =P2^0; //Data or Instrument Select RSsbit RW =P2^1; //Write or Read R/Wsbit Enable =P2^2; //6800 mode Enable single Esbit Mcs =P2^3; //Master chip enable CS1sbit Scs =P2^4; //Slave chip enable CS2sbit Lcd_Rst=P2^5; //Lcm reset RSTvoid delay(unsigned int t) //延时子程序{unsigned int i,j;for(i=0;i<t;i++)for(j=0;j<10;j++);}void write_com(unsigned char cmdcode) //写指令{Di=0;RW=0;Lcd_Bus=cmdcode;delay(0);Enable=1;delay(0);Enable=0;}void write_data(unsigned char Dispdata) //写数据{Di=1;RW=0;Lcd_Bus=Dispdata;delay(0);Enable=1;delay(0);Enable=0;}void frame() // {unsigned char i;Mcs=1;Scs=1;write_com(Page_Add+0);write_com(Col_Add+0);for(i=0;i<64;i++) write_data(0x01);write_com(Page_Add+7);write_com(Col_Add+0);for(i=0;i<64;i++) write_data(0x80);for(i=0;i<8;i++){Mcs=1;Scs=1;write_com(Page_Add+i);write_com(Col_Add+63);write_data(0xff);Mcs=1;Scs=1;write_com(Page_Add+i);write_com(Col_Add+0);write_data(0xff);}}void Clr_Scr(){unsigned char j,k;Mcs=1;Scs=1;write_com(Page_Add+0);write_com(Col_Add+0);for(k=0;k<8;k++){write_com(Page_Add+k);for(j=0;j<64;j++)write_data(0x00);}}void Disp_Img(unsigned char code *img) //显示图片{unsigned char j,k;Clr_Scr();for(k=0;k<8;k++){Mcs=1;Scs=0;delay(10);write_com(Page_Add+k);write_com(Col_Add+0);for(j=0;j<64;j++) write_data(img[k*128+j]);Mcs=0;Scs=1; delay(10);write_com(Page_Add+k);write_com(Col_Add+0);for(j=64;j<128;j++) write_data(img[k*128+j]);}}void Disp_H_Line() //显示行线{unsigned char i,j;Mcs=1;Scs=1;write_com(Disp_On);write_com(Page_Add);write_com(Start_Line);write_com(Col_Add);for(j=0;j<8;j++){write_com(Page_Add+j);write_com(Col_Add+0);// write_com(Start_Line+0);for(i=0;i<64;i++)write_data(0x55);}}void Disp_V_Line() //显示列线{unsigned char i,j;write_com(Disp_On);write_com(Page_Add);write_com(Start_Line);write_com(Col_Add);for(j=0;j<8;j++){write_com(Page_Add+j);write_com(Col_Add+0);write_com(Start_Line+0);for(i=0;i<32;i++){write_data(0x00);write_data(0xff);}}}void hz_disp16(unsigned char pag,unsigned char col, unsigned char code *hzk) //行列显示{unsigned char j=0,i=0;for(j=0;j<2;j++){write_com(Page_Add+pag+j); //第3、4行write_com(Col_Add+col); //列选for(i=0;i<16;i++) write_data(hzk[16*j+i]);}}void init_lcd() //显示初始化{Lcd_Rst=0;delay(100);Lcd_Rst=1;delay(100);Mcs=1;Scs=1;delay(100);write_com(Disp_Off);write_com(Page_Add+0);write_com(Start_Line+0);write_com(Col_Add+0);write_com(Disp_On);}void Msg(int flg){Clr_Scr();frame();if(flg==0){ //显示“延安大学”Mcs=1;Scs=0;hz_disp16(3,32,yan);delay(4000);hz_disp16(3,48,an);delay(4000);Mcs=0;Scs=1;hz_disp16(3,0,da);delay(4000);hz_disp16(3,16,xue);delay(4000);}else if(flg==1){ //显示“测试完毕”Mcs=1;Scs=0;hz_disp16(3,32,ce);hz_disp16(3,48,shi);Mcs=0;Scs=1;hz_disp16(3,0,wan);hz_disp16(3,16,bi);}}void display_imge1(){Disp_Img(FirstPage);}void display_imge2(){Disp_Img(SecondPage);}字模数据#include <reg52.h>char code yan[]={0x02,0x22,0x72,0x2E,0xE2,0x00,0x04,0xE4,0x04,0x04,0xFC,0x42,0x42,0x42,0x00,0x00,0x40,0x23,0x14,0x08,0x17,0x20,0x20,0x47,0x44,0x44,0x47,0x44,0x44,0x44,0x44,0x00/*"延",0*/};char code an[]={0x80,0x90,0x8C,0x84,0x84,0xF4,0xA5,0x86,0x84,0x84,0x84,0x84,0x94,0x8C,0x84,0x00,0x80,0x80,0x80,0x40,0x47,0x28,0x28,0x10,0x28,0x24,0x43,0xC0,0x40,0x00,0x00,0x00/*"安",1*/};char code da[]={0x20,0x20,0x20,0x20,0x20,0x20,0xA0,0x7F,0xA0,0x20,0x20,0x20,0x20,0x20,0x20,0x00,0x00,0x80,0x40,0x20,0x10,0x0C,0x03,0x00,0x01,0x06,0x08,0x30,0x60,0xC0,0x40,0x00/*"大",2*/};char code xue[]={0x40,0x30,0x10,0x12,0x5C,0x54,0x50,0x51,0x5E,0xD4,0x50,0x18,0x57,0x32,0x10,0x00,0x00,0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x02,0x02,0x02,0x00/*"学",3*/};char code ce[]={0x08,0x31,0x86,0x60,0x00,0xFE,0x02,0xF2,0x02,0xFE,0x00,0xF8,0x00,0x00,0xFF,0x00,0x04,0xFC,0x03,0x00,0x80,0x47,0x30,0x0F,0x10,0x67,0x00,0x07,0x40,0x80,0x7F,0x00,/*"测",0*/};char code shi[]={0x40,0x42,0xDC,0x08,0x00,0x90,0x90,0x90,0x90,0x90,0xFF,0x10,0x12,0x1C,0x10,0x00,0x00,0x00,0x7F,0x20,0x10,0x20,0x20,0x1F,0x10,0x10,0x01,0x06,0x18,0x20,0x78,0x00,/*"试",0*/};char code wan[]={0x00,0x90,0x8C,0xA4,0xA4,0xA4,0xA5,0xA6,0xA4,0xA4,0xA4,0xA4,0x94,0x8C,0x04,0x00, 0x00,0x80,0x40,0x20,0x18,0x07,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x70,0x00,0x00,/*"完",0*/};char code bi[]={0x00,0x00,0xFF,0x88,0x48,0x28,0x08,0x80,0x7F,0x88,0x88,0x88,0x84,0x84,0xE0,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,/*"毕",0*/};unsigned char code FirstPage[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x70,0xFC,0xFC,0x7C,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0xC0,0xF0,0xE0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xF0,0xF0,0xC0,0x80,0xE0,0xFF,0xFF,0xFF,0xFF,0x78,0x78,0xF8,0xF0,0xE0,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xF8,0xF8,0xF8,0xF0,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x06,0x3F,0x3F,0x9C,0x9C,0x3E,0x3C,0x38,0xF8,0xFC,0xFE,0xFE,0xFE,0xFE,0xFC,0xC0,0x80,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x7E,0xFF,0xE1,0x00,0xC0,0xF8,0xFC,0xFC,0xE4, 0xE2,0xC2,0xC2,0xE1,0xA1,0x33,0xF3,0xF3,0xF0,0xE0,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x3B,0x38,0x38,0x1E,0x9F,0x87,0x81,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0xC0,0xFF,0xFF,0xFF,0xFF,0xFB,0xF9,0xF8,0xF8,0xF8,0x78,0x78,0x30,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xF8,0xFC,0xFF,0xFF,0x7F,0x3F,0x3F,0x1F,0x8F,0x8F,0xC3,0xC3,0xE3,0xE1,0xE1,0x31,0x31,0x73,0xE3,0xE3,0x7F,0x3F,0x00,0x00,0x00, 0x00,0x00,0x10,0x78,0xF8,0xF0,0xF0,0xF0,0xFF,0xFF,0xFF,0xDF,0xFF,0xBF,0xB3,0xB0, 0x99,0x9B,0x9F,0x9F,0x9F,0x9E,0x86,0x81,0x81,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x70,0x70,0x78,0x78,0x78,0x78,0x78,0x78,0x78,0x78,0x78,0xF8,0xF8,0xF8,0xFF,0xBF,0x3F,0x3D,0xFC,0xFC,0xFC,0xFC,0x7F,0x1F,0x1F,0x1F,0x1E, 0x0F,0x0E,0x0E,0x1E,0x1F,0x0E,0x04,0x00,0x00,0x00,0x00,0x00,0x81,0x87,0xC7,0xE7, 0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x1F,0x01,0x70,0xF0,0xF0,0xF0,0xF0,0xE0,0xC0,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x67,0xE3,0xE0,0xE0,0xE0,0xE1,0xE3, 0xF3,0xF8,0xFE,0xFF,0xFB,0xF0,0x70,0x70,0x70,0x70,0x60,0x00,0x00,0x00,0x00,0x00, 0x00,0x06,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x07,0x07,0x07,0x07,0x07,0x0F,0x0F,0x07,0x07,0x07,0x0F,0x0F,0x0F,0x0F,0x1F,0x1F,0x0F,0x0F,0x0F,0x07,0x07,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x0E,0x1E,0x1E,0x1E,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x07,0x07,0x07,0x07,0x0F,0x0F,0x1E,0x1E,0x3C,0x3C,0x18,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x07,0x07,0x07,0x07,0x03,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x07,0x0F,0x07,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x1C,0x3C,0x3C,0x3C,0x3C,0x1F,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"C:\Documents and Settings\Administrator\桌面\延安大学字.bmp",0*/};unsigned char code SecondPage[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0xC0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0x80,0x00,0x00,0xC0,0xC0,0xC0,0x80,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x03,0xC1,0xF1,0xFD,0xFF,0xDF,0xC7,0xC0,0x12,0xF3,0xF3,0xF3,0x03,0xFF,0xFF, 0xFF,0x41,0x41,0x41,0x41,0x00,0x00,0x00,0x00,0x00,0x1E,0x1E,0x1E,0x02,0x02,0x02,0xC2,0xF2,0xF2,0x73,0x23,0x03,0x02,0x02,0x02,0x02,0x02,0x3E,0x3E,0x3E,0x00,0x00, 0x00,0x00,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0xFF,0xFF,0xFF,0xFF,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x00,0x00,0x00,0x78,0x78,0x78,0x78,0x8B,0x8B,0x8B,0x8A,0x88,0x89,0x8B,0x89,0x89,0x8C,0x8F,0x8F,0x8F,0x89,0x78,0x78,0x78,0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x1C,0xBC,0xF8,0xFE,0xFF,0x9F,0x81,0x20,0x3F,0x3F,0x3F,0x20,0x3F,0x3F, 0x3F,0x20,0x20,0x20,0x20,0x20,0x00,0x00,0x00,0x03,0x03,0x03,0x03,0x13,0x1F,0x3F,0x3F,0xB7,0xF3,0xE3,0xE3,0xF3,0xFF,0xFF,0x9F,0x87,0x03,0x03,0x03,0x03,0x03,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0xF0,0xF8,0x7E,0x3F,0x0F,0x0F,0x1F,0x7C,0xF8, 0xF0,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0xFC,0xFE,0xFE,0x17,0x13,0x13,0x11,0x11,0x10,0x10,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0xC0,0xC0,0xC0,0xC0,0x80, 0x00,0x06,0x07,0x07,0x03,0x01,0x81,0x81,0x83,0x83,0x83,0x83,0xC6,0xC6,0xC6,0x86,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x00,0x02,0x0E,0xCE,0xC6,0x07,0xC7, 0x83,0x03,0x03,0x01,0x01,0x80,0x81,0x01,0x03,0x03,0x07,0x87,0x87,0x02,0x00,0x00,0x00,0x02,0x07,0x07,0x87,0x83,0x81,0x81,0x80,0x80,0xC0,0xC0,0x80,0x80,0x80,0x80,0x81,0x81,0x03,0x07,0x07,0x03,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x07,0x07,0x07,0x00,0x00,0x00,0x00,0x00,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,0x80,0x80,0xFF,0xFF,0x8D,0x8D,0x8D,0x8C,0xFC,0xFC,0x8C,0x8C, 0x80,0x80,0x00,0x80,0x80,0x80,0xFF,0xFF,0x99,0x99,0x99,0x99,0xF8,0xF8,0x98,0x98,0x80,0x80,0x00,0x33,0x33,0xFF,0xFF,0x33,0x00,0x16,0x36,0xA6,0xFF,0xFF,0xC6,0x66,0x0C,0x00,0x00,0x00,0xA1,0xA1,0xAA,0xEA,0xFF,0xBF,0xAA,0xAA,0xFF,0xFF,0xAA,0xAA, 0xA1,0x81,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x19,0x19,0x0D,0x0D,0x07,0x03,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x07,0x05,0x0D,0x19,0x11,0x01,0x00,0x0C,0x0C,0x07,0x07,0x06,0x00,0x06,0x03,0x19,0x1F,0x0F,0x01,0x03,0x06,0x04,0x00,0x00,0x00,0x1F,0x1F,0x0C,0x06,0x06,0x00,0x0F,0x1F,0x18,0x18,0x18,0x1E,0x0C,0x00,0x00,0x00,0x10,0x10,0x1B,0x1B,0x0C,0x06,0x06,0x0C,0x8B,0x9B,0x18,0x10,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x00,0xC0,0xC0,0x00,0x00,0x00,0x80,0xC0,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0, 0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x18,0x18,0xF8,0xF9,0x03,0x00,0x01,0xF1,0xF1,0x31,0x31,0x31,0x3F,0x3F,0x00,0x00,0x00,0x30,0x18,0x3C,0x36,0xF3,0xF1,0x30,0x30,0x33,0xF7,0xFE,0x1C,0x38,0x10,0x00,0x00,0xFF,0xFF,0xD8,0xDF,0xDF,0x18,0x7F,0x7F,0xCB,0xFF,0xFF,0xCB,0x7F,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x0C,0x06,0x00,0x0F,0x1F,0x18,0x18,0x18,0x18,0x1C,0x1C,0x00,0x00,0x08,0x18,0x0C,0x06,0x03,0x01,0x00,0x18,0x18,0x0F,0x07,0x00,0x00,0x00,0x00,0x18,0x0F,0x03,0x00,0x1F,0x1F,0x06,0x06,0x07,0x07,0x06,0x1F,0x1F,0x06,0x06,0x00,0x00,0x00,0x00,0x00,0x00,/*"C:\Documents and Settings\Administrator\桌面\乒乓球记分牌.bmp",0*/};/×××××××××××××××××××××××××××××××××××××××库函数.h××××××××××××××××××××××××××××××××××××××/ void delay(unsigned int t);void write_com(unsigned char cmdcode);void write_data(unsigned char Dispdata);void frame();void Clr_Scr();void Disp_Img(unsigned char code *img);void Disp_H_Line();void Disp_V_Line();void hz_disp16(unsigned char pag,unsigned char col, unsigned char code *hzk); void init_lcd();void Msg(int flg);void display_imge1(void);void display_imge2(void);。
基于 STM32--LCD12864驱动程序STM32 LCD12864 驱动程序(头文件)(2012-05-29 21:25:08) 转载▼标签:杂谈#ifndef LCD12864_H#define LCD12864_H#define LCD_CONTROL GPIOD//默认LCD12864的控制口在 PD口#define LCD_DATAPORTGPIOD//默认LCD12864的数据口在 PD口#define LCD_RESET_PinGPIO_Pin_12 // 默认LCD12864的复位引脚连接到 PD.12 也可不用#define LCD_RS_Pin GPIO_Pin_13 // 默认LCD12864 RS -- PD.13#define LCD_RW_PinGPIO_Pin_14 // 默认LCD12864 RW -- PD.14#define LCD_EN_Pin GPIO_Pin_15 // 默认LCD12864 E -- PD.15#define LCD_CONTROL_CLOCKRCC_APB2Periph_GPIOD //默认 LCD12864的控制口时钟#define LCD_DATAPORT_CLOCKRCC_APB2Periph_GPIOD //默认 LCD12864的数据口时钟#define LCD_RS_1LCD_CONTROL->BSRR&=~LCD_RS_Pin;LCD_CONTROL->BSRR |=LCD_RS_Pin //RS 置高电平#define LCD_RS_0LCD_CONTROL->BRR&=~LCD_RS_Pin;LCD_CONTROL->BRR |=LCD_RS_Pin //RS 置低电平#define LCD_RW_1 LCD_CONTROL->BSRR &=~LCD_RW_Pin;LCD_CONTROL->BSRR|=LCD_RW_Pin //RW 置高电平#define LCD_RW_0 LCD_CONTROL->BRR &=~LCD_RW_Pin;LCD_CONTROL->BRR|=LCD_RW_Pin //RW 置低电平#define LCD_EN_1LCD_CONTROL->BSRR &=~LCD_EN_Pin;LCD_CONTROL->BSRR|=LCD_EN_Pin //EN 置高电平#define LCD_EN_0LCD_CONTROL->BRR&=~LCD_EN_Pin;LCD_CONTROL->BRR |=LCD_EN_Pin //EN 置低电平#define LCD_RESET_0 LCD_CONTROL->BRR= LCD_RESET_Pin // 复位#define LCD_RESET_1 LCD_CONTROL->BSRR= LCD_RESET_Pin // 复位脚拉高#define DATAOUT LCD_DATAPORT->ODR&=0xff00;LCD_DATAPORT->ODR // 数据输出寄存器#define DATAIN LCD_DATAPORT->IDR //数据输入寄存器#define LCD_BF((DATAIN)&0x0080)//忙状态void LCD_delayus(unsigned long n); //n(us)void LCD_delayms(unsigned long n); //n(ms)void LCD_WriteInitcmd(uint8_t initcmd); 延时延时//写初始化命令void LCD_WaitLaisure(void); //一直等待到 LCD内部操作完成,变为空闲状态void LCD_Writecmd(uint8_t cmd); //写命令到 LCD12864void LCD_WriteByte(uint8_t byte); //写一字节数据到 LCD12864void LCD_pos(uint16_t pos); //LCD显示位置设置col);// void 设定 LCD12864的显示地址,根据习惯LCD_DispChar(char ch); //显示一个字符voidrow,uint16_tLCD_Setpos_DispChar(uint16_t col,char ch);//在指定位置显示一个字符void LCD_DispString(char str[]); // 显示一个字符串,显示位置需提前设定//在指定位置显示一个字符串void LCD_Setpos_DispString(uint16_t row,uint16_t col,char str[]);void LCD_Dispnum(uint32_t num); //显示一个不超过 8 位的整数,显示位置需提前设置//在指定位置显示一个不超过 8 位的整数void LCD_Setpos_Dispnum(uint16_t row,uint16_t col,uint32_t num);void LCD_DispDecimal(uint32_t num,uint16_tdot);// 显示一个有效位不超过 8 位的浮点数 , 显示位置需要提前设定//在指定位置显示一个有效位不超过 8 位的浮点数void LCD_Setpos_DispDecimal(uint16_t row,uint16_t col,uint32_t num,uint16_t dot);//显示日历,显示日期与时间void LCD_DispDateTime(uint32_t year,uint16_t month,uint16_t day,uint16_t hour,uint16_tmin,uint16_t sec);void LCD_DispPicture(const unsigned char picture[]); //显示一幅图像128*64//屏幕整体左移一格,用于滚动显示void LCD_ShiftLeft(void);//屏幕整体右移一格,用于滚动显示void LCD_ShiftRight(void);//清屏,清除显示void LCD_Clear(void);//使光标还回原点位置void LCD_Return(void);//关显示void LCD_Close(void);//开显示void LCD_Open(void);void LCD_FlickerChar(uint16_t row,uint16_t col);//关闭字符闪烁void LCD_CloseFlicker(void);//屏幕秒闪烁一次void LCD_FlickerScreen(void);void LCD_PORT_Init(void);//LCD连接端口初始化void LCD_Init(void);//LCD配置初始化#endif#include "stm32f10x.h"#include "stm32f10x_gpio.h"#include "LCD12864.h"#include "picture.h"// 延时 n(us)void LCD_delayus(unsigned long n) {unsigned long j;while(n--){ j=8;while(j--);}}// 延时 n(ms)void LCD_delayms(unsigned long n) {while(n--)LCD_delayus(1100);}//写初始化命令void LCD_WriteInitcmd(uint8_t initcmd){LCD_RS_0;LCD_RW_0;LCD_EN_1;DATAOUT |= initcmd;LCD_delayus(600);LCD_EN_0;LCD_RW_1;}//一直等待到 LCD内部操作完成,变为空闲状态void LCD_WaitLaisure(void){uint16_t flag=0x00;LCD_RS_0;LCD_RW_1;do{LCD_EN_0;LCD_delayus(5);LCD_EN_1;LCD_delayus(5);flag=(uint16_t)LCD_BF;}while(flag);}// 写命令到 LCD12864void LCD_Writecmd(uint8_t cmd){LCD_WaitLaisure();LCD_RS_0;LCD_RW_0;LCD_EN_1;DATAOUT |= cmd;LCD_delayus(600); //经过测试,取600。
液晶显示器LCD12864驱动程序#include<msp430g2553.h>#include "lcd12864.h"#include "typedef.h"#define cyCS BIT0 //P2.0,片选信号#define cySID BIT1 //P2.1,串行数据#define cyCLK BIT2 //P2.2,同步时钟#define cyPORT P2OUT#define cyDDR P2DIRvoid Write_8bits(u8 W_bits){u8 i;cyDDR |= cyCLK + cySID; //设置输出方向for(i = 0; i < 8; i++){if(( W_bits << i )&0x80){cyPORT |= cySID;}else{cyPORT &= ~cySID;}delay_ms(1);cyPORT |= cyCLK;delay_ms(1);delay_ms(1);cyPORT &= ~cyCLK;}}void w_1byte(u8 RS, u8 w_data){u8 H_Data,L_Data;u8 tmp_Data = 0xf8;cyDDR |= cyCS; //设置CS口为输出if(RS == 0) tmp_Data &= ~0x02;else tmp_Data |= 0x02;H_Data = w_data; //高位数据H_Data &= 0xf0;L_Data = w_data; //低位数据L_Data &= 0x0f;L_Data <<= 4;cyPORT |= cyCS;Write_8bits(tmp_Data);Write_8bits(H_Data);Write_8bits(L_Data);cyPORT &= ~cyCS;}void init_Lcd(void){cyDDR |= cyCLK + cySID + cyCS; //相应的位端口设置为输出delay_ms(10); //延时等待液晶完成复位w_1byte(0,0x30);delay_ms(1);w_1byte(0,0x02);delay_ms(5);w_1byte(0,0x0c);delay_ms(1);w_1byte(0,0x01);delay_ms(5);w_1byte(0,0x06);delay_ms(1);}//清屏void clear_lcd(void){delay_ms(1);w_1byte(0,0x01);delay_ms(5);}void lcd_pos(u8 x,u8 y)//定位{u8 pos;switch(x){case 1:pos=0x80;break;case 2:pos=0x90;break;case 3:pos=0x88;break;case 4:pos=0x98;break;default:pos=0x80;}pos += y;w_1byte(0,pos);}//显示汉字void Disp_HZ(const u8 * pt,u8 num){u8 i;for(i = 0;i < num*2;i++){w_1byte(1,*(pt++));}}//显示字符void Disp_Ch(const u8 ch){w_1byte(1, ch);}//汉字和字符混合显示void disp_lcd_str(u8 x, u8 y, const u8 *str, u8 len) {u8 i;lcd_pos(x, y);for(i = 0;i < len && *str; ){if(*(str) >= 0x80){w_1byte(1,*(str++));w_1byte(1,*(str++));i++;i++;}else{w_1byte(1,*(str++));i++;}}}。
/*****************************************************************12864的驱动显示源文件=====LCD12864.c*****************************************************************/#include <reg52.h>#include <intrins.h>/*-------- 12864的接口设置 --------*/#define LCD_DATA_PORT P2sbit LCD_RS =P1^1;sbit LCD_RW = P1^2;sbit LCD_EN = P1^3;sbit LCD_PSB =P1^4;//===================================================================== ============////============================控制基础函数=========================================////===================================================================== ============///***********************************************函数名:LCD_wait入口参数:无功能:LCD12864读忙等待的操作***********************************************/void LCD_Wait(void){LCD_DATA_PORT=0xff;LCD_RS=0;LCD_RW=1;LCD_EN=1;_nop_();while( LCD_DA TA_PORT&0x80 );LCD_EN=0;}/***********************************************函数名:LCD_write_comm入口参数:content:内容功能:向LCD12864写命令***********************************************/void LCD_WriteCommand(unsigned char content){LCD_RS=0;LCD_RW=0;LCD_DATA_PORT=content;_nop_();LCD_EN=1;_nop_();LCD_EN=0;}/*********************************************** 函数名:LCD_WriteByte入口参数:content:内容功能:向LCD12864写数据***********************************************/ void LCD_WriteData(unsigned char content){LCD_Wait();LCD_RS=1;LCD_RW=0;LCD_DATA_PORT=content;_nop_();LCD_EN=1;_nop_();LCD_EN=0;}/*********************************************** 函数名:LCD_ReadData入口参数:无功能:从LCD12864读数据***********************************************/ unsigned char LCD_ReadData(void){unsigned char dat=0;LCD_Wait();LCD_DATA_PORT=0xff;LCD_RS=1;LCD_RW=1;LCD_EN=0;LCD_EN=1;_nop_();dat=LCD_DA TA_PORT;return dat;}//===================================================================== ============////=======================液晶的初始化设置==========================================////===================================================================== ============///***********************************************函数名:LCD_Init入口参数:无功能:LCD12864的初始化设置***********************************************/void LCD_Init(void){unsigned char i=0xff;LCD_PSB=1; //控制方式选择并口while(i--); //启动需要一定的延时LCD_WriteCommand ( 0x30 ); //中文模式LCD_WriteCommand ( 0x30 );LCD_WriteCommand ( 0x0c ); //显示设置LCD_WriteCommand ( 0x06 );LCD_WriteCommand ( 0x01 ); //清屏}//===================================================================== ============////==================文本模式下有关的驱动控制=======================================////===================================================================== ============///***********************************************函数名:LCD_Clear入口参数:无功能:LCD12864的清屏函数***********************************************/void LCD_Clear(void){LCD_WriteCommand(0x01);}/***********************************************函数名:LCD_Locate入口参数:y:行;x:列功能:定位光标***********************************************/void LCD_Locate(unsigned char y,unsigned char x){switch( y ){case 0 :LCD_WriteCommand ( 0x80+x );break;case 1 :LCD_WriteCommand ( 0x90+x );break;case 2 :LCD_WriteCommand ( 0x88+x );break;case 3 :LCD_WriteCommand ( 0x98+x );break;default :break;}}/***********************************************函数名:LCD_PutString入口参数:*ptr:数据指针;功能:显示字符串***********************************************/void LCD_PutString(unsigned char *ptr){while(*ptr != '\0'){LCD_WriteData(*ptr++);}}/***********************************************函数名:LCD_PutString_Add入口参数:*ptr:数据指针;功能:指定位置显示字符串***********************************************/void LCD_PutString_Add(unsigned char y,unsigned char x,unsigned char *ptr) {LCD_Locate(y,x);LCD_PutString(ptr);}/***********************************************函数名:LCD_ClearScreen入口参数:无功能:图形模式下的清屏函数***********************************************/void LCD_ClearScreen(void){unsigned char i;unsigned char j;LCD_WriteCommand( 0x34 );LCD_WriteCommand( 0x36 );for(j=0;j<64;j++){LCD_WriteCommand( 0x80+j ) ; //yLCD_WriteCommand( 0x80 ) ; //xfor(i=0;i<16;i++){LCD_WriteData( 0x00 ) ;LCD_WriteData( 0x00 ) ;}}LCD_WriteCommand( 0x30 ); //返回文本模式}/***********************************************函数名:LCD_DrawPixel入口参数:无功能:图形模式下的画点函数***********************************************/void LCD_DrawPixel(unsigned char x, unsigned char y, unsigned char Color) {unsigned char Row , Tier , Tier_bit ;unsigned char temp_h, temp_l ;if((x>127)||(y>63)) //超范围{return ;}LCD_WriteCommand( 0x34 ) ; //图形模式LCD_WriteCommand( 0x36 ) ; //开图形显示Tier = x>>4;Tier_bit = x&0x0f;if(y < 32){Row = y;}else{Row = y - 32 ;Tier += 8 ;}LCD_WriteCommand( Row + 0x80 ) ;LCD_WriteCommand( Tier + 0x80 ) ;LCD_ReadData() ; //假读temp_h = LCD_ReadData() ;temp_l = LCD_ReadData() ;LCD_WriteCommand( Row + 0x80 ) ;LCD_WriteCommand( Tier + 0x80 ) ;if( Tier_bit < 8 ){switch( Color){case 0 : temp_h &=( ~( 0x01 << ( 7 - Tier_bit ))) ; break ;case 1 : temp_h |= ( 0x01 << ( 7 - Tier_bit )) ; break ;case 2 : temp_h ^= ( 0x01 << ( 7 - Tier_bit )) ; break ;default : break ;}}else{switch(Color){case 0 : temp_l &= (~( 0x01 << ( 15 - Tier_bit ))) ; break ;case 1 : temp_l |= ( 0x01 << ( 15 - Tier_bit )) ; break ;case 2 : temp_l ^= ( 0x01 << ( 15 - Tier_bit )) ; break ;default : break ;}}LCD_WriteData( temp_h ) ;LCD_WriteData( temp_l ) ;LCD_WriteCommand( 0x30 ) ; //返回文本模式}/***********************************************函数名:LCD_DrawLine_X入口参数:无功能:图形模式下的画点函数***********************************************/void LCD_DrawLine_X(unsigned char y0, unsigned char x0, unsigned char x1, unsigned char fColor){unsigned char n;if(x0 > x1){n = x1;x1 = x0;x0 = n;}if(fColor==2){for(n=x0; n <= x1; n++){if(n%2==0){LCD_DrawPixel(n, y0, 0);}else{LCD_DrawPixel(n, y0, 1);}}}else{for(n=x0; n <= x1; n++){LCD_DrawPixel(n, y0, fColor);}}}/***********************************************函数名:LCD_DrawLine_Y入口参数:无功能:图形模式下的画点函数***********************************************/void LCD_DrawLine_Y(unsigned char x0, unsigned char y0, unsigned char y1, unsigned char fColor){unsigned char n;if(y0 > y1){n = y1;y1 = y0;y0 = n;}if(fColor==2){for(n=y0; n <= y1; n++){if(n%2==0){LCD_DrawPixel(x0, n, 1);}else{LCD_DrawPixel(x0, n, 0);}}}else{for(n=y0; n <= y1; n++){LCD_DrawPixel(x0, n, fColor);}}}/***********************************************函数名:LCD_DrawLine入口参数:无功能:图形模式下的画线函数***********************************************/void LCD_DrawLine(unsigned char x0, unsigned char y0, unsigned char x1, unsigned char y1, unsigned char Color ){/*根据屏幕大小改变变量类型(如改为int 型)*/unsigned char t, distance;unsigned char x=0, y=0;char delta_x, delta_y ;char incx, incy;if((x0>127)||(x1>127)||(y0>63)||(y1>63)) //超出显示范围{return ;}delta_x = x1 - x0;delta_y = y1 - y0;//=================================//if(delta_x > 0){incx = 1;}else if(delta_x == 0){LCD_DrawLine_Y(x0, y0, y1, Color);return;}else{delta_x = -delta_x; //绝对值incx = -1 ;}//=================================//if(delta_y > 0){incy = 1;}else if(delta_y == 0){LCD_DrawLine_X(y0, x0, x1, Color);return;}else{delta_y = -delta_y; //绝对值incy = -1;}//=================================//if(delta_x > delta_y){distance = delta_x ;}else{distance = delta_y ;}//=================================///* Draw Line*/for(t=0; t <= distance+1; t++ ){LCD_DrawPixel(x0, y0, Color) ;x += delta_x ;y += delta_y ;if(x > distance){x -= distance ;x0 += incx ;}if(y > distance){y -= distance ;y0 += incy ;}}}/*************************** 结束*********************************/。
初学STM32,写一个简单的128*64LCD驱动程序/**************************************************************************** 【功能说明】I/O端口功能、方向设定****************************************************************************/ voidLCD_Port_OutConfig(void){GPIO_InitTypeDef GPIO_InitStructure;/* 配置所用管脚为推免输出,端口速度为50MHz*/GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|\GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|\GPIO_Pin_13|GPIO_Pin_14;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(GPIO_LCD, &GPIO_InitStructure);}voidLCD_Port_InConfig(void){GPIO_InitTypeDef GPIO_InitStructure;/* 配置所用管脚为推免输出,端口速度为50MHz*/GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|\GPIO_Pin_6|GPIO_Pin_7;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING ;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(GPIO_LCD, &GPIO_InitStructure);}/**************************************************************************** 【功能说明】LCD 写字节函数入口参数data:" 命令/数据标志(data:写显示数据)****************************************************************************/LCD_WriteData(u16 data){u16 ReadValue;LCD_Port_InConfig();do{LCD_I();LCD_R();LCD_E_1();Delay_us(dly);LCD_E_0();Delay_us(dly);}while(GPIO_ReadInputDataBit(GPIO_LCD,GPIO_Pin_7));LCD_Port_OutConfig();LCD_D();LCD_W();ReadValue = GPIO_ReadOutputData(GPIO_LCD);data=0xff00&ReadValue|data;GPIO_Write(GPIO_LCD,data);ReadValue = GPIO_ReadOutputData(GPIO_LCD);GPIO_Write(GPIO_LCD,ReadValue);LCD_E_1();Delay_us(dly);LCD_E_0();Delay_us(dly);}/**************************************************************************** 【功能说明】LCD 写指令函数入口参数inst="cmd" 命令(cmd:写控制指令)****************************************************************************/ voidLCD_WriteCmd(u16 cmd){u16 ReadValue;LCD_Port_InConfig();doLCD_I();LCD_R();LCD_E_1();Delay_us(dly);LCD_E_0();Delay_us(dly);}while(GPIO_ReadInputDataBit(GPIO_LCD,GPIO_Pin_7));//读忙标志LCD_Port_OutConfig();LCD_I();LCD_W();ReadValue = GPIO_ReadOutputData(GPIO_LCD);cmd=0xff00&ReadValue|cmd;GPIO_Write(GPIO_LCD,cmd);ReadValue = GPIO_ReadOutputData(GPIO_LCD);GPIO_Write(GPIO_LCD,ReadValue);LCD_E_1();Delay_us(dly);LCD_E_0();Delay_us(dly);}/************************************************************************** 【功能说明】读Lcd 显示数据**************************************************************************/ u16LCD_ReadData(void){u16 ReadValue;LCD_Port_InConfig();LCD_E_1();Delay_us(dly);LCD_E_0();Delay_us(dly);LCD_E_1();LCD_D();LCD_R();ReadValue = GPIO_ReadInputData(GPIO_LCD);ReadValue = ReadValue&0x00ff;return ReadValue;}/*****************************************************************************清屏*********************************************************************/voidLCD_Clear(void){u8 i,k;LCD_CS1_H();LCD_CS2_H();for(i=0;i<8;i++){LCD_WriteCmd(0xb8+i);LCD_WriteCmd(0xc0);for(k=0;k<64;k++){LCD_WriteCmd(0x40+k);LCD_WriteData(0x00);LCD_WriteCmd(0x3f);}}}/**************************************************************************** 【功能说明】复位LCD子程序****************************************************************************/ voidLCD_Rest(void){LCD_RET_0();Delay_ms(20);LCD_RET_1();}/*--------------写屏点阵------------------*/voidlat_disp (u8 data1,u8 data2){u8 i,j;LCD_CS1_H();LCD_CS2_H();for(j=0;j<8;j++){LCD_WriteCmd(0xb8+j);LCD_WriteCmd(0xc0);LCD_WriteCmd(0x40);for(i=0;i<32;i++){LCD_WriteData(data1);LCD_WriteCmd(0x3f);LCD_WriteData(data2);LCD_WriteCmd(0x3f);//Delay_us(4);}}}/*******************************************************x:显示字体高度(1~8)y:字显示在第y列(点阵16*16,0~3,8*8,0~7)****x1:显示第x1个字y1:字体宽度,宽为y1的点阵row_x显示字体起始行0~7 ****row_y:显示字体高度定义一个字为y1*row_y的点阵***************************************************/voidLCD_disp(u8 x,u8 y,u8 x1,u8 row_x,u8 y1,u8 row_y,u8 *data){u8 i,j;for(j=0;j<x;j++){LCD_WriteCmd(0xb8+j+row_x);LCD_WriteCmd(0xc0);LCD_WriteCmd(0x40+y*y1);for(i=0;i<y1;i++){LCD_WriteData(data[i+(x1*row_y+j)*y1]);//Delay_us(4);LCD_WriteCmd(0x3f);}}}。
LCD12864液晶驱动编程指南
1.连接硬件:
2.初始化液晶:
在开始使用液晶之前,需要进行初始化。
初始化过程包括设置液晶的
工作模式、显示模式和其他参数。
通过向液晶发送一系列的指令,可以完
成初始化过程。
3.编写驱动程序:
液晶驱动程序的主要目的是将需要显示的内容以及液晶的控制指令发
送给液晶屏。
根据液晶屏的通信方式,可以采用单片机的IO口直接控制
液晶屏,也可以通过SPI或I2C等接口芯片间接控制。
4.显示图形:
5.显示文本:
除了图形外,液晶还可以显示文本。
可以通过设置显示位置和发送需
要显示的文本来实现。
6.更新显示:
当需要更新液晶上的内容时,可以通过重新设置显示的内容和刷新液
晶来实现。
可以定时刷新液晶,或者通过检测外部事件来触发刷新。
7.扩展功能:
除了基本功能外,还可以实现一些扩展功能,如显示动画、滚动显示、倒计时等。
只需要根据需求编写相应的代码即可实现。
总结:
注意事项:
在编写驱动程序时,需要注意及时更新液晶上的内容,避免频繁刷新导致的卡顿现象。
同时,为了保证程序的可移植性,可以将液晶驱动程序与其他功能模块进行分离,便于代码的维护和移植。
/*LCD.C128×64 LCD驱动程序*/#include <INTRINS.H>#include <ABSACC.H>#include "LCD.H"//定义屏幕光标(取值0~63,光标本身不可见)unsigned char LcdCursor;/*函数:LcdLightOn()功能:点亮背光灯*/void LcdLightOn(){LCD_BL = 1;}/*函数:LcdLightOff()功能:熄灭背光灯*/void LcdLightOff(){LCD_BL = 0;}/*函数:LcdGetBF()功能:读出状态位BF返回:BF=1,表示忙,不可进行任何操作BF=0,表示不忙,可以进行正常操作*/bit LcdGetBF(){unsigned char dat;dat = XBYTE[0xD002]; //XBYTE的定义见<ABSACC.H>return (bit)(dat & 0x80);}/*函数:LcdWriteCmd()功能:向LCD发送命令参数:cmd:命令字,详见器件的数据手册*/void LcdWriteCmd(unsigned char cmd){while ( LcdGetBF() );XBYTE[0xD000] = cmd;}/*函数:LcdWriteDat()功能:向LCD写入数据参数:dat,要写入的数据说明:目标地址由地址计数器AC隐含指定,写完后AC自动加1*/void LcdWriteDat(unsigned char dat){while ( LcdGetBF() );XBYTE[0xD001] = dat;}/*函数:LcdReadDat()功能:从LCD读出数据返回:读出的数据*//*unsigned char LcdReadDat(){volatile unsigned char dat;while ( LcdGetBF() );dat = XBYTE[0xD003];dat = XBYTE[0xD003]; //需要连续执行两次才能够读出真正的数据return dat;}*//*函数:LcdSetAC()功能:设置DDRAM(显示数据RAM)的AC(地址计数器)值参数:ac:地址计数器值,范围0~63*/void LcdSetAC(unsigned char ac){ac &= 0x3F;ac |= 0x80;LcdWriteCmd(ac);}/*函数:LcdClear()功能:LCD清屏,并使光标回到0*/void LcdClear(){LcdWriteCmd(0x01); //清屏命令LcdCursor = 0;}/*函数:LcdDelay()功能:延时(t*100)个机器周期*/void LcdDelay(unsigned char t){unsigned char n;do{n = 49;while ( --n != 0 );} while ( --t != 0 );}/*函数:LcdInit()功能:LCD初始化*/void LcdInit(){LcdWriteCmd(0x30); //设置基本指令集LcdDelay(3);LcdWriteCmd(0x30); //设置基本指令集(需要再执行一次)LcdDelay(1);LcdWriteCmd(0x0C); //开启显示LcdDelay(3);LcdClear(); //清屏LcdDelay(250);LcdWriteCmd(0x06); //设置进入点LcdDelay(10);}/*函数:LcdCheckAC()功能:根据光标位置调整AC*/void LcdCheckAC(){switch ( LcdCursor ){case 16:LcdSetAC(16);break;case 32:LcdSetAC(8);break;case 48:LcdSetAC(24);break;case 64:LcdCursor = 0;LcdSetAC(0);break;default:break;}/*函数:LcdPutChar()功能:显示ASCII码参数:c为可显示的ASCII码(0x20~0x7F)*/void LcdPutChar(unsigned char c){LcdWriteDat(c);LcdCursor++;LcdCheckAC();}/*函数:LcdPutHZ()功能:显示汉字参数:ch,cl:汉字编码*/void LcdPutHZ(unsigned char ch, unsigned char cl){if ( LcdCursor & 0x01 ){//显示汉字时,必须偶地址对准,即光标位置不能是奇数LcdPutChar(' '); //额外输出一个空格}LcdWriteDat(ch);LcdWriteDat(cl);LcdCursor += 2;LcdCheckAC();}/*函数:LcdPuts()功能:显示字符串参数:*s:要显示的字符串(可同时包含ASCII码和汉字)*/void LcdPuts(unsigned char *s){unsigned char ch, cl;for (;;){ch = *s++;if ( ch == '\0' ) break;if ( ch < 0x80 ){LcdPutChar(ch);}else{cl = *s++;LcdPutHZ(ch,cl);}}}。
stm32驱动lcd12864程序编辑整理:尊敬的读者朋友们:这里是精品文档编辑中心,本文档内容是由我和我的同事精心编辑整理后发布的,发布之前我们对文中内容进行仔细校对,但是难免会有疏漏的地方,但是任然希望(stm32驱动lcd12864程序)的内容能够给您的工作和学习带来便利。
同时也真诚的希望收到您的建议和反馈,这将是我们进步的源泉,前进的动力。
本文可编辑可修改,如果觉得对您有帮助请收藏以便随时查阅,最后祝您生活愉快业绩进步,以下为stm32驱动lcd12864程序的全部内容。
#include ”12864.h"#include "sys.h"#include ”delay.h”#include "usart。
h”void p_out(void) //把PB命令端口配置成输出{rs();wr();en();psb();}void wr_outite_cmd(u8 cmd) //写命令{p_out();data_out(); //把PB数据端口配置成输出rs_out=0;wr_out=0;en_out=0;GPIOB—〉ODR=((GPIOB—〉ODR&0X00FF)|(cmd〈<8));delay_ms(10);en_out=1;delay_ms(10);en_out=0;}void wr_outite_data(u8 dat) //写数据{p_out();data_out();rs_out=1;wr_out=0;en_out=0;GPIOB—〉ODR=((GPIOB—>ODR&0X00FF)|(dat<〈8)); //把dat给PB高八位delay_ms(10);en_out=1;delay_ms(10);en_out=0;}void LCDClear(void){wr_outite_cmd(0x01); //显示清屏delay_ms(5);wr_outite_cmd(0x34); // 显示光标移动设置delay_ms(5);wr_outite_cmd(0x30); // 显示开及光标设置delay_ms(5);}void locate_x_y(u8 x,u8 y)//指定显示坐标{u8 x2=0;x2=x;if(y<1) y=1;if(y>4) y=4;x&=0x0f;switch(y){case 1:x2|=0x80;break;case 2:x2|=0x90;break;case 3:x2|=0x88;break;case 4:x2|=0x98;break;}wr_outite_cmd(x2);delay_ms(10);}void lcd_init(void){wr_outite_cmd(0x30);delay_ms(10);wr_outite_cmd(0x01);delay_ms(10);wr_outite_cmd(0x06);delay_ms(10);wr_outite_cmd(0x0c);delay_ms(10);}void DisInt(u8 x,u8 y,int fnum) //显示整型变量的函数,最多显示16位的整数。