Puch Buttons Status .

Status
Not open for further replies.

kail123

Newbie level 4
Joined
Jan 23, 2013
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,331
Guys , i really need urgent help regarding push buttons .

i connected one button to RA0 and Led to PWM1 and i tried to increase the brightness and decrease it by one button , the problem is i can not keep the status of the led and the button , if increase it to 64 and released the button,, the led will go back again to previous status and will be OFF . i want every time i press the button to increase the duty to 25 percent and if i released the button i should have the last calculation . my issue how to use one button to control that .??
 

Microcontroller?
c language or assembly?
Compiler name?
These are missing in your post.

- - - Updated - - -

If you use pic microcontroller and microc check this site
embedded-lab.com/blog/?p=1443
 

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);


}
 

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