Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- list p=18F1220
- radix hex
- config WDT=OFF, LVP=OFF, OSC=INTIO2; Disable WDT, Low V Prog and RA6 as a clock
- #include p18f1220.inc ;Header file for SFR definitions
- count equ 0x80
- count2 equ 0x81
- org 0x00
- GOTO StartL ;Executes after reset
- org 0x08 ;High priority
- GOTO HIPRIO
- org 0x20 ;Start the code
- HIPRIO:
- BTFSC PIR1, TMR1IF
- BRA TIMERL ;If timer1 is interrupting then go to timer1 service routine
- RETFIE
- TIMERL:
- BCF T1CON, TMR1ON ;disable timer1
- ;Start of code to be executed during Timer1 interrupts
- TSTFSZ count
- BRA PWMplus10 ;increment loop
- BRA PWMminus10
- PWMplus10: ;Adds 10% power
- MOVLW .10
- ADDWF CCPR1L
- INCF count
- BRA T1done
- PWMminus10: ;subtracts 10% power
- MOVLW .10
- SUBWF CCPR1L
- INCF count2
- TSTFSZ count2
- BRA T1done
- BTG PORTB,3
- MOVLW .252
- MOVWF count
- MOVWF count2
- BRA T1done
- T1done: ;get ready to return from interrupt
- ;Reset Timer1 so next timer interrupt is in approximately 3 seconds
- MOVLW 0xD2
- MOVWF TMR1H
- MOVLW 0x38
- MOVWF TMR1L
- BCF PIR1, TMR1IF ;clear timer1 interrupt flag
- BSF T1CON, TMR1ON ;enable timer1
- RETFIE
- StartL: ;entry point from reset
- ;Initialize all I/O ports
- CLRF PORTA
- CLRF PORTB
- MOVLW 0x7F
- MOVWF ADCON1
- MOVLW 0x0D
- MOVWF TRISA
- MOVLW 0xC7
- MOVWF TRISB
- MOVLW 0x00
- ;Timer1 Initialization + interrupt enable/disable
- BSF INTCON, PEIE ;enable peripheral interrupts
- BSF PIE1, TMR1IE ;enable timer1 interrupt
- BSF IPR1, TMR1IP ;set timer1 priority to high
- MOVLW 0x58 ;Timer 1: "&&&-bit, osc. clock, 1:2 prescale, enabled, internal clk"
- MOVWF T1CON
- ;Set timer 1 so next timer interrupt is in approx 3 seconds
- ;2 secx(10^6 usec/sec)x(sysClk/32usec)x(instClk/4sysClk)x(Tick/2 insClk) = 7812 Ticks
- ;set TMR1H & TMR1L TO [(2^16) - 7812 = 57725] OR (E17D) in hex
- MOVLW 0xD2
- MOVWF TMR1H
- MOVLW 0x38
- MOVWF TMR1L
- BSF T1CON, TMR1ON ;Enable timer1
- BSF INTCON, GIE ;Enable interrupts globally
- ;Following steps setup PWM
- MOVLW 0x00C ;"0000 1100
- MOVWF CCP1CON ;PWM output on P1A Pin18
- CLRF TMR2 ;Timer2 register
- MOVLW 0x05 ;Enable timer and set prescale to 4
- MOVWF T2CON
- BCF PIR1, TMR2IF ;clear timer2 flag
- MOVLW .99
- MOVWF PR2
- MOVLW .0
- MOVWF CCPR1L ;Set power level to 0%
- MOVLW .252
- MOVWF count
- MOVWF count2
- WAITL:
- BTFSS PIR1, TMR2IF
- BRA WAITL
- BCF TRISB,3 ;Set P1A/RB3/CCP1 as an output pin
- BSF PORTB,5 ;turn on LED just to indicate EDbot is on
- MainL: ;waiting in a loop
- BRA MainL
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement