Hi everyone ,recently i got some code for my demo board .bt i met some part dont understand
the 3 red color line ,when i add ,the whole programme will always loop there ,when i delete these code ,my motor can run ,someone can help
Code:
Initialize
bsf STATUS,RP0 ; bank 1
bcf TRISC,1 ; Output: RC1
bcf TRISC,2 ; Output: RC2
movlw b'00001111' ; Outputs: RD2,RD4-RD7
movwf TRISD
movlw b'01110001' ; 8Mhz
movwf OSCCON
movlw b'00001110' ; enable AN0
movwf ADCON1
movwf b'00000101' ; Fosc/16
movwf ADCON2
movlw 0x3F ; 31.2 kHz PWM
movwf PR2
movlw b'00000000' ; 1:2 prescaler for TMR0
movwf T0CON
bcf STATUS,RP0 ; bank 0
clrf PORTD ; turn off windings
clrf PORTC
movlw b'00000001' ; left justified, AN0 selected, module on
movwf ADCON0
movlw 0x07
movwf CMCON ; turn off comparators
clrf CCPR1L
clrf CCPR2L
movlw b'00001100' ; pwm mode
movwf CCP1CON
movwf CCP2CON ; turn on PWM
bsf T2CON,TMR2ON ; turn on Timer 1
bsf T1CON,TMR1ON ; turn on Timer 1
clrf State ; initialize motor state pointer and duty cycle
clrf Index ; index pointer
clrf Mode
clrf ADRESH
movlw 1
movwf StepModeScaler
movwf Counter
clrf Speed
clrf ButtonState ; initialize button state
Main
[COLOR="Red"]btfss INTCON,TMR0IF ; Wait 2.5ms
goto Main
bcf INTCON,TMR0IF[/COLOR]
call ButtonPress ; Call the button press debounce routine
btfsc STATUS,C ; The carry flag is set if a button press just occurred
incf Mode,f ; Change to the next state when a button press occurs.
..............................................................
............................................................
...................................................
the 3 red color line ,when i add ,the whole programme will always loop there ,when i delete these code ,my motor can run ,someone can help
Attachments
Last edited: