📄 lcd.c
字号:
/*
DISPLAY REGISTER
+------+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+LINE 0|00|01|02|03|04|05|06|07|08|09|0A|0B|0C|0D|0E|0F|10|11|12|13|
+------+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+LINE 1|40|41|42|43|44|45|46|47|48|49|4A|4B|4C|4D|4E|4F|50|51|52|53|
+------+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+LINE 2|14|15|16|17|18|19|1A|1B|1C|1D|1E|1F|20|21|22|23|24|25|26|27|
+------+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+LINE 3|54|55|56|57|58|59|5A|5B|5C|5D|5E|5F|60|61|62|63|64|65|66|67|
+------+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*/
#include "lcd.h"
#define LCD_RS PTB_PTB4 //PTA_PTA0
#define LCD_RW PTC_PTC1
#define LCD_E PTC_PTC0
INT8U BusyDetection(void)
{
DDRD = 0x00; // configure PORTD as input
LCD_RS = 0; // RS = 0
LCD_RW = 1; // RW = 1
LCD_E = 1; // E = 1, enable LCD controller
BF = PTD & 0x80; // read busy flag
LCD_E = 0; // E = 0; Disable LCD controller
return BF;
}
void SendInstruction(INT8U instruction)
{
while(BusyDetection());
DDRD = 0xFF; // configure PORTD as output
LCD_RS = 0; // RS = 0
LCD_RW = 0; // RW = 0;
PTD = instruction;
LCD_E = 1; // E = 1; enable LCD controller
LCD_E = 0; // E = 0; Disable LCD controller
}
void SendData(INT8U data)
{
while(BusyDetection());
DDRD = 0xFF; // configure PORTD as output
LCD_RS = 1; // RS = 1
LCD_RW = 0; // RW = 0;
PTD = data;
LCD_E = 1; // E = 1; enable LCD controller
LCD_E = 0; // E = 0; Disable LCD controller
}
void InitializeLCD(void)
{
SendInstruction(0x38); // 8 bit bus mode, 2 line display mode, 5*7 font
SendInstruction(0x38);
SendInstruction(0x0C); // display on, cursor off, blink off
SendInstruction(0x01); // clear screen, curse return home
SendInstruction(0x1E); // increment mode, entire shift off
}
void LoadTemplate(INT8U page[2][40])
{
for(line = 0; line < 2; line++)
{
for(row = 0; row < 40; row++)
{
displayBuffer[line][row] = page[line][row];
}
}
}
void UpdateWholeScreen(void)
{
SendInstruction(0x01);
for(row = 0; row < 40; row++)
{
SendData(displayBuffer[0][row]);
}
SendInstruction(0xC0);
for(row = 0; row < 40; row++)
{
SendData(displayBuffer[1][row]);
}
}
void UpdateSingleCell(INT8U address, INT8U context)
{
SendInstruction(address | 0x80); // set address
SendData(context);
}
void UpdateMultiCell(INT8U address, INT8U length, INT8U context[])
{
SendInstruction(address | 0x80);
for(row = 0; row < length; row++)
{
SendData(context[row]);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -