Electronic Circuits and Projects Forum


Problem with Hi tech C and pic18f4550+lcd

1 2 Last »
Results 1 to 10 of 12
Reply to Thread
  1. #1
    cyrus88
    cyrus88 is offline

    Default Problem with Hi tech C and pic18f4550+lcd

    hi guy, i get “can’t generate code for this expression” when compile using hi tech c. it point me to "(char str[5]={0,0,0,0,0}" when i double click the error. this the bug of the compiler or the program problem.

    here is what the code i am trying
    Interfacing LCD Modules with PIC Microcontrollers. | eXtreme Electronics


    btw, anyone have LCD (jhd162a, i think is compatible with HD447800 ) library that using Hi tech c (newbie in pic18, hi tech c is the only compiler i know)....i had try few library file, but none of it work, hope anyone can share with me. rushing my project T.T .

    i am using pic18f4550 + 20MHZ crystal clock.



    appreciate for the help from anyone....thanks.


    LCD.c
    /************************************************** ******************

    16X2 ALPHANEUMERIC LCD INTERFACING LIBRARY FOR PIC 18F MCUS
    -----------------------------------------------------------

    Easy to use library for interfacing 16x2 lcd in 4 bit mode.
    MCU: PIC18FXXXX Series from Microchip.
    Compiler: HI-TECH C Compiler for PIC18 MCUs (http://www.htsoft.com/)

    Copyrights 2008-2009 Avinash Gupta
    eXtreme Electronics, India

    For More Info visit
    http://www.eXtremeElectronics.co.in

    Mail: me@avinashgupta.com

    ************************************************** ******************/

    #include <htc.h>
    #include <string.h>
    #include <ctype.h>
    #include <pic18.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include "lcd.h"


    #define LCD_DATA_LAT LAT(LCD_DATA)
    #define LCD_E_LAT LAT(LCD_E)
    #define LCD_RS_LAT LAT(LCD_RS)
    #define LCD_RW_LAT LAT(LCD_RW)

    #define LCD_DATA_TRIS TRIS(LCD_DATA)
    #define LCD_E_TRIS TRIS(LCD_E)
    #define LCD_RS_TRIS TRIS(LCD_RS)
    #define LCD_RW_TRIS TRIS(LCD_RW)

    #define LCD_DATA_PORT PORT(LCD_DATA)

    #define SET_E() (LCD_E_LAT|=(1<<LCD_E_POS))
    #define SET_RS() (LCD_RS_LAT|=(1<<LCD_RS_POS))
    #define SET_RW() (LCD_RW_LAT|=(1<<LCD_RW_POS))

    #define CLEAR_E() (LCD_E_LAT&=(~(1<<LCD_E_POS)))
    #define CLEAR_RS() (LCD_RS_LAT&=(~(1<<LCD_RS_POS)))
    #define CLEAR_RW() (LCD_RW_LAT&=(~(1<<LCD_RW_POS)))




    void LCDByte(uint8_t c,uint8_t isdata)
    {
    //Sends a byte to the LCD in 4bit mode
    //cmd=0 for data
    //cmd=1 for command


    //NOTE: THIS FUNCTION RETURS ONLY WHEN LCD HAS PROCESSED THE COMMAND

    uint8_t hn,ln; //Nibbles
    uint8_t temp;

    hn=c>>4;
    ln=(c & 0x0F);

    if(isdata==0)
    CLEAR_RS();
    else
    SET_RS();

    __delay_us(0.500); //tAS

    SET_E();

    //Send high nibble

    temp=(LCD_DATA_LAT & 0XF0)|(hn);
    LCD_DATA_LAT=temp;

    __delay_us(1); //tEH

    //Now data lines are stable pull E low for transmission

    CLEAR_E();

    __delay_us(1);

    //Send the lower nibble
    SET_E();

    temp=(LCD_DATA_LAT & 0XF0)|(ln);

    LCD_DATA_LAT=temp;

    __delay_us(1); //tEH

    //SEND

    CLEAR_E();

    __delay_us(1); //tEL

    LCDBusyLoop();
    }

    void LCDBusyLoop()
    {
    //This function waits till lcd is BUSY

    uint8_t busy,status=0x00,temp;

    //Change Port to input type because we are reading data
    LCD_DATA_TRIS|=0x0F;

    //change LCD mode
    SET_RW(); //Read mode
    CLEAR_RS(); //Read status

    //Let the RW/RS lines stabilize

    __delay_us(0.5); //tAS


    do
    {

    SET_E();

    //Wait tDA for data to become available
    __delay_us(0.5);

    status=LCD_DATA_PORT;
    status=status<<4;

    __delay_us(0.5);

    //Pull E low
    CLEAR_E();
    __delay_us(1); //tEL

    SET_E();
    __delay_us(0.5);

    temp=LCD_DATA_PORT;
    temp&=0x0F;

    status=status|temp;

    busy=status & 0b10000000;

    __delay_us(0.5);
    CLEAR_E();
    __delay_us(1); //tEL
    }while(busy);

    CLEAR_RW(); //write mode
    //Change Port to output
    LCD_DATA_TRIS&=0xF0;

    }

    void LCDInit(uint8_t style)
    {
    /************************************************** ***************

    This function Initializes the lcd module
    must be called before calling lcd related functions

    Arguments:
    style = LS_BLINK,LS_ULINE(can be "OR"ed for combination)
    LS_BLINK :The cursor is blinking type
    LS_ULINE :Cursor is "underline" type else "block" type

    ************************************************** ***************/

    //After power on Wait for LCD to Initialize
    __delay_ms(30);

    //Set IO Ports
    LCD_DATA_TRIS&=(0xF0);
    LCD_E_TRIS&=(~(1<<LCD_E_POS));
    LCD_RS_TRIS&=(~(1<<LCD_RS_POS));
    LCD_RW_TRIS&=(~(1<<LCD_RW_POS));

    LCD_DATA_LAT&=0XF0;
    CLEAR_E();
    CLEAR_RW();
    CLEAR_RS();

    //Set 4-bit mode
    __delay_us(0.3); //tAS

    SET_E();
    LCD_DATA_LAT|=(0b00000010); //[B] To transfer 0b00100000 i was using LCD_DATA_PORT|=0b00100000
    __delay_us(1);
    CLEAR_E();
    __delay_us(1);

    //Wait for LCD to execute the Functionset Command
    LCDBusyLoop(); //[B] Forgot this delay

    //Now the LCD is in 4-bit mode

    LCDCmd(0b00001100|style); //Display On
    LCDCmd(0b00101000); //function set 4-bit,2 line 5x7 dot format
    }
    void LCDWriteString(const char *msg)
    {
    /************************************************** ***************

    This function Writes a given string to lcd at the current cursor
    location.

    Arguments:
    msg: a null terminated string to print


    ************************************************** ***************/
    while(*msg!='\0')
    {
    LCDData(*msg);
    msg++;
    }
    }

    void LCDWriteInt(int val,unsigned int field_length)
    {
    /************************************************** *************
    This function writes a integer type value to LCD module

    Arguments:
    1)int val : Value to print

    2)unsigned int field_length :total length of field in which the value is printed
    must be between 1-5 if it is -1 the field length is no of digits in the val

    ************************************************** **************/

    char str[5]; ={0,0,0,0,0};
    int i=4,j=0;
    while(val)
    {
    str[i]=val%10;
    val=val/10;
    i--;
    }
    if(field_length==-1)
    while(str[j]==0) j++;
    else
    j=5-field_length;

    if(val<0) LCDData('-');
    for(i=j;i<5;i++)
    {
    LCDData(48+str[i]);
    }
    }

    void LCDGotoXY(uint8_t x,uint8_t y)
    {
    if(x<40)
    {
    if(y) x|=0b01000000;
    x|=0b10000000;
    LCDCmd(x);
    }
    }


    Last edited by cyrus88; 27th February 2010 at 12:58 AM.

  2. #2
    smanches
    smanches is offline
    Try taking the 5 out of the array so it's open ended. Not sure if that will work, but it does on some compilers.
    You will not understand anything, if you cannot understand yourself.

  3. #3
    Norlin
    Norlin is offline
    Just change that line to:
    char str[5];

    the array gets populated in the while loop 2 lines later

  4. #4
    upand_at_them
    upand_at_them is offline
    The link you posted doesn't have the line you mentioned. Post the entire program code, because C sometimes generates error messages for lines other than the problem line.

  5. #5
    bugtraker
    bugtraker is offline
    Are you accually trying to put brackests () around the definition?
    Code:
    "(char str[5]={0,0,0,0,0};)"
    Should be like this
    Code:
    char str[5]={0,0,0,0,0};

  6. #6
    Norlin
    Norlin is offline
    If you download the code in the link the OP posted you'll see that the array gets populated in a while loop 2 lines later. In the code it does not have the () and it compiles just fine if you change the line to:
    char str[5];

    It the array needs initializing, you can do it in a separate loop, eg:
    Code:
    for (x = 0;x<5;x++)
    {
      str[x] = 0;
    }
    Last edited by Norlin; 26th February 2010 at 09:47 PM.

  7. #7
    cyrus88
    cyrus88 is offline
    Quote Originally Posted by Norlin View Post
    Just change that line to:
    char str[5];

    the array gets populated in the while loop 2 lines later
    cannot, i get error when compile....
    Error [195] C:\Users\YenFeng\Documents\Downloads\PIC18_LCDlib\ PIC18_LCDlib\lcd_test\lcd.c; 240.13 expression syntax
    Error [312] C:\Users\YenFeng\Documents\Downloads\PIC18_LCDlib\ PIC18_LCDlib\lcd_test\lcd.c; 240.24 ";" expected...........................

    Quote Originally Posted by bugtraker View Post
    Are you accually trying to put brackests () around the definition?
    there is no brackets in the program, i put brackets in here to highlight it. sorry for make you guy confuse.

    Quote Originally Posted by upand_at_them View Post
    The link you posted doesn't have the line you mentioned. Post the entire program code, because C sometimes generates error messages for lines other than the problem line.
    the code is in the download file there, i will post all the code here...
    Last edited by cyrus88; 27th February 2010 at 12:57 AM.

  8. #8
    cyrus88
    cyrus88 is offline
    sorry, after change it char str[5], the code now can compile already, but not sure it can work or not, there is only one row of square box show up, nothing else....

    btw anyone can show me how to set the configuration bit correctly? i am using the configuration bit of the USB bootloader.
    i not dare to set the configuration bit, coz it might spoil my USB bootloader..
    Last edited by cyrus88; 27th February 2010 at 01:28 AM.

  9. #9
    cyrus88
    cyrus88 is offline
    i am using USB port of my laptop to power my circuit, this will be the problem?

  10. #10
    Norlin
    Norlin is offline
    you may need to include the code I posted earlier to initialize the values in the array all to "0"
    as for changing configuration bits, what are you looking to change from the program that was provided?
    USB power from your laptop should work just fine.

1 2 Last »
Reply to Thread

Similar Threads

  1. problem regarding pic18f4550
    By simon_12 in Microcontrollers
    Replies: 5
    Latest: 12th September 2009, 11:51 PM
  2. pic18f4550 and lcd
    By neelam29 in Microcontrollers
    Replies: 16
    Latest: 1st March 2009, 10:23 AM
  3. HD44780 lcd and pic18f4550 and hi tech compiler
    By wojtekww123 in Microcontrollers
    Replies: 1
    Latest: 15th October 2008, 06:57 PM
  4. Pic18f4550 ISCP problem.
    By HerbertMunch in Microcontrollers
    Replies: 18
    Latest: 13th February 2008, 12:37 PM
  5. Anyone have a tech sheet for a Phillips LCD ?
    By Nostrafus in General Electronics Chat
    Replies: 7
    Latest: 8th September 2003, 12:34 AM