Advertisement
Slyfoxx724

engr270 lab5 exp2(3)

Mar 15th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 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. DECF 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 0x67
  70. MOVWF TMR1H
  71. MOVLW 0x31
  72. MOVWF TMR0H
  73. MOVLW 0x68
  74. MOVWF TMR1L
  75. MOVLW 0x2F
  76. MOVWF TMR0L
  77.  
  78. BSF T0CON, TMR0ON ;Enable timer0
  79. BSF INTCON, GIE ;Enable interrupts globally
  80.  
  81. ;Following steps setup PWM
  82. MOVLW 0x00C ;"0000 1100
  83. MOVWF CCP1CON ;PWM output on P1A Pin18
  84.  
  85. CLRF TMR2 ;Timer2 register
  86. MOVLW 0x05 ;Enable timer and set prescale to 4
  87. MOVWF T2CON
  88. BCF PIR1, TMR2IF ;clear timer2 flag
  89.  
  90. MOVLW .99
  91. MOVWF PR2
  92.  
  93. MOVLW .0
  94. MOVWF CCPR1L ;Set power level to 0%
  95.  
  96. MOVLW .2
  97. MOVWF count
  98.  
  99. WAITL:
  100. BTFSS PIR1, TMR2IF
  101. BRA WAITL
  102. BCF TRISB,3 ;Set P1A/RB3/CCP1 as an output pin
  103. BSF PORTB,5 ;turn on LED just to indicate EDbot is on
  104.  
  105. MainL: ;waiting in a loop
  106. BRA MainL
  107.  
  108. Done:
  109. BSF TRISB,3 ;set pin as input to turn off motor
  110.  
  111. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement