Here's something really basic and untested to start with
Code:
'
' PIC Configuration
' =================
@ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON
' Internal Oscillator
' Enable watch dog timer
' Enable power up timer
' Disable MCLR pin
' Enable brown out detect
'
' Hardware configuration
' ======================
TRISIO = %001111 ' GPIO<5:4> as output
' GPIO<3:0> as input
'
CMCON = 7 ' disable analog comparator
ADCON0 = %10000001 ' Right justified results & enable A/D
ANSEL = %00110011 ' Clock source=FRC
' AN<1:0> : analog other to digital
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds
'
' Hardware connection
' ===================
LED0 var GPIO.4
LED1 var GPIO.5
'
' Variables definition
' ===================
ADChannel0 var word
ADChannel1 var word
'
' Hardware/Software initialisation
' ================================
GPIO = 0 ' clear all output
Pause 50 ' internal oscillator settle time
'
' Main Program
' ============
Start:
adcin 0,adchannel0 ' Read AN0
adcin 1,adchannel1 ' Read AN1
'
' A/D results duty
' ================
if adchannel0 < adchannel1 then
High Led0
Low Led1
write 0, adchannel0.highbyte ' Store result in internal EEPROM
write 1, adchannel0.lowbyte
else
High Led1
low Led0
write 0, adchannel1.highbyte ' Store result in internal EEPROM
write 1, adchannel1.lowbyte
endif
pause 500
goto start
Have fun!
Bookmarks