dim j as byte
dim i as integer
main:
'ANSEL = 0x00
'ADCON0 = 1
ADCON1 = %0110
CMCON = 0x07
'ADCON0 = 1
'ADCON1 = 1
' CMCON = 0x07
'VRCON = 0x00
TRISA = %01111
TRISB = %00000000
TRISC = %00000000
TRISD = %00000000
TRISE = %000
PORTA = %00000000
PORTB = %00000000
PORTC = %00000000
PORTD = %00000000
PORTE = %000
CCP1CON = 0x0F '// Select the PWM mode.
CCP2CON = 0x0F '// Select the PWM mode.
CCPR1L = 00
CCPR2L = 00
i = 0
Pwm_Init(5000) ' Initialize PWM module, freq = 5kHz.
Pwm_Start
for j=0 to 5
PORTB=%00010000
Delay_ms(500)
PORTB=%00100000
Delay_ms(500)
next j
PORTB = %00000000
delay_ms(1000)
while true
If PORTA=%01001 then '1,2=0 forw
PORTB=%00110110
CCPR1L = 190
CCPR2L = 200
else
if PORTA=%01100 then 'dbl right
PORTB=%00011010
CCPR1L = 150
CCPR2L = 200
i=0
else
if PORTA=%00011 then 'dbl left
PORTB=%00100101
CCPR1L = 190
CCPR2L = 150
i=0
else
if PORTA=%01011 then 'right
PORTB=%00100100
CCPR1L = 210
CCPR2L = 0
i=0
else
if PORTA=%01101 then 'left
PORTB=%00100010
CCPR1L = 0
CCPR2L = 220
i=0
else
if PORTA=%01111 then
PORTB=%00001001
CCPR1L = 160
CCPR2L = 170
delay_ms(300)
PORTB=%00000000
i=i+1
else
if PORTA=%01110 then
PORTB=%00010010
CCPR1L = 0
CCPR2L = 220
i=0
else
if PORTA=%00111 then
PORTB=%00100100
CCPR1L = 210
CCPR2L = 0
i=0
end if
end if
end if
end if
end if
end if
end if
end if
if i=10 then
while true
PORTB=%00110000
Delay_ms(500)
PORTB=%00000000
Delay_ms(500)
wend
end if
wend
end.