; *******************************************************************
; PICkit 2 Lesson 3 - "Rotate"
;
; Extends Lesson 2 to sequence through the display LEDs.
;
; *******************************************************************
#include <p18cxxx.inc>
     config CPUDIV = NOCLKDIV
     config USBDIV = OFF
     config FOSC   = HS
     config PLLEN  = ON
     config FCMEN  = OFF
     config IESO   = OFF
     config PWRTEN = OFF
     config BOREN  = OFF
     config BORV   = 30
     config WDTEN  = OFF
     config WDTPS  = 32768
     config MCLRE  = ON 
     config HFOFST = OFF
     config STVREN = ON
     config LVP    = OFF
     config XINST  = OFF
     config BBSIZ  = OFF
     config CP0    = OFF
     config CP1    = OFF
     config CPB    = OFF
     config WRT0   = OFF
     config WRT1   = OFF
     config WRTB   = OFF
     config WRTC   = OFF
     config EBTR0  = OFF
     config EBTR1  = OFF
     config EBTRB  = OFF 

     cblock 0
szamlalo1           ;--- három változót definálunk a késleltetéshez
szamlalo2
szamlalo3
Display             ; a megjelenített adat
     endc
     
     org 0
Start:
     clrf      TRISC          ; az egész portot kimenetnek állítja
     movlw     0x08           ; a 3. bitet '1'-be állítjuk
     movwf     Display
MainLoop:
     movf      Display,w      ; előveszi az adatot
     movwf     LATC           ; kirakja az RC portra
     rcall     delay    
     bcf       STATUS,C       ; törli az átvitel jelzőbitet
     rrcf      Display,f      ; jobbra forgatás a Carry biten át
     btfsc     STATUS,C       ; Ugrás, ha C=0 az eredmény!
     bsf       Display,3      ; visszateszi RC3-ba a kicsorgott bitet
     goto      MainLoop

;--- A késleltető szubrutin  ~ 260 msec        
delay:    movlw  0x10
          movwf  szamlalo3
          clrf   szamlalo2
          clrf   szamlalo1
loop:     decfsz szamlalo1    ;1.számláló fogyasztása
          bra    loop
          decfsz szamlalo2    ;2.számláló fogyasztása
          bra    loop
          decfsz szamlalo3    ;3.számláló fogyasztása
          bra    loop
          return
     end
     
