Advertisement
Guest User

Untitled

a guest
Apr 5th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  ;********************************************************************
  3.  ; Filename: LAB6.ASM                                               *
  4.  ; Delays and Sequences with Interupts.                              *
  5.  ; RA 2-4 = LED Outputs
  6.  ; RB 1-5 = LED Outputs
  7.  ;  RB0  = Interrupt SW
  8.  ; RB5,6  = Change Timer
  9.  ;
  10.  ;                                                                  *
  11.  ;********************************************************************
  12.  
  13.         #include    <GENERAL.H>     ;This is the header file you created for this lab#1
  14.  
  15.  KEY        EQU     0X0C        ;This is the user defined DRAM area that
  16. COUNT   EQU     0X0D        ; uses the 68 bytes GPR: range from 0X0C-0X4F
  17. TEMP_W  EQU     0X13        ; Define Temp register for W
  18. TEMP_S  EQU     0X14        ; Define temp register for Status
  19. LCOUNT  EQU     0x15        ; Define "Lightcount" register for ISR
  20. COUNT1  EQU     0X20        ; Inner loop Counter - defined by RB6
  21. COUNT2  EQU     0X21        ; middle loop Counter- defined by RB7
  22. COUNT3  EQU     0X22        ; outer loop Counter
  23.  
  24.  
  25.  
  26.         __CONFIG    0X3FF6  ;This is the control bits for CONFIG register, WDT disabled (0x3FF6 to enable)
  27.  
  28.         GOTO    START
  29.        
  30.         ORG     0X0004      ;Regular INT vector
  31.    
  32.  
  33. ;This is the area where your interrupt service routine goes
  34.  
  35. PUSH
  36. ;This stores the current W and STATUS registers in temporary locations during ISRS
  37.     MOVWF TEMP_W
  38.     SWAPF STATUS,W
  39.     MOVWF TEMP_S
  40.     BTFSC INTCON,INTF   ;check if RB0 Interrupt has occured
  41.     GOTO  ISR       ; Goes to ISR for B0
  42.        
  43. ISR
  44. ;ISR for RB0 interrupt
  45.     INCF    LCOUNT,F
  46.     BCF     INTCON,INTF
  47.     GOTO    POP
  48.  
  49. POP
  50. ;This restores the original W & STATUS registers before returning to the main program
  51.     SWAPF TEMP_S,W
  52.     MOVWF STATUS
  53.     SWAPF TEMP_W,F
  54.     SWAPF TEMP_W,W
  55.     RETFIE
  56.  
  57. ; Main Program
  58.  
  59. START
  60.  
  61.         ; ************ Start Initial Values Set *****************************
  62. ;setup Option_Reg
  63.     MOVLW   0XFF   
  64.     MOVWF   OPTION_REG  ;turn on WDT, set prescaler to 128, define RB0 to rising edge
  65.     CLRW
  66.    
  67. ;Setup TRISA/B
  68.     CLRF    PORTA ; Clears ports a and b
  69.     CLRF    PORTB
  70.     BSF     STATUS,RP0  ;set bank1 TRIS REGs
  71.     MOVLW   0XF0
  72.     MOVWF   TRISA       ;set RA0-RA4 as outputs, RA5-7 as Inputs
  73.     MOVLW   b'11000001' ;
  74.     MOVWF   TRISB       ;set RB0 Input, RB1-RB3 as outputs; RB4-7 as Inputs
  75.     BCF     STATUS,RP0  ;switch to bank 0, normal ops
  76.     CALL    POST_LEDS
  77.  
  78.    
  79. MAIN
  80. ;Main Loop for checking switch status
  81. CLRWDT
  82. BTFSS   PORTB,6
  83. MOVLW   0XFF
  84. MOVLW   0X00
  85. MOVWF   COUNT1
  86. BTFSS   PORTB,7
  87. MOVLW   0XAA
  88. MOVLW   0X00
  89. MOVWF   COUNT2
  90. BTFSS   PORTB,0
  91. ;CALL   AllLights
  92. ;CALL   YLWLED
  93.  
  94. GOTO    MAIN
  95. ;
  96. ;
  97. POST_LEDS
  98.    
  99. ;POST LED - power on with .48sec delay for ops check
  100.     MOVLW   0x2E    ;set initial delay for POST check  
  101.     MOVWF   COUNT1
  102.     MOVLW   0X58
  103.     MOVWF   COUNT2
  104.     MOVLW   0XFF    ; turn on LED's
  105.     MOVWF   PORTA       ; at porta
  106.     MOVWF   PORTB       ; and port b
  107.     CALL    DELAY       ;call the 0.48second delay
  108.     CALL    DELAY       ;DO IT AGAIN
  109.     CLRF    PORTA       ;turn off port A
  110.     CLRF    PORTB       ;turn off port B
  111.     CALL    DELAY       ;call .48s delay
  112.     MOVLW   0x00
  113.     MOVWF   COUNT1
  114.     MOVWF   COUNT2
  115.     MOVWF   LCOUNT;
  116. RETURN
  117.  
  118.     AllLights
  119.                         ;clear wdt
  120.     MOVLW   0XFF        ;set all bits high
  121.     MOVWF   PORTA       ;Set porta high
  122.     MOVWF   PORTB       ;Set PortB high
  123.     CALL    DELAY   ;delay for .48 sec
  124.                         ;clear wdt
  125.     MOVLW   0x00        ;set all off
  126.     MOVWF   PORTA       ;TURN OFF
  127.     MOVWF   PORTB       ;TURN OFF
  128.     CALL    DELAY   ;delay for .48 sec
  129.                         ;clear wdt
  130.  
  131. GOTO MAIN
  132.  
  133. GRNRED
  134.                     ;Clear WDT
  135.     MOVLW   b'00001011' ;values for red and green PortA
  136.     MOVWF   PORTA       ;
  137.     MOVLW   b'00000100' ;values for B
  138.     MOVWF   PORTB
  139.  
  140. GOTO MAIN
  141.  
  142. YLWLED
  143.     CLRWDT              ;Clear WDT
  144.     MOVLW   b'00000100' ;values for ylw leds
  145.     MOVWF   PORTA
  146.     MOVLW   b'00001011' ;values for ylw leds
  147.     MOVWF   PORTB
  148.     CALL    DELAY   ;33msec flash
  149.     MOVLW   b'00000000' ;turn off LEDs
  150.     MOVWF   PORTA       ; for 33msec
  151.     MOVWF   PORTB       ;makes'em flash fast
  152.     CALL    DELAY
  153.  
  154. GOTO MAIN
  155.  
  156.  
  157. DELAY
  158.  
  159.         ;2449991 cycles uses C1=2E, C2=58, C3=06
  160. ;Variable Delay, set from PortB6:7
  161.  
  162. ;   movlw   0x2E    ;  d46
  163. ;   movwf   COUNT1  ; moved to count 1
  164. ;   movlw   0x58    ; d88
  165. ;   movwf   COUNT2  ; moved to count 2
  166.     movlw   0x06    ; d06
  167.     movwf   COUNT3  ; in count 3
  168. Delay_0
  169.     decfsz  COUNT1, f   ; Count down, d46 to 0
  170.     goto    $+2         ; skip to next goto
  171.     decfsz  COUNT2, f   ; decrements d88 to 0
  172.     goto    $+2         ; skip two lines
  173.     decfsz  COUNT3, f   ; decrement from d06 to 0
  174.     goto    Delay_0     ; return to Delay_0
  175.  
  176.     nop     ;5 cycles
  177.     nop     ; of
  178.     nop     ; doing
  179.     nop     ; nothing
  180.     nop     ;
  181.    
  182.             ;6 cycles (including call)
  183.     return
  184.  
  185. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement