Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] A89c2051 c code problem

Status
Not open for further replies.

deve

Newbie level 3
Joined
Jun 3, 2017
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
30
a simple c code like blinking a port or a pin doesn't work but the same code written in assembly works just fine.
I have used keil c51 compiler and sdcc as well but the code simply wont run.

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<reg2051.h>
 
void delay(int n); //delay routine
 
void delay(int n)
{
    int i,j;
    for(i=0;i<=n;i++)
    { 
        for(j=0;j<=1275;j++); //the loop will be occurring at n * 100 times
     }
}
 
void main( )
{ 
    P1=0x00;    //Set port 1 to 0v logic
    P3=0x00;    //Set port 3 to 0v logic
 
    
 
    while(1)
    {
        
          P1=0xAA;   //set port 1 = 1. That is 00000001 on 8bit Port 1
          delay(100); //Call delay routine to pause port 1 state
          P1 = 0x00;  //set port 1 = 0. That is 00000000 on 8bit port 1
          delay(100); // Call delay routine to pause port 1 state
    }
 
}


This code works fine in other 8051 controllers.
I seriously cant figure this one out.:bang:
 

"wont run" isn't a clear specification. "Not blink as intended" would be a possible option if the compiler performs code optimization. Review the compiler manual how to prevent optimization of specific code parts, e.g. use _nop_();
 

wont run as in nothing happens after power and clock is supplied.The code that i gave works fine in other 8051 microcontrollers just not this one.
Srry for any mistakes i m new to this site.

I saw the manual but i dont think the problem is with optimization of code coz this works in other 8051 controllers.I guess it has more to do with placement of code in memory and stack initialization.

but this works in other 8051 microcontrollers.
 

Hi,

What haveyou done to debug the problem?
I recommend to use some port pins to show activity when dedicated pieces of codes are being processed.
Check port state with a scooe.

Klaus
 

Problem sounds like a wrong compiler configuration. Are you using a predefined C2051 configuration or reusing configuration for other C51 processor? In the latter case, e.g. stack overflow might happen due to smaller data memory, review the restrictions paragraph in datasheet.
 

Problem sounds like a wrong compiler configuration. Are you using a predefined C2051 configuration or reusing configuration for other C51 processor? In the latter case, e.g. stack overflow might happen due to smaller data memory, review the restrictions paragraph in datasheet.

Yeah I was working in demo version so the linker was placing my code higher beyond the rom size. Got the unlocked version and it works fine now.
Thankz for the reply
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top