//带中文字库的12864LCD显示程序
#include
#include
#define uchar unsigned char
#define uint unsigned int
//sbit dula = P2^6;
//sbit wela = P2^7;
//SCM12864-05端口定义
#define LCD_DATA P0 //数据口
sbit RS = P3^5; //并行的指令/数据选择信号, H数据, L命令
sbit RW = P3^6; //并行读写选择信号, H读, L写
sbit E = P3^4; //并行使能端, H有效, L无效
sbit PSB = P3^7; //并/串接口选择, H并,L串
sbit RET = P3^3; //复位, L有效
uchar code datas1[] = {"长江大学电信学院"};
uchar code datas2[] = {"自动化系李三 "};
uchar code datas3[] = {"学号20080265 "};
uchar code datas4[] = {"博客:domyself.cu"};
uchar code datas5[] = {"blog.cn "};
uchar code datas6[] = {"邮箱:number "};
uchar code datas7[] = {" "};
uchar code datas8[] = {"欢迎大家与我交流"};
//延时约2us
void delayUs()
{nop_();_nop_();
}
//延时 a * 1ms
void delayMs(uint a)
{
uint i, j;
for(i = a; i > 0; i--)
for(j = 100; j > 0; j--);
}
//检测LCD是否处于忙状态, 若忙返回1, 空闲返回0
bit checkBusy()
{ bit busy;
RS = 0;
RW = 1;
E = 1;
delayUs();
busy = (bit)(LCD_DATA&0x80);
E = 0;
return busy;
}
//等待LCD到空闲
void wait()
{
while(checkBusy());
}
//写命令
void writeCmd(uchar cmd)
{
wait();
RS = 0;
RW = 0;
E = 0;
delayUs();
LCD_DATA = cmd;
delayUs();
E = 1;
delayUs();
E = 0;
}
//写数据
void writeData(uchar dat)
{
wait();
RS = 1;
RW = 0;
E = 0;
delayUs();
LCD_DATA = dat;
delayUs();
E = 1;
delayUs();
E = 0;
}
//初始化LCD
void init()
{
PSB = 1; //并口方式
writeCmd(0x30); //基本指令, 扩充指令为34H
delayMs(10);
writeCmd(0x0c); //显示开, 关光标
delayMs(10);
writeCmd(0x01); //清屏
delayMs(10);
}
void setPosition(uchar x, uchar y)
{ uchar p;
switch(x%4)
{
case 0: p = 0x80; break; //第一行开始地址
case 1: p = 0x88; break; //第二行
case 2: p = 0x90; break; //第三行
case 3: p = 0x98; break; //第四行
}
p += y;
writeCmd(p);
}
void writeString(uchar * str)
{ uchar i = 0;
while(str[i] != '\0')
{
writeData(str[i++]);
}
}
/**//***************************LCD12864***************************/
void main()
{//先关闭数码管, 使两个锁存器锁存, 因开了数码管, USB电压驱动不够, 将 无法使LCD正常工作
//dula = wela = 0;
init();
while(1)
{
setPosition(0, 0);
writeString(datas1);
setPosition(1, 0);
writeString(datas2);
setPosition(2, 0);
writeString(datas3);
setPosition(3, 0);
writeString(datas4);
delayMs(6000);
writeCmd(0x01); //清屏
delayMs(200);
setPosition(0, 0);
writeString(datas5);
setPosition(2, 0);
writeString(datas6);
setPosition(1, 0);
writeString(datas7);
setPosition(3, 0);
writeString(datas8);
delayMs(6000);
}
}
阅读(3319) | 评论(0) | 转发(0) |