Advertisement
Looong

TN VXL 2-2

Mar 9th, 2016
2,534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MPASM 1.55 KB | None | 0 0
  1.         list    p=PIC18f8722
  2.         #include p18f8722.inc
  3.         CONFIG  OSC = HS, WDT = OFF, LVP = OFF
  4.         #define LED LATD
  5.         #define LED_IO TRISD
  6.         #define BUTTON PORTA,RA5
  7.         #define BUTTON_IO TRISA,RA5
  8. ; Begin
  9.         code    0
  10.         goto    initialize
  11.  
  12. ; Memory mapping
  13.         udata
  14. counter res     .3
  15. direction       res     .1
  16. direction_bit   equ     0
  17.         #define DIRECTION direction,direction_bit
  18. ; Start
  19.         PRG code
  20. initialize    
  21.         clrf    LED_IO
  22.         clrf    LED
  23.         movlw   H'0F'
  24.         movwf   ADCON1
  25.         bsf     BUTTON_IO
  26.  
  27. main    btfsc   BUTTON          ; if    button not pushed
  28.         bra     led_change      ; then  change LED
  29.         btg     DIRECTION       ; else  change direction
  30. button_pushed
  31.         btfss   BUTTON
  32.         bra     button_pushed
  33. led_change
  34.         btfsc   DIRECTION
  35.         bra     led_change1
  36.         incf    LED
  37.         bra     led_change2
  38. led_change1
  39.         decf    LED
  40. led_change2
  41.         call    delay_500ms
  42.         bra     main
  43.  
  44. delay_400us
  45.         movlw   .249
  46.         movwf   counter
  47.         nop
  48. delay_400us_loop
  49.         nop
  50.         decfsz  counter
  51.         bra     delay_400us_loop
  52.         return
  53.  
  54. delay_500ms
  55.         movlw   .5
  56.         movwf   counter + 1
  57. delay_500ms_loop1
  58.         movlw   .250
  59.         movwf   counter + 2
  60. delay_500ms_loop2
  61.         call    delay_400us
  62.         decfsz  counter + 2
  63.         bra     delay_500ms_loop2
  64.         decfsz  counter + 1
  65.         bra     delay_500ms_loop1
  66.         return
  67.  
  68.         end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement