AVR 1602液晶字符移动
#include
#define uchar unsigned char
#define uint unsigned int
uchar str1[16]="This is a ASCII";
uchar str2[16]=" Test ";
#include "1602.h"
void port_init()
{
PORTA=0xff;
DDRA=0xff;
PORTB=0xff;
DDRB=0xff;
PORTD=0xff;
DDRD=0xff;
}
void init()
{
MCUCR=0x0a;
GICR=0xc0;
SREG=0x80;
}
void disline(uchar w) //字符移动函数
{
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);
//初始化结束
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;
}
}
//-----------------1602库函数-----------------------
#define RS PORTB_Bit0
#define RW PORTB_Bit1
#define EN PORTB_Bit2
#define DATA PORTA
#define busy 0x80
void delay(int k)
{
int i,j;
for(i=0;i
for(j=0;j<1140;j++);
}
}
void wait()
{
uchar val;
DATA=0xff;
RS=0;
RW=1;
__no_operation();
__no_operation();
EN=1;
__no_operation();
__no_operation();
DDRA=0x00;
val=PINA;
while(val&busy)
{
val=PINA;
}
EN=0;
DDRA=0xff;
}
void writecmd(uchar cmd)
{
wait();
RS=0;
RW=0;
__no_operation();
DATA=cmd;
__no_operation();
EN=1;
__no_operation();
__no_operation();
EN=0;
}
void writedata(uchar data)
{
wait();
RS=1;
RW=0;
__no_operation();
DATA=data;
__no_operation();
EN=1;
__no_operation();
__no_operation();
EN=0;
}
void displayonechar(uchar x,uchar y,uchar dda)
{
y&=0x01;
x&=0x0f;
if(y)x|=0x40;
x|=0x80;
writecmd(x);
writedata(dda);
}
void displaychar(uchar x,uchar y,uchar *p)
{
y&=0x01;
x&=0x0f;
while(*p!=)
{
if(x<=0x0f)
{
displayonechar(x,y,*p);
p++;
x++;
}
}
}
AVR1602液晶字符移 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)