I am using 16f877
Mikro C .
i sued similar to the code in
https://embedded-lab.com/blog/?p=1443 but i changed to be for one button but was not working then i tried to use the MikroC Buttons library and i got same issue . the above example has tow buttons but i want to control the Led by one buttons only . any advice please .
- - - Updated - - -
I am using 16f877
Mikro C .
i sued similar to the code in http://embedded-lab.com/blog/?p=1443 but i changed to be for one button but was not working then i tried to use the MikroC Buttons library and i got same issue . the above example has tow buttons but i want to control the Led by one buttons only . any advice please .
- - - Updated - - -
This is My Code :
unsigned short current_duty, old_duty;
bit oldstate;
void Main() {
ADCON1=7;
PORTA = 255;
TRISA = 255; // configure PORTA pins as input
PORTB = 0; // set PORTB to 0
TRISB = 0; // designate PORTB pins as output
PORTC = 0; // set PORTC to 0
TRISC = 0; // designate PORTC pins as output
PWM1_Init(5000); // Initialize PWM1 module at 5KHz
old_duty = 0;
current_duty = 0; // initial value for current_duty
PWM1_Set_Duty (current_duty);
PWM1_Start(); // start PWM1
do {
if (oldstate && Button(&PORTA, 0, 1, 0)) {
Delay_ms(5);
}
if (old_duty < 255) {
old_duty = old_duty +60;
PWM1_Set_Duty (current_duty);
Delay_ms(60);
}
if (current_duty != old_duty){
current_duty = old_duty;
PWM1_Set_Duty (current_duty);
}
if (RA0_bit) { // button on RA0 pressed
Delay_ms(20);
portb.F7=1;
delay_ms(500);
}
Delay_ms(5);
}
while(1);
}