Advertisement
Looong

TN VXL 2-BT2

Mar 9th, 2016
2,937
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MPASM 1.60 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.         movlw   H'C0'
  23.         movwf   LED
  24.         movlw   H'0F'
  25.         movwf   ADCON1
  26.         bsf     BUTTON_IO
  27.         clrf    direction
  28.  
  29. main    btfsc   BUTTON          ; if    button not pushed
  30.         bra     led_change      ; then  change LED
  31.         btg     DIRECTION       ; else  change direction
  32. button_pushed
  33.         btfss   BUTTON
  34.         bra     button_pushed
  35. led_change
  36.         btfsc   DIRECTION
  37.         bra     led_change1
  38.         rlncf   LED
  39.         bra     led_change2
  40. led_change1
  41.         rrncf   LED
  42. led_change2
  43.         call    delay_500ms
  44.         bra     main
  45.  
  46. delay_400us
  47.         movlw   .249
  48.         movwf   counter
  49.         nop
  50. delay_400us_loop
  51.         nop
  52.         decfsz  counter
  53.         bra     delay_400us_loop
  54.         return
  55.  
  56. delay_500ms
  57.         movlw   .5
  58.         movwf   counter + 1
  59. delay_500ms_loop1
  60.         movlw   .250
  61.         movwf   counter + 2
  62. delay_500ms_loop2
  63.         call    delay_400us
  64.         decfsz  counter + 2
  65.         bra     delay_500ms_loop2
  66.         decfsz  counter + 1
  67.         bra     delay_500ms_loop1
  68.         return
  69.  
  70.         end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement