Advertisement
Slyfoxx724

ENG270 LAB5 EXP1

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