Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

MPLAB compiling error

Status
Not open for further replies.

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:

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:

You don't need to mention the port simply give Pin number like RE1=1;RC1=0; etc
For TRISC you may pass the hex value like TRISC=0X08,TRISA=0X3F; etc as per your requirement.
 

owh alright..
i've tried again..
and now it appear another error stating:

Error [500] ; 0. undefined symbols:
_InitLCD(load.obj) _DisplayString(load.obj)

How actually this means?
 

hay won poh Ting please read below thread completely and implement your self and then after if any error then post your code here using wrap
Code:
 tag.

[URL="https://saeedsolutions.blogspot.in/2012/12/how-to-display-custom-characters-on-lcd.html"]https://saeedsolutions.blogspot.in/2012/12/how-to-display-custom-characters-on-lcd.html[/URL]
 

You don't need to mention the port simply give Pin number like RE1=1;RC1=0; etc
For TRISC you may pass the hex value like TRISC=0X08,TRISA=0X3F; etc as per your requirement.

Actually, the way Won Poh Ting entered the code for the port/pins/registers is the preferred way for the newer versions of HiTech C. If you are setting a port/register value, you can use the port/register name. If you are setting a bit value, you can use PORTbits.bitname (example: TRISEbits.TRISE0 = 0;). The assignments in Init_LCD (TRISE1 = 0;) were wrong but the rest were correct.

Also, there is nothing wrong with entering 0 instead of 0x00 as numbers. Actually, when I set up my TRIS registers, I enter it in binary (0b01011110 vs. 0x5e vs 94) since it's easier for me to tell which pin is an input and which is an output. All three values I listed still set the register to the same value.
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top