di2483.txt ;************************************************************************************************ ; LISTING 1--MULTIPLEXING DIP SWITCHES TO SINGLE I/O PORT ; ; "uC multiplexes DIP switches to I/O port," EDN, Feb 17, 2000, pg 150 ; http://www.ednmag.com/ednmag/reg/2000/02172000/designideas.htm#04di3 ;*********************************************************************************************** ;Microcontroller Multiplexes Multiple DIP Switches to Single I/O Port ;Author: Gregg Willson, ACS Defense, Inc. ;Define constants list p=16c63 #include "c:\mpasm\P16C63.inc" ;Define RAM storage locations for DIP switch values TMP0 equ h'20' TMP1 equ h'21' TMP2 equ h'22' TMP3 equ h'23' ;Main Routine Read_32_DIP_Switches call Initialize_Ports ;Setup ports for multiplexing movlw b'11111110' ;Get ready to make port A, bit 0 an output call Read_DIP_Sw ;Read the first DIP switch movwf TMP0 ;Save in temporary register movlw b'11111101' ;Get ready to make port A, bit 1 an output call Read_DIP_Sw ;Read the second DIP switch movwf TMP1 ;Save it movlw b'11111011' ;Get ready to make port A, bit 2 an output call Read_DIP_Sw ;Read the third DIP switch movwf TMP2 ;Save it movlw b'11110111' ;Get ready to make port A, bit 3 an output call Read_DIP_Sw ;Read the fourth DIP switch movwf TMP3 ;Save it return ; DONE ;Subroutines Initialize_Ports bcf STATUS, RP0 ;Select register Bank 0 movlw b'00000000' ;Default port A outputs to 0 to ground switches movwf PORTA bsf STATUS, RP0 ;Select register Bank 1 movlw b'11111111' ;Make port B all inputs movwf TRISB movwf TRISA ;Make port A all inputs initially bcf OPTION_REG, 7 ;Option: Enable weak internal pullups on port B return Read_DIP_Sw ;Enable DIP Switch based on W register value bsf STATUS, RP0 ;Select register Bank 1 movwf TRISA ;DIP switch is now selected ;Read the data bcf STATUS, RP0 ;Select register Bank 0 movf PORTB, W ;Put switch values in W register return END