• AVR Freaks

Hot!PIC16F877A-LCD Loosing data when called with other functions

Author
SanjyotKadu
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2020/02/10 04:24:00
  • Location: 0
  • Status: offline
2020/03/27 09:13:30 (permalink)
0

PIC16F877A-LCD Loosing data when called with other functions

Hi ,
 
I have interfaced pic16f877a with LCD 16X2 interface . I i run the program with to just write on LCD Screen it works fine but if i enable other functions it does not works and LCD Stops responding . 
On development board everything was working fine , now i am doing same setup on breadboard and this problem is coming .
Fun :  ShoCurDatTim(); is used to send the data to LCD
Fun :  void SchDispScr(void) ; is the main function which calls "ShoCurDatTim"
 
below given is the task prepared to run above given functions :
if we do :
 
const TaskTable_t TakTableArr[] =
{
{ShoCurDatTim, 300},
{OneSecTmr , 1000}
};
 
with below given it does not work :
const TaskTable_t TakTableArr[] =
{
{SchDispScr, 20},
{OneSecTmr , 1000}
};
 
my breadboard reset  circuit does not any capacitor connected to it , its just the switch and 10k resistor connected to MCLR pin.
#1

12 Replies Related Threads

    ric
    Super Member
    • Total Posts : 27115
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: PIC16F877A-LCD Loosing data when called with other functions 2020/03/28 18:00:44 (permalink)
    +2 (2)
    Can't fault find with only  a handful of the files.
    Where is your code initialising the TRIS registers? I can only see TRISD being initialised in the lcd.c file.
     
    Also note, the old PIC16F877A is a poor chip to try multitasking on. The Rread-modify-write nature of the PORTx registers makes it awkward to prevent pin changes affecting other pins.
    A newer PIC16F devices with LATx registers would make it much safer.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11828
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: PIC16F877A-LCD Loosing data when called with other functions 2020/03/28 19:35:32 (permalink)
    +3 (3)
    You haven't shown all of your code; how did you decide the problem is in those files?
     
    //Application function is called from Interrupt

     
    That doesn't sound like a good idea.
    #3
    SanjyotKadu
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2020/02/10 04:24:00
    • Location: 0
    • Status: offline
    Re: PIC16F877A-LCD Loosing data when called with other functions 2020/03/28 22:37:52 (permalink)
    0
    Hi All, good afternoon , as the code is bit i though to skip it ,now attaching the entire code here .
     
    and as pic16f877a is very readily available and cheap also , so i decided to use it. Please suggest for any alternatives  i guess the code will again get bigger . Is it good idea to use pic16 ? or should i go for multi tasking OS or pic18 or pic32?
    #4
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11828
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: PIC16F877A-LCD Loosing data when called with other functions 2020/03/28 23:15:27 (permalink)
    +2 (2)
    You don't need "multitasking" for something like this.  Read about state machines.
     
    It appears you're effectively running your entire application in the interrupt handler which is completely backwards from how your code should be structured.  Your timer interrupt should set a flag which your main loop will see and act upon.
    #5
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11828
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: PIC16F877A-LCD Loosing data when called with other functions 2020/03/28 23:21:12 (permalink)
    +1 (1)
     
    Is it good idea to use pic16 ?

     
    There are much better PIC16 parts than the  PIC16F877A.  Even if you stay with that, change your compiler to XC8.
    #6
    ric
    Super Member
    • Total Posts : 27115
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: PIC16F877A-LCD Loosing data when called with other functions 2020/03/28 23:28:59 (permalink)
    +2 (2)
    SanjyotKadu
    Hi All, good afternoon , as the code is bit i though to skip it ,now attaching the entire code here .

    I see you've tried to make your code modular, which means your TRIS setting code is spread all over a number of files and very hard to follow. You seem to set TRISD in multiple places, not just the LCD module.
    That's a very PC way of doing things, I much prefer to do all the initialisation in a single place to make it easy to see conflicts/ommisions.
    Also, doing all of your code inside the interrupt service is a really bad idea in a PIC16 chip.
    You only have a single interrupt service, so all other interrupts are disabled while you are servicing one.
    Well written ISR code should do the minimum possible to clear the interrupt source, and get out again ASAP.
    Slow operations (like writing to an LCD) should be done by non-interrupt code.
     

    and as pic16f877a is very readily available and cheap also , so i decided to use it.

    Where are you?
    The PIC16F1xxx chips are pretty cheap, usually less than the PIC16F877, unles you're buying from a small corner store that only stocks a handful of components.

    Please suggest for any alternatives

    Do you mean alternative chips?
    Again, where are you buying from?

    i guess the code will again get bigger .

    Why do you guess that?
    The newer chips are actually easier to program.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #7
    SanjyotKadu
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2020/02/10 04:24:00
    • Location: 0
    • Status: offline
    Re: PIC16F877A-LCD Loosing data when called with other functions 2020/03/28 23:55:52 (permalink)
    0
    "doing all of your code inside the interrupt service is a really bad idea in a PIC16 chip" 
    --> as suggested , i will modify it to just update a flag and main to handle the function using this flag  and will keep interrupts routine minimal.
     
    Right now i am in INDIA, Bangalore and  Yes i picked it up from store nearby to me. the alternative to this was "PIC16F18877", to order one chip everything will come from different country, and in this learning phase i just wanted to use local chips.
     
    alternative to chips (controllers)
     
    so, For sure there is problem with LCD Timings , and according to suggestions , because it is not structured good this problem is coming ?  Should  LCD Task be normal routine ? just function and should not be called periodically  ? (right now i am calling complete app after every 300 mili sec.)? I though of keeping LCD as separate task which will be called after every 100 mili sec and if anyone wants to write on LCD he should give the data to this task . But i am not liking this approach as it will increase the code, may be i am lazy but is this not fine that , i call LCDWrire () function and data should appear on LCD rather than , creating separate task for LCD and then make a pipe/global variable send data to that task and then data will appear on LCD?   
    or what are suggestion to handle it ?
     
    in future i want to add , some GSM modem interface some more relays some code to handle analog devices like temperature and humidity control and more stuffs. objective is to enhance myself in embedded world . so code may increase.  
     
    and thank you for your valuable suggestions .
    post edited by SanjyotKadu - 2020/03/29 00:02:02
    #8
    SanjyotKadu
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2020/02/10 04:24:00
    • Location: 0
    • Status: offline
    Re: PIC16F877A-LCD Loosing data when called with other functions 2020/03/29 00:03:42 (permalink)
    0
    my compiler is XC8 and i am using MPLAB X V5.1
    #9
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11828
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: PIC16F877A-LCD Loosing data when called with other functions 2020/03/29 00:57:48 (permalink)
    +1 (1)
    When you get your timer interrupt flag, do whatever needs to be done periodically.  When you get a button press, act on that.  Think in terms of responding to events, not "tasks".
    #10
    SanjyotKadu
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2020/02/10 04:24:00
    • Location: 0
    • Status: offline
    Re: PIC16F877A-LCD Loosing data when called with other functions 2020/03/30 03:52:12 (permalink)
    0
    i have updated interrupt function with flag in it and taking out application . but still LCD Behaving in same way . any more suggestions ?
    #11
    ric
    Super Member
    • Total Posts : 27115
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: PIC16F877A-LCD Loosing data when called with other functions 2020/03/30 04:17:07 (permalink)
    +1 (1)
    Please show what your code looks like now.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #12
    SanjyotKadu
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2020/02/10 04:24:00
    • Location: 0
    • Status: offline
    Re: PIC16F877A-LCD Loosing data when called with other functions 2020/03/30 21:32:58 (permalink)
    0
    Please find modified code as an attachment , change is in "main.c" and in "Timer_1_Configuration.c",
    i tested this code on development board and again the LCD Works fine but on breadboard circuit it is not working .
    so if it works on Development board then code should be fine , (that's what i am thinking)
     
    On breadboard i have created power supply using LM 78051 (With capacitor 470 micro F and 1 micro f ) this circuit converts voltage from 12 to 5 , and its giving 5 volts correctly ,checked with multi meter .
     
    in the development board the capacitors used for 20 Mz crystal is 33 pf  and i am using 22pf , will this make difference in timings ?
     
    other than crystal and Power supply i have reset circuit on breadboard .
     
    or can there be situation of noise ??
     
     
     
    #13
    Jump to:
    © 2020 APG vNext Commercial Version 4.5