📄 lcd.c~
字号:
/*------------------------------------------------------------
FileName : lcd.c
Created by : ZhengYanbo
Created date : 2006.3.17
Last modified: 2006.3.25
Comments: : serial drive for st7920
-------------------------------------------------------------*/
#include "lcd.h"
#include "type.h"
flash byte CGRAM[] = {0x10};
//**********************************************************
//初始化与LCD连接的端口
void LCD_port_init(void)
//**********************************************************
{
//SID output mode
SID_PIN_OUT();
//CLK output mode
CLK_PIN_OUT();
//CS output mode
CS_PIN_OUT();
}
//**********************************************************
//用串行方式写一个字节数据到LCD
void serial_write_byte(byte data)
//**********************************************************
{
byte i;
//SID pin output mode
SID_PIN_OUT();
CLK_PIN_OUT();
CS_PIN_OUT();
for(i=0; i<8; i++)
{
if(data & 0x80)
SET_SID();
else
CLR_SID();
//send clk
CLR_CLK();
#asm("nop");
SET_CLK();
data<<=1;
}
}
//**********************************************************
//以串行方式从LCD中读一个字节,返回数据
byte serial_read_byte(void)
//**********************************************************
{
byte i, temp=0;
//SID pin input mode
SID_PIN_IN();
CLK_PIN_OUT();
CS_PIN_OUT();
for(i=0; i<8; i++)
{
temp<<=1;
//send clk
CLR_CLK();
#asm("nop");
SET_CLK();
//wait pin steady
#asm("nop");
temp |= (byte)SID_PIN;
}
return(temp);
}
//**********************************************************
//读LCD的状态,读出BF信号
byte LCD_read_status(void)
//**********************************************************
{
byte temp;
LCD_Enable();
//send 0b11111100
serial_write_byte(LCD_READ_STATUS);
//read upper 4 bits
temp = serial_read_byte() & 0xF0;
//read lower 4 bits
temp = (serial_read_byte() & 0xF0)>>4 + temp;
LCD_Disable();
//return its value
return(temp);
}
//**********************************************************
//忙信号BF检查
//返回: 1->success 0->error(time out)
byte check_busy(void)
//**********************************************************
{
byte time_out;
time_out=255;
while(LCD_read_status()&0x80)
{
time_out--;
//check time out
if(time_out==0) return 0;
};
return 1;
}
//**********************************************************
//写命令到LCM
void LCDWriteCmd(byte command)
//**********************************************************
{
//not check BF state
//delay_us(100);
//check busy
check_busy();
LCD_Enable();
//send 0b11111000
serial_write_byte(LCD_WRITE_COMMAND);
//write upper 4 bits
serial_write_byte(command & 0xF0);
//write lower 4 bits
serial_write_byte((command<<4) & 0xF0);
LCD_Disable();
}
//**********************************************************
//写数据到LCM
void LCDWriteData(byte data)
//**********************************************************
{
//not check BF state
//delay_us(100);
//check busy
check_busy();
LCD_Enable();
//send 0b11111010
serial_write_byte(LCD_WRITE_DATA);
//write upper 4 bits
serial_write_byte(data & 0xF0);
//write lower 4 bits
serial_write_byte((data<<4) & 0xF0);
LCD_Disable();
}
//***********************************************************
//Initialize LCD, then print logo
void InitLCD(void)
//***********************************************************
{
delay_ms(50); //Wait LCD ready
LCD_port_init(); //Init LCD port
LCDWriteCmd(0x30); //function set
delay_us(100);
LCDWriteCmd(0x30); //function set
delay_us(100);
LCDWriteCmd(0x0C); //display on, cursor off
delay_us(100);
LCDWriteCmd(0x01); //clear lcd
delay_ms(10);
LCDWriteCmd(0x06); //Entry mode set
//Write LCD CGRAM
LCD_Write_CGRAM(128);
//Printing Logo
//LCDclrscr();
gotoxy(0,0);
writestring("VS1003 Player");
gotoxy(1,0);
writestring("版本: CF v1.0");
delay_ms(2000);
//second screen
LCDclrscr();
writestring("Key & Com Ctrl");
gotoxy(1,0);
writestring("Date:2007.5.18");
delay_ms(2000);
}
//***********************************************************
void LCD_Write_CGRAM(byte nBytes)
//***********************************************************
{
//Load user's font characters
byte i;
//Set CGram addres;
LCDWriteCmd(0x40);
//load CGRAM characters
for(i=0;i<nBytes;i++) LCDWriteData(CGRAM[i]);
}
//***********************************************************
void writechar(byte value)
//***********************************************************
{
//Write 1 character
//#asm("cli");
LCDWriteData(value);
//Set High status
LCD_Hi_Z();
}
//***********************************************************
//Write a string from flash ROM
void writestring(byte flash *strn)
//***********************************************************
{
while (*strn!=0) writechar(*strn++);
}
//***********************************************************
//Gotoxy function. X=line number, Y=character position
void gotoxy(byte line, byte position)
//***********************************************************
{
byte address;
address=lcdLineStart[line]+position;
LCDWriteCmd(address);
}
//***********************************************************
//Clear LCD
void LCDclrscr(void)
//***********************************************************
{
LCDWriteCmd(0x01);
delay_ms(5); //Writing cycle time is 4.6ms for LCD128X64.
}
//***********************************************************
//Setup curson blink, based on player state
void blink(byte on_off)
//***********************************************************
{
//if on_off = 1 blink on, if on_off=0 blink off
LCDWriteCmd(0x0C + (on_off & 1));
}
//***********************************************************
//Write a decimal number on LCD
void writeNumber(word value)
//***********************************************************
{
byte temp[8],i=0;
do {
temp[i++]=value%10;
value=value/10;
}
while (value>0);
//start from back and print the number
for(;i>0;) writechar(temp[--i]+48);
}
//end of lcd.c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -