AVR单片机写的1602程序,不知道问题出在哪里
#include<iom16v.h>#include<macros.h>#defineuintunsignedint#defineucharunsignedchar#de...
#include<iom16v.h>
#include<macros.h>
#define uint unsigned int
#define uchar unsigned char
#define set_en PORTB|=BIT(0)
#define clr_en PORTB&=~BIT(0)
//使能端
#define set_rs PORTB|=BIT(1)
#define clr_rs PORTB&=~BIT(1)
//rs
#define set_rw PORTB|=BIT(2)
#define clr_rw PORTB&=~BIT(2)
//rw
#define PA PORTA
#define PB PORTB
uchar table[]=" bu guan zen yang";
uchar table1[]=" Never give up";
uchar num;
uchar table2[]={
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,
0xc6,0xa1,0x86,0x8e
};
void delay()
{
uint i,j;
for(i=110;i>0;i--)
for(j=100;j>0;j--);
}
void write_com(uchar com)
{
clr_rs;
delay();
clr_rw;
delay();
PA=com;
delay();
set_en;
delay();
clr_en;
delay();
}
void write_data(uchar data)
{
set_rs;
delay();
clr_rw;
delay();
PA=data;
delay();
set_en;
delay();
clr_en;
delay();
}
void init()
{
DDRA=0XFF;
PA=0XFF; //数据输入端口
DDRB=0XFF;
PB=0XFF;
clr_en;
clr_rw;
write_com(0x38);
delay();
write_com(0x0c);
delay();
write_com(0x06);
delay();
write_com(0x01);
delay();
}
void main()
{
init();
delay();
write_com(0x80);
delay();
for(num=0;num<16;num++)
{
write_data(table[num]);
delay();
}
write_com(0x80+0x40);
delay();
for(num=0;num<14;num++)
{
write_data(table1[num]);
delay();
}
while(1);
} 展开
#include<macros.h>
#define uint unsigned int
#define uchar unsigned char
#define set_en PORTB|=BIT(0)
#define clr_en PORTB&=~BIT(0)
//使能端
#define set_rs PORTB|=BIT(1)
#define clr_rs PORTB&=~BIT(1)
//rs
#define set_rw PORTB|=BIT(2)
#define clr_rw PORTB&=~BIT(2)
//rw
#define PA PORTA
#define PB PORTB
uchar table[]=" bu guan zen yang";
uchar table1[]=" Never give up";
uchar num;
uchar table2[]={
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,
0xc6,0xa1,0x86,0x8e
};
void delay()
{
uint i,j;
for(i=110;i>0;i--)
for(j=100;j>0;j--);
}
void write_com(uchar com)
{
clr_rs;
delay();
clr_rw;
delay();
PA=com;
delay();
set_en;
delay();
clr_en;
delay();
}
void write_data(uchar data)
{
set_rs;
delay();
clr_rw;
delay();
PA=data;
delay();
set_en;
delay();
clr_en;
delay();
}
void init()
{
DDRA=0XFF;
PA=0XFF; //数据输入端口
DDRB=0XFF;
PB=0XFF;
clr_en;
clr_rw;
write_com(0x38);
delay();
write_com(0x0c);
delay();
write_com(0x06);
delay();
write_com(0x01);
delay();
}
void main()
{
init();
delay();
write_com(0x80);
delay();
for(num=0;num<16;num++)
{
write_data(table[num]);
delay();
}
write_com(0x80+0x40);
delay();
for(num=0;num<14;num++)
{
write_data(table1[num]);
delay();
}
while(1);
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询