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
- org 0x00
- GOTO StartL ;Executes after reset
- org 0x08 ;High priority
- GOTO HIPRIO
- org 0x20 ;Start the code
- HIPRIO:
- BTFSC PIR1, TMR1IF
- BRA pwm20 ;If timer1 is interrupting then go to timer1 service routine
- BTFSC INTCON, TMR0IF
- BRA pwm50
- RETFIE
- pwm50:
- BCF T0CON, TMR0ON ;disable tmr0
- INCF count
- BZ Done
- MOVLW .50
- MOVWF CCPR1L
- BCF INTCON, TMR0IF ;clear tmr0 interrupt flag
- BSF T1CON, TMR1ON ;enable tmr1
- RETFIE
- pwm20:
- BCF T1CON, TMR1ON ;disable timer1
- BTG PORTA,7 ;toggle motor direction
- MOVLW .20
- MOVWF CCPR1L
- BCF PIR1, TMR1IF ;clear tmr1 interrupt flag
- BSF T0CON, TMR0ON ;enable tmr0
- 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
- ;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
- BCF PIR1, TMR1IF ;clear tmr1 flag
- BSF INTCON, TMR0IE ;enable tmr0 interrupt
- BSF INTCON2,TMR0IP ;enable tmr0 priority to high
- BCF INTCON, TMR0IF ;clear tmr0 flag
- MOVLW 0x58 ;Timer 1: "&&&-bit, osc. clock, 1:2 prescale, enabled, internal clk"
- MOVWF T1CON
- MOVLW 0x00
- MOVWF T0CON
- ;Set timers so next timer interrupt is in approx 5 seconds
- MOVLW 0xB3
- MOVWF TMR1H
- MOVWF TMR0H
- MOVLW 0xB5
- MOVWF TMR1L
- MOVWF TMR0L
- BSF T0CON, TMR0ON ;Enable timer0
- 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 .50
- MOVWF CCPR1L ;Set power level to 50%
- MOVLW .254
- MOVWF count
- 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
- Done:
- BTG PORTB,3 ;disable motor
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement