|
我用ATmega16控制LCD1602显示数数据,为什么无显示。但在仿真软件上却可以。单片机频率为4M
[复制链接]
/*?????¨??RS*/
#define RS_CLR PORTB&=~(1 << PB1)/*????????*/
#define RS_SET PORTB|=(1 << PB1)/*????????*/
/*RW*/
#define RW_CLR PORTC&=~(1 << PC5)/*????????*/
#define RW_SET PORTC|=(1 << PC5)/*????????*/
/*E*/
#define E_CLR PORTC&=~(1 << PC4)/*????????*/
#define E_SET PORTC|=(1 << PC4)/*????????*/
#define XS PORTA
void busy() //?ì?é??????
{
unsigned char i,j;
for(i=0;i<200;i++)
for(j=0;j<10;j++);
}
void inorder(unsigned char order) //???ü??
{
XS=order;
RS_CLR; //RS=0;
RW_CLR; //RW=0;
E_SET; //E=1;
busy();
E_CLR; //E=0;
}
void indata(unsigned char datar) //??????
{
XS=datar;
RS_SET; //RS=1;
RW_CLR; //RW=0;
E_SET; //E=1;
busy();
E_CLR ; //E=0;
}
void initlcd (void)
{
inorder(0x01);
inorder(0X38); //8??2??5X7???ó
inorder(0X0f); //?????÷??????±ê??????????
inorder(0X06); //??×?????????±ê×???????
inorder(0x01); //??????
}
以上程序为"1602.h"文件
#include
#define uchar unsigned char
#define uint unsigned int
#include "1602.h"
void port_init(void)
DDRA = 0xFF;
//PORTA = 0x00;
{
DDRB = 0xFF;
//PORTB = 0x00;
DDRC = 0xFF;
//PORTC = 0x00;
}
void main()
{
port_init();
initlcd ();
inorder(0x80); //??±ê???òLCD???????×????
indata('A'); //????
indata('B'); //????
indata('C'); //????
indata('D'); //????
inorder(0xc0); //??±ê???òLCD???????×????
indata(0x30); //????
indata(0x30); //????
indata(0x30); //????
indata(0x30); //????
while(1);
}
|
|