Keil Logo

[8051] Use keil-C simulator and debug problem?

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Details Message
Read-Only
Author
shihwen chou
Posted
15-Jun-2018 07:41 GMT
Toolset
C51
New! [8051] Use keil-C simulator and debug problem?

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.

Read-Only
Author
Andrew Neil
Posted
15-Jun-2018 07:45 GMT
Toolset
None
New! Illegible code

Please follow the instructions for posting source code.

Look at this picture to help you: http://www.danlhenry.com/caps/keil_code.png

Read-Only
Author
shihwen chou
Posted
15-Jun-2018 07:50 GMT
Toolset
C51
New! RE: [8051] Use keil-C simulator and debug problem?

Sorry, new post for code alignment

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(the problem point, I don't know who changes it.)------->0 (enter Timer1-ISR again, it becomes 0, but 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 and let the 8051 does not use DATA:0x0~0x1F in running time?

Thanks a lot.

Read-Only
Author
Andrew Neil
Posted
15-Jun-2018 08:22 GMT
Toolset
C51
New! RE: new post for code alignment

You didn't follow the instructions, did you ?

Look at that picture again: http://www.danlhenry.com/caps/keil_code.png

it's really not hard, and it would be obvious from the preview when it's worked.

Read-Only
Author
shihwen chou
Posted
19-Jun-2018 08:24 GMT
Toolset
C51
New! RE: new post for code alignment

Dear all, Sorry, I just see your reply now.

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;

  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(the problem point, I don't know who changes it.)------->0 (enter Timer1-ISR again, it becomes 0, but 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 and let the 8051 does not use DATA:0x0~0x1F in running time?

Thanks a lot.

Read-Only
Author
joe blow
Posted
19-Jun-2018 19:30 GMT
Toolset
C51
New! RE: new post for code alignment
  U8 u8LedTmp0_IDATA=0; //DATA:0x0~0x7F static U8 u8LedTmp0_XDATA=0;
As a temporary variable will always be set to 0 at ISR entry
  u8LedTmp0_IDATA=LED_FPGA_LED7;
set to a value never used
  u8LedTmp0_IDATA=~u8LedTmp0_IDATA;
zeroing it out


what are you trying to do? nothing??

I dislike you include IDATA in a label of soething you have no idea where it goes

Read-Only
Author
shihwen chou
Posted
20-Jun-2018 13:49 GMT
Toolset
C51
New! RE: new post for code alignment
  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;

1. Yes, it does nothing. I just monitor where the variables are placed.
2. About IDATA label , Sorry I forgot to modify it's name. It should be DATA, because this variable(u8LedTmp0_IDATA) will be placed in DATA area.

Read-Only
Author
Andrew Neil
Posted
20-Jun-2018 13:52 GMT
Toolset
C51
New! RE: I forgot to modify its name

Which is exactly why you should not have it in the name at all - as Joe said!

Read-Only
Author
shihwen chou
Posted
20-Jun-2018 14:03 GMT
Toolset
C51
New! RE: new post for code alignment

Please ignore my Q2. I just know the root cause. Thank you.

Next Thread | Thread List | Previous Thread Start a Thread | Settings

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.