[SOLVED] having single error in lcd program

Status
Not open for further replies.

PRABAKARDEVA

Full Member level 2
Joined
Sep 16, 2013
Messages
127
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Location
Chennai
Visit site
Activity points
2,168
Error [876] D:\program\exlcd.c; 4. syntax error when i compile lcd program, m having error like this,couldn't rectify the problem,anyone tell it pls...what is that error?
 

99% you are missing to include a header file into the directory where your *.c file exist.
or better will be to post your code here.
check the folder where you've the project and check whether it has all the header files in it which had been included in program???
 


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include<pic.h>
#include<htc.h>
 
__CONFIG(HS  &  WDTDIS  & LVPDIS  &  UNPROTECT  & PWRTDIS  BORDIS);
 
#define _XTAL_FREQ    16000000
#define RS RE1
#define EN RE2
//#define D0 RD0
//#define D1 RD1
//#define D2 RD2
//#define D3 RD3
//#define D4 RD4
//#define D5 RD5
//#define D6 RD6
//#define D7 RD7
 
void lcd_init(void);
void lcd_command(unsigned int);
void lcd_data(unsigned int);
void lcd_print(unsigned char*);
void main()
{
    lcd_init();
    
 
        
    lcd_print((unsigned char *)"HELLO");
    __delay_ms(1000);
    lcd_print((unsigned char *)"world");
    __delay_ms(1000);
    
    }
    void lcd_print(unsigned char array[])
    {
        unsigned char i;
        for(i=0;array[i]!='\0';i++)
        lcd_data(array[i]);
        }
        
    
    void lcd_init(void)
    {
            PORTD=0;
    TRISD=0;
        TRISE1=0;
        TRISE2=0;
        lcd_command(0x01);
    lcd_command(0X80);
            lcd_command(0X06);
        
        }
        void lcd_command(unsigned int command)
        {
            RS=0;
            PORTD=command;
            EN=1;
            __delay_ms(1000);
            EN=0;
            __delay_ms(1000);
            }
    
    void lcd_data(unsigned int data)
    {
        RS=1;
        PORTD=data;
        EN=1;
        __delay_ms(1000);
        EN=0;
        __delay_ms(1000);
        }





this is my program.....
 
Last edited by a moderator:

have you check about the inclusion of header files in your project directory?
and if your header files contain any other header files then include them also into your project directory.
It seems that some of your declarations are in header files so I can't comment anything about the code without examine the header files.
and the possibility of error is quite less as you're getting error[876]. Better to make a new project and include everything one by one in it.
step by step execution may locate the error location
 

i had written the entire code source file itself.....i didnt write any separate header files....so there is no need to include header files.....
 

I guess maybe the __CONFIG and __delay might be the calls to assembly functions, which might be creating a problem. I might be wrong. Do update me.
 

__config and __delay functions are predefined functions in hi tech compiler ofmplab ide for pic controller.u can see that in manual guide of hi tech compiler for users.
 

Well try this one also: (I am not sure whether it has considered as a error by hi tech compiler or not but give it a try) I haven't use hitech, but this is the basic rule so it may affect here!?

- There are 2 basic forms of include directory :
1) angle brackets: insstructs the preprocessors to search for the
included file using a predefined location. Normally used for
system level header which are common do different projects &
source file.
2) double quote mark: It should be store in a project directory it
self.

So just try using :
#include "pic.h"
#include "htc.h"
 

Try this. See if this Compiles. I think the lcd code is wrong. The initialization is incorrect.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <pic.h>
#include <htc.h>
 
    __CONFIG(HS & WDTDIS & LVPDIS & UNPROTECT & PWRTDIS BORDIS);
 
#define _XTAL_FREQ 16000000
 
#define RS RE1
#define EN RE2
 
 
void lcd_init(void);
void lcd_command(unsigned char);
void lcd_data(unsigned char);
void lcd_print(unsigned char*);
 
void main()
{
    lcd_init();
 
    lcd_print("HELLO");
    __delay_ms(1000);
    lcd_print("world");
    __delay_ms(1000);
    
    while(1){
        
            ;       
    }
}
void lcd_print(unsigned char *myStr)
{
    
    while(*myStr)
        lcd_data(*myStr++);
}
 
 
void lcd_init(void)
{
        
    TRISD = 0x00;
    PORTD = 0x00;
    TRISE1 = 0;
    TRISE2 = 0; 
    
    lcd_command(0x01);
    lcd_command(0X80);
    lcd_command(0X06);
 
}
 
void lcd_command(unsigned char command)
{
    RS = 0;
    PORTD = command;
    EN=1;
    __delay_ms(10);
    EN = 0;
    __delay_ms(10);
 
}
 
void lcd_data(unsigned char data)
{
    RS = 1;
    PORTD = data;
    EN = 1;
    __delay_ms(10);
    EN = 0;
    __delay_ms(10);
}



If it still gives error then replace these


Code C - [expand]
1
2
#define RS RE1
#define EN RE2



with these


Code C - [expand]
1
2
#define RS PORTEbits.RE1
#define EN PORTEbits.RE2

 

Which PIC are you using?

There is a missing & in CONFIG between PWRTDIS and BORDIS


Code C - [expand]
1
__CONFIG(HS & WDTDIS & LVPDIS & UNPROTECT & PWRTDIS BORDIS);

 
Last edited:

the compiler doesn't consider the portebits.re1.it gives the error for this configuration.m using pic 16f877a.
 


Code C - [expand]
1
PORTEbits.RE1



Compiles fine for me. Which version of Compiler are you using?

The CONFIG statement is wrong.

This code compiles fine for PIC16F877A.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <pic.h>
#include <htc.h>
 
    __CONFIG(FOSC_HS & WDTE_OFF & PWRTE_OFF & CP_OFF & BOREN_ON & LVP_OFF & CPD_OFF & DEBUG_OFF);
 
 
#define _XTAL_FREQ 16000000
 
#define RS RE1
#define EN RE2
 
 
void lcd_init(void);
void lcd_command(unsigned char);
void lcd_data(unsigned char);
void lcd_print(unsigned char*);
 
void main()
{
    lcd_init();
 
    lcd_print("HELLO");
    __delay_ms(1000);
    lcd_print("world");
    __delay_ms(1000);
    
    while(1){
        
            ;       
    }
}
 
void lcd_print(unsigned char *myStr)
{
    
    while(*myStr)
        lcd_data(*myStr++);
}
 
 
void lcd_init(void)
{
        
    TRISD = 0x00;
    PORTD = 0x00;
    TRISE1 = 0;
    TRISE2 = 0; 
    
    lcd_command(0x01);
    lcd_command(0X80);
    lcd_command(0X06);
 
}
 
void lcd_command(unsigned char command)
{
    RS = 0;
    PORTD = command;
    EN=1;
    __delay_ms(10);
    EN = 0;
    __delay_ms(10);
 
}
 
void lcd_data(unsigned char data)
{
    RS = 1;
    PORTD = data;
    EN = 1;
    __delay_ms(10);
    EN = 0;
    __delay_ms(10);
}

 

whatever you had said...i changed all those things in my code..it gives a lot of errors which are shown below.



arning [359] D:\program\podd.c; 26.20 illegal conversion between pointer types
pointer to const unsigned char -> pointer to unsigned char
Error [194] D:\program\podd.c; 26.20 ")" expected
Error [195] D:\program\podd.c; 26.20 expression syntax
Warning [359] D:\program\podd.c; 28.20 illegal conversion between pointer types
pointer to const unsigned char -> pointer to unsigned char
Error [194] D:\program\podd.c; 28.20 ")" expected
Error [195] D:\program\podd.c; 28.20 expression syntax
Error [314] D:\program\podd.c; 47.1 ";" expected
Error [254] D:\program\podd.c; 54.1 undefined variable: "command"

- - - Updated - - -

i dont know the version for the compiler..but mplab ide 8.56.
 

Hi Prabakardeva

I tried your code and there is an issue with __CONFIG arguments i.e. the fuses which you want to use.
Please change it something like this

Code:
__CONFIG(WDTE_OFF & PWRTE_ON & BOREN_ON & LVP_OFF & CPD_OFF & CP_OFF & CPD_OFF & DEBUG_OFF);

else you can use like this

Code:
__CONFIG(0x3F3A)

This can be found in the .inc file for your device which is 16F877A, you can see this in the HiTech install directory

I could compile after changing these.

HTML:
Executing: "C:\Program Files (x86)\HI-TECH Software\PICC\9.83\bin\picc.exe" -otest.cof -mtest.map --summary=default --output=default edab.p1 --chip=16F877A -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error   [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s" 
HI-TECH C Compiler for PIC10/12/16 MCUs (Lite Mode)  V9.83
Copyright (C) 2011 Microchip Technology Inc.
(1273) Omniscient Code Generation not available in Lite mode (warning)

Memory Summary:
    Program space        used    DDh (   221) of  2000h words   (  2.7%)
    Data space           used     Eh (    14) of   170h bytes   (  3.8%)
    EEPROM space         used     0h (     0) of   100h bytes   (  0.0%)
    Configuration bits   used     1h (     1) of     1h word    (100.0%)
    ID Location space    used     0h (     0) of     4h bytes   (  0.0%)


Running this compiler in PRO mode, with Omniscient Code Generation enabled,
produces code which is typically 40% smaller than in Lite mode.
See http://microchip.htsoft.com/portal/pic_pro for more information.

Loaded C:\Users\Ananthashayana\Desktop\test.cof.

********** Build successful! **********

- - - Updated - - -

I believe the single error could be because of you not adding your .c file in the MPLAB env in the source file list. It normally returns Error[with some number] no file arguments.
 

This can be found in the .inc file for your device which is 16F877A, you can see this in the HiTech install directory

Actually, a better option when coding in C is to add the device specific header file to your project window, p16f877a.h or pic16f877a.h, which contains all available Configuration Register Flags and typically descriptions of each flag.

The device specific header file also contains available identifiers for registers, bits, etc for the specific device.

I typically add the device specific header file to my projects and reference it while coding.

Also including the following header in neither required nor recommended as the htc.h header file automatically includes all required header files specific to the device:

Code:
#include<pic.h>

Therefore only the following is required for device specific features:

Code:
#include<htc.h>


BigDog
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…