Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;********************************************************************
- ; Filename: LAB6.ASM *
- ; Delays and Sequences with Interupts. *
- ; RA 2-4 = LED Outputs
- ; RB 1-5 = LED Outputs
- ; RB0 = Interrupt SW
- ; RB5,6 = Change Timer
- ;
- ; *
- ;********************************************************************
- #include <GENERAL.H> ;This is the header file you created for this lab#1
- KEY EQU 0X0C ;This is the user defined DRAM area that
- COUNT EQU 0X0D ; uses the 68 bytes GPR: range from 0X0C-0X4F
- TEMP_W EQU 0X13 ; Define Temp register for W
- TEMP_S EQU 0X14 ; Define temp register for Status
- LCOUNT EQU 0x15 ; Define "Lightcount" register for ISR
- COUNT1 EQU 0X20 ; Inner loop Counter - defined by RB6
- COUNT2 EQU 0X21 ; middle loop Counter- defined by RB7
- COUNT3 EQU 0X22 ; outer loop Counter
- __CONFIG 0X3FF6 ;This is the control bits for CONFIG register, WDT disabled (0x3FF6 to enable)
- GOTO START
- ORG 0X0004 ;Regular INT vector
- ;This is the area where your interrupt service routine goes
- PUSH
- ;This stores the current W and STATUS registers in temporary locations during ISRS
- MOVWF TEMP_W
- SWAPF STATUS,W
- MOVWF TEMP_S
- BTFSC INTCON,INTF ;check if RB0 Interrupt has occured
- GOTO ISR ; Goes to ISR for B0
- ISR
- ;ISR for RB0 interrupt
- INCF LCOUNT,F
- BCF INTCON,INTF
- GOTO POP
- POP
- ;This restores the original W & STATUS registers before returning to the main program
- SWAPF TEMP_S,W
- MOVWF STATUS
- SWAPF TEMP_W,F
- SWAPF TEMP_W,W
- RETFIE
- ; Main Program
- START
- ; ************ Start Initial Values Set *****************************
- ;setup Option_Reg
- MOVLW 0XFF
- MOVWF OPTION_REG ;turn on WDT, set prescaler to 128, define RB0 to rising edge
- CLRW
- ;Setup TRISA/B
- CLRF PORTA ; Clears ports a and b
- CLRF PORTB
- BSF STATUS,RP0 ;set bank1 TRIS REGs
- MOVLW 0XF0
- MOVWF TRISA ;set RA0-RA4 as outputs, RA5-7 as Inputs
- MOVLW b'11000001' ;
- MOVWF TRISB ;set RB0 Input, RB1-RB3 as outputs; RB4-7 as Inputs
- BCF STATUS,RP0 ;switch to bank 0, normal ops
- CALL POST_LEDS
- MAIN
- ;Main Loop for checking switch status
- CLRWDT
- BTFSS PORTB,6
- MOVLW 0XFF
- MOVLW 0X00
- MOVWF COUNT1
- BTFSS PORTB,7
- MOVLW 0XAA
- MOVLW 0X00
- MOVWF COUNT2
- BTFSS PORTB,0
- ;CALL AllLights
- ;CALL YLWLED
- GOTO MAIN
- ;
- ;
- POST_LEDS
- ;POST LED - power on with .48sec delay for ops check
- MOVLW 0x2E ;set initial delay for POST check
- MOVWF COUNT1
- MOVLW 0X58
- MOVWF COUNT2
- MOVLW 0XFF ; turn on LED's
- MOVWF PORTA ; at porta
- MOVWF PORTB ; and port b
- CALL DELAY ;call the 0.48second delay
- CALL DELAY ;DO IT AGAIN
- CLRF PORTA ;turn off port A
- CLRF PORTB ;turn off port B
- CALL DELAY ;call .48s delay
- MOVLW 0x00
- MOVWF COUNT1
- MOVWF COUNT2
- MOVWF LCOUNT;
- RETURN
- AllLights
- ;clear wdt
- MOVLW 0XFF ;set all bits high
- MOVWF PORTA ;Set porta high
- MOVWF PORTB ;Set PortB high
- CALL DELAY ;delay for .48 sec
- ;clear wdt
- MOVLW 0x00 ;set all off
- MOVWF PORTA ;TURN OFF
- MOVWF PORTB ;TURN OFF
- CALL DELAY ;delay for .48 sec
- ;clear wdt
- GOTO MAIN
- GRNRED
- ;Clear WDT
- MOVLW b'00001011' ;values for red and green PortA
- MOVWF PORTA ;
- MOVLW b'00000100' ;values for B
- MOVWF PORTB
- GOTO MAIN
- YLWLED
- CLRWDT ;Clear WDT
- MOVLW b'00000100' ;values for ylw leds
- MOVWF PORTA
- MOVLW b'00001011' ;values for ylw leds
- MOVWF PORTB
- CALL DELAY ;33msec flash
- MOVLW b'00000000' ;turn off LEDs
- MOVWF PORTA ; for 33msec
- MOVWF PORTB ;makes'em flash fast
- CALL DELAY
- GOTO MAIN
- DELAY
- ;2449991 cycles uses C1=2E, C2=58, C3=06
- ;Variable Delay, set from PortB6:7
- ; movlw 0x2E ; d46
- ; movwf COUNT1 ; moved to count 1
- ; movlw 0x58 ; d88
- ; movwf COUNT2 ; moved to count 2
- movlw 0x06 ; d06
- movwf COUNT3 ; in count 3
- Delay_0
- decfsz COUNT1, f ; Count down, d46 to 0
- goto $+2 ; skip to next goto
- decfsz COUNT2, f ; decrements d88 to 0
- goto $+2 ; skip two lines
- decfsz COUNT3, f ; decrement from d06 to 0
- goto Delay_0 ; return to Delay_0
- nop ;5 cycles
- nop ; of
- nop ; doing
- nop ; nothing
- nop ;
- ;6 cycles (including call)
- return
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement