Hot!Need assistance with pic18f4520 programming to display voltages and ampere using 16x4 LCD

Page: 12 > Showing page 1 of 2
Author
toomer
New Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2018/11/17 00:50:12
  • Location: 0
  • Status: offline
2018/11/20 06:39:13 (permalink)
0

Need assistance with pic18f4520 programming to display voltages and ampere using 16x4 LCD

Hi everyone i am a student who is currently learning about pic18f4520 programming and i have encountered problems with 16x4 LCD programming to display voltages values, current values and a heading text and the voltages and current reading needs to constantly update when there is a change in value. i tried googling but the information about this pic is not much so i used what i have researched and written a coding on my own but it is not displaying anything and quite a few errors so i hope that u guys can help me with it and if you guys spot any error in my schematic please tell me thanks. I have attached the schematic, coding and error of my program and the LCD should display in this format:
Solar Panel
(spacing)
Voltages: y V
Current: x mA
*y and x denotes the value* 
 
 
 
 
post edited by toomer - 2018/11/27 06:26:51

Attached Image(s)

#1

35 Replies Related Threads

    1and0
    Access is Denied
    • Total Posts : 8525
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Need assistance with pic18f4520 programming to display voltages and ampere using 16x4 2018/11/20 06:55:58 (permalink)
    +1 (1)
    Your lcddata() function accepts only an unsigned char, certainly not a string with format specifier and neither two arguments.
    post edited by 1and0 - 2018/11/20 06:57:06
    #2
    pcbbc
    Super Member
    • Total Posts : 509
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: Need assistance with pic18f4520 programming to display voltages and ampere using 16x4 2018/11/20 07:18:03 (permalink)
    +1 (1)
    With any programming assignment, especially so on a new platform that you are unfamiliar with, do not try to write the whole program in one go.
    Start with writing a simple "Hello World!" to the LCD.  The other stuff (such a formatting strings to include voltage and current) can come later.
    This is especially true in an embedded environment where debugging is not always the easiest.
     
    Start by coding a routine void lcdwritestr (unsigned char* str); function, for writing just a string:
    lcdwritestr("Hello World");

    This will need to call lcddata (and also possibly lcdcmd) internally to perform the write a single character at a time until the null string terminator is reached.
     
    Also, please learn how to use the correct code tags...
    [ code ] lcdwritestr("Hello World"); [ /code ]
    ...in your posts so your code is correctly formatted.
    #3
    1and0
    Access is Denied
    • Total Posts : 8525
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Need assistance with pic18f4520 programming to display voltages and ampere using 16x4 2018/11/20 07:30:46 (permalink)
    +1 (1)
    Your comment says LCD uses 4 lines, which I assumed data lines, but your lcdcmd() and lcddata() toggle E only once. I'd suggest getting the LCD routines work first displaying a single character at different positions first.
    #4
    jack@kksound
    code tags!
    • Total Posts : 2892
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: Need assistance with pic18f4520 programming to display voltages and ampere using 16x4 2018/11/20 12:48:26 (permalink)
    +1 (1)
    Also always write to LATx registers NOT PORTx registers, use the PORTx for reading. See RMW issues for why.
    example:
    PORTAbits.RA1 = 1;
    should be:;
    LATAbits.RA1 = 1;
     
    etc.
    #5
    dan1138
    Super Member
    • Total Posts : 2894
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: Need assistance with pic18f4520 programming to display voltages and ampere using 16x4 2018/11/20 20:09:52 (permalink)
    +2 (2)
    toomer
    Hi everyone I am a student who is currently learning about pic18f4520 programming and I have encountered problems with 16x4 LCD programming to display voltages values, current values and a heading text and the voltages and current reading needs to constantly update when there is a change in value. I tried googling but the information about this PIC is not much so I used what I have researched and written a coding on my own but it is not displaying anything and quite a few errors so I hope that u guys can help me with it and if you guys spot any error in my schematic please tell me thanks. I have attached the schematic, coding and error of my program.


    This is your first post so welcome to the forum.

    The good new is that so far you have done well by posting your code and schematic.

    The bad news is that you seem out of your depth regarding embedded circuit and code design.

    The PIC18F4520 in an 8-bit micro-controller, XC8 is a C compiler, MPLABX is just a development environment. It does not have much in the way of a code generator or integrated library functions for reading analog inputs or sending formatted strings of data to an LCD module.

    When you do not use a C code generation tool then you will have to create these functions.

    The posted code makes a fair stab as sending a byte to the LCD module. But it is not adequate for sending formatted data like a printf() function.

    Your functions for reading analog data show no comprehension of how to use the PIC Analog to Digital Conversion function block or on how a C function returns a value.

    The PIC18F4520 will require that you create a lot of "building blocks" of code before you can start to implement your application.

    There are examples of code for dealing with the ADC and LCD but I doubt you can find any example that integrates the things you seem to need explained. Your problem is that an Internet search finds a lot of crap code on these topics. To know good code from bad code it takes the experience you haven't got yet.

    To sum up your code it is flawed in design and implementation.

    Your schematic fails due to the same shortage of experience.

    The LCD connections look likely to work with the Proteus simulation. The Hall effect current sensor requires an external operational amplifier to expand the output voltage of the ACS712 to work with the PIC Analog to Digital Converter.
    post edited by dan1138 - 2018/11/20 20:31:45
    #6
    toomer
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2018/11/17 00:50:12
    • Location: 0
    • Status: offline
    Re: Need assistance with pic18f4520 programming to display voltages and ampere using 16x4 2018/11/20 23:59:55 (permalink)
    0
    hmm i see thanks for all your replies. if i may ask, how do i code in such a way that the LCD display the voltage and current values required and do i use while(1) so that the values displayed at the LCD consistently updates when there is a change in values?
    post edited by toomer - 2018/11/21 00:09:51
    #7
    qhb
    Superb Member
    • Total Posts : 7869
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: online
    Re: Need assistance with pic18f4520 programming to display voltages and ampere using 16x4 2018/11/21 00:34:07 (permalink)
    +1 (1)
    You're still trying to run before you can walk.
    First you need to be able to flash one LED slowly.
    Then display a simple message on the LCD like "Hello World"
    #8
    toomer
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2018/11/17 00:50:12
    • Location: 0
    • Status: offline
    Re: Need assistance with pic18f4520 programming to display voltages and ampere using 16x4 2018/11/21 03:18:44 (permalink)
    0
    okay i will try to display the message first but idk whether am i able to code the message as currently my understanding on coding LCD is not much and thanks 
    #9
    pcbbc
    Super Member
    • Total Posts : 509
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: Need assistance with pic18f4520 programming to display voltages and ampere using 16x4 2018/11/21 03:38:06 (permalink)
    +1 (1)
    toomerOkay, I will try to display the message first but IDK whether am I able to code the message as currently my understanding on coding LCD is not much
    Well, here's a spec sheet for the LM041L display I think you are using.  Ask questions about the parts you don't understand.
    #10
    toomer
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2018/11/17 00:50:12
    • Location: 0
    • Status: offline
    Re: Need assistance with pic18f4520 programming to display voltages and ampere using 16x4 2018/11/21 05:00:02 (permalink)
    0
     As of now i am able to run the code for the text without error however i am unable to display the message
    #11
    pcbbc
    Super Member
    • Total Posts : 509
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: Need assistance with pic18f4520 programming to display voltages and ampere using 16x4 2018/11/21 05:39:12 (permalink)
    +1 (1)
    toomerAs of now I am able to run the code for the text without error. However I am unable to display the message.
    Post your modified code.  We're not psychic. wink: wink


    #12
    toomer
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2018/11/17 00:50:12
    • Location: 0
    • Status: offline
    Re: Need assistance with pic18f4520 programming to display voltages and ampere using 16x4 2018/11/21 06:32:22 (permalink)
    0
    #include <xc.h>

    #include <stdio.h>
    #pragma config OSC=HS
    #pragma config PWRT = OFF
    #pragma config WDT =OFF
    #pragma config DEBUG = OFF, LVP = OFF

    void lcdcmd(unsigned char value);
    void msdelay ();
    void lcddata(unsigned char value);
    void lcdwritestr (const char* str);

    void main(void)
    {
    TRISD =0x00;
    PORTD =0x00;
    ADCON1 =0x0F;
    TRISE = 0x00;
    PORTE = 0x00;
    msdelay();
    lcdcmd(0x0C); // Display On and Cursor Off
    lcdcmd(0x01); // Clear display screen
    lcdcmd(0x06); // Increment cursor
    lcdcmd(0x80); // Set cursor position to 1st line, 1st column
    lcdcmd (0xC0); // Set cursor position to 2nd line, 1st column
    lcdcmd (0x90); // Set cursor position to 3rd line, 1st column
    lcdcmd (0xD0); // Set cursor position to 4th line, 1st column
    msdelay ();
    }
    void lcdwritestr (const char* str)
    {

    lcdwritestr ("Hello World");
    }
    void lcdcmd(unsigned char value)
    {
    PORTD =value;
    PORTEbits.RE0 =0;//rs
    PORTEbits.RE1 =0;//rw
    PORTEbits.RE2=1;//en
    msdelay ();
    PORTEbits.RE2=0;//en
    }

    void lcddata (unsigned char value)
    {
    PORTD =value;
    PORTEbits.RE0 =1; //rs
    PORTEbits.RE1 =0; //rw
    PORTEbits.RE2=1; //en
    msdelay();
    PORTEbits.RE2=0; // en
    }
    void msdelay ()
    {
    int i;
    for (i=0; i < 1000; i++)
    _delay (1000);
    }

    post edited by toomer - 2018/11/21 06:37:42
    #13
    toomer
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2018/11/17 00:50:12
    • Location: 0
    • Status: offline
    Re: Need assistance with pic18f4520 programming to display voltages and ampere using 16x4 2018/11/21 06:40:18 (permalink)
    0
    please advise thanks
    #14
    MBedder
    Circuit breaker
    • Total Posts : 6553
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    Re: Need assistance with pic18f4520 programming to display voltages and ampere using 16x4 2018/11/21 06:48:11 (permalink)
    +1 (1)
    Haven't you been told how to handle individual port bits? (hint: message #5)
    #15
    toomer
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2018/11/17 00:50:12
    • Location: 0
    • Status: offline
    Re: Need assistance with pic18f4520 programming to display voltages and ampere using 16x4 2018/11/21 06:51:00 (permalink)
    0
    hmm sorry might have overlooked  i will try again and update in abit
    #16
    toomer
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2018/11/17 00:50:12
    • Location: 0
    • Status: offline
    Re: Need assistance with pic18f4520 programming to display voltages and ampere using 16x4 2018/11/21 06:57:10 (permalink)
    0
    i just change PORTx to LATx but i am receiving this kind of error

    Attached Image(s)

    #17
    MBedder
    Circuit breaker
    • Total Posts : 6553
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    Re: Need assistance with pic18f4520 programming to display voltages and ampere using 16x4 2018/11/21 07:06:14 (permalink)
    +1 (1)
    I just have noticed that message #5 has a severe error - instead of LATAbits.RAx John should have written LATAbits.LATAx.
    #18
    toomer
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2018/11/17 00:50:12
    • Location: 0
    • Status: offline
    Re: Need assistance with pic18f4520 programming to display voltages and ampere using 16x4 2018/11/21 07:17:56 (permalink)
    0
    after i changed to LATXbits.LATX my lcd still does not display any text
    #include <xc.h>
    #include <stdio.h>
    #pragma config OSC=HS
    #pragma config PWRT = OFF
    #pragma config WDT =OFF
    #pragma config DEBUG = OFF, LVP = OFF

    void lcdcmd(unsigned char value);
    void msdelay ();
    void lcddata(unsigned char value);
    void lcdwritestr (const char* str);

    void main(void)
    {
    TRISD =0x00;
    PORTD =0x00;
    ADCON1 =0x0F;
    TRISE = 0x00;
    PORTE = 0x00;
    msdelay();
    lcdcmd(0x0C); // Display On and Cursor Off
    lcdcmd(0x01); // Clear display screen
    lcdcmd(0x06); // Increment cursor
    lcdcmd(0x80); // Set cursor position to 1st line, 1st column
    lcdcmd (0xC0); // Set cursor position to 2nd line, 1st column
    lcdcmd (0x90); // Set cursor position to 3rd line, 1st column
    lcdcmd (0xD0); // Set cursor position to 4th line, 1st column
    msdelay ();
    }
    void lcdwritestr (const char* str)
    {

    lcdwritestr ("Hello World");
    }
    void lcdcmd(unsigned char value)
    {
    PORTD =value;
    LATEbits.LATE0 =0;//rs
    LATEbits.LATE1 =0;//rw
    LATEbits.LATE2=1;//en
    msdelay ();
    LATEbits.LATE2=0;//en
    }

    void lcddata (unsigned char value)
    {
    PORTD =value;
    LATEbits.LATE0 =1; //rs
    LATEbits.LATE1 =0; //rw
    LATEbits.LATE2=1; //en
    msdelay();
    LATEbits.LATE2=0; // en
    }
    void msdelay ()
    {
    int i;
    for (i=0; i < 1000; i++)
    _delay (1000);
    }

    post edited by toomer - 2018/11/21 07:19:34
    #19
    pcbbc
    Super Member
    • Total Posts : 509
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: Need assistance with pic18f4520 programming to display voltages and ampere using 16x4 2018/11/21 07:26:38 (permalink)
    0
    Post your new code or we are guessing what is now on lines 42, 48, 49, 50 and 52.
     
    Edit: I see you have done that.
     
    1. Function lcdwritestr is not being called from main.
    2. Implementation of lcdwritestr just calls itself recursively.  This is nonsense.
    main needs to have this line in it:
    lcdwritestr ("Hello World");

    And inside the implementation of lcdwritestr you need a while loop to process the characters in const char* str and call function lcddata (probably) with each until you reach the null terminator.
    post edited by pcbbc - 2018/11/21 07:34:01
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2018 APG vNext Commercial Version 4.5