#//頭信息
#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);
}
}