📄 lcd.c
字号:
#include "lcdhead.h"
/*******************************************/
//延时函数
/*******************************************/
void TimeDelay(ulint m)
{
ulint j;
ulint i;
for(i=0; i<m; i++)
for(j=0; j<109; j++)
_NOP();
}
/****************************************************/
// IO Routine
/******************************************************/
/*void SdCmd(uchar Command) //send command
{
_WR = 1; // init all control signal
_RD = 1;
RS = 0; // for command
LCDBUS = Command;
_CS = 0; // enable the access
_nop_();
_WR = 0;
_nop_();
_WR = 1;
_nop_();
_CS = 1; // disable the access
}*/
/***********************************************************/
//发送命令字
/***********************************************************/
void SendCmd(uchar command)
{
LCD_WR_HI;
LCD_RS_LO; //for command
LCD_Data = command;
LCD_CS_LO;
_NOP();
LCD_WR_LO;
_NOP();
LCD_WR_HI;
_NOP();
LCD_CS_HI;
}
/*************************************************************/
//发送数据字
/*************************************************************/
void SendData(uchar data)
{
LCD_WR_HI;
LCD_RS_HI; //for data
LCD_Data = data;
LCD_CS_LO;
_NOP();
LCD_WR_LO;
_NOP();
LCD_WR_HI;
_NOP();
LCD_CS_HI;
}
/***************************************************************/
/*void initLCDM(void)
{
_RES = 1; // reset pin
_RES = 0;
delayms(1);
_RES = 1;
delayms(1);
SdCmd(0x00);SdCmd(0xCD); delayms(1); // Whole Chip LCD Controller Reg(Char Mode)
SdCmd(0x10);SdCmd(0x29); delayms(1); // Whole Chip Cursor Control Reg(disable cursor)
SdCmd(0x11);SdCmd(0x10); delayms(1); // Distance of Words or Lines Reg(cursor=1,gap=0)
SdCmd(0x90);SdCmd(0x04); delayms(1); // Shift Clock Control Reg(320x240, 61Hz)
SdCmd(0xF0);SdCmd(0xA0); delayms(1); // Font Control Reg
SdCmd(0x20);SdCmd(0x27); delayms(1); // Active Window Right Reg
SdCmd(0x30);SdCmd(0xEF); delayms(1); // Active Window Bottom Reg(240 duty)
SdCmd(0x40);SdCmd(0x00); delayms(1); // Active Window Left Reg
SdCmd(0x50);SdCmd(0x00); delayms(1); // Active Window Top Reg
SdCmd(0x21);SdCmd(0x27); delayms(1); // Display Window Right Reg
SdCmd(0x31);SdCmd(0xEF); delayms(1); // Display Window Bottom Reg(240 duty)
SdCmd(0x41);SdCmd(0x00); delayms(1); // Display Window Left Reg
SdCmd(0x51);SdCmd(0x00); delayms(1); // Display Window Top Reg
SdCmd(0x81);SdCmd(0x40); delayms(1); // by default
SdCmd(0xD0);SdCmd(ContrastLevel); delayms(1); // enable the contrast control, set to 32
}
*/
/***********************************************************************************************/
void LCDInit(void)
{
LCD_RESET_HI;
LCD_RESET_LO;
TimeDelay(1);
LCD_RESET_HI;
TimeDelay(1);
SendCmd(0x00);SendCmd(0xcd); TimeDelay(1);
SendCmd(0x10);SendCmd(0x29); TimeDelay(1);
SendCmd(0x11);SendCmd(0x10); TimeDelay(1);
SendCmd(0x90);SendCmd(0x04); TimeDelay(1);
SendCmd(0xF0);SendCmd(0xA0); TimeDelay(1);
SendCmd(0x20);SendCmd(0x27); TimeDelay(1);
SendCmd(0x30);SendCmd(0xEF); TimeDelay(1);
SendCmd(0x40);SendCmd(0x00); TimeDelay(1);
SendCmd(0x50);SendCmd(0x00); TimeDelay(1);
SendCmd(0x21);SendCmd(0x27); TimeDelay(1);
SendCmd(0x31);SendCmd(0xEF); TimeDelay(1);
SendCmd(0x41);SendCmd(0x00); TimeDelay(1);
SendCmd(0x51);SendCmd(0x00); TimeDelay(1);
SendCmd(0x81);SendCmd(0x40); TimeDelay(1);
SendCmd(0xD0);SendCmd(0x06); TimeDelay(1);
}
/****************************************************************/
// LCD Contrast Contral
/****************************************************************/
void LCD_Contrast(uchar level)
{
uchar i;
i = 0x10 + level;
SendCmd(0xD0);SendCmd(i); TimeDelay(20);
}
/******************************************************************/
/*void WriteGraphicScreen(uchar *GDData)
// DisplayData should be 320x240/8 = 9600byte
// set to graphic display
{
uchar TempData;
uchar i, j;
SdCmd(0x60); SdCmd(0x00); // set cursor X location to 0
SdCmd(0x70); SdCmd(0x00); // set cursor Y location to 0
SdCmd(0x00); SdCmd(0xC5); // normal power mode, Graphical mode,
// display on, normal display.
for(i=0;i<240;i++)
{
for(j=0;j<40;j++)
{
TempData=(*(GDData+(i*40)+j));
SdData(TempData);
}
}
}*/
void DispalyGraphicScreen(uchar *Pic)
{
uchar tempdata;
uchar i,j;
SendCmd(0x00);SendCmd(0xc5);
SendCmd(0x60);SendCmd(0x00); //set cursor X location to 0
SendCmd(0x70);SendCmd(0x00); //set cursor Y location to 0
for(i=0;i<240;i++)
{
for(j=0;j<40;j++)
{
tempdata=(*(Pic+(i*40)+j));
SendData(tempdata);
}
}
}
void WriteTextScreen(uchar *TxtData)
// DisplayData should be 20(x2)x15 = 600byte
// set to char display
{
uchar TempData;
uchar i,j;
SendCmd(0x00); SendCmd(0xCD); TimeDelay(1); // normal power mode, Char mode
// display on, normal display
SendCmd(0x60); SendCmd(0x00); TimeDelay(1); // set cursor X location to 0
SendCmd(0x70); SendCmd(0x00); TimeDelay(1); // set cursor Y location to 0
for (j=0; j<15; j++)
{
for(i=0; i<40; i++)
{
TempData=(*(TxtData+(j*40)+i));
SendData(TempData);
// _NOP();_NOP();_NOP();_NOP();
// _NOP();_NOP(); _NOP(); _NOP();
}
}
}
/*****************************************************************************************/
void LCDClear(void)
{
uchar i,j;
SendCmd(0x00);SendCmd(0xc5);
SendCmd(0x60);SendCmd(0x00);
SendCmd(0x70);SendCmd(0x00);
for(i=0;i<240;i++)
{
for(j=0;j<40;j++)
{
SendData(0x00);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -