Won Poh Ting
Newbie level 3
- Joined
- Apr 5, 2014
- Messages
- 3
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 19
I'm currently dealing with TCS230 color sensor interfacing with PIC16F877A. When i compiled my code with MPLAB, it appears to be error. Below is the code for LCD.c for display:
The compiler appear errorundefined identifier "PORTEbits" and also struct/union required. How actually this mean and how it cn be solved?
Code:
#include <htc.h>
#include "LCD.h"
void InitLCD(void)
{
TRISA = 0;
TRISE = 0;
TRISE0 = 0;
TRISE1 = 0;
TRISE2 = 0;
TRISB1 = 0;
TRISB2 = 0;
WriteLCDCommand(0x38);// 8 BIT DATA LENGTH AND NUMBER OF DISPLAY LINES
WriteLCDCommand(0x0E); // Turn on cursor
WriteLCDCommand(0x01); //Set cursor to line1
WriteLCDCommand(0x06);// CLEAR THE DISPLAY
}
void ConfigDataIn(void)
{
//TRISA = 0xFF;
//TRISEbits.TRISE0 = 1;
//TRISEbits.TRISE1 = 1;
}
void ConfigDataOut(void)
{
//TRISA = 0x00;
//TRISEbits.TRISE0 = 0;
//TRISEbits.TRISE1 = 0;
}
//RS = RC2, RW = RC1, EN = RC0
unsigned char Enable;
void EnableLCD(void)
{
//TRISEbits.TRISE1 = 1;
PORTEbits.RE2 = 1;
LCDDelay(500);
Enable = 1;
}
void DisableLCD(void)
{
LCDDelay(500);
PORTEbits.RE2 = 0;
Enable = 0;
//TRISEbits.TRISE1 = 0;
}
void EnableRead(void)
{
//TRISBbits.TRISB1 = 1;
PORTBbits.RB1 = 1;
LCDDelay(500);
}
void EnableWrite(void)
{
PORTBbits.RB1 = 0;
//TRISBbits.TRISB1 = 0;
LCDDelay(500);
}
void EnableData(void)
{
//TRISBbits.TRISB2 = 1;
PORTBbits.RB2 = 1;
LCDDelay(500);
}
void EnableCommand(void)
{
PORTBbits.RB2 = 0;
//TRISBbits.TRISB2 = 0;
LCDDelay(500);
}
unsigned char Tmp;
void WriteData(unsigned char Data)
{
unsigned char i;
Tmp = Data;
PORTA = Tmp;
Tmp =((Data >> 7)&0x01)<<1;
Tmp |=(Data >> 6)&0x01;
Tmp |= Enable << 2;
PORTE = Tmp;
LCDDelay(1000);
}
unsigned char IData;
unsigned char IsLCDBusy(void)
{
if( RE1 == 1)
return TRUE;
else
return FALSE;
}
void LCDDelay(unsigned short i)
{
unsigned short j;
j = 0;
while(j < i)
j++;
}
unsigned char RetVal;
void CheckLCDReady(void)
{
/*do
{
//ClrWdt();
DisableLCD();
ConfigDataIn();// Make LCD data port direction for status check as input.
//LCD_COMMAND_LINE_DIRECTION=OUTPUT;// Make LCD control lines port as output.
EnableRead();// R/W=1 READ COMMAND REG
EnableCommand();// RS=0 ACCESS COMMAND REG
EnableLCD(); // Enable pin set.
RetVal = IsLCDBusy();
}while(RetVal==TRUE); // Check 7th bit.
// Disable Enable pin.
DisableLCD();
EnableWrite(); // R/W=0 for write operation to write.
ConfigDataOut();// Make LCD data port as output.
LCDDelay(100);*/
}
void WriteLCDCommand(unsigned char Command)
{
CheckLCDReady();
EnableWrite();// R/W=0 // make r/w low to write.
EnableCommand();//RS=0 // make rs =0 for command
EnableLCD(); // enable lcd pin=1;
LCDDelay(100);
WriteData(Command); // send Command to lcd data port
LCDDelay(100);
DisableLCD(); // disable enable pin=0;
}
void WriteLCDData(unsigned char Data)
{
//call ascii coversion.
CheckLCDReady();
EnableWrite(); //WRITE OPERATION, R/W=0
EnableData();// RS=1 for lcd data write.
EnableLCD(); // enable lcd pin=1;
LCDDelay(100);
WriteData(Data); // send data to lcd data port
LCDDelay(100);
DisableLCD(); // disable enable pin=0;
LCDDelay(1000);
}
void DisplayString(unsigned char LineNumber,
unsigned char *pData,
unsigned char Value,
unsigned char MessageType)
{
unsigned char Index;
unsigned char Byte1;
unsigned char Byte2;
unsigned char Byte3;
SetLine(LineNumber);
//for(Index=0;Index < 5;Index++)
// WriteLCDData(pData[Index]);
for(Index=0;pData[Index]!='\0';Index++)
{
WriteLCDData(pData[Index]);
}
if(MessageType==DATA_WRITE)
{
Binary2Ascii(Value,&Byte1,&Byte2,&Byte3);
WriteLCDData(Byte3);
WriteLCDData(Byte2);
WriteLCDData(Byte1);
}
else
{}
}
void SetLine(unsigned char LineNumber)
{
switch(LineNumber)
{
case 1:WriteLCDCommand(0x01);
break;
case 2:WriteLCDCommand(0xC0);
break;
default:
break;
}
}
void Binary2Ascii(unsigned char HexValue,
unsigned char *pByte1,
unsigned char *pByte2,
unsigned char *pByte3)
{
*pByte1=0;
*pByte2=0;
*pByte3=0;
while(HexValue >= 0x64 )
{
++(*pByte3);
HexValue=HexValue - 0x64;
}
while(HexValue >= 0x0A)
{
++(*pByte2);
HexValue=HexValue - 0x0A;
}
*pByte1=HexValue; // Remainder is the lower decimal.
*pByte1=*pByte1|0x30; // Convert decimal to Ascii.
*pByte2=*pByte2|0x30; // Convert decimal to Ascii.
*pByte3=*pByte3|0x30; // Convert decimal to Ascii.
The compiler appear errorundefined identifier "PORTEbits" and also struct/union required. How actually this mean and how it cn be solved?
Last edited: