This is the code i'm using, write works fine at 4mhz but not at 20.
define osc 20
data @0,4
clear
pulsos var byte
velocidad var word
circunferencia var byte
x var word ; valor del display
num var byte ; variable para la salida del display
boton var byte ; variable del comando button
demora var byte ; demora para button
wsave var byte $20 system
ssave var byte bank0 system
psave var byte bank0 system
r0save VAR WORD bank0
r1save VAR WORD bank0
r2save VAR WORD bank0
r3save VAR WORD bank0
fsave var byte bank0 system
rm1save var word bank0
TRISA = %11111111
TRISB = %00000000
goto start
define INTHAND display
start:
option_reg = %00000011
intcon = %00000000
read 0,circunferencia
intcon = %10100000
main:
if porta.2 = 0 then gosub setup
count porta.3,1000,pulsos
velocidad = pulsos * circunferencia
velocidad = velocidad * 36
velocidad = velocidad / 10
x = velocidad
goto main
setup:
x = circunferencia
pause 500
setup1:
x = circunferencia
if porta.2 = 0 then gosub config
if porta.1 = 0 then
intcon = %00000000
write 0,circunferencia
intcon = %10100000
return
endif
goto setup1
config:
circunferencia = circunferencia + 1
if circunferencia = 216 then circunferencia = 0
pause 100
return
asm
display
movwf wsave
swapf STATUS, W
clrf STATUS
movwf ssave
movf PCLATH, W
movwf psave
movf FSR,w
movwf fsave
endasm
r0save = R0
r1save = R1
r2save = R2
r3save = R3
rm1save = RM1
num = x dig 0
portb = num
high portb.4
pause 7
low portb.4
num = x dig 1
portb = num
high portb.5
pause 7
low portb.5
num = x dig 2
portb = num
high portb.6
pause 7
low portb.6
TMR0 = 0
INTCON.2 = 0
R0 = r0save
R1 = r1save
R2 = r2save
R3 = r3save
RM1 = rm1save
asm
bcf INTCON, 1
movf fsave,w
movwf FSR
movf psave, W
movwf PCLATH
swapf ssave, W
movwf STATUS
swapf wsave, F
swapf wsave, W
retfie
endasm
Bookmarks