Please help support the site by donating at the link below.https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8ZRU34U47BESW
list p=12f683include <p12f683.inc>__config 0x0FB4errorlevel -302MODE EQU 0x70INNER EQU 0x71OUTER EQU 0x72w_temp EQU 0x73status_temp EQU 0x74MODE_temp EQU 0x75 ORG 0x0000 GOTO Main ORG 0x0004 ;;INTERRUPT BCF INTCON,GPIF ;;GPIO interrupt flag MOVWF w_temp MOVF STATUS,w MOVWF status_temp MOVF MODE,w MOVWF MODE_temp MOVLW 0x00 MOVWF GPIO CALL delay_256ms INCF MODE MOVF status_temp,w MOVWF STATUS SWAPF w_temp,f SWAPF w_temp,w RETFIEMain CLRF MODE ;;Set mode to zero CLRF INNER ;;Set inner to zero CLRF OUTER ;;Set outer to zero BSF STATUS,RP0 ;;Bank 1 CLRF ANSEL ;;Digital I/O MOVLW b'10001000' MOVWF INTCON MOVLW b'100000' MOVWF IOC ;;GP5 interrupt MOVLW b'101000' MOVWF TRISIO ;;GP3,5 inputs BCF STATUS,RP0 ;;Bank 0 CLRF GPIO MOVLW 0x07 MOVWF CMCON0 GOTO Main_LOOPdelay_256ms NOP DECFSZ INNER,f GOTO delay_256ms DECFSZ OUTER,f GOTO delay_256ms RETURNMain_LOOP MOVLW 0x00 ;;if mode 0 XORWF MODE,F BTFSC STATUS,Z ;;If MODE == W GOTO Sub_LOOP0 MOVLW 0x01 ;;if mode 1 XORWF MODE,F BTFSC STATUS,Z ;;If MODE == W GOTO Sub_LOOP1 MOVLW 0x02 ;;if mode 2 XORWF MODE,F BTFSC STATUS,Z ;;If MODE == W GOTO Sub_LOOP2 MOVLW 0x03 ;;if mode 3 XORWF MODE,F BTFSC STATUS,Z ;;If MODE == W GOTO Sub_LOOP3 MOVLW 0x04 ;;if mode 4 XORWF MODE,f BTFSC STATUS,Z GOTO Sub_LOOP_RESET GOTO Main_LOOPSub_LOOP0 ;;MODE 0 loop CLRF GPIO MOVLW 0xFF MOVWF GPIO ;;GPIO to HIGH CALL delay_256ms GOTO Main_LOOPSub_LOOP1 ;;MODE 1 loop CLRF GPIO MOVLW b'010110' MOVWF GPIO CALL delay_256ms GOTO Main_LOOPSub_LOOP2 ;;MODE 2 loop CLRF GPIO MOVLW b'010010' MOVWF GPIO CALL delay_256ms MOVLW b'000101' MOVWF GPIO CALL delay_256ms GOTO Main_LOOPSub_LOOP3 ;;MODE 3 loop CLRF GPIO MOVLW 1<<GP0 MOVWF GPIO CALL delay_256ms MOVLW 1<<GP4 MOVWF GPIO CALL delay_256ms MOVLW 1<<GP2 MOVWF GPIO CALL delay_256ms MOVLW 1<<GP1 MOVWF GPIO CALL delay_256ms GOTO Main_LOOPSub_LOOP_RESET CLRF MODEEND
For enabled interrupt-on-change pins, the values arecompared with the old value latched on the last read ofGPIO. The ‘mismatch’ outputs of the last read are OR’dtogether to set the GPIO Change Interrupt Flag bit(GPIF) in the INTCON register (Register 2-3).Theuser, in the Interrupt Service Routine, clears theinterrupt by:a) Any read or write of GPIO. This will end themismatch condition, then,b) Clear the flag bit GPIF.A mismatch condition will continue to set flag bit GPIF.Reading GPIO will end the mismatch condition andallow flag bit GPIF to be cleared.
Thank you for the reply! it's 4AM here Yes Mplab Sim is what i usually use to check my programsOk well my variables are fine...my interrupt seems to be whats holding me up ( i think it isnt exiting the interrupt properly but i;m unsure)As for the DECFSZim a bit more comfortable with XOR, but how would i be able to use DECFSZ to check MODE's value.or am i just decrementing instead of incrementing the value of MODE Im sure something can be figured out if my interrupt problem was fixed?!?
Main_LOOP MOVLW 0x00 ;;if mode 0 XORWF MODE,F BTFSC STATUS,Z ;;If MODE == W GOTO Sub_LOOP0 MOVLW 0x01 ;;if mode 1 XORWF MODE,F BTFSC STATUS,Z ;;If MODE == W GOTO Sub_LOOP1 MOVLW 0x02 ;;if mode 2 XORWF MODE,F BTFSC STATUS,Z ;;If MODE == W GOTO Sub_LOOP2 MOVLW 0x03 ;;if mode 3 XORWF MODE,F BTFSC STATUS,Z ;;If MODE == W GOTO Sub_LOOP3 GOTO Sub_LOOP_RESET ;;If MODE != 0,1,2,3Sub_LOOP0 ;;MODE 0 loop CLRF GPIO MOVLW 0xFF MOVWF GPIO MOVLW 0x01 ADDWF MODE ;;GPIO to HIGH GOTO Main_LOOPSub_LOOP1 ;;MODE 1 loop CLRF GPIO MOVLW b'010110' MOVWF GPIO MOVLW 0x01 ADDWF MODE GOTO Main_LOOPSub_LOOP2 ;;MODE 2 loop CLRF GPIO MOVLW b'010010' MOVWF GPIO ;CALL delay_256ms MOVLW b'000101' MOVWF GPIO ;CALL delay_256ms MOVLW 0x01 ADDWF MODE GOTO Main_LOOPSub_LOOP3 ;;MODE 3 loop CLRF GPIO MOVLW 1<<GP0 MOVWF GPIO ;CALL delay_256ms MOVLW 1<<GP4 MOVWF GPIO ;CALL delay_256ms MOVLW 1<<GP2 MOVWF GPIO CALL delay_256ms ;MOVLW 1<<GP1 MOVWF GPIO ;CALL delay_256ms MOVLW 0x01 ADDWF MODE GOTO Main_LOOPSub_LOOP_RESET CLRF MODEEND
movlw 0x01 subwf MODE, w btfsc STATUS, Z goto Sub_Loop0 movlw 0x02 subwf MODE, w btfsc STATUS, Z goto Sub_Loop1
list p=12f683include <p12f683.inc>__config 0x0CB4 ;Oscillator = Internal RC NO clock ;Watchdog = OFF ;Power up timer = OFF ;MCE = EXTERNAL ;Configuration ;Code Protect = ON ;EE read protect = OFF ;BOD = BOTH OFF ;IESOM = ENABLED ;Monitor Clock safe = ENABLED errorlevel -302 ;Block error in list fileMODE EQU 0x70 ;Mode counterINNER EQU 0x71 ;Inner loop counterOUTER EQU 0x72 ;Outer loop counterw_temp EQU 0x73 ;Work tempstatus_temp EQU 0x74 ;STATUS tempBIT EQU 0x75 ;Interrupt Flag for incrementing;OUTER128 EQU 0x76 ;Counter for 128ms delay;OUTER64 EQU 0x077 ;Counter for 64ms delay ORG 0x0000 GOTO Declarations ;To declare everything ORG 0x0004 ;|=-INTERRUPT-=| MOVWF w_temp ;WORK saved MOVF STATUS,w ;STATUS saved MOVWF status_temp BTFSC GPIO,GP5 CALL Button_Pressed ;Executes interrupt code MOVF status_temp,w MOVWF STATUS ;Restore STATUS SWAPF w_temp,f ;Restore WORK SWAPF w_temp,w BCF INTCON,GPIF RETFIE Declarations CLRF MODE ;Set MODE to 0 CLRF INNER ;Set INNER to 0 CLRF OUTER ;Set OUTER to 0 BSF STATUS,RP0 ;Bank 1 CLRF ANSEL ;Digital I/O MOVLW b'10001000' MOVWF INTCON ;Global and GPIO interupt MOVLW b'100000' MOVWF IOC ;GP5 interrupt MOVLW b'101000' MOVWF TRISIO ;GP3,5 inputs BCF STATUS,RP0 ;Bank 0 CLRF GPIO MOVLW 0x07 MOVWF CMCON0 ;Comparators off GOTO Main_Loop delay ;Defaults to roughly 256ms unless value is moved into outer before call NOP DECFSZ INNER,f GOTO delay ; ~1023 cycles = 1ms DECFSZ OUTER,f GOTO delay ; 1ms * 256 = 256ms RETURN MODE_INCREMENT ;Only called once the interrupt has, adds 1 to MODE, RETURNS to Main loop INCF MODE CLRF BIT GOTO Main_Loop Main_Loop MOVLW 0x01 SUBWF BIT,w BTFSC STATUS,Z ;if interrupt has been called increment MODE GOTO MODE_INCREMENT MOVLW 0x01 SUBWF MODE,w BTFSC STATUS,Z ;IF MODE==1 GOTO Sub_LOOP1 MOVLW 0x02 SUBWF MODE,w BTFSC STATUS,Z ;IF MODE==2 GOTO Sub_LOOP2 MOVLW 0x03 SUBWF MODE,w BTFSC STATUS,Z ;IF MODE==3 GOTO Sub_LOOP3 MOVLW 0x04 SUBWF MODE,w BTFSC STATUS,Z ;IF MODE==4 GOTO Sub_LOOP4 MOVLW 0x05 SUBWF MODE,w BTFSC STATUS,Z ;IF MODE==5 GOTO Sub_LOOP5 MOVLW 0x06 SUBWF MODE,w BTFSC STATUS,Z ;IF MODE==6 GOTO Sub_LOOP6 MOVLW 0x07 SUBWF MODE,w BTFSC STATUS,Z ;IF MODE==7 GOTO Sub_LOOP7 MOVLW 0x08 SUBWF MODE,w BTFSC STATUS,Z ;IF MODE==8 GOTO Sub_LOOP8 GOTO Sub_LOOP_RESETSub_LOOP1 CLRF GPIO ;MODE 1 loop GOTO Main_LoopSub_LOOP2 ;MODE 2 loop MOVLW b'010111' MOVWF GPIO GOTO Main_LoopSub_LOOP3 ;MODE 3 loop MOVLW b'010111' MOVWF GPIO CALL delay CALL delay CLRF GPIO CALL delay CALL delay GOTO Main_LoopSub_LOOP4 ;MODE 4 loop MOVLW 1<<GP0 MOVWF GPIO CALL delay MOVLW (1<<GP0|1<<GP4|1<<GP1) MOVWF GPIO CALL delay MOVLW b'010111' MOVWF GPIO CALL delay CLRF GPIO CALL delay GOTO Main_LoopSub_LOOP5 ;MODE 5 loop MOVLW 1<<GP2 MOVWF GPIO CALL delay MOVLW (1<<GP2|1<<GP4|1<<GP1) MOVWF GPIO CALL delay MOVLW b'010111' MOVWF GPIO CALL delay CLRF GPIO CALL delay GOTO Main_LoopSub_LOOP6 ;MODE 6 loop MOVLW b'000101' MOVWF GPIO CALL delay MOVLW b'010010' MOVWF GPIO CALL delay GOTO Main_LoopSub_LOOP7 ;MODE 7 loop MOVLW 1<<GP0 MOVWF GPIO MOVLW 0x80 ;128 in deciaml MOVWF OUTER ;128ms CALL delay MOVLW 1<<GP4 MOVWF GPIO MOVLW 0x80 ;128 in deciaml MOVWF OUTER ;128ms CALL delay MOVLW 1<<GP2 MOVWF GPIO MOVLW 0x80 ;128 in deciaml MOVWF OUTER ;128ms CALL delay MOVLW 1<<GP1 MOVWF GPIO MOVLW 0x80 ;128 in deciaml MOVWF OUTER ;128ms CALL delay GOTO Main_LoopSub_LOOP8 ;MODE 8 loop MOVLW 1<<GP4 MOVWF GPIO CALL delay MOVLW 1<<GP1 MOVWF GPIO CALL delay MOVLW 1<<GP0 MOVWF GPIO CALL delay MOVLW 1<<GP2 MOVWF GPIO CALL delay GOTO Main_LoopSub_LOOP_RESET MOVLW 0x01 MOVWF MODE CLRF GPIO GOTO Main_LoopButton_Pressed MOVLW 0x01 ;Increment has been called BIT = 1 MOVWF BIT RETURN END