Knowledge Base
...
Applied PIC Micro Development
Basics: Working With Hardware
DIP Switches
7min
lead in dip switches have featured extensively in many systems especially where either addressing, unit configuration, or some such similar feature is needed prior to windows 95 "plug and play", the only way to configure the base address of an add on card was by using a dip switch bank dip switch banks are not as common as they used to be, however, they are still available for purchase and remain an uncomplicated way of introducing a "low level" form of human to system interface to configure a unit physical layout dip (dual in line package) switches are available from a single switch to 20 or more they are usually the same size as an equivalent ic holder and have tell tale numbering and small white switches that move horizontally a 4 bit or 4 position lineart example is shown below to illustrate their operation the "on" or "closed" position is labeled on the surface of the set of switches moving the switch into the "on" position closes the circuit moving the switch to the "off" or opposite position opens the circuit moving the switches is best done using a small screw driver along the lines of a "jeweler" set they are available in dip through hole and smt variants implementation implementation can be done in two ways, used as a switch used to represent data used as a switch when used in this manner, the switch may be used to configure a voltage level or power setting for example, on the radix duo, the voltage selection is made using enabling the correct dip switch if used in conjunction with a microcontroller the change in the setting can be read and used to configure a setting in the code sample below, the pin is held hi which is the off position when the switch is moved to the on position the input is pulled to ground as shown in the code sample below, this change can be used when the mcu is powered up to configure a setting //ensure to configure the analog and comparator for your respective device void deviceop(){ if(!portb b0){ // perform function } else{ //reset condition } } void main(){ trisb = 0b00000001; portb = 0x00; deviceop(); while(1){ // run system } } used to represent data when used to represent data, the bank of dip switches would be read simultaneously; all the inputs would be read at the same time when you recall your base 2 or binary maths, then 2^0 = 1, 2^1 = 2, 2^2 = 4, , 2^7 = 128 depending on which switches are enabled, you have a numerical value from 0 to 255 which can be selected //ensure to configure the analog and comparator for your respective device char adrvalu; void deviceop(){ if(!porta b0){ // device is master } else{ //device is slave } adrvalu = portb; } void main(){ trisa = 0b00000001; trisb = 0b11111111; porta = 0x00; portb = 0x00; deviceop(); while(1){ // run the system using the address value } the address value can be used for an ask docid\ bo64tfeviqaou6bfg4pfh based system or an rs485 system if you were implementing an ethernet system, then this 8 bit bank could be used to configure the last octet for example 192 168 1 \[adrvalu] lead out while a little "old school", dip switches remain a useful technique for either configuring a setting or providing data in the form of an address they are fairly cheap and readily available from most electronic suppliers implementation for pcb design is simple using a standard dip package according to the number of switches in the package you have chosen