#include <reg52.h>
#include <intrins.h>
#include "delay.h"
sbit RS = P2^4;
sbit RW = P2^5;
sbit E = P2^6;
sbit RES = P2^3;
sbit PSB = P2^1;
sbit PAUSE = P3^0;
#define DataPort P0 //MCU P0<------> LCM
/*------------------------------------------------
檢測忙位
------------------------------------------------*/
void Check_Busy()
{
RS=0;
RW=1;
E=1;
DataPort=0xff;
while((DataPort&0x80)==0x80);//忙則等待
E=0;
}
/*------------------------------------------------
寫命令
------------------------------------------------*/
void Write_Cmd(unsigned char Cmd)
{
Check_Busy();
RS=0;
RW=0;
E=1;
DataPort=Cmd;
DelayUs2x(5);
E=0;
DelayUs2x(5);
}
/*------------------------------------------------
寫數據
------------------------------------------------*/
void Write_Data(unsigned char Data)
{
Check_Busy();
RS=1;
RW=0;
E=1;
DataPort=Data;
DelayUs2x(5);
E=0;
DelayUs2x(5);
}
/*------------------------------------------------
液晶屏初始化
------------------------------------------------*/
void Init_ST7920()
{
DelayMs(40); //大于40MS的延時程序
PSB=1; //設置為8BIT并口工作模式
DelayMs(1); //延時
RES=0; //復位
DelayMs(1); //延時
RES=1; //復位置高
DelayMs(10);
Write_Cmd(0x30); //選擇基本指令集
DelayUs2x(50); //延時大于100us
Write_Cmd(0x30); //選擇8bit數據流
DelayUs2x(20); //延時大于37us
Write_Cmd(0x0c); //開顯示(無游標、不反白)
DelayUs2x(50); //延時大于100us
Write_Cmd(0x01); //清除顯示,并且設定地址指針為00H
DelayMs(15); //延時大于10ms
Write_Cmd(0x06); //指定在資料的讀取及寫入時,設定游標的移動方向及指定顯示的移位,光標從右向左加1位移動
DelayUs2x(50); //延時大于100us
}
/*------------------------------------------------
用戶自定義字符
------------------------------------------------*/
void CGRAM()
{
int i;
Write_Cmd(0x30);
Write_Cmd(0x40);
}
/*------------------------------------------------
顯示字符串
x:橫坐標值,范圍0~8
y:縱坐標值,范圍1~4
------------------------------------------------*/
void LCD_PutString(unsigned char x,unsigned char y,unsigned char code *s)
{
switch(y)
{
case 1: Write_Cmd(0x80+x);break;
case 2: Write_Cmd(0x90+x);break;
case 3: Write_Cmd(0x88+x);break;
case 4: Write_Cmd(0x98+x);break;
default:break;
}
while(*s>0)
{
Write_Data(*s);
s++;
DelayUs2x(50);
}
}
/*------------------------------------------------
清屏
------------------------------------------------*/
void ClrScreen()
{
Write_Cmd(0x01);
DelayMs(15);
}
/*------------------------------------------------
主程序
------------------------------------------------*/
main()
{
unsigned char i;
CGRAM(); //寫入自定義字符
while(1)
{
Init_ST7920(); //初始化
LCD_PutString(0,1,"重量:");
LCD_PutString(0,2,"單價:");
LCD_PutString(0,3,"總價:");
LCD_PutString(0,4,"");
for(i=0;i<30;i++)
DelayMs(200);
}
}
所以void CGRAM()
{
int i;
Write_Cmd(0x30);
Write_Cmd(0x40);
} 這一串有什么用?對程序的影響是啥? |