Set (Interrupt) PWM signal as output for AT89C51CC01

Status
Not open for further replies.

pshaik

New Member
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.
 
u cant define port pin in this manner(#define PWMPIN P1_0). this simply define portP1 not Port pin

if u want to set port1 then it is ok...if u want set port pin i.e P1.0 then put sbit PWMPIN =P1^0;

and also use while(1) loop for forever like
void main(void)
{
while(1)
{
pwm_setup();
}

}
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…