jbug connecting a lcd to con8

Status
Not open for further replies.



ok ignore this for now, i have kind of figured i need to go thru slowly and try and find the correct syntax for mikroc pro! if i get stuck i will be bothering you all again tho man this is so confusing!! i had wrongly assumed that c code was c code was c code lol i had no idea that diff compilers did things a diff way! no wonder so many people give up. my hat goes off to all of you that have gone thru this no idea stage like i am.
 
i have spnt the last few days trying to figure out what is wrong with the syntax but no luck does anyone have any suggestions? heres the code and errors it generates, my gut feeling is its realy simple
Code:
#define LCDPORT LATA 
#define LCDTRIS TRISA
#define LCD_RS LATBbits.LATB4
#define LCD_TRIS_RS TRISBbits.TRISB4
#define LCD_E LATBbits.LATB1
#define LCD_TRIS_E TRISBbits.TRISB1

void Delay(int); 
void WriteCommand(unsigned char);
void WriteChar(unsigned char);
void WriteNibble(unsigned char);
void WaitLCDBusy(void);
void WriteLCD(unsigned char);
void InitLCD(void);
void PutMessage(rom char*);
void PutMessageAt(unsigned char,unsigned char,rom char*);
void PutHex(unsigned char);
void PutNibble(unsigned char);

//Write a string to the LCD
void PutMessage(rom char *Message){
    while(*Message!=0)
        WriteChar(*Message++);
} 

//Set position and write string.
void PutMessageAt(unsigned char X,unsigned char Y,rom char *Message){
    WriteCommand(0x80+(--Y<<6)+--X);
    while(*Message!=0)
        WriteChar(*Message++);
}

void PutHex(unsigned char Num){
    PutNibble(Num>>4);
    PutNibble(Num&0x0f);
}

void PutNibble(unsigned char num){
    if (num>9){
        WriteChar(num+'A'-10);
    }
    else{
        WriteChar(num+'0');
    }
}

//Initialises the LCD
void InitLCD(void){
    LCDTRIS &= 0xE1;                //ensure data bits are output
    LCD_E=0;                        //clear enable
    LCD_RS = 0;                     //going to write command
    LCD_TRIS_E=0;                   //Set enable to output
    LCD_TRIS_RS=0;                  //set RS to output
    Delay(30);                      //delay for LCD to initialise.
    WriteNibble(0x30);              //Required for initialisation
    Delay(5);                       //required delay
    WriteNibble(0x30);              //Required for initialisation
    Delay(1);                       //required delay
    WriteCommand(0x20);             //set to 4 bit interface
    WriteCommand(0x2c);             //set to 4 bit interface, 2 line and 5*10 font
    WriteCommand(0x01);                //clear display
    WriteCommand(0x06);             //move cursor right after write
    WriteCommand(0x0C);             //turn on display
}

//wait for the LCD to finish last command.
void WaitLCDBusy(void){
	Delay(5);
}

//Send a command to the LCD
void WriteCommand(unsigned char command){
    WaitLCDBusy();                  //wait until not busy
    LCD_RS = 0;                     //setup to send command
    WriteNibble(command>>4);        //write the high nibble
    WriteNibble(command);           //then the low nibble
}

//Send a character to the LCD
void WriteChar(unsigned char chr){
    WaitLCDBusy();                  //wait until not busy
    LCD_RS=1;                       //Setup to send character
    WriteNibble(chr>>4);            //write the high nibble
    WriteNibble(chr);               //then the low nibble
}

//Send any 4 bits to the LCD
void WriteNibble(unsigned char command){
    LCDPORT &= 0xE1;                //clear the data bits
    LCDPORT |= ((command<<1) & 0x1E);    //or in the new data
    LCD_E = 1;                      //enable the LCD interface
    LCD_E = 0;                      //disable it
}

// delay mS at 20MHz
void Delay(int Time){
int i,j;
    for(j=0;j<Time;j++)
        for(i=0;i<275;i++);
}




0 1 mikroCPIC1618.exe -MSF -DBG -pP18F1320 -DL -O11111114 -fo4 -N"C:\Documents and Settings\jason\My Documents\newlcd test.mcppi" -SP"C:\Program Files\Mikroelektronika\mikroC PRO for PIC\defs\" -SP"C:\Program Files\Mikroelektronika\mikroC PRO for PIC\uses\P18\" -SP"C:\Documents and Settings\jason\My Documents\" "newlcd test.c" "__Lib_Math.mcl" "__Lib_MathDouble.mcl" "__Lib_System.mcl" "__Lib_Delays.mcl" "__Lib_LcdConsts.mcl" "__Lib_Lcd.mcl"
0 125 All files Preprocessed in 40 ms
0 121 Compilation Started newlcd test.c
15 300 Syntax Error: ')' expected, but 'Chr' found newlcd test.c
16 369 Specifier needed newlcd test.c
16 300 Syntax Error: ')' expected, but 'char' found newlcd test.c
21 300 Syntax Error: ')' expected, but 'char' found newlcd test.c
24 369 Specifier needed newlcd test.c
24 394 Invalid declarator expected'(' or identifier newlcd test.c
27 369 Specifier needed newlcd test.c
27 300 Syntax Error: ')' expected, but 'char' found newlcd test.c
28 312 Internal error '' newlcd test.c
0 102 Finished (with errors): 04 Jan 2010, 15:36:53 newlcd test.mcppi
 
Last edited:
also one bit of luck my lcd's have turned up just waiting for the pic and unicorn board,a few components and i should be set
 
another question!:d i am rigging something up quick to test the lcd's i am not sure i have a 10k pot handy so if push comes to shove can i connect say a 5k resistor from 5v to pin 3 on the lcd? or do i connect from gnd thru the resistor to pin3(contrast pin)???
 
update.after a mamouth effort from 3v0 and much guidence from him i now have the lcd display working! i will do a proper update and post pics and files soon
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…