atwoz
- 4th January 2008, 04:56
What is wrong with my code below? I'm using a pic16f88, I want to output the value of the voltage divisor in my lcd, I have my lcd connected likes this:
data bits: rb0-rb3
enable bit: rb7
r/s: ra4 (with pull up)
I have a pot wired like this:
pin1 to VDD
pin2 to Ra0 (an0)
pin3 to ground
I'm using the internal oscillator at 4mhz
First, with my old code, I was trying to read the analog input in rb7 but since I saw most examples with ra0 I changed my lcd configuration in order to be able to use ra0. Before I did the change, the lcd worked perfectly but the adcin value displayed was 75, then 181, and it alternated between those 2.
Now with the new code (below), my lcd stopped working.
here is my code:
@ __CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_ON & _MCLR_OFF & _PWRTE_ON & _WDT_ON & _INTRC_IO
@ __CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF
ANSEL = %00011 '
ADCON1 = %10000000
cmcon = 7
OSCCON=%1100000 '
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
define lcd_dreg portb
define lcd_dbit 4
define lcd_ereg portb
define lcd_ebit 7
define osc 4
trisa= %111
advar var word
pause 1000
inicio:
lcdout 254, 1, "iniciando"
lcdout 254, 192, "espera..."
pause 2000
checa:
adcin portb.7, advar
pause 50
lcdout 254, 1, #advar
pause 200
goto checa
data bits: rb0-rb3
enable bit: rb7
r/s: ra4 (with pull up)
I have a pot wired like this:
pin1 to VDD
pin2 to Ra0 (an0)
pin3 to ground
I'm using the internal oscillator at 4mhz
First, with my old code, I was trying to read the analog input in rb7 but since I saw most examples with ra0 I changed my lcd configuration in order to be able to use ra0. Before I did the change, the lcd worked perfectly but the adcin value displayed was 75, then 181, and it alternated between those 2.
Now with the new code (below), my lcd stopped working.
here is my code:
@ __CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_ON & _MCLR_OFF & _PWRTE_ON & _WDT_ON & _INTRC_IO
@ __CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF
ANSEL = %00011 '
ADCON1 = %10000000
cmcon = 7
OSCCON=%1100000 '
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
define lcd_dreg portb
define lcd_dbit 4
define lcd_ereg portb
define lcd_ebit 7
define osc 4
trisa= %111
advar var word
pause 1000
inicio:
lcdout 254, 1, "iniciando"
lcdout 254, 192, "espera..."
pause 2000
checa:
adcin portb.7, advar
pause 50
lcdout 254, 1, #advar
pause 200
goto checa