Hello all,
I am currently working with AT89C51CC01. I am new in Embedded programming. One can see the Datasheet fron the following link.
Atmel - Page Not Found
My work is to make program which gives PWM as output. Just check this code for this.
#include <stdio.h>
#include <reg51.h> // Header file
#define PWMPIN P1_0
unsigned char pwm_width;
void main(void)
{
pwm_setup();
}
void pwm_setup()
{
TMOD = 0; // Timer/Counter Mode Control Register
pwm_width = 160;
EA = 1; // Set to enable all interrupts.
ET0 = 1; // Set to enable timer 0 overflow interrupt.
TR0 = 1; // run control bit [Clear to turn off Timer/Counter 0]
}
/*
void timer0() interrupt 1 {
if(!F0) { //Start of High level
F0 = 1; //Set flag
PWMPIN = 1; //Set PWM o/p pin
TH0 = pwm_width; //Load timer
TF0 = 0; //Clear interrupt flag
return; //Return
}
else { //Start of Low level
F0 = 0; //Clear flag
PWMPIN = 0; //Clear PWM o/p pin
TH0 = 255 - pwm_width; //Load timer
TF0 = 0; //Clear Interrupt flag
return; //return
}
}
*/
when i use interrupt function then program not working.
can anyone tell me what is the problem in this interrupt code?
I have also Oscilloscope to check the PWM signal through MCU.
can anyone know that how can i set o/p pin for PWM?
At which frequency can i give to MCU for PWM o/p?
Thanks in advance.
I am currently working with AT89C51CC01. I am new in Embedded programming. One can see the Datasheet fron the following link.
Atmel - Page Not Found
My work is to make program which gives PWM as output. Just check this code for this.
#include <stdio.h>
#include <reg51.h> // Header file
#define PWMPIN P1_0
unsigned char pwm_width;
void main(void)
{
pwm_setup();
}
void pwm_setup()
{
TMOD = 0; // Timer/Counter Mode Control Register
pwm_width = 160;
EA = 1; // Set to enable all interrupts.
ET0 = 1; // Set to enable timer 0 overflow interrupt.
TR0 = 1; // run control bit [Clear to turn off Timer/Counter 0]
}
/*
void timer0() interrupt 1 {
if(!F0) { //Start of High level
F0 = 1; //Set flag
PWMPIN = 1; //Set PWM o/p pin
TH0 = pwm_width; //Load timer
TF0 = 0; //Clear interrupt flag
return; //Return
}
else { //Start of Low level
F0 = 0; //Clear flag
PWMPIN = 0; //Clear PWM o/p pin
TH0 = 255 - pwm_width; //Load timer
TF0 = 0; //Clear Interrupt flag
return; //return
}
}
*/
when i use interrupt function then program not working.
can anyone tell me what is the problem in this interrupt code?
I have also Oscilloscope to check the PWM signal through MCU.
can anyone know that how can i set o/p pin for PWM?
At which frequency can i give to MCU for PWM o/p?
Thanks in advance.