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
In addition to checking your XDATA, are you sure that is exactly the code that you compiled and ran?
ie, did you copy it from your source file, and paste it into your post?
If you manually re-typed it, it is quite possible that you inadvertently fixed a typo in the process...
firstly thanks ; i use small type memory model, i cant try for the variable with data extension(data unsigned char ilk) becouse my hardware connections is unworkable state now(electric problem). i am new on programming c, also new on assembly, maybe you can give me some advises about of programming 8051 device with c, especially about of interrupt routines. and when i solve my hardware problem i can try program, with your advises.here is my code,(i paste only important parts becouse of 7000 character limit)
static void timer0_isr (void) interrupt TF0_VECTOR using 1 { TR0 = 0; /* stop timer 0 */ TL0 = (timer0_value & 0x00FF); TH0 = (timer0_value >> 8); TR0 = 1; /* start timer 0 */ timer0_tick++; // Increment global var timer_tick (number of 10ms ticks) if (timer0_tick==1000){ a=1; timer0_tick=0; } } void sw_int (void) interrupt IE0_VECTOR using 1{ //port a nin durumuna bak ona gore buton durumunu oku buton durumuna gore current statei degistir EA=0; buton_durum=PSD_reg.DATAIN_A; EA=1; } main() { unsigned char xdata t[5]={'d','u','r','m','u','s'} ; unsigned char xdata *dizim; unsigned char xdata *dizim1; unsigned char xdata *dizim2; unsigned char xdata *dizim3; unsigned char xdata *dizim4; unsigned int xdata sayac=0; unsigned int xdata sayacbasla=0; unsigned int xdata sayacbitir=0; unsigned int xdata kere=0; unsigned int xdata kez=0; unsigned char ilk=0x00; unsigned char ilk_k; EA=1; EX0=1; timer0_init(); // initialize timer0 interrupt counter1_init(); PSD_reg.DIRECTION_A&=0x00; //port a input PSD_reg.DIRECTION_D|=0x02; // set port pin PD1 to output PSD_reg.DATAOUT_D |= LED_ON; // Initialize LED to OFF PSD_reg.DIRECTION_D|=0x04; // set port pin PD2 to output PSD_reg.DATAOUT_D &= LCD_disable; PSD_reg.DATAOUT_D |= LCD_enable; lcd_init ( ); while(1){ if(a==1){ sayac=sayac+(unsigned int)TL1; TL1=0; TH1=0; dizim=int_to_char(sayac); a=0; }//end if switch(curr_state){ case HIZ: printfLCD("hiz konumu \n"); printfLCD(" \n"); printfLCD(" \n"); printfLCD(" \n"); break; case KALIBRASYON: printfLCD("kalibrasyona baslamak icin \n"); printfLCD("7.ve 8. tusa birlikte basiniz \n"); printfLCD(" \n"); printfLCD(" \n"); break; case KALIBRASYONBASLA: if(ilk==0x00){ sayacbasla=sayac; dizim3=int_to_char(sayacbasla); ilk=0x01; ilk_k=0x00; } printfLCD("kalibrasyona basladi\n"); printfLCD(dizim3);printfLCD(" baslangic\n"); printfLCD(" bitirmek icin \n"); printfLCD("8.ve 6. tuslara bir\n"); break; case KALIBRASYONBITIR: if(ilkk==0x00){ sayacbitir=sayac; dizim4=int_to_char(sayacbitir); kere=sayacbitir-sayacbasla; kez=(unsigned int)10L*kere; dizim1=int_to_char(kere); dizim2=int_to_char(kez) ; ilkk=0x21 ; ilk=0x00; } printfLCD("kalibrasyon bitti\n"); printfLCD(dizim4);printfLCD(" bitis\n"); printfLCD("1km icin ");printfLCD(dizim2);printfLCD(" \n"); printfLCD("100m icin ");printfLCD(dizim1);printfLCD(" \n"); break; }//end switch } }
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?
can i explain my question?
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"
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