PDA

View Full Version : problem with output RA2 and RA3



savnik
- 8th December 2006, 07:32
I have the below code.
My problem is that the output RA2 and RA3 not change if (value - P2) >= 1 and (value1 - P3) >= 1.
What wrong i have made;



'************************************************* ***********************

@ DEVICE PIC16F88, MCLR_OFF ' Master Clear Options (Internal)

'******************************** LCD ***********************************

DEFINE LCD_DREG PORTB ' Selection of the port B
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB ' RS on port RB2
DEFINE LCD_RSBIT 2
DEFINE LCD_EREG PORTB ' E on port RB3
DEFINE LCD_EBIT 3
DEFINE LCD_BITS 4 ' Mode 4 bits
DEFINE LCD_LINES 2 ' LCD 2 lines of 16 caracter

'****************************Define ADCIN parameters **********************

DEFINE ADC_BITS 8 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS

'*********************************** VARIABLES *********************

TRISA = %00000011
CMCON = 7 ' PortA = digital I/O
ANSEL = %00000011 ' Will set RA0-RA1 as analog and all others as digital
ADCON0 = %11100001 ' Configure and turn on A/D Module
ADCON1 = %00000010 ' Set PORTA analog and RIGHT justify result

adval var Byte ' Create adval to store result
value var Word

adval1 var Byte ' Create adval1 to store result
value1 var Word

P VAR Byte
P1 VAR Byte
P2 var Word
P3 var Word

PAUSE 500

LCDOUT $FE,1," VOLTMETER "
PAUSE 1000

P2 = P*50/255
P3 = P1*50/255

P2=28
P3=10

NORMAL:

ADCIN 0, adval ' Read channel 0 to adval
value = adval*50/255

ADCIN 1, adval1 ' Read channel 1 to adval1
value1 = adval1*50/255

LCDOUT $FE,1,"VOLT : ",DEC2 value
LCDOUT $FE,$C0,"AMPER: ",DEC2 value1

if (value - P2) >= 1 then
PORTA.2=1
else
PORTA.2=0
endif

if (value1 - P3) >= 1 then
PORTA.3=1
else
PORTA.3=0
endif

PAUSE 500

GOTO NORMAL

mat janssen
- 8th December 2006, 08:25
When I read the datasheet of the 16F88 then I see other configurations than you filled in at adcon0 and adcon1.
You say:
ADCON0 = %11100001 ' Configure and turn on A/D Module
I read for this:
do nothing with adcon0
You say:
ADCON1 = %00000010 ' Set PORTA analog and RIGHT justify result
I read for this:
adcon1 = %10000000 'only right justify and nothing about set port a.

savnik
- 8th December 2006, 09:00
When I read the datasheet of the 16F88 then I see other configurations than you filled in at adcon0 and adcon1.
You say:
ADCON0 = %11100001 ' Configure and turn on A/D Module
I read for this:
do nothing with adcon0
You say:
ADCON1 = %00000010 ' Set PORTA analog and RIGHT justify result
I read for this:
adcon1 = %10000000 'only right justify and nothing about set port a.
I read this
ADCON0.0=1 ' A/D converter module is operating

mat janssen
- 8th December 2006, 09:48
The adcon0,0 is an internal bit to tell us what the condition is of the adc.
You need it if your programm is made in assembler.
All of this is solved for you in the picbasicpro compiler.

savnik
- 8th December 2006, 10:31
i change with this:



CMCON = 7 ' PortA = digital I/O
ANSEL = %00000011 ' Will set RA0-RA1 as analog and all others as digital
TRISA = %00000011
ADCON0 = %11000001 ' Configure and turn on A/D Module
ADCON1 = %00000000 ' Left justified. Six Least Significant bits of ADRESL are read as ‘0’


and work but i want only the positive result and not the negative of command: if (value - P2) >= 1
23 - 25 = -2 (P2=25)
27 - 25 = 2 (P2=25)
the pin PORTA.2 turn on , and for -2 and for 2 , but i want only for 2.
How to make this;

mat janssen
- 8th December 2006, 10:55
Test if the first number is greater then the second number and then do the subtraction. If otherwise then do nothing.

savnik
- 8th December 2006, 13:49
Test if the first number is greater then the second number and then do the subtraction. If otherwise then do nothing.
Thank you.
I use this code:



If value >= P2 then
If (value - P2) >= 1 then
PORTB.1=1
else
PORTB.1=0
endif
endif