This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

conditional if statement

i want use if satement, to do something for the one time, example:

main(){
char k;
k=0;

while(1){

if(k==0){
printfLCD("please only one time\n");
k=1;
}//end if

printfLCD("test message\n");

}//end while
}//end main

but it isnt work, program enters the if statement infinite time. where is the error?, there is anyything about keilc51, which is i dont know? i use upsd3434 8051 microcontroler, sory for my nglish

Parents
  • main()
    {
    unsigned char data ilk;
    
    ilk=0x00;
    while(1){
    switch(curr_state){
    
    case KALIBRASYONBASLA:
    
    if(ilk==0x00){
    dizim3=int_to_char(sayac);
    ilk=0x12;
    ilkk=0x00;
    }
    
    printfLCD("kalibrasyona basladi\n");
    printfLCD(dizim3);printfLCD(" baslangic\n");
    printfLCD(" bitirmek icin    \n");
    printfLCD("8.ve 6. tuslara bir\n");
    
    break;
    }//end switch case
    }//end while
    }//end main
    
    


    i solved my hardware problem, and i tried this
    i follow the value of dizim3 on lcd , but the dizim3 value are changing according to sayac(sayac is the counter1 value , which is increase according to external signal on counter 1 pin) value.the equality in if statement. where is the problem?

Reply
  • main()
    {
    unsigned char data ilk;
    
    ilk=0x00;
    while(1){
    switch(curr_state){
    
    case KALIBRASYONBASLA:
    
    if(ilk==0x00){
    dizim3=int_to_char(sayac);
    ilk=0x12;
    ilkk=0x00;
    }
    
    printfLCD("kalibrasyona basladi\n");
    printfLCD(dizim3);printfLCD(" baslangic\n");
    printfLCD(" bitirmek icin    \n");
    printfLCD("8.ve 6. tuslara bir\n");
    
    break;
    }//end switch case
    }//end while
    }//end main
    
    


    i solved my hardware problem, and i tried this
    i follow the value of dizim3 on lcd , but the dizim3 value are changing according to sayac(sayac is the counter1 value , which is increase according to external signal on counter 1 pin) value.the equality in if statement. where is the problem?

Children
  • Have you tried this in the simulator?

  • in simulator its work normal, i guess trouble related with pointer type variable. and my xdata memory, but i dont know how can i solve this problem

  • here my int_to_char function (i writed), may be trouble is related with this function

    char num_to_char(unsigned char val)     //0-15 arası numerik değeri char 'a dönüştürür
    {
       char c;
       if (val < 10)
       {
         c=val+'0';
       }
       else
       {
         val=val-10;
         c=val + 'A';
       }
       return(c);
    }
    
    
    unsigned char *int_to_char(unsigned long sayim)
    
    {
            unsigned long xdata bolen=1;
            unsigned long xdata sayi;
            char xdata s;
            unsigned char xdata c,d,i,k;
            unsigned char xdata *ch;
    
            sayi=sayim;
    
            if (sayi<=9) s=0;
            else if (sayi<=99) s=1;
            else if (sayi<=999) s=2;
            else if (sayi<=9999) s=3;
            else if (sayi<=99999) s=4;
            else if (sayi<=999999) s=5;
            else if (sayi<=9999999) s=6;
            else if (sayi<=99999999) s=7;
            else if (sayi<=999999999) s=8;
    
            k=s;
    
            for (i=s;i>0;i--)
            {
                    bolen=bolen*10;
            }
    
            *(ch+s+1)='\0';
    
            do
            {
                    d=sayi/bolen;
                    c=num_to_char(d) ;
                    *(ch+k-s)=c;
                    sayi=sayi%bolen;
                    bolen=bolen/10;
                    s--;
    
            }while(s>=0);
    
            return (ch);
    }
    

  • "in simulator its work normal, i guess trouble related with pointer type variable. and my xdata memory"
    Quite possibly.

    You said you're using a uPSD3434E - this chip has JTAG and on-chip debugging, doesn't it?

    So don't guess - hook-up the debugger and see what's actually happening in the target hardware!

  • i dont know using debugger, i can started debug sesion and go step to step, but i only see on the monitor,the mcu special data registers(r0 r1 .. r7 ,a ,b psw) how can i fallow my variables changing when debugging?

  • how can i fallow my variables changing when debugging
    I know that 'read' is a 4 letter word, but, unfortunately the answer to your question is "read the documentation for the debugger". Any debugger without the ability to view a variable, would be too ridiculous to even be released.

    Erik

  • how can i fallow my variables changing when debugging?

    The debugger should offer the ability to "watch" variables and memory locations, as well as "view" whole ranges of memory.

    If it doesn't, throw it out and get one that does.

  • If after extensive reads, you find it doesn't, throw it out and get one that does.

    I do not know how much I know of that has been "thrown out" because the user did not take the time to 'find' a feature. I recall some post somewhere "xxx is a piece of crap, it can not .... I threw it out" to which the response was "as stated in the manual, click x>y>z and it is right there.

    the post from the OP "i can started debug sesion ... but i only see" clearly indicates that reading the documentation is considered "unnecessary" or "troublesome" or maybe even "not cool"

    Erik

  • maybe i can say troublesome

    ok. firstly i will study on debugging , then you can see my questions later.

    finally i want to write my last question;

    xdata unsigned int *ptr _at_ 0x8000;
    is this valid? or is this useful?

    for example;
    *(ptr) = 10;

    *(ptr+1) = 11;

    where are the 10 and 11 values ,in xdata

  • your 'condtruct is wrong, here is a "cheat sheet" extracted from my definition file

                                                // pointer in data in
    #define U8DI  unsigned char   idata * data  // data       idata
    #define U8DX  unsigned char   xdata * data  // data       xdata
    #define U8IX  unsigned char   xdata * idata // idata      xdata
    #define U8XX  unsigned char   xdata * xdata // xdata      xdata
    #define U8IC  unsigned char   code  * idata // idata      code
    #define U8DC  unsigned char   code  * data  // data       code
    #define U8XC  unsigned char   code  * xdata // xdata      code
    #define U8CC  unsigned char   code  * code  // code       code
    

    Erik