Advertisement
Slyfoxx724

ENGR270 LAB5 EXP2(2)

Mar 14th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 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.  
  27. INCF count
  28. BZ Done
  29.  
  30. MOVLW .50
  31. MOVWF CCPR1L
  32. BCF INTCON, TMR0IF ;clear tmr0 interrupt flag
  33. BSF T1CON, TMR1ON ;enable tmr1
  34. RETFIE
  35.  
  36. pwm20:
  37. BCF T1CON, TMR1ON ;disable timer1
  38.  
  39. BTG PORTA,7 ;toggle motor direction
  40. MOVLW .20
  41. MOVWF CCPR1L
  42. BCF PIR1, TMR1IF ;clear tmr1 interrupt flag
  43. BSF T0CON, TMR0ON ;enable tmr0
  44. RETFIE
  45.  
  46. StartL: ;entry point from reset
  47. ;Initialize all I/O ports
  48. CLRF PORTA
  49. CLRF PORTB
  50. MOVLW 0x7F
  51. MOVWF ADCON1
  52. MOVLW 0x0D
  53. MOVWF TRISA
  54. MOVLW 0xC7
  55. MOVWF TRISB
  56. ;Timer1 Initialization + interrupt enable/disable
  57. BSF INTCON, PEIE ;enable peripheral interrupts
  58. BSF PIE1, TMR1IE ;enable timer1 interrupt
  59. BSF IPR1, TMR1IP ;set timer1 priority to high
  60. BCF PIR1, TMR1IF ;clear tmr1 flag
  61. BSF INTCON, TMR0IE ;enable tmr0 interrupt
  62. BSF INTCON2,TMR0IP ;enable tmr0 priority to high
  63. BCF INTCON, TMR0IF ;clear tmr0 flag
  64. MOVLW 0x58 ;Timer 1: "&&&-bit, osc. clock, 1:2 prescale, enabled, internal clk"
  65. MOVWF T1CON
  66. MOVLW 0x00
  67. MOVWF T0CON
  68. ;Set timers so next timer interrupt is in approx 5 seconds
  69. MOVLW 0xB3
  70. MOVWF TMR1H
  71. MOVWF TMR0H
  72. MOVLW 0xB5
  73. MOVWF TMR1L
  74. MOVWF TMR0L
  75.  
  76. BSF T0CON, TMR0ON ;Enable timer0
  77. BSF INTCON, GIE ;Enable interrupts globally
  78.  
  79. ;Following steps setup PWM
  80. MOVLW 0x00C ;"0000 1100
  81. MOVWF CCP1CON ;PWM output on P1A Pin18
  82.  
  83. CLRF TMR2 ;Timer2 register
  84. MOVLW 0x05 ;Enable timer and set prescale to 4
  85. MOVWF T2CON
  86. BCF PIR1, TMR2IF ;clear timer2 flag
  87.  
  88. MOVLW .99
  89. MOVWF PR2
  90.  
  91. MOVLW .50
  92. MOVWF CCPR1L ;Set power level to 50%
  93.  
  94. MOVLW .254
  95. MOVWF count
  96.  
  97. WAITL:
  98. BTFSS PIR1, TMR2IF
  99. BRA WAITL
  100. BCF TRISB,3 ;Set P1A/RB3/CCP1 as an output pin
  101. BSF PORTB,5 ;turn on LED just to indicate EDbot is on
  102.  
  103. MainL: ;waiting in a loop
  104. BRA MainL
  105.  
  106. Done:
  107. BTG PORTB,3 ;disable motor
  108.  
  109. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement