hello all, I m working with AT89C51CC01. My task is to generate PWM as required n stop when not required. For this i had make one program in Keil uVision4. Check the code as follows.
#include <stdio.h> #include "reg_c51.h" void Init(void) { CCON = 0x00; CR = 0x00; P1 = 0x00; } void Init_PWM_Open(void) { CMOD = 0x02; // Setup PCA timer CL = 0x00; CH = 0x00; CCAPM2 = 0x42; // PWM mode. CCAPM4 = 0x42; // PWM mode. CR = 1; // Start PCA Timer. } void main() { Init(); while(1) { if(P2_0 == 1) { Init_PWM_Open(); } else { Init(); } } }
what i expect from this code is:: when P2_0 is 1 then in PCA module 2 n 4 have start to generate PWM..n then when P2_0 is 0 then all pins of P1 must be 0.
But the problem is when i start to run program all Pins of P1 is 0..then when P2_0 is 1 then it generate PWM..but after that when i make P2_0 to 0 then both pins of P1 (module 2 n 4) r remains 1, while i had in Init() write P1 = 0x00 so must port P1 is 0. I want to generate PWM n then when the state of P2_0 is changed then i want to use PCA modules as normal pins of P1.
In datasheet of AT89C51CC01 write that one can stop PCA with CR bit. I had also stop CR in Init() CR = 0x00;..but it´s not give expected o/p.
if u have keil uvision4 s/w then check the performance of this code using simulator.
please help me for this problem or give any other idea or suggestion as early as possible. Thanks in advance.