Grimmjow
Joined: 15 Apr 2009 Posts: 10
|
16f628a dimmer, simple problem |
Posted: Tue Jul 28, 2009 10:51 am |
|
|
Hi there!!
Here is the code:
Code: | #include <16f628a.h>
#fuses INTRC_IO,NOPUT,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,NOMCLR
#use delay (clock=4M)
void main(){
int inc = 0;
int counter = 0;
setup_ccp1(CCP_PWM); // CCP1 set as PWM
setup_timer_2(T2_DIV_BY_16,32,1); // timer2 set at 2 kHz
set_pwm1_duty(inc);
while(TRUE){
if(input(PIN_A0)){
while(input(PIN_A0)){
}
if(counter<4){
inc = inc + 8;
counter++;
}
}
if(input(PIN_A1)){
while(input(PIN_A1) && inc>0){
}
if(counter>0){
inc = inc - 8;
counter--;
}
}
set_pwm1_duty(inc);
}
}
|
Code does the following:
- When a button that is connected to PIN_A0 is pushed, LED is turned on with a duty cycle of 25%.
- Similarly, when a button that is connected to PIN_A1 is pushed, LED is dimmed with a duty cycle of 25%.
Code works but veeerrrryyyy slow LED responds approximately after 15 seconds each time a button is pushed.
I don't think the root of the problem is hardware.
Thanks in advance... |
|