PIC 18f4680 C18 Syntax error help

Status
Not open for further replies.

RePoD

New Member
Hi all,

I am relatively new to working with PIC micros. I am trying to interface a 2 line lcd display with my 18f4680 microcontroller. I am attempting to adapt code I located on the Internet to work with my PIC, however I am getting a "Syntax error" when attempting to compile it. I am using MLAB 8.46 with the C18 compiler v3.35.

My source code is below.

Any assistance would be greatly appreciated.

RePoD

Code:
#include <p18f4680.h>
#include <delays.h>

#define RW_PIN = PORTCbits.RC6   /* PORT for RW */
#define RS_PIN = PORTCbits.RC5   /* PORT for RS */
#define E_PIN = PORTCbits.RC7   /* PORT for E  */

void prnt(unsigned int);
void commd(unsigned int);
void lcd_init(void);

void main(void)
{

	int count=0;

	char output[] = " Hello Daniel, ";
	char output2[] = "How are you? ";

	TRISC=0x00;
	TRISD=0x00;

	PORTC=0x00;
	PORTD=0x00;

	Delay10KTCYx(200);

	lcd_init(); //set up LCD

	while(output[count] != '\0')
	{
		prnt(output[count]);
		count++;
	}
	
	commd(0b11000000);	//Move to next line
	count = 0;

	while(output2[count] != '\0')
	{
		prnt(output2[count]); //Print character to screen
		count++;
	}

	commd(0b10000000);

	while(1)
	{
	}

}

void lcd_init(void)
{
	E_PIN = 0;
	RS_PIN = 0;
	RW_PIN = 0;

	commd(0b00000010); // Set cursor to Home position

	commd(0b00101000); // Set to 4 bit, 2 line, 5x8 font size.

	commd(0b00001100); // Set display text to on, show cursor and blink cursor to off

	commd(0b00000001); // Clear Display

	commd(0b00000010); // Set cursor to Home position
}


//print interface

void prnt(unsigned int character)
{

	PORTD=character >> 4;

	RS_PIN = 1;
	E_PIN = 1;
	E_PIN = 0;
	RS_PIN = 0;

	PORTD=character & 0x0f;

	RS_PIN = 1;
	E_PIN = 1;
	E_PIN = 0;
	RS_PIN = 0;

	Delay1KTCYx(200); 
}


//instruction interface

void commd(unsigned int commd)
{

	PORTD=commd >> 4;
	E_PIN = 1;
	E_PIN = 0;

	PORTD=commd &0x0f;
	E_PIN = 1;
	E_PIN = 0;

	Delay1KTCYx(10);

}
 
Apologies for not including more information,

In MLAB I get a generic "Syntax error" for line 55

void lcd_init(void)
{
E_PIN = 0; //<<<--- Line 55
RS_PIN = 0;
RW_PIN = 0;

commd(0b00000010); /


If I try to compile my code using the C18 command line I get a different error, namely "Type mismatch" for line 4

#include <delays.h>

#define RW_PIN = PORTCbits.RC6 /* PORT for RW *///<<<--- Line 4
#define RS_PIN = PORTCbits.RC5 /* PORT for RS */


Any assistance would be appreciated.
 
Hi all,

Code:
#define RW_PIN = PORTCbits.RC6   /* PORT for RW */
#define RS_PIN = PORTCbits.RC5   /* PORT for RS */
#define E_PIN = PORTCbits.RC7   /* PORT for E  */

Macros are straight text substitution. You don't want or need the "=" there.

Try this:

Code:
#define RW_PIN   PORTCbits.RC6   /* PORT for RW */
#define RS_PIN   PORTCbits.RC5   /* PORT for RS */
#define E_PIN    PORTCbits.RC7   /* PORT for E  */

Brad
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…