串行12864显示:
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit CS=P2^5;
sbit SID=P2^6;
sbit SCLK=P2^7;
sbit RST=P2^2;
sbit CH = P2^4;
void delay(unsigned int t)
{
while(t--);
}
//********************************************************************
void sendbyte(unsigned char zdata)//发送数据
{
unsigned int i;
for(i=0; i<8; i++)
{
if((zdata << i) & 0x80)
{
SID = 1;
}
else
{
SID = 0;
}
SCLK = 0;
SCLK = 1;
}
}
//********************************************************************
void write_com(unsigned char cmdcode)//写串口指令
{
CS = 1;
sendbyte(0xf8);
sendbyte(cmdcode & 0xf0);
sendbyte((cmdcode << 4) & 0xf0);
delay(2);
}
//********************************************************************
void write_data(unsigned char Dispdata)//写串口数据
{
CS = 1;
sendbyte(0xfa);
sendbyte(Dispdata & 0xf0);
sendbyte((Dispdata << 4) & 0xf0);
delay(2);
}
//********************************************************************
void LEDinit()//初始化led
{
RST = 0;
delay(100);
RST = 1;
delay(20000);
write_com(0x30);
delay(50);
write_com(0x0c);
delay(50);
}
//********************************************************************
void stringPlay(unsigned char code *s)//显示字符串
{
while(*s > 0)
{
write_data(*s);
s++;
delay(50);
}
}
//********************************************************************
void Dislay()//显示子函数
{
write_com(0x03);
delay(50);
write_com(0x81);
stringPlay(" 白鹤依山尽,");
write_com(0x91);
stringPlay(" 黄河入海流。");
write_com(0x89);
stringPlay(" 欲穷千里目, ");
write_com(0x98);
stringPlay(" 更上一层楼。");
}
//********************************************************************
void Main()
{
CH = 0;
delay(1);
LEDinit();
delay(10);
while(1)
{
Display();
delay(5000);
}
}
|