Go Down

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


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]


sbit led = P1^0;
unsigned long num;
void delay(num);
void main(void)
P0 = 0x00;
P1 = 0x01;
P2 = 0x00;
P3 = 0x00;
led = 0;
led = 1;
void delay(num)
int i;
int 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?


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.


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


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().
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy



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


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