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] Problem running code on AT89C2051

Status
Not open for further replies.

jeffafa

Newbie level 2
Joined
Oct 7, 2013
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
17
Hello everybody,

I wrote a simple code to blink a led every 1 second for a AT89C2051. The code was writen using Keil uVision 4 with the C51 compiler V9.02 full version. To program the code into the mcu I use a Galep-5 programmer.

When i run the code in the simulator everything works like i would expect it. But when i run it on the mcu nothing happens. Only after i play a little with the RST pin does the led turn on but doesn't start blinking. I think the MCU is stuck in reset so i used the setup in the datasheet but still nothing. After a google search i found a schematic for a dev board so i used that setup but still nothing. (https://www.qsl.net/vu2upx/Projects/2052devbrd.htm)

I could really use some help.

I have included my code:
Code:
#include <reg2051.h> 

#define high 1
#define low 0

/*-----------------------------------------------------------------------------
Definitions for P1 (8 bits)
-----------------------------------------------------------------------------*/
volatile unsigned int overflow_count = 0;

void timer0_ISR (void) interrupt 1
{
	overflow_count++;   /* Increment the overflow count */
}

/*------------------------------------------------
MAIN C function
------------------------------------------------*/
void main (void)
{
/*--------------------------------------
Set Timer0 for 16-bit timer mode.  The
timer counts to 65535, overflows, and
generates an interrupt.

Set the Timer0 Run control bit.
--------------------------------------*/
TMOD = (TMOD & 0xF0) | 0x00;  /* Set T/C0 Mode */
TL0 = 31;											/* Prescaler */
TH0 = 255;										/* Full counter */
ET0 = 1;                      /* Enable Timer 0 Interrupts */
TR0 = 1;                      /* Start Timer 0 Running */
EA = 1;                       /* Global Interrupt Enable */
P1_3 = high;
/*--------------------------------------
Do Nothing.  Actually, the timer 0
interrupt will occur every 65536 clocks.
--------------------------------------*/
while (1)
  {
		if(overflow_count >= 244L)
		{
			overflow_count = 0L;
			if (P1_3 == 1) P1_3 = 0;
			else P1_3 = 1;
		}
  }
}

Thanks in advance!
 

You are not clearing the Timer0 interrupt flag bit and not reloading the TL0 and TH0 registers inside the ISR. The value you are loading into Timer0 registers are 65311 and not 65535.
 

Its not the problem It will automatically reset and will start from 0 after int and he is programmed for it, I think the problem is read modify write operation which is most of times a problem with 8051...
instead of


Code C - [expand]
1
2
if (P1_3 == 1) P1_3 = 0;
 else P1_3 = 1;



declare LED as char variable


Code C - [expand]
1
2
LED = !LED;
 P1_3 = !!LED;

 

Its not the problem It will automatically reset and will start from 0 after int and he is programmed for it, I think the problem is read modify write operation which is most of times a problem with 8051...
instead of


Code C - [expand]
1
2
if (P1_3 == 1) P1_3 = 0;
 else P1_3 = 1;



declare LED as char variable


Code C - [expand]
1
2
LED = !LED;
 P1_3 = !!LED;


Hallo Venkadesh_M,

I found the problem and i'm feeling really really stupid about it:oops:. My crystal was broken and that was the reason it didn't do anything. After replacing the clock it worked perfect. it works even without change the code. thanks for all the help!!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top