RT12232F st7920驱动程序
扫描二维码
随时随地手机看文章
#ifndef__LCD_H__
#define__LCD_H__
#include"type.h"
//LCM122*32PINdefine
#defineCLKPORTC.5//pc5
#defineSIDPORTC.4//pc4
#defineCSPORTB.4//pb4
#defineSET_CLK()CLK=1;
#defineCLR_CLK()CLK=0;
#defineSET_SID()SID=1;
#defineCLR_SID()SID=0;
#defineLCD_Enable()CS=1;
#defineLCD_DISAble()CS=0;
#defineSID_PIN_IN()DDRC.4=0;
#defineSID_PIN_OUT()DDRC.4=1;
#defineCLK_PIN_OUT()DDRC.5=1;
#defineCS_PIN_OUT()DDRB.4=1;
#defineSID_PINPINC.4//readpinx,notport!
#defineLCD_Hi_Z()DDRC&=0xCF;
//lcdserialcommand
//#defineLCD_WRITE_COMMAND0b11111000
//#defineLCD_WRITE_DATA0b11111010
//#defineLCD_READ_STATUS0b11111100
//#defineLCD_READ_DATA0b11111110
#defineLCD_WRITE_COMMAND0xF8
#defineLCD_WRITE_DATA0xFA
#defineLCD_READ_STATUS0xFC
#defineLCD_READ_DATA0xFE
voidserial_write_byte(bytedata);
byteserial_read_byte(void);
voidLCDWriteCmd(bytecommand);
voidLCDWritEDAta(bytedata);
voidInitLCD(void);
voidLCD_Write_CGRAM(bytenBytes);
voidLCD_Write_CGRAM(bytenBytes);
voidwritechar(bytevalue);
voidwritestring(byteflash*strn);
voidgotoxy(byteline,byteposition);
voidLCDclrscr(void);
voidblink(byteon_off);
voidwriteNumber(wordvalue);
#endif
/*------------------------------------------------------------
FileName:lcd.c
Createdby:ZhengYanbo
Createddate:2006.3.17
Lastmodified:2006.3.17
Comments::serialdriveforst7920
-------------------------------------------------------------*/
#include"lcd.h"
#include"type.h"
/*
flashbyteCGRAM[128]=
{
//目录循环
0xE3,0x9E,0x91,0x11,0x89,0x11,0x89,0x1E,
0x89,0x14,0x91,0x12,0xE3,0x91,0x00,0x00,
0x00,0x00,0x3F,0xFC,0x40,0x02,0x40,0x42,
0x40,0x82,0x3D,0xFC,0x00,0x80,0x00,0x40,
//文件循环
0xEE,0x8F,0x84,0x88,0x84,0x88,0xE4,0x8E,
0x84,0x88,0x84,0x88,0x8E,0xEF,0x00,0x00,
0x00,0x00,0x3F,0xFC,0x40,0x02,0x40,0x22,
0x40,0x42,0x3E,0xFC,0x00,0x40,0x00,0x20,
//随机模式
0xE1,0x1B,0x92,0x95,0x94,0x55,0xE7,0xD5,
0xA4,0x51,0x94,0x51,0x00,0x00,0x00,0x00,
0x00,0x00,0x3F,0xFC,0x40,0x02,0x40,0x42,
0x40,0x82,0x3D,0xFC,0x00,0x80,0x00,0x40,
//磁盘循环
0xCE,0x74,0xA4,0x84,0x94,0x85,0x94,0x66,
0x94,0x14,0xA4,0x16,0xCE,0xE5,0x00,0x00,
0x00,0x00,0x3F,0xFC,0x40,0x02,0x40,0x42,
0x40,0x82,0x3D,0xFC,0x00,0x80,0x00,0x40
};*/
//**********************************************************
//用串行方式写一个字节数据到LCD
voidserial_write_byte(bytedata)
//**********************************************************
{
bytei;
//SIDpinoutputmode
SID_PIN_OUT();
CLK_PIN_OUT();
CS_PIN_OUT();
for(i=0;i<8;i++)
{
if(data&0x80)
SET_SID();
else
CLR_SID();
//sendclk
CLR_CLK();
#asm("nop");
SET_CLK();
data<<=1;
}
}
//**********************************************************
//以串行方式从LCD中读一个字节,返回数据
byteserial_read_byte(void)
//**********************************************************
{
bytei,temp=0;
//SIDpininputmode
SID_PIN_IN();
CLK_PIN_OUT();
CS_PIN_OUT();
for(i=0;i<8;i++)
{
temp<<=1;
//sendclk
CLR_CLK();
#asm("nop");
SET_CLK();
//waitpinsteady
#asm("nop");
temp=(byte)SID_PIN;
}
return(temp);
}
//**********************************************************
//读LCD的状态,读出BF信号
byteLCD_read_status(void)
//**********************************************************
{
bytetemp;
LCD_Enable();
//send0b11111100
serial_write_byte(LCD_READ_STATUS);
//readupper4bits
temp=serial_read_byte()&0xF0;
//readlower4bits
temp=(serial_read_byte()&0xF0)>>4+temp;
LCD_Disable();
//returnitsvalue
return(temp);
}
//**********************************************************
//忙信号BF检查
//返回:1->suCCess0->error(timeout)
bytecheck_busy(void)
//**********************************************************
{
bytetime_out;
time_out=255;
while(LCD_read_status()&0x80)
{
time_out--;
//checktimeout
if(time_out==0)return0;
};
return1;
}
//**********************************************************
//写命令到LCM
voidLCDWriteCmd(bytecommand)
//**********************************************************
{
//notcheckBFstate
delay_us(100);
LCD_Enable();
//send0b11111000
serial_write_byte(LCD_WRITE_COMMAND);
//writeupper4bits
serial_write_byte(command&0xF0);
//writelower4bits
serial_write_byte((command<<4)&0xF0);
LCD_Disable();
}
//**********************************************************
//写数据到LCM
voidLCDWriteData(bytedata)
//**********************************************************
{
//notcheckBFstate
delay_us(100);
LCD_Enable();
//send0b11111010
serial_write_byte(LCD_WRITE_DATA);
//writeupper4bits
serial_write_byte(data&0xF0);
//writelower4bits
serial_write_byte((data<<4)&0xF0);
LCD_Disable();
}
//***********************************************************
//InitializeLCD,thenprintlogo
voidInitLCD(void)
//***********************************************************
{
delay_ms(50);//WaitLCDready
LCDWriteCmd(0x30);//functionset
delay_us(100);
LCDWriteCmd(0x30);//functionset
delay_us(100);
LCDWriteCmd(0x0C);//displayon,cursoroff
delay_us(100);
LCDWriteCmd(0x01);//clearlcd
delay_ms(10);
LCDWriteCmd(0x06);//Entrymodeset
//WriteLCDCGRAM
LCD_Write_CGRAM(128);
//PrintingLogo
//LCDclrscr();
gotoxy(0,0);
writestring("ST7920串行驱动");
gotoxy(1,0);
writestring("版本:Testv1.0");
delay_ms(1000);
//secondscreen
LCDclrscr();
writestring("设计:Datazyb");
gotoxy(1,0);
writestring("日期:2006.3.17");
}
//***********************************************************
voidLCD_Write_CGRAM(bytenBytes)
//***********************************************************
{
//Loaduser’sfontcharacters
bytei;
//SetCGramaddres;
LCDWriteCmd(0x40);
//loadCGRAMcharacters
for(i=0;i
//***********************************************************
voidwritechar(bytevalue)
//***********************************************************
{
//Write1character
//#asm("cli");
LCDWriteData(value);
//SetHighstatus
LCD_Hi_Z();
}
//***********************************************************
//WriteastringfromflashROM
voidwritestring(byteflash*strn)
//***********************************************************
{
while(*strn!=0)writechar(*strn++);
}
//***********************************************************
//Gotoxyfunction.X=linenumber,Y=characterposition
voidgotoxy(byteline,byteposition)
//***********************************************************
{
byteaddress;
address=lcdLineStart[line]+position;
LCDWriteCmd(address);
}
//***********************************************************
//ClearLCD
voidLCDclrscr(void)
//***********************************************************
{
LCDWriteCmd(0x01);
delay_ms(5);//Writingcycletimeis4.6msforLCD128X64.
}
//***********************************************************
//Setupcursonblink,basedonplayerstate
voidblink(byteon_off)
//***********************************************************
{
//ifon_off=1blinkon,ifon_off=0blinkoff
LCDWriteCmd(0x0C+(on_off&1));
}
//***********************************************************
//WriteadecimalnumberonLCD
voidwriteNumber(wordvalue)
//***********************************************************
{
bytetemp[8],i=0;
do{
temp[i++]=value%10;
value=value/10;
}
while(value>0);
//startfrombackandprintthenumber
for(;i>0;)writechar(temp[--i]+48);
}
//endoflcd.c