AVR128的程序——1602液晶顯示
#define uchar unsigned char
#define uint unsigned int
unsigned char table[]="I love mcu!";
unsigned char table1[]="very much!";
#define rsout DDRB |= (1<<5)
#define rsset PORTB |=(1<<5)
#define rsclr PORTB &=~(1<<5)
#define rwout DDRB |= (1<<6)
#define rwset PORTB |= (1<<6)
#define rwclr PORTB &= ~(1<<6)
#define enout DDRB |= (1<<7)
#define enset PORTB |= (1<<7)
#define enclr PORTB &= ~(1<<7)
void mcu_init(void);
void Delayms(uint MS)
{
}
void write_com(uchar com)
{
rsclr;
rwclr;
enclr;
PORTA=com;
Delayms(5);
enset;
Delayms(5);
enclr;
}
void write_data(uchar date)
{
rsset;
rwclr;
PORTA=date;
Delayms(5);
enset;
Delayms(5);
enclr;
}
void initlcd(void)
{
write_com(0x38);
Delayms(5);
Delayms(5);
write_com(0x06);
Delayms(5);
Delayms(5);
}
void main(void)
{
mcu_init();
Delayms(30);
initlcd();
write_com(0x80);
for(num=0;num<11;num++)
{
write_data(table[num]);
Delayms(20);
}
write_com(0x80+0x40);
for(num=0;num<10;num++)
{
write_data(table1[num]);
Delayms(20);
}
while(1);
}
void mcu_init(void)
{
}
關(guān)鍵詞:
AVR1281602液晶顯
評論