Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- list p=18f452
- ; Include file, change directory if needed
- include "p18f452.inc"
- include "ConfigRegsPIC18F452.inc"
- ; Start at the reset address. There *must* be code at address
- ; 0x000 since the PC is loaded with address 0 when the processor
- ; comes out of reset. This declares a code section named 'RST'.
- UDATA_ACS
- LOW_COUNTER res 1
- HIGH_COUNTER res 1
- ; Declare a code section at 0x0 named 'RST'. This instruction sends the
- ; program to the actual start of the program.
- RST code 0x0000
- GOTO Setup
- ; Declare a code section at 0x0008 named 'LOW'
- HIGH code 0x8
- GOTO HighPriorityISR
- ; Declare a code section at 0x0008 named 'LOW'
- LOW code 0x18
- GOTO LowPriorityISR
- ; Declare a code section at 0x0030. This is where the actual program logic will start
- SRT code 0x0060
- Setup:
- BCF TRISB, 2 ; Set PORTB<2> to output for the 60Hz PWM
- BCF TRISB, 3 ; SET PORTB<3> to output for the 0.3Hz PWM
- MOVLW D'0' ; Initialise SLOW_COUNTER as D'200'. This will decrement until 0
- MOVWF LOW_COUNTER ; as 0.300Hz is 200 times slower than 60z.
- MOVLW D'0' ; Initialise SLOW_COUNTER as D'200'. This will decrement until 0
- MOVWF HIGH_COUNTER ; as 0.300Hz is 200 times slower than 60z.
- MOVLW 0x12 ; Set CCP1's comparator value corresponding to trigger at 120Hz.
- MOVWF CCPR1L ; This number is based on a 1MHz cycle time.
- MOVLW 0x04
- MOVWF CCPR1H
- MOVLW 0x11 ; Set CCP1's comparator value corresponding to trigger at 120Hz.
- MOVWF CCPR2L ; This number is based on a 1MHz cycle time.
- MOVLW 0x04
- MOVWF CCPR2H
- MOVLW B'10110001'
- MOVWF T1CON
- MOVLW B'11111001'
- MOVWF T3CON
- MOVLW B'00000010'
- MOVWF CCP1CON
- MOVWF CCP2CON
- CALL InterruptSetup
- Main:
- GOTO Main
- InterruptSetup:
- BSF RCON, IPEN ; Enable priority levels on interrupts
- BSF PIE1, CCP1IE ; Enable Interrupts for CCP1
- BSF PIE2, CCP2IE ; Enable Interrupts for CCP2
- BCF PIR1, CCP1IF ; Clear the CCP1 Interrupt Flag
- BCF PIR2, CCP2IF ;
- BSF INTCON, GIEH ; Enables all high priority interrupts
- BSF INTCON, GIEL ; Enables all low priority interrupts
- BSF IPR1, CCP1IP ; high priority for CCP1
- BCF IPR2, CCP2IP ; low priority for CCP2
- RETURN
- HighPriorityISR:
- MOVLW D'9' ; Initialise SLOW_COUNTER as D'200'. This will decrement until 0
- MOVWF HIGH_COUNTER ; as 0.300Hz is 200 times slower than 60z.
- BCF PIR1, CCP1IF ; Clear CCP1 Interrupt Flag
- ;BCF IPR1, CCP1IP ; Set the Interrupt Priority Bit to low
- RETFIE FAST ; Return from Interrupt
- LowPriorityISR:
- MOVLW D'11' ; Initialise SLOW_COUNTER as D'200'. This will decrement until 0
- MOVWF LOW_COUNTER ; as 0.300Hz is 200 times slower than 60z.
- BCF PIR2, CCP2IF ; Clear CCP1 Interrupt Flag
- ;BSF IPR1, CCP1IP ; Set the Interrupt Priority Bit back to high
- MOVLW D'1'
- MOVLW D'1'
- MOVLW D'1'
- MOVLW D'1'
- RETFIE ; Return from Interrupt
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement