AVR128的程序——1602液晶显示
2016-03-04 来源:eefocus
#include
uint i,j;
for( i=0;i
for(j=0;j<1141;j++);
write_com(0x01);
write_com(0x0c);
uint num=0;
DDRA = 0XFF;
PORTA = 0XFF;
DDRC = 0XFF;
PORTC = 0XFF;
DDRF |= 0X0E;
PORTF |= 0X0E;
PORTF &= 0xF0;
DDRB |= 0X10;
PORTB |= 0X10;
rsout;
rwout;
enout;
进入单片机查看更多内容>>
#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)
{
}
相关文章