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
  • 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);
    }
    

Reply
  • 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&#305; numerik de&#287;eri char 'a dönü&#351;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);
    }
    

Children
No data