下面是一段pic开发板上自带的一段代码
是关于1602 4数据线的代码
两个函数void WriteNibble(UINT8_T Cmd,UINT8_T Dat);和void WriteByte(UINT8_T Cmd,UINT8_T Dat);都写在了lcd.c文档里。
从功能上看void WriteNibble(UINT8_T Cmd,UINT8_T Dat)函数是void WriteByte(UINT8_T Cmd,UINT8_T Dat)的子函数
在编译的时候如果将void WriteNibble(UINT8_T Cmd,UINT8_T Dat)放在void WriteByte(UINT8_T Cmd,UINT8_T Dat)后面就出错,提示子函数没有声明类型,默认为int,然后哇啦哇啦还有一堆错误。
但是把子函数放在前面就一切正常。
我知道在main函数里如果调用某段程序需要在它前面声明,难道其它函数也这样吗?但是如果是这样,接下来的LCDInit()函数调用LCDClear()函数时,二者的位置不管怎么放置都不会出错,这是个什么情况啊?
/******************************************************
******************************************************/
void WriteNibble(UINT8_T Cmd,UINT8_T Dat)
{
UINT8_T buf;
if (Cmd) // If Command To be written
LCD_RS = CLEAR;
else // Otherwise we are writing data
LCD_RS = SET; // Set register select according to specified
LCD_RW = WRITE; // Set write mode
LCD_EN = ENABLE; // Disable LCD
LCD_DAT0 = LCD_DAT1 = LCD_DAT2 = LCD_DAT3 = CLEAR; // Clear the data lines
NOP(); // Small delay
NOP();
buf =LATD; // Getting the high nibble
buf &= 0xF0; // Clear the low nibble
LATD = buf | (Dat & 0x0F); // Combine & write back to the data lines
NOP(); // Give the data a small delay to settle
NOP();
LCD_EN = DISABLE; // Enable LCD => The data is taken now
}
/************************************************************
************************************************************/
void WriteByte(UINT8_T Cmd,UINT8_T Dat)
{
WriteNibble(Cmd,Dat >> 4); // Output the high nibble to the LCD
WriteNibble(Cmd,Dat); // Now send the low nibble
}
|