#//头信息
#include <reg51.h>
#include <math.h>
#include <INTRINS.H>
//定义数据类型
#define uchar unsigned char
#define uint unsigned int
#define xchar unsigned char code
#define DataPort P1
#define DELAYMS 80
//端口定义
sbit RS_Port = P2^7;
sbit RW_Port = P2^6;
sbit E_Port = P2^5;
sbit PSB_Port = P2^4;
//输入显示的内容 # 每行显示七个字 要改内内容直接在下边该就行了
// 但是需要留意的是,每行必须七个字 否则乱码 后期我会修改
xchar CorpInf[]=
{
"风速风速风速风"
"风速风速风速风"
"风速风速风速风"
"风速风速风速风"
};
//短延时函数
#pragma disable
void delay(uchar uc_dly)
{
while (uc_dly--);
}
//长延时函数,以秒每单位
#pragma disable
void delays()
{
uchar uc_dly,uc_dly1,uc_dly2;
uc_dly =DELAYMS;
while (uc_dly --)
{
for (uc_dly1=0;uc_dly1<50;uc_dly1++)
for (uc_dly2=0;uc_dly2<50;uc_dly2++);
};
}
//写命令
#pragma disable
void wr_cmd(uchar cmd)
{
E_Port = 0;
_nop_();
_nop_();
RS_Port=0;
_nop_();
_nop_();
RW_Port=0;
_nop_();
_nop_();
E_Port=1;
_nop_();
_nop_();
DataPort=cmd;
_nop_();
_nop_();
E_Port=0;
_nop_();
_nop_();
delay(5);
}
//写数据
#pragma disable
void wr_dat(uchar dat)
{
E_Port = 0;
_nop_();
_nop_();
RS_Port=1;
_nop_();
_nop_();
RW_Port=0;
_nop_();
_nop_();
E_Port=1;
_nop_();
_nop_();
DataPort=dat;
_nop_();
_nop_();
E_Port=0;
_nop_();
_nop_();
delay(5);
}
//显示初始化
#pragma disable
void Init(void)
{
wr_cmd(0x30); //DL=1:8-BIT interface
wr_cmd(0x30); //RE=0:basic instruction
wr_cmd(0x06); //Entire display shift right by 1
wr_cmd(0x08); //Display OFF,Cursor OFF,Cursor position blink OFF
wr_cmd(0x34); //DL=1:8-BIT interface
wr_cmd(0x34); //RE=0:Extend instruction
wr_cmd(0x03);
}
//写入数据的行数以及数据的分布
#pragma disable
void DisGBStr(xchar *CorpInf)
{
uchar uc_GBCnt;
wr_cmd(0x30); //DL=1:8-BIT interface
wr_cmd(0x30); //RE=0:basic instruction
wr_cmd(0x0C); //Display OFF,Cursor OFF,Cursor position blink OFF
wr_cmd(0x80);
for (uc_GBCnt=0;uc_GBCnt<16;uc_GBCnt++)
{
wr_dat(CorpInf[2 * uc_GBCnt]);
wr_dat(CorpInf[2 * uc_GBCnt + 1]);
};
wr_cmd(0x90);
for (uc_GBCnt=0;uc_GBCnt<16;uc_GBCnt++)
{
wr_dat(CorpInf[2 * uc_GBCnt + 32]);
wr_dat(CorpInf[2 * uc_GBCnt + 33]);
};
delays();
}
#pragma disable
void CRAM_OFF()
{
wr_cmd(0x30); //DL=1:8-BIT interface
wr_cmd(0x30); //RE=0:basic instruction
wr_cmd(0x08); //Display ON,Cursor OFF,Cursor position blink OFF
wr_cmd(0x01); //CLEAR
delay(250);
}
void main()
{
EA=1; //Interurupt Enabled
IT0 = 1;//INT0 Low Level Trigger
EX0 = 1;//INT0 Enabled
PSB_Port =1;
_nop_();
delay(250);
//ST7920 Init
Init();
while (1)
{
CRAM_OFF();
DisGBStr(CorpInf);
}
}