📄 charlcd.c
字号:
#include<reg52.h>
#include<intrins.h>
#define MAX_COUNT 20 //每行可显示的个数
sbit RS=P3^7;
sbit R_W=P3^6;
sbit E=P3^5;
sfr PORT=0x80; //PORT=P0
unsigned char code logo[]={" This is LCD module Welcom to you... "};
unsigned char code CGROM[]={0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x1f,0x00,0x1f,0x00,0x1f,0x00,0x1f,0x00,
0x00,0x1f,0x00,0x1f,0x00,0x1f,0x00,0x1f,
0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15,
0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,
0x15,0x0a,0x15,0x0a,0x15,0x0a,0x15,0x0a,
0x0a,0x15,0x0a,0x15,0x0a,0x15,0x0a,0x15,};
//以上图案依此为:
// 全显,空白,横(1,3,5,7),横(2,4,6,8),竖(1,3,5),竖(2,4),点,点
void initial_lcm();
void write_CGROM();
void clear_dis();
void total_dis();
void single_dis(unsigned char line_addr,clum_addr,trans_value);
void transfer(unsigned char trans_value);
void delay_1s();
//-------------main program-----------------//
void main()
{
initial_lcm();
write_CGROM();
while(1)
{
total_dis();
delay_1s();
clear_dis();
single_dis(1,10,'G');
delay_1s();
single_dis(1,10,6);
delay_1s();
}
}
//----------------------- 初始化模组程序 ------------------//
void initial_lcm()
{
RS=0; // RS=0,传送的数据为控制命令,
// RS=1传送的数据为显示数据
transfer(0x01); // Clear Display
transfer(0x38); // Function Set
transfer(0x0c); // Display on/off Control
transfer(0x06); // Entry mode set
}
//------------------ 单个显示程序 ------------------//
void single_dis(unsigned char line_addr,clum_addr,trans_value)
{
unsigned char line;
switch(line_addr)
{
case 1: line=0x80; break;
case 2: line=0xc0; break;
default: break;
}
RS=0;
transfer(line+clum_addr); // 显示地址
RS=1;
transfer(trans_value); // 显示字符
}
//------------------ 全屏显示程序 ------------------//
void total_dis()
{
unsigned char count;
RS=0;
transfer(0x80); // 第一行DDRAM 起始地址
RS=1;
for(count=0;count<MAX_COUNT;count++)
transfer(logo[count]); // 显示第一行字符
RS=0;
transfer(0xc0); // 第二行DDRAM 起始地址
RS=1;
for(count=MAX_COUNT;count<MAX_COUNT+MAX_COUNT;count++)
transfer(logo[count]); // 显示第二行字符
}
//------------------ 清屏显示程序 ------------------//
void clear_dis()
{
unsigned char count;
RS=0;
transfer(0x80); // 第一行DDRAM 起始地址
RS=1;
for(count=0;count<MAX_COUNT;count++)
transfer(0x20); // 显示第一行字符
RS=0;
transfer(0xc0); // 第二行DDRAM 起始地址
RS=1;
for(count=MAX_COUNT;count<MAX_COUNT+MAX_COUNT;count++)
transfer(0x20); // 显示第二行字符
}
//-----------------write CGROM----------------//
void write_CGROM()
{
unsigned char i;
RS=0;
R_W=0;
E=0;
transfer(0x40); // 开启写CGROM模式
RS=1;
R_W=0;
for(i=0;i<64;i++)
{
PORT=CGROM[i];
_nop_();
E=1;
_nop_();
E=0;
_nop_();
}
}
//------------------- 模组数据发送程序 --------------//
void transfer(unsigned char trans_value)
{
unsigned char i;
R_W=0;
E=0;
PORT=trans_value;
_nop_();
E=1;
_nop_();
E=0;
for(i=0;i<150;i++); // 延时
}
//----------------delay1s---------------------//
void delay_1s()
{
unsigned char i,j,k;
for(i=0;i<100;i++)
{
for(j=0;j<100;j++)
{
for(k=0;k<30;k++);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -