how to generate PWM in 8051



/*
developed by S4silver
license type - open source
created on - 11/12/2014
modified on - 11/14/2014
modification details - refactored
developer - Frank Hust Jincson
contact mail id - silverembeddedsolutions@gmail.com
web link - http://s4silver.blogspot.in/p/programmers-colony.html
*/

#include<reg51.h>
#define HIGH 1
#define LOW 0
sbit pwm_out_pin=P1^0;
bit pwm_pulse_flag=HIGH;
unsigned char x=15;
void pwm(void);
main()
{
TMOD=0x43;
pwm_out_pin=0;
while(1)
{
pwm_out_pin=~pwm_out_pin;
pwm();
}
}
void pwm()
{
if(pwm_pulse_flag==HIGH)
{
TL0=x;
TR0=1;
pwm_pulse_flag=LOW;
}
else
{
TL0=255-x;
x++;
if(x==0)
x=15;
TR0=1;
pwm_pulse_flag=HIGH;
}
while(!TF0);
TR0=0;
TF0=0;
}


People who look for this also look for the below topics

blinking of led or port
8051 interfacing DC motor
8051 interfacing with keypad
8051 interfacing with LCD
8051 interfacing with LCD and display Counter
LCD sample program
serial communication (RS-232) in 8051(polling method)
serial with interrupt
how to print serial received data on LCD.
8051 interfacing STEPPER motor
how to use TIMER in 8051
8051 interfacing SEVEN SEGMENT display
Timers with interrupt concept
how to generate PWM in 8051
4 bit LCD interfacing with 8051
8051 Tuitorial
how to install python
Embedded Documents (sensors, protocol...etc)  
Special NEWS

No comments:

Post a Comment