?? 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 + -