📄 pcd8544_driver.c
字号:
#include "PCD8544_Driver.h"
uchar R_now = 0; //记录当前光标所在列(0~79)
uchar P_now = 0; //记录当前光标所在页(0~5)
uchar COLOR_flag = 0; //记录当前显示背景色,默认0:白
/****************底层声明*******************/
void Putchar(uchar ascii); //打印ASCII (' ' ~ '~')
void Sentbyte(uchar thedata, uchar DorI); //送数据,D:1,I:0
/****************基本功能*******************/
void LCD_dpmode(uchar mode) //0:空白,1:全显,2:正常,3:反色 %test pass
{
mode |= ((mode>1)?0x0c:0x08);
mode &= 0x0d;
Sentbyte(mode,0);
}
/********/
void LCD_init() //初始化,同时清屏,置光标(0,0) %test pass
{
uchar volbyte = (uchar)(LCDVOL/0.06-51)|0X80;
INIT_IO; //LCD IO口初始化
// spiInit(3,1); //SPI初始化:模式3,1/8 MCU时钟
CB_8544CS; //低电平片选
CB_8544RST; // 产生一个让LCD复位的低电平脉冲
// _delay_ms(1);
SB_8544RST;
// _delay_us(10);
Sentbyte(BASIC_COM+1,0); //使用扩充指令集
Sentbyte(volbyte,0); //设定液晶电压
Sentbyte(BASIC_COM,0); //使用基本指令集
LCD_dpmode(2); //设定显示模式,正常显示
}
/*
LCD_write_byte(0x21, 0); // 使用扩展命令设置LCD模式
LCD_write_byte(0x80 + 0x48, 0); // 设置偏置电压
LCD_write_byte(0x04 + 0x02, 0); // 温度校正
LCD_write_byte(0x10 + 0x03, 0); // 1:48
LCD_write_byte(0x20, 0); // 使用基本命令
LCD_clear(); // 清屏
LCD_write_byte(0x0c, 0); // 设定显示模式,正常显示
*/
/********/
void LCD_setadd(uchar p, uchar r) //置光标 p页; r列 %test pass
{
R_now = r;
P_now = p;
}
/********/
void LCD_clear() //清屏 %test pass
{
uchar x=0,y=0;
for(;y<6;y++)
{
Sentbyte(y | FRONTPAGE,0);
Sentbyte(FRONTROW,0);
for(x=0;x<84;x++)
Sentbyte(0x00,1);
}
}
/********/
/****************读写功能******************/
void LCD_printI(int i) //打印整数 %test pass
{
uchar tmp[5] , j = 0; //整数化字符数组
if(i < 0)
{
Putchar('-');
i = -i;
}
do
{
tmp[j++] = i % 10;
i /= 10;
}while(i);
for(;j;)
{
Putchar(tmp[--j] + '0');
}
Putchar(' ');
}
void LCD_printSTR(char *datas) //直接写数组*data内容(数,字符串) %test pass
{
char c;
for(;c = *(datas++);)
{
Putchar(c);
}
}
/********/
void LCD_invcol(uchar color) //反色控制,1:反色,0:原色 %test pass
{
COLOR_flag = color;
}
/********/
/****************底层函数******************
void Sentbyte(uchar thedata, uchar DorI) //送数据,D:1,I:0
{
if(DorI)
{
SB_8544DI;
if(COLOR_flag) //反色显示
thedata = ~thedata;
}
else
CB_8544DI;
CB_8544CS;
_delay_us(1);
spiTransferByte(thedata);
SB_8544CS;
}
/****模拟时序****/
void Sentbyte(uchar thedata, uchar DorI) //送数据,D:1,I:0
{
uchar uctmp = 0;
CB_8544CS;
if(DorI)
{
SB_8544DI;
if(COLOR_flag) //反色显示
thedata = ~thedata;
}
else
CB_8544DI;
for(;uctmp<8;uctmp++)
{
if(thedata&(0x80>>uctmp))
SB_8544DB; //为1
else
CB_8544DB; //为0
// _delay_us(1);
CB_8544CLK;
// _delay_us(1);
SB_8544CLK;
// _delay_us(1);
}
SB_8544CS;
SB_8544DI;
SB_8544DB;
}
/********/
void Putchar(uchar ascii) //打印ASCII
{
uchar uctmp;
if(R_now>79) //满行换页
{
P_now++;
R_now = 0;
}
if(P_now>5) //满页回头
P_now = 0;
ascii -= 32; //对应ASCII点阵
Sentbyte(P_now | FRONTPAGE,0);
Sentbyte(R_now | FRONTROW,0);
for(uctmp=0; uctmp<5; uctmp++)
{
Sentbyte(ASCII_5X8[ascii][uctmp], 1);
}
Sentbyte(0x00,1); //写一空列
R_now +=6;
}
/********/
//****************测试函数********************
int main(void)
{
uchar i = 0;
LCD_init();
//DDRB |=0x01; PORTB &= 0xFE;
// LCD_dpmode(3);
while(i<84)
{//LCD_printSTR(PSTR("~~~~~~~~"));
Putchar(' '+i); // ' '
i++;
}
// LCD_clear();
/* LCD_invcol(1);
LCD_setadd(2,20);
LCD_printSTR("ok "); */
// LCD_dpmode(2);
while(1);
return 0;
}
/********/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -