**************************************************************************************************/
这是12864的程序,这个程序比较看不懂,麻烦进行简单的显示嘛
原理图如下:
- #include"FYD12864.h"
- /*************************************************************************************************/
- void Delay_nus(unsigned int nTime)
- {
- unsigned long j;
- while(nTime--)
- {
- j=12;
- while(j--);
- }
- }
- /*************************************************************************************************/
- void LCD12864_Init(void) //初始化LCD12864
- {
- //----------------------------------------------------------------------
- Delay_nus(200);
- SET_LCD12864_CS;
- //----------------------------------------------------------------------
- LCD2864Write_char(0, 0x01); //清除屏幕显示,将DDRAM的地址计数器清零
- Delay_nus(200);
- LCD2864Write_char(0, 0x30); //8BIT控制界面,基本指令集
- Delay_nus(200);
- LCD2864Write_char(0, 0X0C);
- Delay_nus(200);
- LCD2864Write_char(0, 0x01); // 清除屏幕显示,将DDRAM的地址计数器清零
- Delay_nus(200);
- LCD2864Write_char(0, 0x06); // DDRAM的地址计数器(AC)加1
- Delay_nus(200);
- //----------------------------------------------------------------------
- LCD12864_Clear();
- }
- /*************************************************************************************************/
- /*************************************************************************************************/
- void Send_byte(unsigned char bbyte) //发送一个字节
- {
- unsigned char i;
- for(i = 0; i < 8; i++)
- {
- if((bbyte & 0x80) == 0x80) //取出最高位
- {
- SET_LCD12864_STD;
- }
- else
- {
- CLR_LCD12864_STD;
- }
- SET_LCD12864_SCLK;
- CLR_LCD12864_SCLK;
- bbyte <<= 1; //左移
- }
- }
- void LCD2864Write_char(unsigned char Mode, unsigned char ddata) //写指令或数据
- {
- unsigned char CMD_data, Hdata, Ldata;
- if(Mode == 0X00)
- CMD_data = 0xf8; //写指令
- else
- CMD_data = 0xfa; //写数据
- Hdata = ddata & 0xf0; //取高四位
- Ldata = (ddata << 4) & 0xf0; //取低四位
- Send_byte(CMD_data); //发送起始信号
- Delay_nus(10); //延时是必须的
- Send_byte(Hdata); //发送高四位
- Delay_nus(10); //延时是必须的
- Send_byte(Ldata); //发送低四位
- Delay_nus(10); //延时是必须的
- }
- /*************************************************************************************************/
- /*************************************************************************************************/
- void LCD12864_Clear(void) //清屏函数
- {
- // LCD2864Write_char(0,0x01);
- LCD12864_lineclr(1);
- LCD12864_lineclr(2);
- LCD12864_lineclr(3);
- LCD12864_lineclr(4);
- }
- void LCD12864_dispClear(void) //清屏函数
- {
- // LCD2864Write_char(0,0x01);
- LCD12864_lineclr(2);
- LCD12864_lineclr(3);
- LCD12864_lineclr(4);
- }
- /*************************************************************************************************/
- void LCD12864_RE_0_1(void) //文字模式,指令集由0变为1
- {
- LCD2864Write_char(0, 0x30);
- Delay_nus(50);
- LCD2864Write_char(0, 0x34);
- Delay_nus(50);
- LCD2864Write_char(0, 0x36);
- Delay_nus(50);
- }
- //此函数如果在文本模式,可以不要,如果同时显示图和显示字就要及时更换指令集,实现具体是什么操作
- void LCD12864_RE_1_0(void) //图形模式,指令集由1变为0
- {
- LCD2864Write_char(0, 0x36);
- Delay_nus(50);
- LCD2864Write_char(0, 0x32);
- Delay_nus(50);
- }
-
- /*************************************************************************************************/
- void LCD12864_SetAddr(unsigned char VerticalAddr, unsigned char HorizontalAddr) //设定地址
- {
- VerticalAddr &= 0x1F;
- HorizontalAddr &= 0xFF;
- LCD2864Write_char(0,VerticalAddr | 0x80);
- Delay_nus(100);
- LCD2864Write_char(0,HorizontalAddr | 0x80);
- Delay_nus(100);
- }
- void LCD12864_Write_String(uint8_t hang, uint8_t lie, char *StringBuf)
- {
- uint8_t address, i = 0;
- switch(hang)
- {
- case 1:
- address = 0x80;
- break;
- case 2:
- address = 0x90;
- break;
- case 3:
- address = 0x88;
- break;
- case 4:
- address = 0x98;
- break;
- default:
- address = 0x80;
- }
- LCD2864Write_char(0, address + lie);
- for(i = 0; i < 16; i++)
- {
- LCD2864Write_char(1, *StringBuf);
- StringBuf++;
- }
- }
- void LCD12864_DispString2(uint8_t hang, uint8_t lie, char *StringBuf, uint8_t LEN)
- {
- uint8_t address, i = 0;
- switch(hang)
- {
- case 1:
- address = 0x80;
- break;
- case 2:
- address = 0x90;
- break;
- case 3:
- address = 0x88;
- break;
- case 4:
- address = 0x98;
- break;
- default:
- address = 0x80;
- }
- LCD2864Write_char(0, address + lie);
- for(i = 0; i < LEN; i++)
- {
- LCD2864Write_char(1, *StringBuf);
- StringBuf++;
- }
- }
- void LCD12864_DispString3(uint8_t hang, uint8_t lie, const char *StringBuf, uint8_t LEN)
- {
- uint8_t address, i = 0;
- switch(hang)
- {
- case 1:
- address = 0x80;
- break;
- case 2:
- address = 0x90;
- break;
- case 3:
- address = 0x88;
- break;
- case 4:
- address = 0x98;
- break;
- default:
- address = 0x80;
- }
- LCD2864Write_char(0, address + lie);
- for(i = 0; i < LEN; i++)
- {
- LCD2864Write_char(1, *StringBuf);
- StringBuf++;
- }
- }
- void LCD12864_DispString4(uint8_t hang, uint8_t lie, const char *StringBuf, uint8_t LEN)
- {
- uint8_t address, i = 0;
- switch(hang)
- {
- case 1:
- address = 0x80;
- break;
- case 2:
- address = 0x90;
- break;
- case 3:
- address = 0x88;
- break;
- case 4:
- address = 0x98;
- break;
- default:
- address = 0x80;
- }
- LCD2864Write_char(0, address + lie);
- for(i = 0; i < LEN; i++)
- {
- LCD2864Write_char(1, *StringBuf);
- StringBuf++;
- }
- }
-
- /*********************************************************************************************************
- ** 函数名称: Lcd_lineclr()
- ** 功能描述: 清除一行的显示
- ** 输 入: unsigned char row 要清除显示的行
- ** 输 出:
- ** 全局变量: 无
- ** 调用模块: 无
- ** 说明:
- ** 注意:
- *******************************************************************************************************/
- void LCD12864_lineclr(unsigned char row)
- {
- unsigned char i;
- switch(row)
- {
- case 1:
- {
- LCD2864Write_char(0, 0x80);
- for(i = 0; i < 16; i++) LCD2864Write_char(1, ' ');
- break;
- }
- case 2:
- {
- LCD2864Write_char(0, 0x90);
- for(i = 0; i < 16; i++) LCD2864Write_char(1, ' ');
- break;
- }
- case 3:
- {
- LCD2864Write_char(0, 0x88);
- for(i = 0; i < 16; i++) LCD2864Write_char(1, ' ');
- break;
- }
- case 4:
- {
- LCD2864Write_char(0, 0x98);
- for(i = 0; i < 16; i++) LCD2864Write_char(1, ' ');
- break;
- }
- default:
- break;
- }
- }
-
- /*************************************************************************************************
- ** END FILE
- **************************************************************************************************/
- **************************************************************************************************/
- #ifndef __FYD12864_H__
- #define __FYD12864_H__
- /*************************************************************/
- #include<stc15.h> //包含头文件,一般情况不需要改动,头文件包含特殊功能寄存器的定义
- #include<intrins.h>
-
-
- #define uint8_t unsigned char
- #define uint16_t unsigned int
-
- /*************************************************************************************************/
- #define LCD12864_RS_PIN P20 //RS
- #define LCD12864_RW_PIN P21 //RW
- #define LCD12864_RD_PIN P22 //RD-EN
- /*************************************************************************************************/
- //PSB接GND----是串行模式
- //PSB接VCC----是并行模式
- #define SET_LCD12864_CS LCD12864_RS_PIN=1;
- #define CLR_LCD12864_CS LCD12864_RS_PIN=0;
- #define SET_LCD12864_STD LCD12864_RW_PIN=1;
- #define CLR_LCD12864_STD LCD12864_RW_PIN=0;
- #define SET_LCD12864_SCLK LCD12864_RD_PIN=1;
- #define CLR_LCD12864_SCLK LCD12864_RD_PIN=0;
- /*************************************************************************************************/
- //定义7920LCD控制命令 基本命令
- #define Lcd_Clear 0x01 //清除显示
- #define Lcd_Adress_Rest 0x02 //地址归0
- #define Lcd_Set_Entrance_Point 0x04 //设定光标移动方向并指定整体显示是否移动,offset 0x04/0x05/0x06/0x07
- #define Lcd_Display_Status 0x08 //显示状态(整体显示,整体不显示,光标闪烁,光标不闪烁),offset 0x08/0x0C/0x0D/0x0E/0x0F
- #define Lcd_Display_Shift 0x10 //光标或显示移位控制 offset 10H/14H/18H/1CH
- #define Lcd_Set_Function_Basic 0x30 //基本指令集
- #define Lcd_Set_Function_Extend 0x34 //扩展指令集
- #define Lcd_Set_Cgram 0x40 //设定CGRAM 地址 offset 0x00-0x3f
- #define Lcd_Set_Ddram 0x80 //设定DDRAM 地址
- //定义7920LCD控制命令 扩充命令
- #define Lcd_Wait_Mode 0x01 //待命模式 进入待命模式,执行其它命令都可终止待命模式
- #define Lcd_Enable_Iram 0x02 //sr=0 允许设定CGRAM 地址(基本指令)
- #define Lcd_Enable_Vectical_Roll 0x03 //sr=1 允许输入卷动地址
- #define Lcd_Iram_Address 0x40 //sr=1:offset 0x00~0x3
- #define Lcd_Back_White 0x04 //offset 0~3 反白选择
- #define Lcd_Enter_Sleep_Mode 0x08
- #define Lcd_Escape_Sleep_Mode 0x0c
- #define Lcd_Dram_On 0x36
- #define Lcd_Dram_Off 0x34
- #define Lcd_Set_Gdram 0x80 //offset 0x00~0x7f
- extern void LCD12864_Init(void); //初始化LCD12864
- extern void LCD2864Write_char(unsigned char Mode, unsigned char ddata); //写指令或数据
- extern void LCD12864_Clear(void); //清屏函数
- extern void LCD12864_dispClear(void); //清屏函数
-
- extern void LCD12864_RE_0_1(void); //文字模式,指令集由0变为1
- //此函数如果在文本模式,可以不要,如果同时显示图和显示字就要及时更换指令集,实现具体是什么操作
- extern void LCD12864_RE_1_0(void); //图形模式,指令集由1变为0
- extern void LCD12864_SetAddr(unsigned char VerticalAddr, unsigned char HorizontalAddr);
- extern void LCD12864_Write_String(uint8_t hang, uint8_t lie, char *StringBuf);
- extern void LCD12864_DispString2(uint8_t hang, uint8_t lie, char *StringBuf, uint8_t LEN);
- extern void LCD12864_DispString3(uint8_t hang, uint8_t lie, const char *StringBuf, uint8_t LEN) ;
- extern void Disp_img(const unsigned char *img); //图形方式12864显示,字模221--横向取膜
- extern void LCD12864_lineclr(unsigned char row);
- extern void Lcd_linedisp(unsigned char *p, unsigned char row);
- extern void LCDDisp_HEX(uint8_t hang, uint8_t lie, unsigned char HEX_num[], unsigned char cnt); //显示十六进制数
- #endif
- /*****************************************************************/
- //** END FILE
- /*****************************************************************/
复制代码
|