Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. list p=18f452
  2.  
  3. ; Include file, change directory if needed
  4. include "p18f452.inc"
  5. include "ConfigRegsPIC18F452.inc"
  6.  
  7. ; Start at the reset address. There *must* be code at address
  8. ; 0x000 since the PC is loaded with address 0 when the processor
  9. ; comes out of reset. This declares a code section named 'RST'.
  10.  
  11. UDATA_ACS
  12. LOW_COUNTER res 1
  13. HIGH_COUNTER res 1
  14.  
  15. ; Declare a code section at 0x0 named 'RST'. This instruction sends the
  16. ; program to the actual start of the program.
  17. RST code 0x0000
  18. GOTO Setup
  19.  
  20. ; Declare a code section at 0x0008 named 'LOW'
  21. HIGH code 0x8
  22. GOTO HighPriorityISR
  23.  
  24. ; Declare a code section at 0x0008 named 'LOW'
  25. LOW code 0x18
  26. GOTO LowPriorityISR
  27.  
  28. ; Declare a code section at 0x0030. This is where the actual program logic will start
  29. SRT code 0x0060
  30. Setup:
  31. BCF TRISB, 2 ; Set PORTB<2> to output for the 60Hz PWM
  32. BCF TRISB, 3 ; SET PORTB<3> to output for the 0.3Hz PWM
  33.  
  34. MOVLW D'0' ; Initialise SLOW_COUNTER as D'200'. This will decrement until 0
  35. MOVWF LOW_COUNTER ; as 0.300Hz is 200 times slower than 60z.
  36. MOVLW D'0' ; Initialise SLOW_COUNTER as D'200'. This will decrement until 0
  37. MOVWF HIGH_COUNTER ; as 0.300Hz is 200 times slower than 60z.
  38.  
  39.  
  40. MOVLW 0x12 ; Set CCP1's comparator value corresponding to trigger at 120Hz.
  41. MOVWF CCPR1L ; This number is based on a 1MHz cycle time.
  42. MOVLW 0x04
  43. MOVWF CCPR1H
  44.  
  45. MOVLW 0x11 ; Set CCP1's comparator value corresponding to trigger at 120Hz.
  46. MOVWF CCPR2L ; This number is based on a 1MHz cycle time.
  47. MOVLW 0x04
  48. MOVWF CCPR2H
  49.  
  50. MOVLW B'10110001'
  51. MOVWF T1CON
  52. MOVLW B'11111001'
  53. MOVWF T3CON
  54. MOVLW B'00000010'
  55. MOVWF CCP1CON
  56. MOVWF CCP2CON
  57.  
  58. CALL InterruptSetup
  59.  
  60. Main:
  61. GOTO Main
  62.  
  63.  
  64. InterruptSetup:
  65. BSF RCON, IPEN ; Enable priority levels on interrupts
  66. BSF PIE1, CCP1IE ; Enable Interrupts for CCP1
  67. BSF PIE2, CCP2IE ; Enable Interrupts for CCP2
  68. BCF PIR1, CCP1IF ; Clear the CCP1 Interrupt Flag
  69. BCF PIR2, CCP2IF ;
  70. BSF INTCON, GIEH ; Enables all high priority interrupts
  71. BSF INTCON, GIEL ; Enables all low priority interrupts
  72. BSF IPR1, CCP1IP ; high priority for CCP1
  73. BCF IPR2, CCP2IP ; low priority for CCP2
  74.  
  75. RETURN
  76.  
  77.  
  78. HighPriorityISR:
  79. MOVLW D'9' ; Initialise SLOW_COUNTER as D'200'. This will decrement until 0
  80. MOVWF HIGH_COUNTER ; as 0.300Hz is 200 times slower than 60z.
  81. BCF PIR1, CCP1IF ; Clear CCP1 Interrupt Flag
  82.  
  83.  
  84. ;BCF IPR1, CCP1IP ; Set the Interrupt Priority Bit to low
  85. RETFIE FAST ; Return from Interrupt
  86.  
  87.  
  88.  
  89.  
  90. LowPriorityISR:
  91. MOVLW D'11' ; Initialise SLOW_COUNTER as D'200'. This will decrement until 0
  92. MOVWF LOW_COUNTER ; as 0.300Hz is 200 times slower than 60z.
  93. BCF PIR2, CCP2IF ; Clear CCP1 Interrupt Flag
  94. ;BSF IPR1, CCP1IP ; Set the Interrupt Priority Bit back to high
  95. MOVLW D'1'
  96. MOVLW D'1'
  97. MOVLW D'1'
  98. MOVLW D'1'
  99. RETFIE ; Return from Interrupt
  100.  
  101.  
  102.  
  103. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement