Go Down

Topic: problem in 8051 Microcontroller (AT89C51) (Read 325 times) previous topic - next topic

Kiroloes

Jun 25, 2019, 11:18 pm Last Edit: Jun 25, 2019, 11:21 pm by Kiroloes
the microcontroller gives the port 1 and the port 3 2.7V and 0V to 0 and 2.
the code that in the microcontroller:
Code: [Select]

#include<reg51.h>

sbit led = P1^0;
unsigned long num;
void delay(num);
void main(void)
{
P0 = 0x00;
P1 = 0x01;
P2 = 0x00;
P3 = 0x00;
while(1)
{
led = 0;
delay(1000);
led = 1;
delay(1000);
}
}
void delay(num)
{
int i;
int j;
for(i=0;i<num;i++)
{
for(j=0;j<10000;j++)
{
}
}
}

i use the minipro programmer to program and upload the code
i want to know is the microcontroller damaged or no? and what should i do?

westfw

Well, 8051s aren't used in Arduino, so I don't know how many answers you'll get.

IIRC, most 8051-like chips have essentially open-drain outputs on the PORTs.  This means that writing a "1" simply enables a pull-up resistor (on some ports), so that the pins can "source" very little currrent (even though they can "sink" moderate amounts.)  My 89C52 data sheet says they can sink up to 10mA, but output voltage above 2.4V is only guaranteed for source currents of 800uA.  Port 1 and 2 are supposed to have internal pullups, but it looks like port0 is "pure" open-drain - it won't source voltage at all.

Kiroloes

thank you for replaying, but What should i do ? and is the code correct

DrAzzy

#3
Jun 26, 2019, 12:15 am Last Edit: Jun 26, 2019, 12:21 am by DrAzzy
No, your code is wrong.

I think the compiler will optimize out those loops you're hoping to use for a delay, so instead of actually delaying execution, I would wager that your delay implementation has been completely optimized out, so the delay(1000) is executing in a couple of microseconds, rather than acting as a delay.

You also don't appear to actually be changing the LED: You've initialized led=P1^0, so led is ending up set to whatever P1^0 (I'm guessing that's the port register on the 8051's?) is at startup, and then you assign other values to it. But nowhere do you write the new value of led to P1, so you're not changing the pin anywhere after setup().
ATtiny core for 841+1634+828 and x313/x4/x5/x61/x7/x8 series Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts (some assembled), mosfets and awesome prototyping board in my store http://tindie.com/stores/DrAzzy

Kiroloes


jremington

Quote
i use the minipro programmer to program and upload the code
Which compiler are you using?

Kiroloes

#6
Jun 26, 2019, 05:05 pm Last Edit: Jun 26, 2019, 06:30 pm by Kiroloes
Keil uvision5. 8051 Microcontroller (AT89C51) not Arduino

Go Up