# Programming AT89S52 Microcontroller

#### Kittu20

Joined Oct 12, 2022
156
i am newbie. I want to program 8051 using keil uVision software. Here is the basic description.

Code:
Microcontroller : 8051 family ( AT89S52)
Programmer :   Willar programmer 1.0
Software :  Keil uVision 5
Operating System : Windows 10
I have micro controller board shown in following website.

https://www.silicontechnolabs.in/index.php?route=product/product&path=76&product_id=55

I'm looking for the circuit diagram of the board, but when I clicked on the circuit diagram in the link, I couldn't find it. I searched a lot for circuit diagram on internet but i can't find its circuit diagram.

can anyone help me to find the circuit diagram of the board

#### Attachments

• 263.8 KB Views: 1
Last edited:

#### Ya’akov

Joined Jan 27, 2019
6,856
I don’t know anything about this board, but attached is the datasheet, and here is the schematic:

#### Kittu20

Joined Oct 12, 2022
156
I want the LED to be on for one second and off for one second. for this i need a delay function in program but i don't understand how do i get the delay of 1 second.

e.g. how much delay this for loop will give ( us, ms)

C:
//  int occupy 2 bytes of memory and range is 0- 65535 for variable i

void Delay_MS ()
{
unsigned int i

for (i = 0; i < 65535; i++)
{
}
}

Last edited:

#### bidrohini

Joined Jul 29, 2022
96
Regarding the delay, you can see this video. This is quite detailed:

#### Kittu20

Joined Oct 12, 2022
156
Regarding the delay, you can see this video.
I saw the video, nested for loop is used to generate delay. But I still don't understand how to get specific delay.

If I know how long one count takes then I can try to calculate rest delay time.

#### djsfantasi

Joined Apr 11, 2010
8,663
I saw the video, nested for loop is used to generate delay. But I still don't understand how to get specific delay.

If I know how long one count takes then I can try to calculate rest delay time.
That’s what the video is trying to show you. He sets up a for loop and times how long it executes by using the debugger. Through trial and error, he determined the actual number of loops it takes for one millisecond. (He used this count in a function that creates a delay of user specified milliseconds).

One could use a little math to get to a value quicker, but in this case trial and error is workable and simpler to use.

#### Ian0

Joined Aug 7, 2020
6,706
I want the LED to be on for one second and off for one second. for this i need a delay function in program but i don't understand how do i get the delay of 1 second.

e.g. how much delay this for loop will give ( us, ms)

C:
//  int occupy 2 bytes of memory and range is 0- 65535 for variable i

void Delay_MS ()
{
unsigned int i

for (i = 0; i < 65535; i++)
{
}
}
If you write in assembler you will know for certain.
Though, a compiled program on an 8051 trying to do 16-bit arithmetic: it will finish about a week next Tuesday.

#### MrChips

Joined Oct 2, 2009
27,679
If you have an oscilloscope it would be easier as you can time the 1ms inner loop.
Assuming that you don't have an oscilloscope you will have to do it by trial and error.
Here is how I would do it. I would create a nested loop and aim to time ten 1-second flashes with a stop watch.

C:
#define DELAY 1234 // adjust this value to get the correct time

void delay_1ms(void)
{
unsigned int i;
for ( i = 0; i < DELAY; i++)
}

void delay_ms(unsigned int ms)
{
while(ms--) delay_1ms();
}

void main(void)
{
% initialize GPIO LED output port
while (1)
{
% turn on LED
delay_ms(1000);
% turn off LED
delay_ms(1000);
}
}

#### Kittu20

Joined Oct 12, 2022
156
I don't know what is the problem, but when I program to AT89S52. I am getting communication error message.
My port setting is in single digit COM4. I have placed the IC in the correct position Pin number 1 is on the side of the handle.

#### MrChips

Joined Oct 2, 2009
27,679
What PC and OS are you using?
What hardware connection are you using to get COM4?
Serial COM ports using DE9 connectors were made obsolete a long time ago.

#### Kittu20

Joined Oct 12, 2022
156
What PC and OS are you using?
What hardware connection are you using to get COM4?
Serial COM ports using DE9 connectors were made obsolete a long time ago.
Microcontroller : 8051 family ( AT89S52)
Programmer IDE: Willar programmer 1.0
Programmer : 8051 USB programmer https://alselectro.wordpress.com/tag/8051-usb-programmer/
Software : Keil uVision 5
Operating System : Windows 10