Advertisement
Slyfoxx724

ENGR270 LAB5 EXP2 final

Mar 15th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. list p=18F1220
  2. radix hex
  3. config WDT=OFF, LVP=OFF, OSC=INTIO2; Disable WDT, Low V Prog and RA6 as a clock
  4.  
  5. #include p18f1220.inc ;Header file for SFR definitions
  6.  
  7. count equ 0x80
  8.  
  9. org 0x00
  10. GOTO StartL ;Executes after reset
  11.  
  12. org 0x08 ;High priority
  13. GOTO HIPRIO
  14.  
  15. org 0x20 ;Start the code
  16.  
  17. HIPRIO:
  18. BTFSC PIR1, TMR1IF
  19. BRA pwm20 ;If timer1 is interrupting then go to timer1 service routine
  20. BTFSC INTCON, TMR0IF
  21. BRA pwm50
  22. RETFIE
  23.  
  24. pwm50:
  25. BCF T0CON, TMR0ON ;disable tmr0
  26. BCF INTCON, TMR0IF
  27.  
  28. INCF count
  29. BZ Done
  30.  
  31. MOVLW .50
  32. MOVWF CCPR1L
  33. BCF INTCON, TMR0IF ;clear tmr0 interrupt flag
  34. BSF T1CON, TMR1ON ;enable tmr1
  35. RETFIE
  36.  
  37. pwm20:
  38. BCF T1CON, TMR1ON ;disable timer1
  39. BCF PIR1, TMR1IF
  40.  
  41. BTG PORTA,7 ;toggle motor direction
  42. MOVLW .20
  43. MOVWF CCPR1L
  44. BCF PIR1, TMR1IF ;clear tmr1 interrupt flag
  45. BSF T0CON, TMR0ON ;enable tmr0
  46. RETFIE
  47.  
  48. StartL: ;entry point from reset
  49. ;Initialize all I/O ports
  50. CLRF PORTA
  51. CLRF PORTB
  52. MOVLW 0x7F
  53. MOVWF ADCON1
  54. MOVLW 0x0D
  55. MOVWF TRISA
  56. MOVLW 0xC7
  57. MOVWF TRISB
  58. ;Timer1 Initialization + interrupt enable/disable
  59. BSF INTCON, PEIE ;enable peripheral interrupts
  60. BSF PIE1, TMR1IE ;enable timer1 interrupt
  61. BSF IPR1, TMR1IP ;set timer1 priority to high
  62. BCF PIR1, TMR1IF ;clear tmr1 flag
  63. BSF INTCON, TMR0IE ;enable tmr0 interrupt
  64. BSF INTCON2,TMR0IP ;enable tmr0 priority to high
  65. BCF INTCON, TMR0IF ;clear tmr0 flag
  66. MOVLW 0xD8 ;Timer 1: "&&&-bit, osc. clock, 1:2 prescale, enabled, internal clk"
  67. MOVWF T1CON
  68. MOVLW 0x00
  69. MOVWF T0CON
  70. ;Set timers so next timer interrupt is in approx 5 seconds
  71. MOVLW 0xB3
  72. MOVWF TMR1H
  73. MOVLW 0x31
  74. MOVWF TMR0H
  75. MOVLW 0xB3
  76. MOVWF TMR1L
  77. MOVLW 0x2F
  78. MOVWF TMR0L
  79.  
  80. BSF T0CON, TMR0ON ;Enable timer0
  81. BSF INTCON, GIE ;Enable interrupts globally
  82.  
  83. ;Following steps setup PWM
  84. MOVLW 0x00C ;"0000 1100
  85. MOVWF CCP1CON ;PWM output on P1A Pin18
  86.  
  87. CLRF TMR2 ;Timer2 register
  88. MOVLW 0x05 ;Enable timer and set prescale to 4
  89. MOVWF T2CON
  90. BCF PIR1, TMR2IF ;clear timer2 flag
  91.  
  92. MOVLW .99
  93. MOVWF PR2
  94.  
  95. MOVLW .0
  96. MOVWF CCPR1L ;Set power level to 0%
  97.  
  98. MOVLW .254
  99. MOVWF count
  100.  
  101. WAITL:
  102. BTFSS PIR1, TMR2IF
  103. BRA WAITL
  104. BCF TRISB,3 ;Set P1A/RB3/CCP1 as an output pin
  105. BSF PORTB,5 ;turn on LED just to indicate EDbot is on
  106.  
  107. MainL: ;waiting in a loop
  108. TSTFSZ count
  109. BRA MainL
  110. BRA Done
  111.  
  112. Done:
  113. BSF TRISB,3 ;disable motor by setting pin as input
  114.  
  115. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement