di2529.txt ;*************************************************************************************************** ; MICROCONTROLLER ASSEMBLY-LANGUAGE PROGRAM ; ; "Microcontroller multiplexes six digital potentiometers," EDN, May 11, 2000, pg 190 ; ; http://www.ednmag.com/ednmag/reg/2000/051100/designideas.htm#10di7 ;************************************************************************************************ : Written by Ted Salazar ;=============5160_di1.asm=====6/26/99 ; Design Idea for controlling up ; to six MAX5160 digital pots using ; the PIC16F84 with MUX circuitry. ; Porta0 =>up ; Porta1 =>down ;------------------------------------ list p=16f84 radix hex ;------------------------------------ ; Memory map pc equ 0x02 status equ 0x03 porta equ 0x05 portb equ 0x06 a0temp equ 0x0c a0temp_s equ 0x0d a1temp equ 0x0e a0xora1 equ 0x0f ncount equ 0x10 mcount equ 0x11 xcount equ 0x12 up_or_down equ 0x13 shift_r equ 0x14 ;------------------------------------ ;**** ;Main ;**** org 0x000 start movlw 0x00 ;0x00 to w tris portb ;portb all outputs movlw 0xff ;0xff to w movwf portb ;portb set high movlw 0xff ;0xff to w tris porta ;porta all inputs movf porta,w ;copy porta to w movwf a0temp ;w to a0temp movwf a1temp ;w to a1temp movwf a0temp_s;w to a0temp_s rlf a0temp_s,f ;shifts 1 bit left ;result in a0temp_s movf a0temp_s,w ; a0temp_s to w movwf a0xora1 ; w to a0xora1 movf a1temp,w ;a1temp to w xorwf a0xora1,f ;xor w and a0temp_s ;result in a0xora1 btfss a0xora1,1 ;skip if bit 1 is set goto start movf a0temp,w ;a0temp to w movwf up_or_down ;w to up_or_down movlw 0xff ;0xff to w andwf up_or_down,f ;"and" a0temp w/ 0xff ;result in up_or_down btfsc up_or_down,0 ;skip to "up" if clear goto down ;skipped to "up" call initialize call pick_cs_ call mux movwf portb ;w(cs_ to low) to portb nop bsf portb,7 ;set u/d\ high nop nop nop nop call increment nop nop nop nop call initialize call delay goto start ;------------------------------------ ; pick_cs_ Subroutine picks the correct ; cs_ to use by muxing A4 A3 A2 ; from porta. ; A4 A3 A2 ; 0 0 0 =>CS0 ; 0 0 1 =>CS1 ; 0 1 0 =>CS2 ; 0 1 1 =>CS3 ; 1 0 0 =>CS4 ; 1 0 1 =>CS5 ; 1 1 0 =>CS5 default to CS5 ; 1 1 1 =>CS5 default to CS5 ;******* pick_cs_ ;******* movf porta,w ;porta to w andlw 0x1c ;"and" 0x1c w\ porta ; a7,a6,a5,a4,a3,a2,a1,a0 ; 0 ,0 ,0 ,? ,? ,? ,X ,X ; 0 ,0 ,0 ,1 ,1 ,1 ,0 ,0 ; 0, 0 ,0 ,? ,? ,? ,0 ,0 movwf shift_r ;w to shift_r bcf status,0 ;clear carry flag rrf shift_r,f ;shift porta right 1 bit bcf status,0 ;clear carry flag rrf shift_r,f ;shift porta right 1 bit bcf status,0 ;clear carry flag movf shift_r,w ;shift_f to w return ;------------------------------------ ;------------------------------------ ; mux subroutine ; This sub uses a lookup table for ; 8 to 1 mux. Porta: a4(msb),a3,a2 ;***** mux ;***** addwf pc,f ;add w to pc retlw 0xfe ;clear cs0 to low retlw 0xfd ;clear cs1 to low retlw 0xfb ;clear cs2 to low retlw 0xf7 ;clear cs3 to low retlw 0xef ;clear cs4 to low retlw 0xdf ;clear cs5 to low retlw 0xdf ;clear cs5 to low retlw 0xdf ;clear cs5 to low ;------------------------------------ ;MAX5160 Initialize Subroutine ;This subroutine initializes the cs\, ;inc\ and u\d\ lines for the 5160. ;********* initialize ;********* movlw 0xff ;0xff to w movwf portb ;portb all high return ;------------------------------------ ; Increment Subroutine ; This Sub increments the pot by ; clearing inc\ to a low. This ; can mean an increment up or down. ;******** increment ;******** bcf portb,6 ;clear inc\ low nop nop nop nop return ;------------------------------------ ;down Subroutine ;This subroutine decrements the pot. ;******* down ;******* call initialize call pick_cs_ call mux movwf portb ;w(cs_ to low) to portb nop bcf portb,7 ;clears u/d\ low nop nop nop nop call increment nop nop nop nop call initialize call delay goto start ;------------------------------------ ;Delay Subroutine ;This subroutine utilizes nested loops ;to obtain a 2 second delay. ;The delay works in ~200ms intervals ;so change xcount to change the delay. ;For example, xcount=0x0a=10dec ;10 x 200ms = 2sec. ;**** delay ;**** movlw 0x0a ;0x0a to w movwf xcount ;to xcount loadm movlw 0xff ;0xff to w movwf mcount ;to mcount loadn movlw 0xff ;0xff to w movwf ncount ;to ncount decn decfsz ncount,f;dec n goto decn decfsz mcount,f;dec m goto loadn ;jump to loadn decfsz xcount,f;dec x goto loadm ;jump to loadm return ;------------------------------------ end ;------------------------------------ ;Blast time ; memory unprotected ; watchdog timer disabled ; 4Mhz standard Xtal ; power-up timer on ;====================================