Advertisement
Slyfoxx724

Lab 3 assembly code

Feb 8th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. ;---------------------------------------------------
  2. ;FILE: EDbotTest.asm
  3. ;DESC: Design to test ED bot basic functionality
  4. ;DEVICE: PICmicro (PIC18F1220)
  5. ;---------------------------------------------------
  6.  
  7. list p=18F1220
  8. radix hex
  9. config WDT=OFF, LVP=OFF, OSC=INTIO2
  10.  
  11. #include p18F1220.inc ;This header file includes address and bit definitions for all SFR's
  12.  
  13. #define dCount 0x80
  14. #define dCountInner 0x81
  15.  
  16. org 0x000
  17.  
  18. ;Initialize all I/O ports
  19. CLRF PORTA
  20. CLRF PORTB
  21. MOVLW 0x7F
  22. MOVWF ADCON1
  23. MOVLW 0x0D
  24. MOVWF TRISA
  25. MOVLW 0xC7
  26. MOVWF TRISB
  27. MOVLW 0x00
  28.  
  29. ;Toggle Portb,5 direction, and delay.
  30. ;start by going forward for first delay cycle
  31. Main:
  32. BSF PORTB,4 ;Enable Right motor
  33. BSF PORTA,6 ;Forward Right
  34. BSF PORTB,3 ;Enable Left motor
  35. BSF PORTA,7 ;Forward Left
  36. MOVLW .2
  37. CALL Delay
  38. BSF PORTA,6 ;Forward Right
  39. CALL Loop1
  40.  
  41. Loop1:
  42. BCF PORTA,7 ;Backward Left
  43. BSF PORTA,6 ;Forward Right
  44. MOVLW .2
  45. CALL Delay
  46. BSF PORTA,7 ;Forward Left
  47. BSF PORTA,6 ;Forward Right
  48. MOVLW .2
  49. CALL Delay
  50. CALL Loop2
  51.  
  52. Loop2:
  53. BCF PORTA,7 ;Backward Left
  54. BSF PORTA,6 ;Forward Right
  55. MOVLW .1
  56. CALL Delay
  57. BSF PORTA,7 ;Forward Left
  58. BSF PORTA,6 ;Forward Right
  59. MOVLW .2
  60. CALL Delay
  61. CALL Loop1
  62.  
  63. ;Delay function uses the Wreg value as the number of 1/10 of second delays
  64. Delay:
  65. MOVWF dCount
  66. DelayLoop:
  67. CALL DelayOnce
  68. DECF dCount
  69. BNZ DelayLoop
  70. RETURN
  71. DelayOnce:
  72. CLRF dCountInner ;Internal Delay loop
  73. DelayOnceLoop:
  74. NOP
  75. INCF dCountInner
  76. BNZ DelayOnceLoop
  77. RETURN
  78.  
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement