Skip to content

Instantly share code, notes, and snippets.

@Xhendos
Created October 4, 2017 20:22
Show Gist options
  • Save Xhendos/f6b40cc2f15927a36c858c11f14e63ad to your computer and use it in GitHub Desktop.
Save Xhendos/f6b40cc2f15927a36c858c11f14e63ad to your computer and use it in GitHub Desktop.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; Created by : Youri Klaassens ;
; Date : 4 October, 2017 ;
; Description : Rotate all 4 LEDS ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#include <p16f1829.inc>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; Configuration bits ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
__CONFIG _CONFIG1, (_FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF);
__CONFIG _CONFIG2, (_WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _LVP_OFF);
cblock 0x70 ;First location address where common RAM starts
__delay1 ;Define first variable which is used to decrement
__delay2 ;Define second variable which is used to decrement
endc
org 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; INIT ;
; ;
; Set the speed of the internal oscillator to 500 kHz ;
; Move the correct values to the correct RAM location. ;
; __delay2 (outer loop) will get the default value (0xFF) ;
; Set the LED pattern 1 0 0 0 into the LATC register ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
INIT:
banksel OSCCON ;Go to bank1 for the internal oscillator register
movlw b'00111000' ;Set the internal oscillator to 500 kHz
banksel TRISC ;Go to bank for the TRISC register
clrf TRISC ;Set all bits in the TRISC register to 0 (indicates OUTPUT)
banksel LATC ;Go to bank for the LATC register
movlw b'00001000' ;Set LED DS4 logic HIGH.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; DELAY ;
; ;
; Create a sleep function of 1,5 seconds ;
; This is done by decrementing 2 variables in common RAM ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DELAY:
decfsz __delay1, f ;Decrement 1 from the value in register 0x70
bra DELAY ;Go to label DELAY if the value in register 0x70 is not 0
decfsz __delay2, f ;Decrement 1 from the value in register 0x71
bra DELAY ;Go to label DELAY if the value in register 0x71 is not 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; SHIFTBITS ;
; ;
; Shift the current pattern of bits in register LATC 1 position to the right ;
; If the binair number we shifted out is not 0 (must be 1), set the last LED logic HIGH ;
; After we shifted the binair numbers in reigster LATC go to label DELAY and start again ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SHIFTBITS:
lsrf LATC, f ;Shift all bits in the LATC register 1 position to the right
;Place the result of the right shift operation back to the register
btfsc STATUS, C ;Is the bit we just shifted out equal to 0?
;Skip the next assembly instruction.
bsf LATC, 3 ;Set in the LATC register 00001000. This causes LED DS3 to lit.
goto DELAY ;Go back to label DELAY to start the proces again.
end ;We will never reach this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment