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);
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);
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
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("ST7920串行驱动");
gotoxy(1,0);
writestring("版本:Test v1.0");
delay_ms(1000);
//second screen
LCDclrscr();
writestring("设计:Datazyb");
gotoxy(1,0);
writestring("日期:2006.3.17");
}
//***********************************************************
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.
上一页 [1] [2] [3] 下一页
本文关键字:程序 AVR单片机,单片机-工控设备 - AVR单片机