Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[AVR] Can someone share a simple code snippet for blinking an LED using the AT89S52 microcontroller? How can I modify the code to change the blinking freq.

Hi,

AT89S52 is no AVR .. its an 80C52 compatible microcontroller.

Many thousands of examples/tutorials/explanations/videos in the internet. I guess it´s one of the most often posted examples.
I personally don´t think we need another one.

Klaus
 
Hi,

AT89S52 is no AVR .. its an 80C52 compatible microcontroller.

Many thousands of examples/tutorials/explanations/videos in the internet. I guess it´s one of the most often posted examples.
I personally don´t think we need another one.

Klaus
Klause maybe you can use your compiler to convert from your fave AVR tool into 80C52 machine code. But I didn't see AVR in the question. ;)
--- Updated ---

I wonder who came up with the cute "Blinky" name for their code

Code:
#include <REGX52.h>
delay(unsigned int y){
unsigned int i,j;
for(i=0;i< y;i++){
for(j=0;j< 1275;j++){}
}
}

main(){
while(1){
delay(1000);
P1_0 = 0;
delay(1000);
P1_0 = 1;
}
}
 
That type of 'delay' function (post #3) is very error prone for a coupel of reasons:
Firstly it depends totally on the clock frequency for the timing using it's 'magic number'. That is when it works at all!
Secondly, many compilers, even with the lowest level of optimisation, will see the two loops as 'empty' and remove them. Therefore the function will simply return immediately.
How you make a proper delay function really depends on the environment. Sometimes making the loop variables 'volatile' works, but as they are local the compiler might still not generate any code.
You can use assembler which generally means the code will not be optimised. Many compilers will provide a delay function in their runtime library that is either a tested externa function or a macro that generates in-line assembler.
You can also use a timer.
Susan
 

LaTeX Commands Quick-Menu:

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top