Page 1 of 1

The AT89S52 microcontroller

PostPosted: Sat Nov 16, 2013 2:03 pm
by Brian Griffin
Someone happened to give this microcontroller to me because it's not been used, so I have an idea - let's try to program something inside it!

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/.

Re: The AT89S52 microcontroller

PostPosted: Mon Nov 18, 2013 8:52 am
by ober
Brian, thanks for sharing.

I was learning 68000 mikroP from Motorola and move to 68HC11 for microC. I have experience in using AT89C51, and I am using Assembly too. Back then, there is no free compiler or maybe we did not search it.

Re: The AT89S52 microcontroller

PostPosted: Mon Nov 18, 2013 4:08 pm
by Brian Griffin
ober WROTE:Brian, thanks for sharing.

I was learning 68000 mikroP from Motorola and move to 68HC11 for microC. I have experience in using AT89C51, and I am using Assembly too. Back then, there is no free compiler or maybe we did not search it.


SDCC was started at year 2000, according to the webpage, but back then we do not have good access to the internet.

Fast forward to today it seems very easy to program a microcontroller, just use the ISP and we are good to go. :)