Programming the Atmel AT89S52 is not terribly difficult if you have the USBASP stick, but if you don't have, and you have an extra parallel port at your PC with a cable, you can build your own programmer. Refer to the website. I'll post up the improved schematics here later.
However, those good C compilers for 8051 are not really available for free, and luckily we have the SDCC. You can get the SDCC here. Create a new file name "hello.c" or something, and then copy the code provided. Don't worry about the inline assembler - I fine-tuned the delays a bit more.
- CODE: SELECT_ALL_CODE
#include <mcs51\at89x52.h>
void delayMs(unsigned int inputDelay) {
for(;inputDelay; inputDelay--)
{
__asm
push 0
push 1
mov r0, #49
mov r1, #10
00002$:
00001$:
djnz r0, 00001$
mov r0, #49
djnz r1, 00002$
pop 1
pop 0
__endasm;
}
}
void main()
{
while(1)
{
P2_0 = 0;
delayMs(500);
P2_0 = 1;
delayMs(500);
}
}
In the command prompt, switch to the directory you are working on, and then compile it by typing
- CODE: SELECT_ALL_CODE
sdcc hello.c
This code switches on the LED for 500ms, and then off for 500ms and again.
The P2_0 is at the 21st pin of the microcontroller. Sink the pin with the LED and the 330ohms resistor. 12mhz crystal too is needed for the project.
The AT89S52 is based on the old 8052 microcontroller. Nothing fancy, no A/D and all that other peripherals, and it's really slow. Back then many were working on the 8051 and the 68HC11, but now we have the PIC and the ARMs together.
Reference: Delay routine courtesy of http://8051.scottmay.org/.