stack overflow/20x4LCD error

Discussion in 'Embedded Systems and Microcontrollers' started by harsha3842, Jul 13, 2013.

  1. harsha3842

    Thread Starter New Member

    Jul 5, 2013
    24
    0
    using pic18f4520 and mplab c18 compiler for the below program
    1) the program stops working within a minute(stack overflow?)
    2) the first character of last line in 20x4 lcd keeps blinking
    3) code works in 16x2 lcd but on a 20x4 lcd displays output of its choice and cannot be controlled
    initialization of lcd and adc is fine
    pls help me out,point out the error

    Code ( (Unknown Language)):
    1.  
    2. #include <p18f4520.h>
    3. #include <adc.h>
    4. #include <stdlib.h>
    5. #include <delays.h>
    6. #include <stdio.h>
    7.  
    8. #define    lcdport    LATB
    9. #define    E        LATDbits.LATD7
    10. #define    RS        LATDbits.LATD6
    11. #define    p_bar    PORTAbits.RA1
    12. #define    wh_l    PORTCbits.RC0
    13. #define    wh_ul    PORTCbits.RC1
    14. #define    sph_l    PORTCbits.RC2
    15. #define    sph_ul    PORTCbits.RC3
    16. #define    sp_on    PORTDbits.RD0
    17. #define    sp_off    PORTDbits.RD1
    18. #define    _XTAL_FREQ 20000000
    19.  
    20. #pragma config WDT=OFF,LVP=OFF,STVREN=OFF,MCLRE=OFF
    21.  
    22. unsigned int adc_out=0;
    23. int reg1,reg2,reg3;
    24. float adc_rpm;
    25.  
    26. unsigned char convolt[5];
    27. unsigned char anim[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
    28. unsigned char anim0[8]={0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19};
    29. unsigned char anim1[8]={0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E};
    30. unsigned char anim2[8]={0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F};
    31. unsigned char anim3[8]={0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F};
    32. unsigned char anim4[8]={0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13};
    33.  
    34. void lcdbuild(unsigned char,unsigned char *);
    35. void lcdmsg(const rom char *);
    36. void lcdstr(unsigned char *);
    37. void lcdcomm(unsigned char);
    38. void lcddata(unsigned char);
    39. void lcdout(unsigned char);
    40. void dispchar(void);
    41. void animate(void);
    42. void animate1(void);
    43. void animate2(void);
    44. void animate3(void);
    45. void animate4(void);
    46. void lcdinit(void);
    47. void clear(void);
    48. void blank(void);
    49. void blink(void);
    50. void blink_1(void);
    51. void blink_2(void);
    52. void blink_3(void);
    53. void loop(void);
    54. void ucall(void);
    55. void pcall(void);
    56. void scall(void);
    57. void adc(void);
    58. void pressure(void);
    59. void workhead(void);
    60. void sphere(void);
    61. void spindle(void);
    62.  
    63. void main (void)
    64. {
    65.     TRISA = 0x0F;
    66.     TRISB = 0x00;
    67.     TRISC = 0xFF;
    68.     TRISD = 0x0F;
    69.     lcdinit();
    70.     dispchar();
    71.     animate();
    72.     lcdcomm(0x86);
    73.     lcdmsg("MAXPRECI");
    74.     animate1();
    75.     animate2();
    76.     animate3();
    77.     animate4();
    78.     animate3();
    79.     animate2();
    80.     animate1();
    81.     animate();
    82.     Delay10KTCYx(1000);
    83.     Delay10KTCYx(1000);
    84.     lcdcomm(0xCD);
    85.     lcdmsg("RPM:");
    86.     lcdcomm(0x94);
    87.     lcdmsg("WH:");
    88.     lcdcomm(0x9E);
    89.     lcdmsg("SPH:");
    90.     OpenADC(ADC_FOSC_32 &
    91.             ADC_RIGHT_JUST &
    92.             ADC_4_TAD,ADC_CH0 &
    93.             ADC_INT_OFF &
    94.             ADC_VREFPLUS_VDD &
    95.             ADC_VREFMINUS_VSS, 7);
    96.     while(1)
    97.     {
    98.         loop();
    99.     }
    100.     CloseADC();
    101. }
    102.  
    103. void loop(void)
    104. {
    105.     adc();
    106. //    pressure();
    107.     if(wh_l==1 | wh_ul==1)
    108.     workhead();
    109.     else if(sph_l==1 | sph_ul==1)
    110.     sphere();
    111.     else if(sp_on==1 | sp_off==1)
    112.     spindle();
    113. }
    114.  
    115. void pressure(void)
    116. {
    117.     if(p_bar==1)
    118.     {
    119.         reg3=0;
    120.         clear();
    121.         lcdcomm(0xC0);
    122.         lcdmsg("Pressure OK");
    123.     }
    124.     if(p_bar==0)
    125.     {
    126.         reg3=1;
    127.         blank();
    128.         lcdcomm(0xD4);
    129.         lcdmsg("Pressure Below 6BAR");
    130.         pcall();
    131.     }
    132. }
    133.  
    134. void workhead(void)
    135. {
    136.     if(wh_l==1)
    137.     {
    138.         reg1=0;
    139.         lcdcomm(0x97);
    140.         lcdmsg("Lock");
    141.     }
    142.     if(wh_ul==1)
    143.     {
    144.         reg1=1;
    145.         ucall();
    146.     }
    147. }
    148.  
    149. void sphere(void)
    150. {
    151.     if(sph_l==1)
    152.     {
    153.         reg2=0;
    154.         lcdcomm(0xA2);
    155.         lcdmsg("Lock");
    156.     }
    157.     if(sph_ul==1)
    158.     {
    159.         reg2=1;
    160.         ucall();
    161.     }
    162. }
    163.  
    164. void spindle(void)
    165. {
    166.     if(sp_on==1)
    167.     {
    168.         scall();
    169.     }
    170.     if(sp_off==1)
    171.     {
    172.         blank();
    173.         lcdcomm(0xD4);
    174.         lcdmsg("Spindle:OFF");
    175.     }
    176. }
    177.  
    178. void ucall(void)
    179. {
    180.     while(reg1==1 & reg2!=1)
    181.     {
    182.         lcdcomm(0x97);
    183.         lcdmsg("UnLock");
    184.         blink_1();
    185.         loop();
    186.     }
    187.     while(reg2==1 & reg1!=1)
    188.     {
    189.         lcdcomm(0xA2);
    190.         lcdmsg("UnLock");
    191.         blink_2();
    192.         loop();
    193.     }
    194.     while(reg1==1 & reg2==1)
    195.     {
    196.         lcdcomm(0x97);
    197.         lcdmsg("UnLock");
    198.         lcdcomm(0xA2);
    199.         lcdmsg("UnLock");
    200.         blink_3();
    201.         loop();
    202.     }
    203. }
    204.  
    205. void pcall(void)
    206. {
    207.     while(reg3==1)
    208.     {
    209.         lcdcomm(0xC0);
    210.         lcdmsg("Low Pressure");
    211.         blink();
    212.         pressure();
    213.     }
    214. }
    215.  
    216. void scall(void)
    217. {
    218.     if(reg1==0 & reg2==0)
    219.     {
    220.         blank();
    221.         lcdcomm(0xD4);
    222.         lcdmsg("Spindle:ON");
    223.     }
    224.     if(reg1==1 | reg2==1)
    225.     {
    226.         blank();
    227.         lcdcomm(0xD4);
    228.         lcdmsg("Error WH/SPH UnLock");
    229.     }
    230. }
    231.  
    232. void adc(void)
    233. {
    234.     SetChanADC (ADC_CH0);
    235.     Delay10KTCYx(10);
    236.     lcdcomm(0xD1);
    237.     lcdmsg("    ");
    238.     ConvertADC();
    239.     while(BusyADC());
    240.     adc_out=ReadADC();
    241.     adc_rpm=(adc_out*500.0)/1024;
    242.     itoa(adc_rpm,convolt);
    243.     lcdcomm(0xD1);
    244.     lcdstr(convolt);
    245.     Delay10KTCYx(1000);
    246. }
    247.  
    248. void dispchar(void)
    249. {
    250.     lcdbuild(0,anim);
    251.     lcdbuild(1,anim1);
    252.     lcdbuild(2,anim2);
    253.     lcdbuild(3,anim3);
    254.     lcdbuild(4,anim4);
    255.     lcdbuild(5,anim0);
    256. }
    257.  
    258. void lcdbuild(unsigned char location, unsigned char *ptr)
    259. {
    260.     unsigned char i;
    261.     if(location<8)
    262.     {
    263.         lcdcomm(0x40+(location*8));
    264.         for(i=0;i<8;i++)
    265.         {
    266.             lcddata(ptr[i]);
    267.         }
    268.     }
    269. }
    270.  
    271. void lcdmsg(const rom char *Message)
    272. {
    273.     const rom char *Pos = Message;
    274.     while(*Pos!=0)
    275.         lcddata(*Pos++);
    276. }
    277.  
    278. void lcdstr(unsigned char *str)
    279. {
    280.     int i=0;
    281.     while(str[i]!='\0')
    282.     {
    283.         lcddata(str[i]);
    284.         i++;
    285.     }
    286. }
    287.  
    288. void lcdcomm(unsigned char i)
    289. {
    290.     RS =0;
    291.     lcdout(i);
    292.     Delay1KTCYx(2);
    293. }
    294.  
    295. void lcddata(unsigned char i)
    296. {
    297.     RS =1;
    298.     lcdout(i);
    299.     Delay1KTCYx(2);
    300. }
    301.  
    302. void lcdout(unsigned char dat)
    303. {
    304.     lcdport = dat;
    305.     E = 1;
    306.     Delay1TCY();
    307.     E = 0;
    308. }
    309.  
    310. void lcdinit(void)
    311. {
    312.     lcdport=0x00;
    313.     Delay1KTCYx(40);
    314.     lcdout(0x30);
    315.     Delay1KTCYx(15);
    316.     lcdout(0x20);
    317.     Delay1KTCYx(15);
    318.     lcdcomm(0x38);
    319.     lcdcomm(0x0C);
    320.     lcdcomm(0x01);
    321.     lcdcomm(0x06);
    322.     lcdcomm(0x80);
    323. }
    324.  
    325. void blank(void)
    326. {
    327.     lcdcomm(0xD4);
    328.     lcdmsg("                    ");
    329. }
    330.  
    331. void clear(void)
    332. {
    333.     lcdcomm(0xC0);
    334.     lcdmsg("            ");
    335. }
    336.  
    337. void blink(void)
    338. {
    339.     Delay10KTCYx(200);
    340.     lcdcomm(0xC0);
    341.     lcdmsg("            ");
    342.     Delay10KTCYx(100);
    343. }
    344.  
    345. void blink_1(void)
    346. {
    347.     Delay10KTCYx(200);
    348.     lcdcomm(0x97);
    349.     lcdmsg("      ");
    350.     Delay10KTCYx(100);
    351. }
    352.  
    353. void blink_2(void)
    354. {
    355.     Delay10KTCYx(200);
    356.     lcdcomm(0xA8);
    357.     lcdmsg("      ");
    358.     Delay10KTCYx(100);
    359. }
    360.  
    361. void blink_3(void)
    362. {
    363.     Delay10KTCYx(200);
    364.     lcdcomm(0x97);
    365.     lcdmsg("      ");
    366.     lcdcomm(0xA8);
    367.     lcdmsg("      ");
    368.     Delay10KTCYx(100);
    369. }
    370.  
    371. void animate(void)
    372. {
    373.     lcdcomm(0x80);
    374.     lcdmsg("  ");
    375.     lcdcomm(0x82);
    376.     lcddata(3);
    377.     lcdcomm(0x83);
    378.     lcddata(2);
    379.     lcdcomm(0x84);
    380.     lcddata(1);
    381.     lcdcomm(0x85);
    382.     lcddata(5);
    383.     lcdcomm(0x8E);
    384.     lcddata(4);
    385.     lcdcomm(0x8F);
    386.     lcddata(1);
    387.     lcdcomm(0x90);
    388.     lcddata(2);
    389.     lcdcomm(0x91);
    390.     lcddata(3);
    391.     lcdcomm(0x92);
    392.     lcdmsg("  ");
    393.     Delay10KTCYx(100);
    394. }
    395.  
    396. void animate1(void)
    397. {
    398.     lcdcomm(0x80);
    399.     lcdmsg("   ");
    400.     lcdcomm(0x83);
    401.     lcddata(2);
    402.     lcdcomm(0x84);
    403.     lcddata(1);
    404.     lcdcomm(0x85);
    405.     lcddata(5);
    406.     lcdcomm(0x8E);
    407.     lcddata(4);
    408.     lcdcomm(0x8F);
    409.     lcddata(1);
    410.     lcdcomm(0x90);
    411.     lcddata(2);
    412.     lcdcomm(0x91);
    413.     lcdmsg("   ");
    414.     Delay10KTCYx(100);
    415. }
    416.  
    417. void animate2(void)
    418. {
    419.     lcdcomm(0x80);
    420.     lcdmsg("    ");
    421.     lcdcomm(0x84);
    422.     lcddata(1);
    423.     lcdcomm(0x85);
    424.     lcddata(5);
    425.     lcdcomm(0x8E);
    426.     lcddata(4);
    427.     lcdcomm(0x8F);
    428.     lcddata(1);
    429.     lcdcomm(0x90);
    430.     lcdmsg("    ");
    431.     Delay10KTCYx(100);
    432. }
    433.  
    434. void animate3(void)
    435. {
    436.     lcdcomm(0x80);
    437.     lcdmsg("     ");
    438.     lcdcomm(0x85);
    439.     lcddata(5);
    440.     lcdcomm(0x8E);
    441.     lcddata(4);
    442.     lcdcomm(0x8F);
    443.     lcdmsg("     ");
    444.     Delay10KTCYx(100);
    445. }
    446.  
    447. void animate4(void)
    448. {
    449.     lcdcomm(0x80);
    450.     lcdmsg("      ");
    451.     lcdcomm(0x8E);
    452.     lcdmsg("      ");
    453.     Delay10KTCYx(100);
    454. }
    455. [/i][/i][/i]
     
    Last edited by a moderator: Jul 13, 2013
  2. WBahn

    Moderator

    Mar 31, 2012
    17,716
    4,788
    You're kidding, right?

    You expect strangers to wade through your code and find your problem for you when it is pretty evident you have made very little effort to even narrow down the problem yourself?
     
  3. absf

    Senior Member

    Dec 29, 2010
    1,492
    371
    Your code is for 18F4520 but your schematics mcu used 16f877. Which one is correct? Your code or your circuit?

    How did you connect your 20x4 LCD?

    Allen
     
    Last edited: Jul 13, 2013
  4. harsha3842

    Thread Starter New Member

    Jul 5, 2013
    24
    0
    the wiring is identical to pic16f..
    lcd databus is port b
    rs and e is rd6 and rd7
    r/w is gnd

    im trying to figure out since 2 days but unable to find out the error
    if its stack overflow error how to get over it?
     
  5. WBahn

    Moderator

    Mar 31, 2012
    17,716
    4,788
    HOW have you been trying to figure it out and what have you discovered?

    Think about it. If I posted a nearly five hundred lines of uncommented, unformatted code and told you that it wasn't working properly, would you be willing to wade through it and find the problem? Would you be willing to even attempt it?
     
  6. MrChips

    Moderator

    Oct 2, 2009
    12,421
    3,357
    Your problem is calling loop( ) from ucall( ).
     
    harsha3842 likes this.
  7. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Or something else. If it stops at the same time I would look software. If the time is random I would look hardware.

    Is that where the cursor is?

    These devices work similarly but have different addresses for where the lines of characters are stored. The address don't run in the order you would expect, so flowing from on line may put you at a line above that. READ THE DATA SHEET FOR YOUR DEVICE.

    Based upon what evidence?




    I see it !! After carefully reading your schematic I discovered you did not connect the LCD to the PIC.

    Next time, two words: CODE TAGS !!!
     
    harsha3842 likes this.
  8. harsha3842

    Thread Starter New Member

    Jul 5, 2013
    24
    0
    Hi im new to this forum and dono much about exactly wat details to be given while asking a doubt..
    i find u not encouraging enough to help me out in solving my prob..
    so pls let others who are trying to help me out instead of giving such ideas even to them..
    thanx
     
  9. harsha3842

    Thread Starter New Member

    Jul 5, 2013
    24
    0
    1) it stops at the same time..(the prob was found to be stack overflow)
    stvren in config just doubles the time but doesn't stop it completely
    2) i've switched off the cursor blinking using 0x0c as the command instead of 0x0E or 0x0F
    3) i've studied the data sheet and pretty much ok with the display
    lines start from 0x80,0xc0,0xd4 and 0x94
    4) evidence is that it works as expected unless the program stops and doesn't show black boxes or junk value
    the circuit diagram is just the pic part which is implemented on a pcb
    lcd wiring is done manually,port b to databus e & rs to rd6 and rd7...
    no issues with this thoug..
    im new to this coding and form so got no idea about code tags..
     
  10. MrChips

    Moderator

    Oct 2, 2009
    12,421
    3,357
    I gave you the problem.
     
    harsha3842 likes this.
  11. WBahn

    Moderator

    Mar 31, 2012
    17,716
    4,788
    As you wish. Somewhat of a shame, since after you added the code tags to make your code more readable I was able to spot what is almost certainly the cause of your stack overflows in less than a minute of looking through your code.

    But since I am not encouraging enough for you, I will do as you ask and let others help you out instead.
     
  12. harsha3842

    Thread Starter New Member

    Jul 5, 2013
    24
    0
    changed the code as below still the prob persists
    used switch cases

    #include <p18f4520.h>
    #include <adc.h>
    #include <stdlib.h>
    #include <delays.h>
    #include <stdio.h>

    #define lcdport LATB
    #define E LATDbits.LATD7
    #define RS LATDbits.LATD6
    #define wh_l PORTCbits.RC0
    #define wh_ul PORTCbits.RC1
    #define sph_l PORTCbits.RC2
    #define sph_ul PORTCbits.RC3
    #define sp_on PORTDbits.RD0
    #define sp_off PORTDbits.RD1
    #define p_bar PORTDbits.RD2
    #define _XTAL_FREQ 20000000

    #pragma config WDT=OFF,LVP=OFF,OSC=HS,STVREN=ON

    unsigned int adc_out=0;
    int a=0,reg1=0,reg2=0;
    float adc_rpm=0;

    unsigned char convolt[5];
    unsigned char anim[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
    unsigned char anim0[8]={0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19};
    unsigned char anim1[8]={0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E};
    unsigned char anim2[8]={0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F};
    unsigned char anim3[8]={0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F};
    unsigned char anim4[8]={0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13};

    void lcdbuild(unsigned char,unsigned char *);
    void lcdmsg(const rom char *);
    void lcdstr(unsigned char *);
    void lcdcomm(unsigned char);
    void lcddata(unsigned char);
    void lcdout(unsigned char);
    void dispchar(void);
    void animate(void);
    void animate1(void);
    void animate2(void);
    void animate3(void);
    void animate4(void);
    void lcdinit(void);
    void clear(void);
    void blank(void);
    void blink(void);
    void blink_1(void);
    void blink_2(void);
    void blink_3(void);
    void loop(void);
    void swt(void);
    void adc(void);

    void main (void)
    {
    TRISA = 0xFF;
    TRISB = 0x00;
    TRISD = 0x0F;
    TRISC = 0x0F;
    lcdinit();
    dispchar();
    animate();
    lcdcomm(0x86);
    lcdmsg("MAXPRECI");
    animate1();
    animate2();
    animate3();
    animate4();
    animate3();
    animate2();
    animate1();
    animate();
    Delay10KTCYx(1000);
    lcdcomm(0xCD);
    lcdmsg("RPM:");
    lcdcomm(0x94);
    lcdmsg("WH:");
    lcdcomm(0x9E);
    lcdmsg("SPH:");
    OpenADC(ADC_FOSC_32 &
    ADC_RIGHT_JUST &
    ADC_4_TAD,ADC_CH0 &
    ADC_INT_OFF &
    ADC_VREFPLUS_VDD &
    ADC_VREFMINUS_VSS,7);
    while(1)
    {
    adc();
    loop();
    }
    CloseADC();
    }

    void loop(void)
    {
    if(wh_l==1)
    {
    reg1=0;
    a=1;
    }
    if(sph_l==1)
    {
    reg2=0;
    a=2;
    }
    if(wh_ul==1)
    {
    reg1=1;
    }
    if(sph_ul==1)
    {
    reg2=1;
    }
    if(reg1==1&&reg2!=1)
    {
    a=3;
    }
    if(reg2==1&&reg1!=1)
    {
    a=4;
    }
    if(reg1==1&&reg2==1)
    {
    a=5;
    }
    swt();
    }

    void swt(void)
    {
    switch(a){
    case 1:
    lcdcomm(0x97);
    lcdmsg("Lock");
    break;
    case 2:
    lcdcomm(0xA2);
    lcdmsg("Lock");
    break;
    case 3:
    lcdcomm(0x97);
    lcdmsg("UnLock");
    blink_1();
    break;
    case 4:
    lcdcomm(0xA2);
    lcdmsg("UnLock");
    blink_2();
    break;
    case 5:
    lcdcomm(0x97);
    lcdmsg("UnLock");
    lcdcomm(0xA2);
    lcdmsg("UnLock");
    blink_3();
    break;
    }
    }

    void base(void)
    {
    /* if(p_bar==1)
    {
    reg4=1;
    clear();
    lcdcomm(0xC0);
    lcdmsg("Pressure OK");
    }
    if(p_bar==0)
    {
    reg4=2;
    blank();
    lcdcomm(0xD4);
    lcdmsg("Pressure Below 6BAR");
    while(reg4==1)
    {
    lcdcomm(0xC0);
    lcdmsg("Low Pressure");
    blink();
    }
    if(sp_on==1)
    {
    reg3=2;
    }
    if(sp_off==1)
    {
    reg3=1;
    blank();
    lcdcomm(0xD4);
    lcdmsg("Spindle:OFF");
    }
    if(reg1==2 && reg2==2)
    {
    blank();
    lcdcomm(0xD4);
    lcdmsg("Spindle:ON");
    }
    if(reg1==1 || reg2==1)
    {
    blank();
    lcdcomm(0xD4);
    lcdmsg("Error WH/SPH UnLock");
    }*/
    }

    void adc(void)
    {
    SetChanADC (ADC_CH0);
    Delay10KTCYx(10);
    lcdcomm(0xD1);
    lcdmsg(" ");
    ConvertADC();
    while(BusyADC());
    adc_out=ReadADC();
    adc_rpm=(adc_out*500.0)/1024;
    itoa(adc_rpm,convolt);
    lcdcomm(0xD1);
    lcdstr(convolt);
    Delay10KTCYx(1000);
    }

    void dispchar(void)
    {
    lcdbuild(0,anim);
    lcdbuild(1,anim1);
    lcdbuild(2,anim2);
    lcdbuild(3,anim3);
    lcdbuild(4,anim4);
    lcdbuild(5,anim0);
    }

    void lcdbuild(unsigned char location, unsigned char *ptr)
    {
    unsigned char i;
    if(location<8)
    {
    lcdcomm(0x40+(location*8));
    for(i=0;i<8;i++)
    {
    lcddata(ptr);
    }
    }
    }

    void lcdmsg(const rom char *Message)
    {
    const rom char *Pos = Message;
    while(*Pos!=0)
    lcddata(*Pos++);
    }

    void lcdstr(unsigned char *str)
    {
    int i=0;
    while(str!='\0')
    {
    lcddata(str);
    i++;
    }
    }

    void lcdcomm(unsigned char i)
    {
    RS =0;
    lcdout(i);
    Delay1KTCYx(2);
    }

    void lcddata(unsigned char i)
    {
    RS =1;
    lcdout(i);
    Delay1KTCYx(2);
    }

    void lcdout(unsigned char dat)
    {
    lcdport = dat;
    E = 1;
    Delay1TCY();
    E = 0;
    }

    void lcdinit(void)
    {
    lcdport=0x00;
    Delay1KTCYx(40);
    lcdout(0x30);
    Delay1KTCYx(15);
    lcdout(0x20);
    Delay1KTCYx(15);
    lcdcomm(0x38);
    lcdcomm(0x0C);
    lcdcomm(0x01);
    lcdcomm(0x06);
    lcdcomm(0x80);
    }

    void blank(void)
    {
    lcdcomm(0xD4);
    lcdmsg(" ");
    }

    void clear(void)
    {
    lcdcomm(0xC0);
    lcdmsg(" ");
    }

    void blink(void)
    {
    Delay10KTCYx(200);
    lcdcomm(0xC0);
    lcdmsg(" ");
    Delay10KTCYx(100);
    }

    void blink_1(void)
    {
    Delay10KTCYx(200);
    lcdcomm(0x97);
    lcdmsg(" ");
    Delay10KTCYx(100);
    }

    void blink_2(void)
    {
    Delay10KTCYx(200);
    lcdcomm(0xA2);
    lcdmsg(" ");
    Delay10KTCYx(100);
    }

    void blink_3(void)
    {
    Delay10KTCYx(200);
    lcdcomm(0x97);
    lcdmsg(" ");
    lcdcomm(0xA2);
    lcdmsg(" ");
    Delay10KTCYx(100);
    }

    void animate(void)
    {
    lcdcomm(0x80);
    lcdmsg(" ");
    lcdcomm(0x82);
    lcddata(3);
    lcdcomm(0x83);
    lcddata(2);
    lcdcomm(0x84);
    lcddata(1);
    lcdcomm(0x85);
    lcddata(5);
    lcdcomm(0x8E);
    lcddata(4);
    lcdcomm(0x8F);
    lcddata(1);
    lcdcomm(0x90);
    lcddata(2);
    lcdcomm(0x91);
    lcddata(3);
    lcdcomm(0x92);
    lcdmsg(" ");
    Delay10KTCYx(100);
    }

    void animate1(void)
    {
    lcdcomm(0x80);
    lcdmsg(" ");
    lcdcomm(0x83);
    lcddata(2);
    lcdcomm(0x84);
    lcddata(1);
    lcdcomm(0x85);
    lcddata(5);
    lcdcomm(0x8E);
    lcddata(4);
    lcdcomm(0x8F);
    lcddata(1);
    lcdcomm(0x90);
    lcddata(2);
    lcdcomm(0x91);
    lcdmsg(" ");
    Delay10KTCYx(100);
    }

    void animate2(void)
    {
    lcdcomm(0x80);
    lcdmsg(" ");
    lcdcomm(0x84);
    lcddata(1);
    lcdcomm(0x85);
    lcddata(5);
    lcdcomm(0x8E);
    lcddata(4);
    lcdcomm(0x8F);
    lcddata(1);
    lcdcomm(0x90);
    lcdmsg(" ");
    Delay10KTCYx(100);
    }

    void animate3(void)
    {
    lcdcomm(0x80);
    lcdmsg(" ");
    lcdcomm(0x85);
    lcddata(5);
    lcdcomm(0x8E);
    lcddata(4);
    lcdcomm(0x8F);
    lcdmsg(" ");
    Delay10KTCYx(100);
    }

    void animate4(void)
    {
    lcdcomm(0x80);
    lcdmsg(" ");
    lcdcomm(0x8E);
    lcdmsg(" ");
    Delay10KTCYx(100);
    }
     
  13. WBahn

    Moderator

    Mar 31, 2012
    17,716
    4,788
    That's certainly the one that pops out.

    But he appears to also have an error that is just setting him up for buffer overflows.
     
    harsha3842 likes this.
  14. harsha3842

    Thread Starter New Member

    Jul 5, 2013
    24
    0
    the above code runs but it doesn't wait for any inputs displys outputs on its own..
    not getting this part
     
  15. harsha3842

    Thread Starter New Member

    Jul 5, 2013
    24
    0
    yes u've given the prob
    i've come out of the stack overflow prob but the output is not dependent on the inputs it displays wat ever it wants
     
  16. MrChips

    Moderator

    Oct 2, 2009
    12,421
    3,357
    Well don't expect me to fix the logic of your code.
    Did you draw a flow chart?
     
  17. WBahn

    Moderator

    Mar 31, 2012
    17,716
    4,788
    Because you have a logic error that is, at best, resulting in the wrong thing being displayed and, almost certainly, is resulting in buffer overflows.
     
    harsha3842 likes this.
  18. harsha3842

    Thread Starter New Member

    Jul 5, 2013
    24
    0
    this is the base of the code
    it runs well wen simulated but wen burnt onto the pic
    it takes only the first input
    when i give the sec input every other output is displayed
    unable to find any logic errors
    would be pleased if someone pointed out were the logic is going wrong...

    void loop(void)
    {
    while(1)
    {
    adc();
    if(WHL==1)
    {
    reg1*=0;
    lcdcomm(0x97);
    lcdmsg("Lock");
    }
    if(WHUL==1)
    {
    reg1=1;
    swt=reg1+reg2;
    }
    if(SPHL==1)
    {
    reg2*=0;
    lcdcomm(0xA2);
    lcdmsg("Lock");
    }
    if(SPHUL==1)
    {
    reg2=2;
    swt=reg1+reg2;
    }
    switch(swt)
    {
    case 1:
    lcdcomm(0x97);
    lcdmsg("UnLock");
    blink_1();
    break;
    case 2:
    lcdcomm(0xA2);
    lcdmsg("UnLock");
    blink_2();
    break;
    case 3:
    lcdcomm(0x97);
    lcdmsg("UnLock");
    lcdcomm(0xA2);
    lcdmsg("UnLock");
    blink_3();
    break;
    }
    }
    return;
    }
     
  19. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    harsha3842: do you realize hardly anyone will look at long stretches of code that is not posted within code tags?

    You get then with the # button when you post. If you hit the preview button you will see what they do before you post.
     
    harsha3842 likes this.
  20. harsha3842

    Thread Starter New Member

    Jul 5, 2013
    24
    0
    ya i know but im sorry
    im desperate to get the result stuck since two days
    the code would work in 16x2 but having trouble in 20x4

    void loop(void)
    {
    while(1)
    {
    adc();
    when work head lock switch is pressed
    Code ( (Unknown Language)):
    1. if(WHL==1)
    2.         {
    3.             reg1*=0;
    4.             lcdcomm(0x97);
    5.             lcdmsg("Lock");
    6.         }
    if work head lock switch is pressed
    Code ( (Unknown Language)):
    1. if(WHUL==1)
    2.         {
    3.             reg1=1;
    4.             swt=reg1+reg2;
    5.         }
    if sphere lock is pressed
    Code ( (Unknown Language)):
    1. if(SPHL==1)
    2.         {
    3.             reg2*=0;
    4.             lcdcomm(0xA2);
    5.             lcdmsg("Lock");
    6.         }
    if sphere unlock is pressed
    Code ( (Unknown Language)):
    1. if(SPHUL==1)
    2.         {
    3.             reg2=2;
    4.             swt=reg1+reg2;
    5.         }
    case to check if only one unlock is pressed or multiple unlocks pressed
    Code ( (Unknown Language)):
    1. switch(swt)
    {
    case 1:
    if only work head unlock is pressed blink this part
    Code ( (Unknown Language)):
    1. lcdcomm(0x97);
    2.             lcdmsg("UnLock");
    3.             blink_1();
    break;
    case 2:
    if only sphere unlock is pressed blink this part
    Code ( (Unknown Language)):
    1. lcdcomm(0xA2);
    2.             lcdmsg("UnLock");
    3.             blink_2();
    break;
    case 3:
    if both unlocks are pressed blink both together
    Code ( (Unknown Language)):
    1. lcdcomm(0x97);
    2.             lcdmsg("UnLock");
    3.             lcdcomm(0xA2);
    4.             lcdmsg("UnLock");
    5.             blink_3();
    break;
    }
    }
    return;
    }


    in the above code the loop is continuously checking for inputs from portC

    the error is
    workhead lock and unlock works fine
    but after tat the output display unlock for both and doesnt read input and change according to it
     
Loading...