stack overflow/20x4LCD error

Thread Starter

harsha3842

Joined Jul 5, 2013
24
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

Rich (BB code):
#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    p_bar    PORTAbits.RA1
#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    _XTAL_FREQ 20000000

#pragma config WDT=OFF,LVP=OFF,STVREN=OFF,MCLRE=OFF

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

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 ucall(void);
void pcall(void);
void scall(void);
void adc(void);
void pressure(void);
void workhead(void);
void sphere(void);
void spindle(void);

void main (void)
{
    TRISA = 0x0F;
    TRISB = 0x00;
    TRISC = 0xFF;
    TRISD = 0x0F;
    lcdinit();
    dispchar();
    animate();
    lcdcomm(0x86);
    lcdmsg("MAXPRECI");
    animate1();
    animate2();
    animate3();
    animate4();
    animate3();
    animate2();
    animate1();
    animate();
    Delay10KTCYx(1000);
    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)
    {
        loop();
    }
    CloseADC(); 
}

void loop(void)
{
    adc();
//    pressure();
    if(wh_l==1 | wh_ul==1)
    workhead();
    else if(sph_l==1 | sph_ul==1)
    sphere();
    else if(sp_on==1 | sp_off==1)
    spindle();
}

void pressure(void)
{
    if(p_bar==1)
    {
        reg3=0;
        clear();
        lcdcomm(0xC0);
        lcdmsg("Pressure OK");
    }
    if(p_bar==0)
    {
        reg3=1;
        blank();
        lcdcomm(0xD4);
        lcdmsg("Pressure Below 6BAR");
        pcall();
    }
}

void workhead(void)
{
    if(wh_l==1)
    {
        reg1=0;
        lcdcomm(0x97);
        lcdmsg("Lock");
    }
    if(wh_ul==1)
    {
        reg1=1;
        ucall();
    }
}

void sphere(void)
{
    if(sph_l==1)
    {
        reg2=0;
        lcdcomm(0xA2);
        lcdmsg("Lock");
    }
    if(sph_ul==1)
    {
        reg2=1;
        ucall();
    }
}

void spindle(void)
{
    if(sp_on==1)
    {
        scall();
    }
    if(sp_off==1)
    {
        blank();
        lcdcomm(0xD4);
        lcdmsg("Spindle:OFF");
    }
}

void ucall(void)
{
    while(reg1==1 & reg2!=1)
    {
        lcdcomm(0x97);
        lcdmsg("UnLock");
        blink_1();
        loop();
    }
    while(reg2==1 & reg1!=1)
    {
        lcdcomm(0xA2);
        lcdmsg("UnLock");
        blink_2();
        loop();
    }
    while(reg1==1 & reg2==1)
    {
        lcdcomm(0x97);
        lcdmsg("UnLock");
        lcdcomm(0xA2);
        lcdmsg("UnLock");
        blink_3();
        loop();
    }
}

void pcall(void)
{
    while(reg3==1)
    {
        lcdcomm(0xC0);
        lcdmsg("Low Pressure");
        blink();
        pressure();
    }
}

void scall(void)
{
    if(reg1==0 & reg2==0)
    {
        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(0xA8);
    lcdmsg("      ");
    Delay10KTCYx(100);
}

void blink_3(void)
{
    Delay10KTCYx(200);
    lcdcomm(0x97);
    lcdmsg("      ");
    lcdcomm(0xA8);
    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);
}
 

Attachments

Last edited by a moderator:

WBahn

Joined Mar 31, 2012
30,072
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?
 

absf

Joined Dec 29, 2010
1,968
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:

Thread Starter

harsha3842

Joined Jul 5, 2013
24
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?
 

WBahn

Joined Mar 31, 2012
30,072
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?
 

ErnieM

Joined Apr 24, 2011
8,377
1) the program stops working within a minute(stack overflow?)
Or something else. If it stops at the same time I would look software. If the time is random I would look hardware.

2) the first character of last line in 20x4 lcd keeps blinking
Is that where the cursor is?

3) code works in 16x2 lcd but on a 20x4 lcd displays output of its choice and cannot be controlled
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.

initialization of lcd and adc is fine
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 !!!
 

Thread Starter

harsha3842

Joined Jul 5, 2013
24
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?
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
 

Thread Starter

harsha3842

Joined Jul 5, 2013
24
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..
 

WBahn

Joined Mar 31, 2012
30,072
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
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.
 

Thread Starter

harsha3842

Joined Jul 5, 2013
24
I gave you the problem.
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);
}
 

Thread Starter

harsha3842

Joined Jul 5, 2013
24
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;
}
 

ErnieM

Joined Apr 24, 2011
8,377
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.
 

Thread Starter

harsha3842

Joined Jul 5, 2013
24
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
Rich (BB code):
if(WHL==1)
        {
            reg1*=0;
            lcdcomm(0x97);
            lcdmsg("Lock");
        }
if work head lock switch is pressed
Rich (BB code):
if(WHUL==1)
        {
            reg1=1;
            swt=reg1+reg2;
        }
if sphere lock is pressed
Rich (BB code):
if(SPHL==1)
        {
            reg2*=0;
            lcdcomm(0xA2);
            lcdmsg("Lock");
        }
if sphere unlock is pressed
Rich (BB code):
if(SPHUL==1)
        {
            reg2=2;
            swt=reg1+reg2;
        }
case to check if only one unlock is pressed or multiple unlocks pressed
Rich (BB code):
switch(swt)
{
case 1:
if only work head unlock is pressed blink this part
Rich (BB code):
lcdcomm(0x97);
            lcdmsg("UnLock");
            blink_1();
break;
case 2:
if only sphere unlock is pressed blink this part
Rich (BB code):
lcdcomm(0xA2);
            lcdmsg("UnLock");
            blink_2();
break;
case 3:
if both unlocks are pressed blink both together
Rich (BB code):
lcdcomm(0x97);
            lcdmsg("UnLock");
            lcdcomm(0xA2);
            lcdmsg("UnLock");
            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
 
Top