You have no items in your shopping cart.

Subtotal:Rs.0.00
8051 Boards

8051 Tutorial-Create a square wave of 50% duty cycle on Port1

8051-tutorial-create-a-square-wave-of-50-duty-cycle-on-por-2

‘C’ Program to generate a square wave of 50% duty cycle on port1 using 8051 microcontroller

#include<reg51.h>                         //Define 8051 Registers

void DelayMs(unsigned int a);             //Delay function

sbit Port1=P1^0;                          //Set the bit in P1^0

//————————-

//       Main Program

//————————-

void main()

{

while(1)                            //Loop forever

{

Port1 = 1;                    //Set the bit0 in port1 to high

DelayMs(200);                 //Delay time for 20ms

Port1 = 0;                    //Set the bit0 in port1 to low

DelayMs(200);                 //Delay time for 20ms

}

}

///—————————————-

// DELAY at 11.0592MHz crystal.

// Calling the routine takes about 22us, and then

// each count takes another 1.02ms.

//—————————————-

void DelayMs(unsigned int count)

{

unsigned int i;

while(count)

{

i = 115;

while(i>0) i–;

count–;

}

}

 

Tags : 8051 program8051 projects8051 source code8051 Tutorial-Create a square wave of 50% duty cycle on Port1
Pantech

The author Pantech