We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Dear all, my code is listed as below, my 8051 is Cast R8051XC2
sbit LED_FPGA_LED7=P1^0; sbit LED_FPGA_LED6=P1^1; sbit LED_FPGA_LED5=P1^2; sbit LED_FPGA_LED4=P1^3;
sbit LED_FPGA_LED3=P0^0; sbit LED_FPGA_LED2=P0^1; sbit LED_FPGA_LED1=P0^2; sbit LED_FPGA_LED0=P0^3;
void Timer0_IntHandler(void) interrupt 1 { static U8 u8Count0=0; U16 u16tmp=0; bit bLedTemp0_BDATA=0; U8 u8LedTmp0_IDATA=0; //DATA:0x0~0x7F static U8 u8LedTmp0_XDATA=0;
EAL = 0; ET0 = 0;
TH0=0x01; TL0=0x55;
bLedTemp0_BDATA=LED_FPGA_LED7; u8LedTmp0_IDATA=LED_FPGA_LED7; u8LedTmp0_XDATA=LED_FPGA_LED7;
bLedTemp0_BDATA=~bLedTemp0_BDATA; u8LedTmp0_IDATA=~u8LedTmp0_IDATA; u8LedTmp0_XDATA=~u8LedTmp0_XDATA;
LED_FPGA_LED7=~LED_FPGA_LED7; if(0==(u8Count0%5)){ LED_FPGA_LED6=~LED_FPGA_LED6; }
u8Count0++; ET0 = 1; EAL = 1; }
void Timer1_IntHandler(void) interrupt 3 { static U8 u8Count1=0; bit bLedTemp1=0;
EAL=0; ET1=0;
if(0==(u8Count1%10)){ bLedTemp1=LED_FPGA_LED5; LED_FPGA_LED5=(~bLedTemp1); //LED_FPGA_LED5=~LED_FPGA_LED5; } if(0==(u8Count1%15)){ bLedTemp1=LED_FPGA_LED4; LED_FPGA_LED4=(~bLedTemp1); //LED_FPGA_LED4=~LED_FPGA_LED4; u8StnCount++; }
u8Count1++; ET1=1; EAL=1; }
void Timer2_ISR (void) interrupt 5 { static U8 u8Count2=0; EAL=0; ET2=0; #if 0 if(!(u8Count2%50)){ static U8 u8ShowCount=0; Drv_WriteByteToStn(1,0,0x41+u8ShowCount); u8ShowCount++; }
u8Count2++; #endif TF2=0; //clear overflow flag ET2=1; EAL=1; }
void EX3_ISR (void) interrupt 10 { bit bEx3Temp=0; EAL=0; EX3=0;
bEx3Temp=LED_FPGA_LED3; LED_FPGA_LED3=(~bEx3Temp); //LED_FPGA_LED3=~LED_FPGA_LED3;
EX3=1; EAL=1; }
void EX4_ISR (void) interrupt 11 { bit bEx4Temp=0; EAL=0; EX4=0;
bEx4Temp=LED_FPGA_LED2; LED_FPGA_LED2=~bEx4Temp; //LED_FPGA_LED2=~LED_FPGA_LED2;
EX4=1; EAL=1; }
void EX5_ISR (void) interrupt 12 { bit bEx5Temp=0; EAL=0; EX5=0; bEx5Temp=LED_FPGA_LED1; LED_FPGA_LED1=(~bEx5Temp); //LED_FPGA_LED1=~LED_FPGA_LED1;
EX5=1; EAL=1; }
void EX6_ISR (void) interrupt 13 { bit bEx6Temp=0; EAL=0; EX6=0; bEx6Temp=LED_FPGA_LED0; LED_FPGA_LED0=(~bEx6Temp); //LED_FPGA_LED0=~LED_FPGA_LED0;
EX6=1; EAL=1; }
I use simulator in Keil-C Q1: The initial value of LEDs all are "1". The interrupt occured sequence is EX3 -> EX4 --> Timer0 ->EX5 ->Timer1 -> EX6 ->Timer0 ->Timer1 my main function is always runnging in while(1){ } loop and doing nothing.
When I use debug mode to trace the changing of LEDs. After running Timer1-ISR, the all valus of LEDs change correctly. But after Timer1-ISR and before EX6-ISR I don't know why the LED_FPGA_LED4 changes from 0 to 1.
LED_FPGA_LED7=1 --->0--------->1 LED_FPGA_LED6=1 --->0--------->0 LED_FPGA_LED5=1 ----->0 LED_FPGA_LED4=1 ----->0->1------->0 (enter Timer1-ISR again, it becomes 0, but who changes it?) |->(the problem point, I don't know who changes it.)
LED_FPGA_LED3=1 ->0 LED_FPGA_LED2=1 -->0 LED_FPGA_LED1=1 ---->0 LED_FPGA_LED0=1 ---------->0
Q2: In the Timer0-ISR, I declares several variables, one of them is u8LedTmp0_IDATA. I found it will be located at DATA:0x7 in running time. But it seems I could not change it's value after u8LedTmp0_IDATA=LED_FPGA_LED7. It always keeps in the same value. After I check the 8051 specification. it says the 0x0~0x1F are work registers for R0~R7. Is it the root casue? How could I set the keil-C not use 0x0~0x1F in running time?
Thanks a lot.