新闻中心

EEPW首页>嵌入式系统>设计应用> AVR单片机1602液晶程序

AVR单片机1602液晶程序

作者: 时间:2016-11-29 来源:网络 收藏
端口定义在程序里面采用8位数据模式,程序测试通过.
#include
#include
#define uchar unsigned char
#define uint unsigned int
#pragma data:code
uchar shu;
const uchar table[15]={
"yinqing@163.com"
};
const uchar table1[]={
"www.51hei.com "
};
/**********************************/
/************延时子程序************/
/**********************************/
void delay(uint z)//延时
{
uint x,y;
for(x=500;x>0;x--)
for(y=z;y>0;y--);
}
/**********************************/
/***********写指令子程序***********/
/**********************************/
void xeizhi(uchar tem)//写指令子程序
{
PORTC&=~BIT(6);//将RS控制端置0
PORTC&=~BIT(0);//将RW控制端置0
delay(10);
PORTA=tem;//将要读的指令放到PA口
PORTC|=BIT(0);//将使能端置0
delay(10);
PORTC&=~BIT(0);//将使能端置1
}
/**********************************/
/************读数子程序************/
/**********************************/
void duzhi(uchar tee)//写数子程序
{
PORTC|=BIT(6);//将RS控制端置1
PORTC&=~BIT(0);//将RW控制端置0
delay(10);
PORTA=tee;//将要读的数放到PA口
PORTC|=BIT(0);//将使能端置0
delay(10);
PORTC&=~BIT(0);//将使能端置1
}
/**********************************/
/***************主程序*************/
/**********************************/
void main()
{
DDRA=0xff;
DDRC|=BIT(6)|BIT(7)|BIT(0);//将3个控制端全部设为输出
PORTC&=~BIT(7);//将RW端置0
xeizhi(0x01);
xeizhi(0x38);
xeizhi(0x0c);
xeizhi(0x06);
/*******************第一行显示****************/
xeizhi(0x80);//将数据放显示区
for(shu=0;shu<15;shu++)
duzhi(table[shu]);
/*******************第二行显示****************/
xeizhi(0xc0);//将数据放在显示区
for(shu=0;shu<15;shu++)//查询15次得到要显示的数
duzhi(table1[shu]);//查表得到想要的数,和上面结合妙妙啊!
while(1);
}


关键词:AVR单片机1602液

评论


技术专区

关闭