views:

77

answers:

4

Hello all,

I am trying to program Blinky program from Keil complier to P89LPC936 microcontroller through a universal programmer(SuperPro). But the microcontroller is not running. But when i write a simple program in assambly and program the same hardware it works fine. Please I need help regarding it where i am doing wrong.

Here is code >>> Code:

/* Blinky.C - LED Flasher for the Keil LPC900 EPM Emulator/Programmer Module */

#include <REG936.H>   // register definition

void delay (unsigned long cnt)
{
  while (--cnt);
}

void main()
{
  unsigned char i;

  P1M1 |= 0x20;
  P1M2 &= 0xDF;

  P2M1 &= 0xE7;
  P2M2 |= 0x18;

delay (20000);
  for(;;)
  { for (i = 0x01; i; i <<= 1)
    { P2 = i;    // simulate running lights
      delay (20000);
    }
    for (i = 0x80; i; i >>= 1)
    { P2 = i;
      delay (20000);
    }
  }
}

Here is Hex file >>>

:10006B008F0B8E0A8D098C08780874FF12004DECEB
:06007B004D4E4F70F32210
:100003004391205392DF53A4E743A5187F207E4EEC
:100013007D007C0012006B7B01EB6013F5A07F2059
:100023007E4E7D007C0012006BEB25E0FB80EA7BBB
:1000330080EB60E3F5A07F207E4E7D007C00120004
:070043006BEBC313FB80EA25
:01004A002293
:04FFF00023001E00CC
:08FFF800000000000000000001
:030000000200817A
:0C00810078FFE4F6D8FD75810B02000347
:10004B007401FF3395E0FEFDFC080808E62FFFF670
:10005B0018E63EFEF618E63DFDF618E63CFCF622E9
:00000001FF

And here is the assembly code and its hex file which is working absolutely right.

Code:
; LPC936A1.A51
; Oct 7, 2010                   PCB: ?

; Features:     ?
;               ?


$mod51


RL1     bit     P2.3
RL2     bit     P2.4

                DSEG AT 20H
FLAG1:  ds      1
STACK:  ds      1


FRL1    bit     FLAG1.0                 ; Relay 1


                CSEG
                org     0H
                ajmp    Reset

                org     30H
Reset:          mov     0A5H,#0FFH

Start:          mov     c,FRL1                  ;
                mov     RL1,c
                cpl     c
                mov     FRL1,c
                mov     RL2,c

                acall   Delay0

                ajmp    Start

Delay0:         mov     R7,#250
Delay:          mov     R6,#61
Delay1:         nop
                nop
                nop
                nop
                nop

                nop
                nop
                nop
                djnz    R6,Delay1
                djnz    R7,Delay
                ret

Text:           DB      '(C) DIGIPOWER 2010'
Text0:          DB      ' LPC936A1 '

                END


And its hex is
:020000000130CD
:1000300075A5FFA20092A3B3920092A411400133D0
:100040007FFA7E3D0000000000000000DEF6DFF2D7
:10005000222843292044494749504F5745522032CE
:0D006000303130204C5043393336413120CF
:00000001FF

Please help i m stuck.

Regards Dani

+1  A: 

I don't work with keil tools for a long time and I never used that micro, so probably I won't be able to help you much.

  • Did you tried running it on the emulator?
  • Try to put a breakpoint in main and check if it stops there. There might me some issue with c_start and your main isn't being called.
  • Look at the assembly of the initialization code and check for something odd. I think you can check the assembly code generated by the compiler. You might have to turn on some option to generate intermediate files

You might also check "Electronics and Robotics" at stackexchange. There you may find people working with electronics that might provide better help.

jassuncao
+1  A: 

You say that you write a program in assembly and it works fine, but not in C. Have you verified that your C environment is configured to place your code and data in the correct spots in memory?

Also, some chips have a "reset vector" that is called when the chip is first powered and also when the chip resets. Does your C environment set this vector correctly? Does it put code that will jump to your program when it starts to run?

San Jacinto
It may be the problem. But i have used the defaul start900.a51 startup file which includes default settings for interrupt vector. Do you have any example how to make it correct.
Adnan
I'm sorry, I don't. These were just general things I've had to do in the past with other chips (HC12, i8051, etc.). Proper memory locations for your routines and data, as well as your stack and interrupt code will depend on the memory map for your specific chip. Also, setting these things in your C environment probably is specific to each tool.
San Jacinto
A: 

Try:

void delay (unsigned long cnt)
{
  while (--cnt) {
#pragma asm
      NOP
#pragma endasm
 }
}
nategoose
A: 

Disassemble or compile the C to assembler to see what the compiler is doing. What is working or not in your C program? does the led just glow? Your assembler looks to be burning about 140,000 instructions but the C maybe 40,000? that could make the difference between an led you can see with your eyes and one that looks to be on but not blinking.

The C program appears to be setting up registers that the assembler does not. is there a bug there? are they disabling something that shouldnt be touched?

bottom line is you need to move the two programs toward each other, complicate the assembler until it approaches what the C is doing and adjust the C toward the assembler (have to look at the output of the compiler though).

dwelch
Ok.. thats good idea... i will work on it. But Y the C code is running on simulator right.
Adnan
what is it that it is doing or not doing? If the leds glows it could be blinking just fine, your eye cannot see it. but a simulator would. Or do the leds remain off? Simulators rarely reflect reality. often allowing read only memory to be written, providing memory at addresses beyond the chip, etc.
dwelch
No it is not the mater, If i don't blink them and let them on continuous even then i don't get them glow and pins don't show output voltage either.
Adnan