📄 t6963c_drv.c
字号:
/*************************************************************************
* File name: T6963C_DRV.c
* Author:
* Version: 1.0
* Date:
* Description:
*************************************************************************/
#include "iom64v.h"
#include "macros.h"
#include "external.h"
#include "T6963C_drv.h"
#include "main.h"
// 初始化LCM
void LCM_init(void)
{
CBI_LCM_RES(); // 给LCM复位信号
delayms(2);
SBI_LCM_RES();
LCM_BL_OFF();
LCM_write_cmd3(0x00, 0x00, LCM_GRH_HOME); // 设置图形显示区域首地址GraphAddr
LCM_write_cmd3(0x1e, 0x00, LCM_GRH_WIDTH); // 设置图形显示区宽度LineChar 240bit/8
LCM_write_cmd1(LCM_CURSOR_SHAPE); // 设置光标形状为下横线
LCM_write_cmd1(LCM_MODE_OR); // 显示方式设置为逻辑或合成
LCM_write_cmd1(0x98); // 显示开关设置:图形方式
LCM_clear();
LCM_BL_ON();
}
//清除屏幕(清所有8K存储空间)
void LCM_clear(void)
{
unsigned i, j;
LCM_write_cmd3(0x00, 0x00, LCM_ADDR_POINTER); //设置显示存储器首地址
LCM_write_cmd1(LCM_AUTO_WR);
CBI_LCM_CE();
for (i=0; i<128; i++) {
for (j=0; j<30; j++) {
auto_write_dat(0x00);
}
}
SBI_LCM_CE();
LCM_write_cmd1(LCM_AUTO_OVER);
}
/*
void cursor_on(unsigned char row, unsigned char col)
{
LCM_write_cmd3(col, row, 0x21); // 设置光标位置
LCM_write_cmd1(0xa0); // 设置光标形状
LCM_write_cmd1(0x96); // 开光标
}
void cursor_off(void)
{
LCM_write_cmd1(0x94);
}
*/
// 指令写入函数
void write_cmd(unsigned char cmd)
{
LCM_state01();
LCM_CMD_enable();
LCM_DAT_DDR = 0xff; // A口方向为输出
LCM_WR_DAT_PORT = cmd;
NOP();
NOP();
CBI_LCM_WR();
NOP();
NOP();
SBI_LCM_WR();
}
//数据写入函数
void write_dat(unsigned char dat)
{
LCM_state01();
LCM_DAT_enable(); // 选数据通道
LCM_DAT_DDR = 0xff; // A口方向为输出
LCM_WR_DAT_PORT = dat;
NOP();
NOP();
CBI_LCM_WR();
NOP();
NOP();
SBI_LCM_WR();
}
// 数据自动写入函数
void auto_write_dat(unsigned char dat)
{
LCM_state3();
LCM_DAT_enable(); // 选数据通道
LCM_DAT_DDR = 0xff; // A口方向为输出
LCM_WR_DAT_PORT = dat;
NOP();
NOP();
CBI_LCM_WR();
NOP();
NOP();
SBI_LCM_WR();
}
/*
// 数据自动读出函数
unsigned char auto_read_dat(void)
{
unsigned char dat = 0x00;
LCM_state2();
LCM_DAT_enable(); // 选数据通道
LCM_DAT_DDR = 0x00; // A口方向为输入
LCM_WR_DAT_PORT = 0xff;
CBI_LCM_RD();
NOP();
NOP();
dat = LCM_RD_DAT_PORT;
SBI_LCM_RD();
return (dat);
} */
// 向LCM写入cmd
void LCM_write_cmd1(unsigned char cmd)
{
CBI_LCM_CE();
write_cmd(cmd);
SBI_LCM_CE();
}
// 向LCM写入cmd, dat1
void LCM_write_cmd2(unsigned char dat1, unsigned char cmd)
{
CBI_LCM_CE();
write_dat(dat1);
write_cmd(cmd);
SBI_LCM_CE();
}
// 向LCM写入cmd, dat1, dat2
void LCM_write_cmd3(unsigned char dat1, unsigned char dat2, unsigned char cmd)
{
CBI_LCM_CE();
write_dat(dat1);
write_dat(dat2);
write_cmd(cmd);
SBI_LCM_CE();
}
// 读取LCM状态
unsigned char LCM_read_state(void)
{
unsigned char state;
LCM_WR_DAT_PORT = 0xff;
LCM_DAT_DDR = 0x00; // PORTA为input with pull-up
LCM_CMD_enable(); // 选指令通道
CBI_LCM_RD();
NOP();
NOP();
state = LCM_RD_DAT_PORT;
NOP();
NOP();
SBI_LCM_RD();
return (state);
}
// S0:指令读写状态,0:忙 S1:数据读写状态,0:忙
void LCM_state01(void)
{
while ( (LCM_read_state() & 0x03) != 0x03 );
}
// S2:数据自动读状态
void LCM_state2(void)
{
while ( (LCM_read_state() & 0x04) != 0x04 );
}
// S3:数据自动写状态
void LCM_state3(void)
{
while ( (LCM_read_state() & 0x08) != 0x08 );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -