AVR 1602液晶字符移動
#include
#define uchar unsigned char
#define uint unsigned int
#define uint unsigned int
uchar str1[16]="This is a ASCII";
uchar str2[16]=" Test ";
uchar str2[16]=" Test ";
#include "1602.h"
void port_init()
{
PORTA=0xff;
DDRA=0xff;
PORTB=0xff;
DDRB=0xff;
PORTD=0xff;
DDRD=0xff;
}
{
PORTA=0xff;
DDRA=0xff;
PORTB=0xff;
DDRB=0xff;
PORTD=0xff;
DDRD=0xff;
}
void init()
{
MCUCR=0x0a;
GICR=0xc0;
SREG=0x80;
}
{
MCUCR=0x0a;
GICR=0xc0;
SREG=0x80;
}
void disline(uchar w) //字符移動函數(shù)
{
uchar i;
for(i=0;i<16;i++)
{
displayonechar(i,1,w); //字符顯示在第二行 即字母A--Z
w++;
if(w>90)w=65; //字符顯示限定范圍A--Z
}
delay(500);
}
{
uchar i;
for(i=0;i<16;i++)
{
displayonechar(i,1,w); //字符顯示在第二行 即字母A--Z
w++;
if(w>90)w=65; //字符顯示限定范圍A--Z
}
delay(500);
}
void main()
{
uchar w=65;
port_init();
init();
//1602設備初始化
delay(15);
writecmd(0x38);
delay(5);
writecmd(0x38);
delay(5);
writecmd(0x38);
writecmd(0x80);
writecmd(0x01);
writecmd(0x06);
writecmd(0x0c);
delay(500);
//初始化結束
{
uchar w=65;
port_init();
init();
//1602設備初始化
delay(15);
writecmd(0x38);
delay(5);
writecmd(0x38);
delay(5);
writecmd(0x38);
writecmd(0x80);
writecmd(0x01);
writecmd(0x06);
writecmd(0x0c);
delay(500);
//初始化結束
writecmd(0x01);
writecmd(0x0c);
displaychar(0,0,str1);
delay(1000);
writecmd(0x01);
writecmd(0x0c);
displaychar(0,1,str2);
delay(1000);
writecmd(0x01);
writecmd(0x0c);
while(1)
{
disline(w++); //字符移動模式
if(w>90)w=65;
}
}
writecmd(0x0c);
displaychar(0,0,str1);
delay(1000);
writecmd(0x01);
writecmd(0x0c);
displaychar(0,1,str2);
delay(1000);
writecmd(0x01);
writecmd(0x0c);
while(1)
{
disline(w++); //字符移動模式
if(w>90)w=65;
}
}
//-----------------1602庫函數(shù)-----------------------
#define RS PORTB_Bit0
#define RW PORTB_Bit1
#define EN PORTB_Bit2
#define DATA PORTA
#define busy 0x80
#define RW PORTB_Bit1
#define EN PORTB_Bit2
#define DATA PORTA
#define busy 0x80
關鍵詞:
AVR1602液晶字符移
評論