;;The objective of this code is to beable to choose a value and beable to wirelessly transmit a value to another module. When a value is recieved it is stored in memory and rotated with other values recoeved ;;;;;;;;; ; logic ; ;;;;;;;;; ; Main routine : Continuously update the displays ; Interupts: IOCB INTONRECIEVE ; Inputs: UP, DOWN, SEND, ; Outputs: CurrentVal,FirstDisp,SecondDisp,ThirdDisp,FourthDisp (7Seg) ; Pool for button press depending on situation change CURRENTVAL or transmit it. ; ; #include __config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF) org 0 ;Declare Variables cblock 0x20 DISPLAY FIRSTDISP SECONDDISP THIRDDISP FOURTHDISP CURRENTDISP STATUS_TEMP TEMP DELAY1 DELAY2 GROUND W_TEMP endc goto PORTS ;Skip interupt ;;;;;;;;;;;;;; ; INTERUPT ; ;;;;;;;;;;;;;; org 0x04 INTERUPT: bcf INTCON,7 ;Turn off interupts movwf W_TEMP ; Move W to temp bcf STATUS,RP0 ; Goto bank 0 bcf STATUS,RP1 ; Goto bank 0 btfsc INTCON,0 ; Check for IOCA/B int goto BUTTONPRESS ; Yes, goto buttonpress routine btfss PIR1,RCIF ; No, Check if value recieved goto OUT ; No, leave interupt call RX ; Yes , recieve the value OUT: ; movf W_TEMP,w ; Restore W bcf PIR1,RCIF ; Clear flag bcf INTCON,0 ; Clear flags bsf INTCON,7 ; Restart interupts retfie ; Return from interupt BUTTONPRESS: btfss PORTA,3 ;Check first button call INCREASE ;Goto said function btfss PORTB,4 ;Check Decrement button pressed, call DECREASE ;Goto Said function btfss PORTB,6 ;Check if TX button pressed call TX ; Goto TX routine call DELAY ; Button Debounce goto OUT INCREASE: incf DISPLAY ;Increment display movlw 0x0A ; Move 10d to W bcf STATUS,2 ;Clear Z bit subwf DISPLAY,w ;Subtract w from display btfsc STATUS,2 ;Check if z bit set clrf DISPLAY ; Yes, clear display return ; no, return DECREASE: incf DISPLAY ;Increment display (incase 0) bcf STATUS,2 ;Z bit decf DISPLAY ;Decrement display btfsc STATUS,2 ; Check z bit goto INITIALIZE ;Yes, reinitialize the display decf DISPLAY ;No, Decrement display return INITIALIZE: movlw 0x09 ;Move 9d to w movwf DISPLAY ; Move it to display return TX: btfss PIR1 , TXIF ; TXIF is set if TXREG has no character goto $-1 ; Loop until TXIF is cleared movf DISPLAY,w ; Data to be transmitted over serial port movwf TXREG ; Copy data to transmit register bsf STATUS,RP0 ; RAM PAGE 1 btfss TXSTA , TRMT ; Wait until transmission is completed goto $-1 ; Loop back until transmission completed bcf STATUS,RP0 ; Bank 0 return RX: btfss PIR1,RCIF ; Wait for value to be recieved goto $-1 ; loop bcf PIR1,RCIF ; Clear flag movf RCREG,w ; Move recieved word to w movwf TEMP ; then to var temp clrf FOURTHDISP ;Clear 4th display <- 3rd Disp <- Second Display <- First Display <- Temp movfw THIRDDISP movwf FOURTHDISP movfw SECONDDISP movwf THIRDDISP movfw FIRSTDISP movwf SECONDDISP movfw TEMP movwf FIRSTDISP return DELAY: ; Generic Dela routine decfsz DELAY1 goto DELAY decfsz DELAY2 goto DELAY return PORTS: ; Analog bsf STATUS,RP1 ; Bank 2 clrf ANSEL ; All pins are digital I/O clrf ANSELH ; All pins are digital I/O bcf STATUS,RP1 ; Bank 0 ; Tris bsf STATUS,RP0 ; goto bank 1 movlw 0x00 ; Move the hex value of 0 to multi purpose register W movwf TRISC ; make IO PortC all output movlw b'01010000' ; Move move b'01010000' to w movwf TRISB ; move to tris movlw b'00001000' ;Make porta.3 input rest output movwf TRISA bcf STATUS,RP0 ; goto bank 0 ;Interupt bsf INTCON,7 ;Set up global interupts bsf INTCON,6 ;Peripferal Interupts bsf INTCON,3 ; IOCA/B interupt bsf STATUS,RP0 ; Bank 1 bsf PIE1,5 ; Enable Interupt on Recieve bcf STATUS,RP0 ; Bank 0 bcf PIR1,RCIF ; Clear Flag bcf INTCON,0 ; IOCA/B change flag ; IOCB bsf STATUS,RP1 ;Bank2 movlw b'01010000' ; Make ports 4 and 6 IOC movwf IOCB bcf STATUS,RP1 bsf STATUS,RP0 ;Bank1 ; IOCA movlw b'00001000' ;Make porta.3 IOC movwf IOCA ;serial comm transmit movlw d'25' ; Move the value of 25 or 0x19, to the baud rate genrator movwf SPBRG ; this will make the baud rate = to 9600 at a 4mhz internal clock in high speed mode bsf TXSTA,BRGH ;baud rate high bsf TXSTA,TXEN ;Enable Transmision bcf TXSTA,SYNC ;asyncronous bcf STATUS,RP0 ;Exit bank 1 ;Serial comm Recieve bsf RCSTA,SPEN ;Set serial port enable high bsf RCSTA,CREN ; Enable reciever ; Initalize clrf DISPLAY clrf FIRSTDISP clrf SECONDDISP clrf THIRDDISP clrf FOURTHDISP movlw 0x01 ;Move 0x01 to ground movwf GROUND movlw 0x20 ;Start pointer at DISLAY location: 0x20 movwf FSR ;;;;;;;;;;;;;;;;;; ; MAIN ROUTINE ; ;;;;;;;;;;;;;;;;;; MAIN: bsf STATUS,RP0 ;goto bank 1 and turn off display movlw 0xff movwf TRISA movlw 0xff movwf TRISC bcf STATUS,RP0 ;bank 0 ;Begin rotate movfw INDF call TABLE movwf PORTC movfw GROUND movwf PORTA ;Turn on Displays bsf STATUS,RP0 movlw 0x00 ; Move the hex value of 0 to multi purpose register W movwf TRISC ; make IO PortC all output movlw b'00001000' ; Make porta all input movwf TRISA bcf STATUS,RP0 ;Finish rotating rlf GROUND call RA3 incf FSR movlw 0x25 bcf STATUS,2 subwf FSR,w btfsc STATUS,2 call CLEAR goto MAIN RA3: btfss GROUND,3 return rlf GROUND return CLEAR: movlw 0x20 movwf FSR movlw 0x01 movwf GROUND return TABLE: ;Generic lookup table addwf PCL ; 1; retlw b'00111111';0 ;;;;;;; retlw b'00000110';1 6 ; ; 2 retlw b'01011011';2 ; 7 ; retlw b'01001111';3 ;;;;;;; retlw b'01100110';4 5 ; ; 3 retlw b'01101101';5 ; ; retlw b'01111100';6 ;;;;;;; retlw b'00000111';7 4 retlw b'01111111';8 retlw b'01100111';9 return end ;end