Friday, 31 October 2014

Generate a Delay using for loop in Embedded C using Microcontroller 8051

/* In Microcontroller programming if you want to generate a normal delay then you can generate using for loop also.
Here i m gonna write a program to toggle a bit of port P0 of microcontroller using delay.
*/

#include<Reg51.h>

sbit MyBit = PO^1 ;
void My_Delay(unsigned char z) ;

void main()
{
   while(1)
       {
          MyBit = 1 ;
            My_Delay(1500) ;
          MyBit = 0 ;
            My_Delay(1500) ;
       }


}

void My_Delay(unsigned char z)
   {
       int i ;
   for(i=0 ; i <= z ; i++) ; //to generate more delay you can use two for loops
   }

Proteous Simulation of above code is here



No comments:

Post a Comment

Compiler for C,C++ and Python {paste your programme to see the output}