Is MCLR tied high?
Not sure if this helps, but this is a section of code that uses an 18f4580, with four pots on port A
It uses DT's analogue include file, which might be worth downloading and including in your own codeCode:; config settings 18F2550/4550/18F4580, 20mhz crystal ASM __CONFIG _CONFIG1H, _OSC_HSPLL_1H __CONFIG _CONFIG2L, _PWRT_ON_2L __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H __CONFIG _CONFIG3H, _PBADEN_OFF_3H __CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L ENDASM DEFINE OSC 48 ADCON1 = $0F clear DEFINE ADC_BITS 10 ' Set-up ADC for fastest 10-bit results DEFINE ADC_CLOCK 2 DEFINE ADC_SAMPLEUS 5 INCLUDE "DT_Analog.pbp" MaxSetPoint CON 500 ' Pot fully clockwise - gives max setting 50 degrees MinSetPoint CON 100 ' Pot fully counter clockwise - sets min setting 10 degrees ADbits = 14 ' set A/D resolution to 14-bits CMCON = 7 ' disable Comparators ADCON1 = %00001011 ' sets up Analogue pins ADCON2.7 = 1 ' ADFM bit isn't in ADCON1 anymore ;----[Port settings]---------------------------------------------------- TRISA = %11001111
Not sure what the Pickit3 does, I know the MCLR pin needs to be held high (~10K resistor) to run the processor...give that a try
Turns out this was a MPASM issue. Once I had that resolved the program worked.
I cant seem to get some of the ADC readings to write to EEPROM. Channels 0 and 1 work perfectly the others write anything. Any idea whats going on? I think all the ports are set correctly.
Define OSC 48
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
adval var word ' Create adval to store result
adval1 var word
adval2 var word ' Create adval to store result
adval3 var word
adval4 var word ' Create adval to store result
adval5 var word
TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %00000000 ' Set PORTA analog and right justify result
ADCON2.7=1
TRISB = %00011111
TRISC = %00000000
TRISE = %00001111
RCSTA.7 = 0
loop1:
ADCIN 0, adval
pause 1
write 0, adval
adcin 1, adval1
pause 1
write 1, adval1
adcin 2, adval2
pause 1
write 2, adval2
adcin 3, adval3
pause 1
write 3, adval3
adcin 4, adval4
pause 1
write 4, adval4
adcin 5, adval5
pause 1
write 5, adval5
SEROUT PortC.6,2,[adval, adval1, adval2, 10]
portc.6 = 0
portc.7 = 0
pause 200
goto loop1
End
how many bytes in a word ?
adval var word ' Create adval to store result
adval1 var word
adval2 var word ' Create adval to store result
adval3 var word
adval4 var word ' Create adval to store result
adval5 var word
.............................
pause 1
write 0, adval
adcin 1, adval1
pause 1
write 1, adval1
Jmgelba, you need to index the memory pointer by 2 for it to store a word or, something like this:
write 1, adval1.lowbyte
write 2, adval1.highbyte
then you can read them back by using:
READ 1,value to read the entire word.
Dave Purola,
N8NTA
EN82fn
Bookmarks