Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;*******************************************************************************
- ;
- ; CS 131: Assembly Language Programming
- ; Filename:
- ; Date:
- ; Author:
- ; Description:
- ;
- ;*******************************************************************************
- ; PIC16F684 Configuration Bit Settings
- ; ASM source line config statements
- #include "p16F684.inc"
- ; CONFIG
- ; __config 0xF0F4
- __CONFIG _FOSC_INTOSCIO & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _IESO_OFF & _FCMEN_OFF
- ;*******************************************************************************
- ; Variables
- ;*******************************************************************************
- GPR_VAR UDATA
- loop1 RES 1
- loop2 RES 1
- loop3 RES 1
- flag RES 1
- ;*******************************************************************************
- ; Reset Vector
- ;*******************************************************************************
- RES_VECT CODE H'0000' ; processor reset vector
- goto START ; go to beginning of program
- ; TODO ADD INTERRUPTS HERE IF USED
- ;*******************************************************************************
- ; MAIN PROGRAM
- ;*******************************************************************************
- MAIN_PROG CODE ; let linker place main program
- START
- banksel PORTC
- movlw B'00110000'
- movwf PORTC
- movlw H'07'
- movwf CMCON0 ; Set up digital I/O
- banksel ANSEL
- clrf ANSEL
- movlw B'00110000'
- movwf TRISC
- bcf STATUS, RP0
- bsf PORTC, RC0
- movlw H'50' ; Initialize looping at H'40'
- clrf flag ; Set flag to 0
- ;incf flag
- ; Execute the loops
- LOOPSTART
- movwf loop1 ; Move current W value in loop1 counter
- SLOOP1
- movwf loop2 ; Move current W value into loop2 counter
- decfsz loop1 ; Loop 1 step
- goto SLOOP2 ; Loop 1 body is Loop 2
- goto SWITCH ; Switch and rotate after loop 1 is completed
- SLOOP2
- movwf loop3 ; Move current W value into loop3 counter
- decfsz loop2 ; Loop 2 step
- goto SLOOP3 ; Loop 2 body is Loop 3
- goto SLOOP1 ; When Loop 2 is done, goto beginning of Loop 1
- SLOOP3
- nop
- decfsz loop3
- goto SLOOP3
- goto SLOOP2
- ; Switch the direction of the rotation by changing flag if we're at the
- ; rightmost or leftmost LED.
- SWITCH
- btfsc PORTC,RC3 ; Switch to rotating right if RC3 is on
- goto RIGHT
- btfsc PORTC,RC0
- goto LEFT ; Switch to rotating left is RC0 is on
- goto ROTATE ; Rotate if we don't switch
- RIGHT
- decf flag
- goto ROTATE
- LEFT
- incf flag
- goto ROTATE
- ; Rotate to the left/right based on the value in flag
- ROTATE
- bcf STATUS,C ; Rotation uses the carry bit.
- ; We set it to zero to be safe.
- btfss flag,0
- goto NOTONE
- goto ISONE
- NOTONE
- rrf PORTC
- goto LOOPSTART
- ISONE
- rlf PORTC
- goto LOOPSTART
- END
Advertisement
Add Comment
Please, Sign In to add comment