LCM功能
手册上LCM部分没有例程,说明不够详细,只能靠猜测自己写,结果失败了,软件模拟没问题。#if MY_FUN_ENABLE_C1602
/*
void my_fun_c1602_busy(void)
{
unsigned char t;
t = 0x80;
P_SW2 |= 0x80;
while (t & 0x80)
{
LCMIFCR = 0x86; // Read Command
t = LCMIFDATL;
}
P_SW2 &= 0x7f;
}
void my_fun_c1602_write_command(unsigned x)
{
my_fun_c1602_busy();
P_SW2 |= 0x80;
LCMIFDATL = x;
LCMIFCR = 0x84; // Write Command
P_SW2 &= 0x7f;
}
void my_fun_c1602_write_data(unsigned x)
{
my_fun_c1602_busy();
P_SW2 |= 0x80;
LCMIFDATL = x;
LCMIFCR = 0x85; // Write Data
P_SW2 &= 0x7f;
}
void my_fun_c1602_initialization(void)
{
P_SW2 |= 0x80;
LCMIFCFG = 0x01; // 禁止中断, P2数据口, M6800模式
LCMIFCFG2 = 0x5f; // E = P42, RS = P41, RW = P40
LCMIFDATL = 0x38; // 初始化, 8 Bit bus, 双行显示, 5x7 点阵
LCMIFCR = 0x84; // Write Command
INSIDE_TIME_BEEP = 5; // 延时40-50ms
while(INSIDE_TIME_BEEP);
P_SW2 &= 0x7f;
my_fun_c1602_write_command(0x01);
my_fun_c1602_write_command(0x02);
my_fun_c1602_write_command(0x06);
my_fun_c1602_write_command(0x0f); //6c
}
*/
void my_fun_c1602_busy(void)
{
unsigned char t;
t = 0x80;
while (t & 0x80)
{
LCD_EN = 0;
LCD_RS = 0; // Write Command
LCD_RW = 1;
LCD_DAT = 0xff;
my_fun_public_delay();
LCD_EN = 1;
my_fun_public_delay();
t = LCD_DAT;
LCD_EN = 0;
my_fun_public_delay();
}
}
void my_fun_c1602_write_command(unsigned char x)
{
my_fun_c1602_busy();
LCD_RS = 0; // Write Command
LCD_RW = 0;
LCD_EN = 0;
LCD_DAT = x;
my_fun_public_delay();
LCD_EN = 1;
my_fun_public_delay();
LCD_EN = 0;
my_fun_public_delay();
LCD_DAT = 0xff;
}
void my_fun_c1602_write_data(unsigned char x)
{
my_fun_c1602_busy();
LCD_RS = 1; // Write Data
LCD_RW = 0;
LCD_EN = 0;
LCD_DAT = x;
my_fun_public_delay();
LCD_EN = 1;
my_fun_public_delay();
LCD_EN = 0;
my_fun_public_delay();
LCD_DAT = 0xff;
}
void my_fun_c1602_printf(unsigned char x, unsigned char y, unsigned char *s)
{
unsigned char i;
x = x & 0x3f;
y = y & 0x01;
my_fun_c1602_write_command(x + (y * 0x40) + 0x80);
for (i = 0; i < strlen(s); i++) my_fun_c1602_write_data(s);
}
void my_fun_c1602_initialization(void)
{
my_fun_c1602_write_command(0x38);
INSIDE_TIME_BEEP = 5;
while(INSIDE_TIME_BEEP);
my_fun_c1602_write_command(0x01);
my_fun_c1602_write_command(0x02);
my_fun_c1602_write_command(0x06);
my_fun_c1602_write_command(0x0c);
}
#endif
STC32G实验箱例程包里面有LCM接口驱动TFT屏的例子可以参考
这个压缩包在官网https://www.stcai.com/yyfa上有
本帖最后由 zhp 于 2022-11-29 12:37 编辑
使用LCM读写数据和命令,可参考下面的代码
void lcm_wait()
{
while (!(LCMIFSTA & 0x01));
LCMIFSTA &= ~0x01;
}
void lcm_write_cmd(char cmd)
{
LCMIFDATL = (cmd);
LCMIFCR = 0x84;
lcm_wait();
}
void lcm_write_data(char dat)
{
LCMIFDATL = (dat);
LCMIFCR = 0x85;
lcm_wait();
}
char lcm_read_status()
{
LCMIFCR = 0x86;
lcm_wait();
return LCMIFDATL;
}
char lcm_read_data()
{
LCMIFCR = 0x87;
lcm_wait();
return LCMIFDATL;
}
谢谢,示例藏得够深:D
我先核对下楼上得 研究一上午任然失败,液晶没任何反应,看了下二楼提供的65号DEMO,检测LCD忙部分都被注释掉了,用得还是常规方法,难道你们自己也没成功?
下面是修改过的程序,有空的话帮忙看看哪里还有错。
LCM暂时不用了
void my_fun_c1602_end(void)
{
while (!(LCMIFSTA & 0x01));
LCMIFSTA &= ~0x01;
}
void my_fun_c1602_busy(void)
{
do {LCMIFCR = 0x86; my_fun_c1602_end();} while (LCMIFDATL & 0x80);
}
void my_fun_c1602_write_command(unsigned char x)
{
P_SW2 |= 0x80;
my_fun_c1602_busy();
LCMIFDATL = x;
LCMIFCR = 0x84; // Write Command
my_fun_c1602_end();
P_SW2 &= 0x7f;
}
void my_fun_c1602_write_data(unsigned char x)
{
P_SW2 |= 0x80;
my_fun_c1602_busy();
LCMIFDATL = x;
LCMIFCR = 0x85; // Write Data
my_fun_c1602_end();
P_SW2 &= 0x7f;
}
void my_fun_c1602_initialization(void)
{
P_SW2 |= 0x80;
LCMIFCFG = 0x01; // 禁止中断, P2数据口, M6800模式
LCMIFCFG2 = 0x5f; //0x45 // E = P42, RS = P41, RW = P40
LCMIFSTA &= ~0x01;
LCMIFDATL = 0x38; // 初始化, 8 Bit bus, 双行显示, 5x8 点阵
LCMIFCR = 0x84; // Write Command
my_fun_c1602_end();
P_SW2 &= 0x7f;
INSIDE_TIME_BEEP = 5; // 延时50ms
while(INSIDE_TIME_BEEP);
my_fun_c1602_write_command(0x01);
my_fun_c1602_write_command(0x02);
my_fun_c1602_write_command(0x06);
my_fun_c1602_write_command(0x0c);
}
实验箱例程驱动LCD接口原先都是使用推挽输出模式,读取状态时用IO口驱动方式方便调整输入输出模式。其实使用LCM接口检测忙状态也是可以的,附件例程已经通过测试验证,请参考。
另外,再发一份IO口驱动1602的例程供参考,效果如下:
谢谢,我不会为了某个功能专门试验,这次要用到LCD,想起有LCM这个功能,就按照相应硬件连线,就算试验失败也不影响使用,等有机会再继续。
STC挺好用的,目前用的8A8K64S4A12和8A8K64D4,就是内存太小,能加到32K就好了。 STC32G12K128, SRAM 是 12K, FLASH 是 128K 12K还是太小,目前大约用到20K,只好加了一片IDT71V256,好像没有国产的3.3V的62256,5V的也都是拆机片,不符合主要芯片使用国产的政策;FLASH倒是够了,40K不到,能不能设计少量大内存的种类,比如64D4/32G等,内存32K-48K最好,价格翻倍也能接受,当ARM用。
整个系统都用 3.3V 的 可能更容易买到 相应的器件,STC 现在都是 1.9V ~ 5.5V, SRAM 3.3V 的更多, 5V 也是可以跑 3.3V 的
页:
[1]
2