微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > AVR128的程序——1602液晶显示

AVR128的程序——1602液晶显示

时间:11-22 来源:互联网 点击:
#include

#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)

{

uint i,j;

for( i=0;i

for(j=0;j<1141;j++);

}

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);

write_com(0x01);

Delayms(5);

write_com(0x06);

Delayms(5);

write_com(0x0c);

Delayms(5);

}

void main(void)

{

uint num=0;

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)

{

DDRA = 0XFF;

PORTA = 0XFF;

DDRC = 0XFF;

PORTC = 0XFF;

DDRF |= 0X0E;

PORTF |= 0X0E;

PORTF &= 0xF0;

DDRB |= 0X10;

PORTB |= 0X10;

rsout;

rwout;

enout;

}


Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top