#include<avr/io.h>
#define uchar unsigned char
#define uint unsigned int
void delay(uint ms)
{
uint i,j;
for(i=0;i<ms;i++)
{
for(j=0;j<1141;j++);
}
}
void write_com(uchar com)
{
PORTC&=~_BV(0);//rs为低电平
PORTC&=~_BV(1);//rw为低电平
PORTA=com;
PORTC&=_BV(2);//开使能
delay(5);
PORTC&=~_BV(2);//关使能
}
void write_dat(uchar dat)
{
PORTC|=_BV(0);//rs为高电平
PORTC&=~_BV(1);//rw为低电平
PORTA=dat;
PORTC&=_BV(2);//开使能
delay(5);
PORTC&=~_BV(2);//关使能
}
void lcd_init()
{
PORTC&=~_BV(2);//关使能
write_com(0X38);
delay(5);
write_com(0X01);//清零指令
delay(5);
write_com(0X0C);//0X0F 显示光标并闪烁
delay(5);
write_com(0X06);
delay(5);
}
int main()
{
lcd_init();
DDRA=0XFF;
DDRC=0XFF;
while(1)
{
MCUCSR|=(1<<7); //关闭JTAG
MCUCSR|=(1<<7);
write_com(0X80+0X10);//显示起始位
delay(5);
write_dat(0X41);
}
} |