john120
Banned
- Joined
- Aug 13, 2011
- Messages
- 257
- Helped
- 11
- Reputation
- 22
- Reaction score
- 10
- Trophy points
- 1,298
- Activity points
- 0
looks like a standard keypad switch. These usually have a dome switch underneath, or a carbon resistive contact against the PCB.
Chances are that its just got a bit dirty and some cleaning is required. Carbon-tetra-chloride ( CCl4) used to be popular for such purposes.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 //mikroC Code #define SW1 PORTB.F0 if(SW1){ Delay_ms(50) if(SW1){ //Do what you want here } } //MPLAB C18 or Hi-Tech or XC8 C Code #define SW1 PORTBbits.RB0 if(SW1){ _delay_ms(50) if(SW1){ //Do something } }
The buttons are just ordinary TACT switches and when button is pressed the corresponding uC pin to which the switch is wired becomes high. You need to check if pin is high with a debounce delay.
Example C code, If switch is connected to RB0 then
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 //mikroC Code #define SW1 PORTB.F0 if(SW1){ Delay_ms(50) if(SW1){ //Do what you want here } } //MPLAB C18 or Hi-Tech or XC8 C Code #define SW1 PORTBbits.RB0 if(SW1){ _delay_ms(50) if(SW1){ //Do something } }
I have already mentioned the code. If your are using AVR Studio or Atmel Studio then change #define SW1 PORTB.F0 to #define SW1 PINC0. This is for switch 1. Write similar codes for SW2, SW3, SW4.
You don't need any adc to read the switch. If multiple switches are connected to the same pin then adc is used to detect the switch pressed and for that each button will place a different voltage at the adc input pin. For your circuit you need to use digital input pin to read the switches and I have already given the code for one switch. Write similar code for the other switches. For my code when button is pressed pin becomes 1 (high) and depending upon that some code is executed. The voltage at the digital input pin should be >= VIH for a high condition.
Remove the resistors between buttons and uC pins.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?