Advertisement
Slyfoxx724

ENGR270 LAB5 EXP2

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