下面为源程序,还没编完,但是就是在chk_busy()里面忙标志一直回读“忙”,不解,求助!请各位大神指教!
#include <pic18fxx2.h>
#define nop() asm("nop")
#define uint unsigned int
#define uchar unsigned char
#define LcdData PORTD
#define LcdRS RE0 //指令数据口
#define LcdRW RE1 //读写控制口
#define LcdEn RE2 //使能端口
#define LcdPS RB4 //串并口选择
#define LcdRst RB5 // 复位端
#define Busy RD7 //忙标志位
#define dat 1
#define comm 0
#define x1 0x80
#define x2 0x88
#define y 0x80
void delay(uint Deconst);
void chk_busy(void);//测忙程序
void send2lcd(uchar dat_comm,uchar content);//向lcd发送指令数据程序
void init_port(void);
void init_lcd(void);
void lat_disp(uchar data1,uchar data2);//点阵
//--------------------------------------------------------
void delay(uint Deconst)
{
while(Deconst--);
}
//--------------------------------------------------------
void chk_busy(void)
{
TRISD=0xff;//RD为输入
LcdRS=0;
LcdRW=1;
LcdEn=1;
while(Busy==1); //!!!!!!!!!!!!!!!!!!就卡在这了!!!!!!!
LcdEn=0;
TRISD7=0x00;//RD恢复为输出
}
//---------------------------------------------------------
void send2lcd(uchar dat_comm,uchar content)
{
chk_busy();//忙标志检查
if (dat_comm)
{
LcdDC=1;
LcdRW=0;
}
else
{
LcdDC=0;
LcdRW=0;
}
PORTD=content;
LcdEn=1;
delay(5);
LcdEn=0;
}
//---------------------------------------------------------
void init_port(void)//IO口初始化
{
TRISD=0x00;
TRISE=0x00;
TRISB4=0;
TRISB5=0;
}
//----------------------------------------------------------
void init_lcd(void)
{
LcdRst=1;//禁用复位
LcdPS=1;//选择并口工作方式
delay(50);
send2lcd(comm,0x30);
delay(250);//
send2lcd(comm,0x30);
delay(90);//
send2lcd(comm,0x3C);//
send2lcd(comm,0x38);//
send2lcd(comm,0x01);//
}
//---------------------------------------------------------
void lat_disp(uchar data1,uchar data2)
{
uchar i,j,k,x;
x=x1;
for (k=0;k<2;k++)
{
for(j=0;j<16;j++)
{
for (i=0;i<8;i++)
{
send2lcd(comm,0x34);
send2lcd(comm,y+j*2);
send2lcd(comm,x+i);
send2lcd(comm,0x30);
send2lcd(dat,data1);
send2lcd(dat,data1);
}
for (i=0;i<8;i++)
{
send2lcd(comm,0x34);
send2lcd(comm,y+j*2+1);
send2lcd(comm,x+i);
send2lcd(comm,0x30);
send2lcd(dat,data2);
send2lcd(dat,data2);
}
}
x=x2;
}
send2lcd(comm,0x36);
}
main(void)
{
INTCON=0x00;
init_port();
init_lcd();
send2lcd(comm,0x01);
send2lcd(comm,0x06);
send2lcd(comm,0x0c);
lat_disp(0x00,0x00);
while(1);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
---------------------------------------------------------------------
int i;
for (i=0; i<2000; i++) { if (Busy==0) break; }
不管忙不忙, 循环次数一到, 退出返回
一周热门 更多>