#include <AT89X55.H>
#include <LCD.h>
#include <8255.h>
#include <ABSACC.H>
void ST7920_Init(void)
{
_8255_CS=0;
PBYTE[_8255_Cortrol]= _8255_Init;
_8255_CS=1;
ST7920_WriteInstruction(ST7920_FUN_SET);
ST7920_WriteInstruction(ST7920_CURSOR_Line);
ST7920_WriteInstruction(ST7920_MODE_SET);
}
/*
***********************************************************************************************
* Write Data RAM
*
* Description: Write Data RAM
*
* Arguments : Data value written to RAM
*
* Returns : none
*
* Notes : 1)
***********************************************************************************************
*/
void ST7920_WriteData(unsigned char temp)
{
unsigned char cDate;
E12864=0; //E=0
cDate=temp;
ST7920_RS=1; //RS=1
_8255_CS=0;
PBYTE[_8255_Cortrol]=PC_2_RST; //RW=0
PBYTE[_8255_A]=cDate; //Write date to Lcd
_8255_CS=1;
E12864=1; //E=1
Delayl(0x1A);
}
/*
***********************************************************************************************
* Write Instruction Register
*
* Description: Write Instruction Register
*
* Arguments : Instruction value written to Instruction Register
*
* Returns : none
*
* Notes : 1)
***********************************************************************************************
*/
void ST7920_WriteInstruction(unsigned char temp)
{
unsigned char cDate;
E12864=0; //E=0
cDate=temp;
ST7920_RS=0; //RS=0
_8255_CS=0;
PBYTE[_8255_Cortrol]=PC_2_RST; //RW=0
PBYTE[_8255_A]=cDate; //Write date to Lcd
_8255_CS=1;
E12864=1; //E=1
Delayl(0x1A);
}
void DspTitle(void)
{
unsigned char Title[] = {"GSM/GPRS通信测试V1.01 2006年05月"
"上海第二工业大学电子电气工程学院"};
WriteOneScreen(0x0,64,Title);
}
/*
***********************************************************************************************
* Write Line Data
*
* Description: Write Data to Line (ST7920)
*
* Arguments : startAddress is the start address of the Line (80 ~ 9F)
* dataNum is the number of data to be written to Line
* dataVector is a pointer to the header of the data vector
* Returns : none
*
* Notes : 1) MAY have problem while interrupts are being enabled
* 2) data length is UP to 16 bytes
*
***********************************************************************************************
*/
void ST7920_Write_Line (unsigned char startAddress, unsigned char dataNum,
unsigned char *dataVector)
{
ST7920_WriteInstruction(startAddress);
while(dataNum > 0)
{
ST7920_WriteData(*dataVector);
dataNum--;
dataVector++;
}
}
/*
***********************************************************************************************
* Write Full Screen
*
* Description: Write Full Screen (ST7920)
*
* Arguments : startAddress is the start address of the start (80 ~ 9F)
* dataNum is the number of data to be written to Line (0~64)
* dataVector is a pointer to the header of the data vector
*
* Returns : none
*
* Notes : 1) data length is UP to 16 bytes
***********************************************************************************************
*/
void WriteOneScreen(unsigned char startAddress, unsigned char dataNum,unsigned char *dataVector)
{
unsigned char cLoop;
cLoop = startAddress;
while(dataNum > 0)
{
switch(cLoop)
{
case 0x0:
ST7920_WriteInstruction(0x80);
break;
case 0x10:
ST7920_WriteInstruction(0x90);
break;
case 0x20:
ST7920_WriteInstruction(0x88);
break;
case 0x30:
ST7920_WriteInstruction(0x98);
break;
}
cLoop=(cLoop+1)&0x3f;
ST7920_WriteData(*dataVector);
dataNum--;
dataVector++;
}
}
void Delayl(unsigned int time)
{
while (time > 0)time--;
}
评论0