Hi. I have this simple code that defines some constants in code: #include <REG922.H> code const unsigned char LEDRegister0[] = {0xff,0xfe,0xfd,0xfb,0xff,0xff,0xff,0xff,0xf7,0xff,0xff,0xbf}; code const unsigned char LEDRegister1[] = {0x7f,0xff,0xff,0xff,0xef,0xfd,0xfb,0xf7,0xff,0xbf,0xfe,0xff}; code const unsigned char Pattern1[] = {54,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,21,25,27,30,33,36,40,45,50,50,45,40,36,33,30,27,25,21,19,19,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1}; code const unsigned char Pattern2[] = {54,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,21,25,27,30,33,36,40,45,50,50,45,40,36,33,30,27,25,21,19,19,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1}; code const unsigned char Pattern3[] = {54,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,21,25,27,30,33,36,40,45,50,50,45,40,36,33,30,27,25,21,19,19,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1}; void main() { unsigned char i; P1M1 = 0; for(;;) { P1 = 0xaa; P1 = 0x55; } } When I simulate this code it runs fine, but when I download it to my chip (an LPC920), it doesn't run. I then remove the last constant definition named Pattern3, recompile and now the code simulates AND runs in the chip. I started from the Blinky example and simply changed the target chip to compile. I'm using small memory model and small code size (2k or less). If anyone can tell me what I'm doing wrong, I would be grateful. Thanks, Marc.
The code is working. Its your eyes that is not fast enough.
"when I download it to my chip (an LPC920), it doesn't run." How do you know that? What actually happens?
"I started from the Blinky example and simply changed the target chip to compile. " That's not true! Here's the code of Blinky.c:
/* BLINKY.C - LED Flasher for the Keil MCBx51 Evaluation Board with 80C51 device*/ #include <REG51F.H> void wait (void) { /* wait function */ ; /* only to delay for LED flashes */ } void main (void) { unsigned int i; /* Delay var */ unsigned char j; /* LED var */ while (1) { /* Loop forever */ for (j=0x01; j< 0x80; j<<=1) { /* Blink LED 0, 1, 2, 3, 4, 5, 6 */ P1 = j; /* Output to LED Port */ for (i = 0; i < 10000; i++) { /* Delay for 10000 Counts */ wait (); /* call wait function */ } } for (j=0x80; j> 0x01; j>>=1) { /* Blink LED 6, 5, 4, 3, 2, 1 */ P1 = j; /* Output to LED Port */ for (i = 0; i < 10000; i++) { /* Delay for 10000 Counts */ wait (); /* call wait function */ } } } }
I have a scope connected to the output pins of the LPC920. When I compile and download the code without the Pattern3 declaration, the chip's pins toggle. I see them on the scope. When I add the Pattern3 declaration, and download the code again, the pins don't toggle, they don't even get to output mode, they seem to stay in high împedance mode because I read flat 0V on the scope. I know this isn't the original Blinky. I just wanted to have the simplest code snippet to isolate exactly when it stop working. I have checked (and hand disassembled) the HEX file and all seems to be in order. Is there a hardware register I forgot to set somewhere? Perhaps the declaration is put in RAM instead of ROM and that eats up my stack space? Anyway, thanks for any helpful input, and I will continue to investigate this strange behaviour.
what does the M51 state as end of used code space? Erik
here is a Copy/Paste of a part of my M51 file. BL51 BANKED LINKER/LOCATER V5.12, INVOKED BY: C:\KEIL\C51\BIN\BL51.EXE Blinky.obj, START900.obj TO Blinky RAMSIZE (256) CODE (0X0000-0X07FF) MEMORY MODEL: SMALL INPUT MODULES INCLUDED: Blinky.obj (BLINKY) START900.obj (?C_STARTUP) LINK MAP OF MODULE: Blinky (BLINKY) TYPE BASE LENGTH RELOCATION SEGMENT NAME ----------------------------------------------------- * * * * * * * D A T A M E M O R Y * * * * * * * REG 0000H 0008H ABSOLUTE "REG BANK 0" IDATA 0008H 0001H UNIT ?STACK * * * * * * * C O D E M E M O R Y * * * * * * * CODE 0000H 0003H ABSOLUTE CODE 0003H 004FH UNIT ?CO?BLINKY CODE 0052H 000CH UNIT ?C_C51STARTUP CODE 005EH 000BH INBLOCK ?PR?MAIN?BLINKY 0069H FF87H *** GAP *** CODE FFF0H 000CH ABSOLUTE Thanks, Marc.
now, what does it look like "When I add the Pattern3 declaration" (the case where it fail) Erik
Forgive me, but the M51 from before is with the Pattern2[] AND Pattern3[] definitions commented out. This one is with them both active. It looks like this: BL51 BANKED LINKER/LOCATER V5.12, INVOKED BY: C:\KEIL\C51\BIN\BL51.EXE Blinky.obj, START900.obj TO Blinky RAMSIZE (256) CODE (0X0000-0X07FF) MEMORY MODEL: SMALL INPUT MODULES INCLUDED: Blinky.obj (BLINKY) START900.obj (?C_STARTUP) LINK MAP OF MODULE: Blinky (BLINKY) TYPE BASE LENGTH RELOCATION SEGMENT NAME ----------------------------------------------------- * * * * * * * D A T A M E M O R Y * * * * * * * REG 0000H 0008H ABSOLUTE "REG BANK 0" IDATA 0008H 0001H UNIT ?STACK * * * * * * * C O D E M E M O R Y * * * * * * * CODE 0000H 0003H ABSOLUTE CODE 0003H 00BDH UNIT ?CO?BLINKY CODE 00C0H 000CH UNIT ?C_C51STARTUP CODE 00CCH 000BH INBLOCK ?PR?MAIN?BLINKY 00D7H FF19H *** GAP *** CODE FFF0H 000CH ABSOLUTE I think the problem lies in the memory spaces, but I am not competent enough to follow all the segments from the startup to the C code, etc... Thanks, Marc.
I found a solution to my problem, even though I don't fully understand what happened. When I program my chip using the ICP method with the MCB900 board, I get the errors mentionned previously. But I tried programming it using the ISP method (instead of the ICP method) and the code runs just fine, like the simulator predicted. I must have been doing something wrong with using the ICP method. I was however, able to reprogram the ISP code in FLASH using the ICP method. BTW, I now use Erik's NoTouch approach for ISP. I changed his code to a simple LJMP 0700H if the TX pin is held low (instead of being pulled up) on startup. Thanks everyone! :) Marc.