Aseng
Newbie level 4
Everyone,
First of all, I am here is a newbie in this forum.
I am using a MikroC for compiler from Mikroelektronika, I want to build a PWM based on IC UC PIC16F877A, this code I copied paste from other in this forum, I try for few times to compile the project but his doesn't work, when I do simulate in a proteusView attachment pwm pic16f877a.7z.
So I need some help to correction what is going on this code problem.
This project is PWM, RA0 - RA7 is an input and the an output is RC0 -RC5, what I want is when I press RA0 then RC0 will up slowly and also for the rest.
So could you please help me to solved this matter.
On below is attached for the project.
View attachment pwm pic16f877a.7z
Many Thanks.
First of all, I am here is a newbie in this forum.
I am using a MikroC for compiler from Mikroelektronika, I want to build a PWM based on IC UC PIC16F877A, this code I copied paste from other in this forum, I try for few times to compile the project but his doesn't work, when I do simulate in a proteusView attachment pwm pic16f877a.7z.
So I need some help to correction what is going on this code problem.
This project is PWM, RA0 - RA7 is an input and the an output is RC0 -RC5, what I want is when I press RA0 then RC0 will up slowly and also for the rest.
So could you please help me to solved this matter.
On below is attached for the project.
Code:
sbit LED1 at RC0_bit;
sbit LED2 at RC1_bit;
sbit LED3 at RC2_bit;
sbit LED6 at RC3_bit;
sbit LED4 at RC4_bit;
sbit LED5 at RC5_bit;
#define SW_PORT PORTA
#define SW_TEST_VAL 0xD7
#define PWM_FREQ 5000
unsigned short gPwmDuty = 255;
void testButtonRelease() {
while((SW_PORT & 0xF7) != 0xF7);
}
void main() {
CMCON = 7;
TRISA = 0xFF;
TRISC = 0x00;
PORTA = 0x00;
PORTC = 0x00;
PWM1_Init(PWM_FREQ);
PWM1_Set_Duty(gPwmDuty);
PWM1_Start();
while(1) {
if((SW_PORT & SW_TEST_VAL) == 0xD6) {
Delay_ms(80);
testButtonRelease();
LED1 = ~LED1;
}
else if((SW_PORT & SW_TEST_VAL) == 0xD5) {
Delay_ms(80);
testButtonRelease();
LED2 = ~LED2;
}
else if((SW_PORT & SW_TEST_VAL) == 0xD3) {
Delay_ms(80);
testButtonRelease();
LED3 = ~LED3;
}
else if((SW_PORT & SW_TEST_VAL) == 0xC7) {
Delay_ms(80);
testButtonRelease();
LED4 = ~LED4;
}
else if((SW_PORT & SW_TEST_VAL) == 0x97) {
Delay_ms(80);
testButtonRelease();
if((gPwmDuty >= 0) && (gPwmDuty <= 254)) {
gPwmDuty++;
PWM1_Set_Duty(gPwmDuty);
}
}
else if((SW_PORT & SW_TEST_VAL) == 0x57) {
Delay_ms(80);
testButtonRelease();
if((gPwmDuty <= 255) && (gPwmDuty > 0)) {
gPwmDuty--;
PWM1_Set_Duty(gPwmDuty);
}
}
}
}
Many Thanks.