Knowledge Base
...
Applied PIC Micro Development
Basics: Working With Hardware
Rotary BCD Switch
5min
lead in in the previous topic, we investigated the 8 bit dip bank, where the switches could represent simple switches or coded binary the rotary coded switch is an intuitive piece of hardware, where depending on the position of the switch, a specific bcd value is available see also bcd binary coded decimal docid\ cw743n662tsrc7eil r4n working with the rotary switch shown below is a wurth electronic rotary switch, with the nine positions labeled on the switch when used in a project, and installed in a target pcb, the switch produces a coded decimal output, which translates to the same position on the dial the four input bits would then be wired or connected to the mcu the pinout and dimensional specifications are shown below bcd implementation you may have to stretch your memories back to the books to when you first learned about bcd (binary coded decimal) inspecting the pin layout of the switch below the implementation can be straightforward what the truth table indicates are the outputs that will be conducting, depending on the position wired up to the microcontroller and read in the same way as the dip switch discussed previously, the rotary switch is an alternative to the dip switch bank it is important to note that although the switch's output is bcd, it only provides 0 9 in decimal code sample //ensure to configure the analog and comparator for your respective device char bcdvalu; void deviceop(){ bcdvalu = porta; } void main(){ trisa = 0b00001111; trisb = 0b11111111; porta = 0x00; portb = 0x00; deviceop(); while(1){ // perform application tasks } lead out implementing the rotary switch does require taking into consideration the value that is inputted if the rotary switch is connected to the lower 4 bits you have a bcd value