|
//************************************************** // AVR8515 和 HD74480字符LCD的接口程序 // // 硬件连接方式:LCD的D0-D7接8515的c口, // LCD的 RS ->PA0 // LCD的 RW ->PA1 // LCD的 E ->PA0 // !!!注意VEE,有时需要接负电源 // // dailizhou@0451.com
//**************************************************
#include<io8515v.h>
#define RS_H asm("sbi 0x1B,0") #define RS_L asm("cbi 0x1B,0") #define RW_H asm("sbi 0x1B,1") #define RW_L asm("cbi 0x1B,1") #define E_H asm("sbi 0x1b,2") #define E_L asm("cbi 0x1b,2")
//****************************************** void Delay() { unsigned char di; for(di=0;di<20;di++); }
//判断lcd是否是内部操作状态 char Lcd_Busy() { char rb; DDRC=0x0; //端口c设为输入方式 E_L; RS_L; RW_H; Delay(); E_H; Delay(); rb=PINC; rb=rb&0x80; E_L; DDRC=0xff; //端口c设为输出方式
return rb; }
//向Lcd发送命令程序 void Lcd_Command(unsigned char bComm) { while(Lcd_Busy()); E_L; RS_L; RW_L; Delay(); E_H; PORTC=bComm; Delay(); E_L; Delay();
}
//向lcd写入一个字符 void Lcd_Write(char wb) { while(Lcd_Busy()); E_L; RS_H; RW_L; Delay(); E_H; PORTC=wb; Delay(); E_L; Delay(); }
//初始化时用的写命令程序,和Lcd_Command的区别是不判断忙标志 void Lcd_InitCommand(unsigned char bComm) { E_L; RS_L; RW_L; Delay(); E_H; PORTC=bComm; Delay(); E_L; }
//初始化:8位接口,2行x16字符的工作方式 void Lcd_Init() { char i; Lcd_InitCommand(0x30); for(i=0;i<100;i++) Delay(); Lcd_InitCommand(0x30); for(i=0;i<10;i++) Delay(); Lcd_InitCommand(0x30);
Lcd_Command(0x38); Lcd_Command(0x08); Lcd_Command(0x01); Lcd_Command(0x06); Lcd_Command(0x02); Lcd_Command(0x0E); }
//一个测试LCD的小程序 int main() { const char *str="Hello,This is Dai in HIT.";
DDRA=0xFF; DDRC=0xFF; Lcd_Init();
while(*str) Lcd_Write( *str++ );
while(1); return 0;
} //缺少的是一个读显示RAM中数据的程序,自己加上吧
|