futz
Active Member
For Junebug users, here's the final silly little demo program. It flashes LED 1 with delay set by VR1 and flashes LED 2 with delay set by VR2.
When both pots are full CCW (counter-clockwise) the LEDs will appear to both be on full time. They are both blinking still, but very quickly.
Now on to bigger and better things!![Big Grin :D :D](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
When both pots are full CCW (counter-clockwise) the LEDs will appear to both be on full time. They are both blinking still, but very quickly.
Code:
list p=18F1320
include <p18F1320.inc>
CONFIG OSC=INTIO2,WDT=OFF,MCLRE=ON,LVP=OFF
cblock 0x00
d1,d2,d3,speed,speed2,temp
endc
org 0x0000
init bsf OSCCON,IRCF2 ;set to 8MHz clock
bsf OSCCON,IRCF1
bsf OSCCON,IRCF0
movlw b'00001010' ;set PORTA to all outs except RA1 and RA3
movwf TRISA
clrf TRISB
clrf LATA ;and zero them
clrf LATB
movlw b'00000100' ;init a/d
movwf ADCON0
movlw b'01110101'
movwf ADCON1
movlw b'00011101'
movwf ADCON2
main call analog ;read the a/d pins
bsf LATA,0 ;blink LED 1
bcf LATA,6
bsf TRISA,7
call delay ;with delay length determined by VR1
bcf LATA,0
bcf LATA,6
bcf TRISA,7
call delay
bcf LATA,0 ;blink LED2
bsf LATA,6
bsf TRISA,7
call delay2 ;with delay length determined by VR2
bcf LATA,0
bcf LATA,6
bcf TRISA,7
call delay2
goto main
analog movlw b'00000101' ;enable A/D, AN1
movwf ADCON0
bsf ADCON0,GO ;go do a/d conversion
adloop btfsc ADCON0,DONE
goto adloop
movff ADRESH,speed ;get the value in speed
incf speed,F ;prevent loop value from going to 0
movlw b'00001101' ;enable A/D, AN3
movwf ADCON0
bsf ADCON0,GO ;go do a/d conversion
adloop2 btfsc ADCON0,DONE
goto adloop2
movff ADRESH,speed2 ;get the value in speed2
incf speed2,F ;prevent loop value from going to 0
return
delay movlw 0xff
movwf d1
movff speed,d2
delay_0 decfsz d1,F
goto $+6
decfsz d2,F
goto delay_0
return
delay2 movlw 0xff
movwf d1
movff speed2,d2
delay_3 decfsz d1,F
goto $+6
decfsz d2,F
goto delay_3
return
END
Now on to bigger and better things!