大家好,刚接触PIC的单片机。完成一个简单程序,就让1602液晶显示一组字符。我是用C语言编的,但是奇怪的是这个程序就是不执行Write_LCD_Data()这个函数。我是新手弄了好半天也不知道什么问题。请看出问题的人说一下,谢谢。C编译器用的是PICC的免费版。
#include <pic.h>
#include <htc.h>
__CONFIG(WDTDIS&XT&LVPDIS&DEBUGDIS);
#define PORTAIT(adr,bit) ((unsigned)(&adr)*8+(bit))
#define DelayNop() {asm("NOP");asm("NOP");asm("NOP");asm("NOP");}
static bit LCD_RS @PORTAIT(PORTC,0);
static bit LCD_RW @PORTAIT(PORTC,1);
static bit LCD_EN @PORTAIT(PORTC,2);
bit LCD_Busy_Check();
void Write_LCD_Command(unsigned char cmd);
void Write_LCD_Data(unsigned char dat);
void LCD_Initialise();
//LCD忙标志检测函数
bit LCD_Busy_Check()
{
static bit result;
LCD_RS = 0;
LCD_RW = 1;
LCD_EN = 1;
DelayNop();
TRISB=0xFF;
result = (bit)(PORTB&0x80);
LCD_EN=0;
return result;
}
//LCD写命令
void Write_LCD_Command(unsigned char cmd)
{
while(LCD_Busy_Check());
TRISB=0;
LCD_RS = 0;
LCD_RW = 0;
LCD_EN = 0;
asm("NOP");
asm("NOP");
PORTB = cmd;
DelayNop();
LCD_EN = 1;
DelayNop();
LCD_EN = 0;
}
//LCD写数据
void Write_LCD_Data(unsigned char dat)
{
while(LCD_Busy_Check());
TRISB=0;
LCD_RS = 1;
LCD_RW = 0;
LCD_EN = 0;
asm("NOP");
asm("NOP");
PORTB =dat;
DelayNop();
LCD_EN = 1;
DelayNop();
LCD_EN = 0;
}
//LCD初始化函数
void LCD_Initialise()
{ Write_LCD_Command(0x01);
Delay(1000);
Write_LCD_Command(0x38);
Delay(1000);
Write_LCD_Command(0x0c);
Delay(1000);
Write_LCD_Command(0x06);
Delay(1000);
}
//设置LCD显示位置
void Set_LCD_POS(unsigned char pos)
{
Write_LCD_Command(pos|0x80);
}
void main(void)
{
unsigned char i;
TRISC=0;
LCD_Initialise();
Delay(10);
Set_LCD_POS(0x01);
i=0;
while(dis1[i]!='\0')
{
Write_LCD_Data(dis1[i]);
i++;
}
Set_LCD_POS(0x42);
i=0;
while(dis2[i]!='\0')
{
Write_LCD_Data(dis2[i]);
i++;
}
} |