基于STC12C5410AD的字庫型12864的使用
#include intrins.h>
sbit E_CLK =P1^2; //時(shí)鐘使能
sbit RW_SID=P1^1;//串行數(shù)據(jù)輸入、輸出端
sbit RS_CS =P1^0;//片選端
//宏定義
#define uint unsigned int
#define uchar unsigned char
//下面是數(shù)組定義
uchar code ts[]={"黃河遠(yuǎn)上白云間"};
uchar code tw[]={"一片孤城萬仞山"};
uchar code ta[]={"羌笛何須怨楊柳"};
uchar code tb[]={"春風(fēng)不度玉門關(guān)"};
//延時(shí)子函數(shù)
void delay(unsigned int xms)
{
unsigned int i,j;
for(i=0; ixms; i++)
for(j=0;j110;j++)
{};
}
//串行發(fā)送一字節(jié)數(shù)據(jù)
void Send_Byte(unsigned char dat)
{
unsigned char i;
for(i=0;i8;i++)
{
delay(1);
P1M0=0;
P1M1=1;
E_CLK=0; //時(shí)鐘線拉低
if(dat0x80)
RW_SID=1;
else
RW_SID=0;
E_CLK=1;
dat=dat1;
}
}
//控制命令
void Send_command(unsigned char dat)
{
P1M0=0;
P1M1=1;
RS_CS=1;
Send_Byte(0xF8);//11111,00,0 RW=0,RS=0 同步標(biāo)志
Send_Byte(dat0xF0);//高四位
Send_Byte((dat0x0F)4);//低四位
RS_CS=0;
}
//顯示數(shù)據(jù)或單字節(jié)字符
void Send_Dat(unsigned char dat)
{
RS_CS=1;
Send_Byte(0xFA);//11111,01,0 RW=0,RS=1
Send_Byte(dat0xF0);//高四位
Send_Byte((dat0x0F)4);//低四位
RS_CS=0;
}
void display_1()
{
uchar a;
Send_command(0x80);
for(a=0;a14;a++)
{
Send_Dat(ts[a]);
}
}
void display_2()
{
uchar b;
Send_command(0x90);
for(b=0;b14;b++)
{
Send_Dat(tw[b]);
}
}
void display_3()
{
uchar c;
Send_command(0x88);
for(c=0;c14;c++)
{
Send_Dat(ta[c]);
}
}
void display_4()
{
uchar d;
Send_command(0x98);
for(d=0;d14;d++)
{
Send_Dat(tb[d]);
}
}
//初始化 LCD
void init(void)
{
P1M0=0;
P1M1=1;
RS_CS=0;
delay(1);
Send_command(0x30);//功能設(shè)置,一次送8位數(shù)據(jù),基本指令集
Send_command(0x0c);//0000,1100 整體顯示,游標(biāo)on,游標(biāo)位置on
Send_command(0x01);//0000,0001 清DDRAM
Send_command(0x02);//0000,0010 DDRAM地址歸位
Send_command(0x80);//1000,0000 設(shè)定DDRAM 7位地址000,0000到地址計(jì)數(shù)器AC
}
void main(void)
{
init();
delay(1);
display_1();
display_2();
display_3();
display_4();
while(1);
}
評(píng)論