📄 cm240128.c
字号:
#include "c8051F020.h"
#include "CM240128.H"
#include <absacc.h>
#include <intrins.h>
#include <string.h>
#define uchar unsigned char
#define lcd_rs P3_0
#define lcd_wr P3_1
#define lcd_rd P3_2
#define lcd_cs1 P3_3
#define lcd_cs2 P3_4
#define lcd_busy P3_5
#define lcd_int P3_6
#define lcd_rst P3_7
#define DataIo P2
#define LcdWait() _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
code unsigned char IniReg[]= { 0, 1, 2, 3,0x10,0x11,0x12,0x21,0x31,0x41,0x51,0x20,0x30,0x40,0x50,0x60,0x61,0x70,0x71,0x72,0x80,0x81,0x91,0x90,0xA0,0xA1,0xA2,0xA3,0xB0,0xB1,0xC0,0xC1,0xC8,0xC9,0xCA,0xD0,0xE0,0xF0,0xF1,0x81};
code unsigned char IniData[]={0xC9,0xF0,0x10,0x80,0x6B, 0,0x91,0x1D,0x7F, 0, 0,0x1D,0x7F, 0, 0, 0, 0, 0, 0,0x9F,0xAA, 0, 0,0x0F,0x11, 0, 0, 0,0x27,0xEF,0x00,0x0A,0x80,0x80, 0,0x80, 0,0xA0,0x0F,0x04};
//------------------------------------------------------------------------------------------------------------------------------
void Lcd_WRReg(uchar regnada)
{
DataIo = regnada;
lcd_cs1 = 0; // chip enable.
lcd_rd = 1; //
lcd_rs = 0; // rs = 0;
LcdWait();
lcd_wr = 0; // wr = 0;
LcdWait();
lcd_wr = 1; // wr = 1;
LcdWait();
lcd_rs = 1; // rs = 1;
lcd_cs1 = 1; // chip disable.
}
//------------------------------------------------------------------------------------------------------------------------------
void Lcd_RegWrite(uchar regname,uchar regdata) //写资料到缓存器
{
Lcd_WRReg(regname);
LcdWait();
Lcd_WRReg(regdata);
}
//------------------------------------------------------------------------------------------------------------------------------
void Lcd_WRData(uchar wrdata) //写资料到DDRAM
{
while(lcd_busy == 1);
DataIo = wrdata;
lcd_cs1 =0; // chip enable.
lcd_rd = 1; //
lcd_rs = 1; // rs = 1;
LcdWait();
lcd_wr = 0; // wr = 0;
LcdWait();
lcd_wr = 1; // wr = 1;
LcdWait();
lcd_rs = 1; // rs = 1;
lcd_cs1 =1; // chip disable.
}
//------------------------------------------------------------------------------------------------------------------------------
/*
uchar Lcd_ReadReg(uchar regname) //读缓存器
{
uchar reg_rddata;
Lcd_WRReg(regname);
DataIo = 0xff;
lcd_cs1 =0; // chip enable.
lcd_wr = 1; // wr = 1;
lcd_rs = 0; // rs = 0;
lcd_rd = 0; // rd = 0;
reg_rddata = DataIo;
lcd_rd = 1; // rd = 1;
lcd_rs = 1; // rs = 1;
lcd_cs1 =1; // chip disable.
return reg_rddata;
}
*/
//------------------------------------------------------------------------------------------------------------------------------
void LcdDelay(unsigned long val)
{
while (val--);
}
/************************************************************************
函数功能: 液晶初始化函数
入口参数: 无
出口参数: 无
************************************************************************/
void Lcd_Init(void)
{
unsigned char bI;
lcd_rst = 1;
lcd_rst = 0;
LcdDelay(100000);
lcd_rst = 1;
LcdDelay(10000);
for(bI = 0; bI<sizeof(IniReg); bI++)
{
Lcd_RegWrite(IniReg[bI],IniData[bI]);
}
// Lcd_RegWrite(0,0x20);
// Lcd_RegWrite(0x20,0x1d); /*设定显示视窗和工作视窗*/
// Lcd_RegWrite(0x21,0x1d);
// Lcd_RegWrite(0x30,0x7f);
// Lcd_RegWrite(0x31,0x7f);
// Lcd_RegWrite(0x40,0);
// Lcd_RegWrite(0x41,0);
// Lcd_RegWrite(0x50,0);
// Lcd_RegWrite(0x51,0);
// Lcd_RegWrite(0xE0,0x45); /* 清屏 */
// Lcd_RegWrite(0xF0,0x88);
// Delay(1);
// Lcd_RegWrite(0,0xC9); /*系统工作方式*/
// Lcd_RegWrite(1,2); /*系统时钟8MHZ*/
// Lcd_RegWrite(0x90,0x0F); /*设定屏幕刷新周期*/
// Lcd_RegWrite(0x10,0xff); /*光标*/
// Lcd_RegWrite(0x60,0); /*光标位置*/
// Lcd_RegWrite(0x70,0);
// Lcd_RegWrite(0,0x20);
Lcd_RegWrite(0x10,0x2b);
Lcd_RegWrite(0,0xcd);
Lcd_RegWrite(0x60,0); /*光标位置*/
Lcd_RegWrite(0x70,0);
//for (bI=0; bI<255 ; bI++)
//{
// Lcd_WRData(0x63);
//}
}
//------------------------------------------------------------------------------
void SetCurrLoc(unsigned char x,unsigned char y)
{
unsigned int i;
Lcd_RegWrite(0x60,x); /*光标位置*/
Lcd_RegWrite(0x70,y);
for(i=0;i<1000;i++);
}
//------------------------------------------------------------------------------
void ClrDisplay(void)//清屏幕
{
Lcd_Init();
Lcd_RegWrite(0xf0,0xa8);
}
//------------------------------------------------------------------------------
/*
void DisplayLine(unsigned char *pbuf,unsigned char len)
{
while(len--)
Lcd_WRData(*pbuf++);
}
*/
//------------------------------------------------------------------------------
void DisplayFill(unsigned char buf,unsigned char len)
{
while(len--)
Lcd_WRData(buf);
}
//------------------------------------------------------------------------------
void DisplayStr(unsigned char *pbuf,unsigned char maxcnt)
{
while((*pbuf!=0)&&(maxcnt--!=0))
Lcd_WRData(*pbuf++);
}
//------------------------------------------------------------------------------
//拼音输入法显示函数
//pbuf 要显示的字符串
//maxcnt 最多反白显示的字符数
void DisplayPYStr(unsigned char *pbuf,unsigned char maxcnt)
{
Lcd_RegWrite(IniReg[4],(IniData[4]&(~0x20)));
while((*pbuf!=0)&&(maxcnt--!=0))
Lcd_WRData(*pbuf++);
Lcd_RegWrite(IniReg[4],(IniData[4]|0x20));
}
//------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -