基于ATMEGA16的12864程序,想做个简单显示程序,但是不知道程序出了什么问题。我用的是PC口。
#include<mega16.h>#include<delay.h>#defineucharunsignedchar#defineuintunsignedint#def...
#include<mega16.h>
#include<delay.h>
#define uchar unsigned char
#define uint unsigned int
#define CTRPORT PORTC
#define CTRDDR DDRC
#define RS PORTA7// 1:输入数据 ;0:输入命令
#define set_rs() CTRPORT |= (1 << RS)
#define clr_rs() CTRPORT &= ~(1 << RS)
#define RW PORTA6//1:读数据 0:写数据
#define set_rw() CTRPORT |= (1 << RW)
#define clr_rw() CTRPORT &= ~(1 << RW)
#define E PORTA5
#define set_e() CTRPORT |= (1 << E)
#define clr_e() CTRPORT &= ~(1 << E)
#define PSB PORTA4 //串并口选择 1:并口模式; 0:串口模式;
#define set_psb() CTRPORT |= (1 << PSB)
#define clr_psb() CTRPORT &= ~(1 << PSB)
#define LcdData PORTC
#define LcdPin PINC
#define LcdDdr DDRC
uchar table[]={"这个程序怎么写"};
void delay(unsigned int t)
{ unsigned int i,j;
for(i=0;i<t;i++)
for(j=0;j<10;j++);
}
void delay_ms(unsigned int t)
{ unsigned int i,j;
for(i=0;i<t;i++)
for(j=0;j<120;j++);
}
void port_int()
{
PORTA=0xff;
DDRA=0xff;
PORTB=0xff;
DDRB=0xff;
PORTC=0xff;
DDRC=0xff;
PORTD=0xff;
DDRB=0xff;
}
//写数据
void Lcd_Writedata(unsigned char dispdata)
{
set_rs();
clr_rw();
clr_e();
LcdData=dispdata;
delay_ms(5);
set_e();
delay_ms(5);
clr_e();
}
//写指令代码
void Lcd_WriteCmd(unsigned char cmdcode)
{
while(1)
clr_rs();
clr_rw();
clr_e();
LcdData=cmdcode;
delay_ms(5);
set_e();
delay_ms(5);
clr_e();
}
void lcd_pos(uchar X,uchar Y)
{ uchar pos;
if (X==1)
{X=0x80;}
else if(X==2)
{X=0x90;}
else if(X==3)
{X=0x88;}
else if(X==4)
{X=0x98;}
pos=X+Y;
Lcd_WriteCmd(pos);
}
void LCDclean()
{
Lcd_WriteCmd(0x01);
delay_ms(5);
Lcd_WriteCmd(0x34);
delay_ms(5);
Lcd_WriteCmd(0x30);
delay_ms(5);
}
//初始化LCD
void Lcd_Init()
{
set_psb(); //选择并行方式
Lcd_WriteCmd(0x30); //选择基本指令集
delay_ms(5);
Lcd_WriteCmd(0x0c); //开显示(无游标、不反白)
delay_ms(5);
Lcd_WriteCmd(0x01); //清除显示,并且设定地址指针为00H
delay_ms(5);;
}
void main()
{ uchar j;
port_int();
Lcd_Init();
LCDclean();
lcd_pos(2,0);
for(j=0;j<8;j++)
{ Lcd_Writedata(table[j]);
delay_ms(5);
}
} 展开
#include<delay.h>
#define uchar unsigned char
#define uint unsigned int
#define CTRPORT PORTC
#define CTRDDR DDRC
#define RS PORTA7// 1:输入数据 ;0:输入命令
#define set_rs() CTRPORT |= (1 << RS)
#define clr_rs() CTRPORT &= ~(1 << RS)
#define RW PORTA6//1:读数据 0:写数据
#define set_rw() CTRPORT |= (1 << RW)
#define clr_rw() CTRPORT &= ~(1 << RW)
#define E PORTA5
#define set_e() CTRPORT |= (1 << E)
#define clr_e() CTRPORT &= ~(1 << E)
#define PSB PORTA4 //串并口选择 1:并口模式; 0:串口模式;
#define set_psb() CTRPORT |= (1 << PSB)
#define clr_psb() CTRPORT &= ~(1 << PSB)
#define LcdData PORTC
#define LcdPin PINC
#define LcdDdr DDRC
uchar table[]={"这个程序怎么写"};
void delay(unsigned int t)
{ unsigned int i,j;
for(i=0;i<t;i++)
for(j=0;j<10;j++);
}
void delay_ms(unsigned int t)
{ unsigned int i,j;
for(i=0;i<t;i++)
for(j=0;j<120;j++);
}
void port_int()
{
PORTA=0xff;
DDRA=0xff;
PORTB=0xff;
DDRB=0xff;
PORTC=0xff;
DDRC=0xff;
PORTD=0xff;
DDRB=0xff;
}
//写数据
void Lcd_Writedata(unsigned char dispdata)
{
set_rs();
clr_rw();
clr_e();
LcdData=dispdata;
delay_ms(5);
set_e();
delay_ms(5);
clr_e();
}
//写指令代码
void Lcd_WriteCmd(unsigned char cmdcode)
{
while(1)
clr_rs();
clr_rw();
clr_e();
LcdData=cmdcode;
delay_ms(5);
set_e();
delay_ms(5);
clr_e();
}
void lcd_pos(uchar X,uchar Y)
{ uchar pos;
if (X==1)
{X=0x80;}
else if(X==2)
{X=0x90;}
else if(X==3)
{X=0x88;}
else if(X==4)
{X=0x98;}
pos=X+Y;
Lcd_WriteCmd(pos);
}
void LCDclean()
{
Lcd_WriteCmd(0x01);
delay_ms(5);
Lcd_WriteCmd(0x34);
delay_ms(5);
Lcd_WriteCmd(0x30);
delay_ms(5);
}
//初始化LCD
void Lcd_Init()
{
set_psb(); //选择并行方式
Lcd_WriteCmd(0x30); //选择基本指令集
delay_ms(5);
Lcd_WriteCmd(0x0c); //开显示(无游标、不反白)
delay_ms(5);
Lcd_WriteCmd(0x01); //清除显示,并且设定地址指针为00H
delay_ms(5);;
}
void main()
{ uchar j;
port_int();
Lcd_Init();
LCDclean();
lcd_pos(2,0);
for(j=0;j<8;j++)
{ Lcd_Writedata(table[j]);
delay_ms(5);
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询