;controls two dual 7 segment diplays. ;Recieves values via SPI from another PIC ; porta, 0 is data (input) for spi with primary pic ; porta, 1 is clock (input) for spi with primary pic ; porta, 2 is cs (input) for spi with primary pic ; portb, 0-3 are 4 bits to be sent to 7447 ; portb, 7 is to activate the mosfet that controls the upper digit of target speed ; portb, 6 is to activate the mosfet that controls the lower digit of target speed ; portb, 5 is to activate the mosfet that controls the upper digit of actual speed ; portb, 4 is to activate the mosfet that controls the lower digit of actual speed ;----------------------------------------------------------------------------------------------- LIST P=16F84 errorlevel 0,-305 INCLUDE "P16F84.inc" __CONFIG _CP_OFF & _WDT_OFF & _XT_OSC & _PWRTE_ON ;----------------------------------------------------------------------------------------------- aspeed equ 0c ; actual speed tspeed equ 0d ; target speed hspace equ 0e ; space for holding misc information cbit equ 0f ; counter for inbyte subroutine databyte equ 10 ; data recieved from primary pic via inbyte subroutine is dumped into this file register espace equ 11 ; hex to dec gspace equ 12 ; hex to dec ;----------------------------------------------------------------------------------------------- setup org 0 clrf portb ; clears all the bits in portb clrf porta ; clears all the bits in porta clrf status ; clears all the bits in status bsf status, rp0 ; switches to bank 1 movlw 0 ; --> movwf trisb ; sets portb as output movlw H'ff' ; --> movwf trisa ; sets porta as input bcf status, rp0 ; switches back to bank 0 ;----------------------------------------------------------------------------------------------- init movlw H'88' ; --> movwf tspeed ; set target speed movlw H'88' ; --> movwf aspeed ; set actual speed loop movf tspeed, w ; --> andlw H'f0' ; isolate the upper 4 digits of target speed and store in hspace movwf hspace ; --> swapf hspace, w ; store the upper 4 digits of target speed (obtained from hspace) as the lower 4 digits of w iorlw H'80' ; set w to 1000xxxx (activates mosfet attached to pin 10) movwf portb ; send the message btfss porta, 2 ; check cs on primary pic to see if there is a message for us call getmsg ; if cs is low, recieve message from primary pic movf tspeed, w ; --> andlw H'0f' ; isolate the lower 4 digits of target speed and store in w iorlw H'40' ; set w to 0100xxxx (activates mosfet attached to pin 11) movwf portb ; send the message btfss porta, 2 ; check cs on primary pic to see if there is a message for us call getmsg ; if cs is low, recieve message from primary pic movf aspeed, w ; --> andlw H'f0' ; isolate the upper 4 digits of actual speed and store in hspace movwf hspace ; --> swapf hspace, w ; store the upper 4 digits of actual speed (obtained from hspace) as the lower 4 digits of w iorlw H'20' ; set w to 0010xxxx (activates mosfet attached to pin 12) movwf portb ; send the message btfss porta, 2 ; check cs on primary pic to see if there is a message for us call getmsg ; if cs is low, recieve message from primary pic movf aspeed, w ; --> andlw H'0f' ; isolate the lower 4 digits of actual speed and store in w iorlw H'10' ; set w to 0001xxxx (activates mosfet attached to pin 13) movwf portb ; send the message btfss porta, 2 ; check cs on primary pic to see if there is a message for us call getmsg ; if cs is low, recieve message from primary pic goto loop ; back to the begining ;=============================================================================================== datarol movlw H'64' subwf databyte, w btfss status, c goto proc1 movlw H'64' subwf databyte, f proc1 movf databyte, w movwf espace movlw H'00' movwf gspace movlw H'0a' cutit subwf espace, f btfss status, c goto printit incf gspace, f goto cutit printit btfsc gspace, 0 goto notz btfsc gspace, 1 goto notz btfsc gspace, 2 goto notz btfss gspace, 3 return notz movf gspace, w movwf espace movlw H'0a' down subwf databyte, f decfsz espace, f goto down swapf gspace, w iorwf databyte, f return ;=============================================================================================== ; if you can't figure this out you deserve a kick ;----------------------------------------------------------------------------------------------- getmsg call inbyte call datarol movf databyte, w movwf tspeed call inbyte call datarol movf databyte, w movwf aspeed return ;=============================================================================================== ; "inbyte" subroutine gets a byte from the primary pic ; porta, 0 is data (input) ; porta, 1 is clock (input) ; porta, 2 is cs (input) ;----------------------------------------------------------------------------------------------- inbyte movlw H'08' ; --> movwf cbit ; set up the eight cycles for sending 8 bits cloop btfss porta, 1 ; --> goto cloop ; when clock goes up it will stop waiting btfss porta, 0 ; check data bcf databyte, 0 ; if data was a 0 record a 0 btfsc porta, 0 ; if data was a 0 don't do command for if data was a 1 bsf databyte, 0 ; if data was a 1 record a 1 rlf databyte, f ; line up the next bit aloop btfsc porta, 1 ; --> goto aloop ; when clock goes down it will stop waiting decfsz cbit, f ; -- goto cloop ; -- rrf databyte, f ; line up the next bit return ; -- ;=============================================================================================== end ; --