
Originally Posted by
ruijc
Acetronics,
you said that you re-wrote my code and it worked...
One question:
Have you made any changes ?
.
Hi, Ruijc
I did not make any noticeable change to your " functionnal " program ( = the part that runs )
BUT ... as I told you, The config section took me ~ 50 lines.
Here is your headache : The processor config lines !!!
Code:
'*****************************************************************************
'*****************************************************************************
'09/12/2007
'
'Lecture de 2 temp avec LM35 ( ambiant temp ... LOL ! )
'
'PIC 16F88 @ 4Mhz
'*****************************************************************************
'Config
@ __CONFIG _CONFIG1, _CP_OFF & _CCP1_RB3 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_ON & _WDT_ON & _INTRC_IO
@ __CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF
OSCCON = %01101110 'Internal RC w/ I/Os
INTCON = 0
PIE1 = 0
PIE2 = 0
CMCON = 7
CVRCON = 0
'*****************************************************************************
'DEFINEs
'*****************************************************************************
'OSC
DEFINE osc 4
'*****************************************************************************
'
'ADC
DEFINE ADC_BITS 10 ' Set number of bits in result ( 8 or 10 bits )
'DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS
'*****************************************************************************
'
'LCD
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 4
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 5
DEFINE LCD_BITS 4
DEFINE LCD_COMMANDUS 2000
'*****************************************************************************
'ADC parameters
ADCON0 = %11000000 ' clock source
ADCON1 = %10000011 ' set porta.0 and .1 analog and right justify result
ANSEL = %00000011 ' Porta.0 and .1 used by ADC
'*****************************************************************************
' variables
va1 var word
va2 var word
temp var word
volt var word
LM351 con 0
LM352 con 1
CLEAR
'*****************************************************************************
'I/O's
PORTA = %00000000
PORTB = %00000000
TRISA = %00000011
TRISB = %00000000
'*****************************************************************************
'PINS
LM35_1 var PORTA.0
LM35_2 var PORTA.1
a2 var PORTA.2
a3 var PORTA.3
a4 var PORTA.4
MCLR var PORTA.5
a6 var PORTA.6
a7 var PORTA.7
DATA1 var PORTB.0
DATA2 var PORTB.1
DATA3 var PORTB.2
DATA4 var PORTB.3
R_S var PORTB.4
E var PORTB.5
b6 var PORTB.6
LED var PORTB.7
'*****************************************************************************
'*****************************************************************************
'
'*****************************************************************************
'Init LCD
pause 500 'init LCD
lcdout $fe,1 'clear LCD
loop:
ADCIN LM351, va1 ' 15 °C ... 150 /5000*1024 = 30.72 ... 30 = NOT GOOD !!!
ADCIN LM352, va2
'temp = (va1 */ 500 ) >> 2
temp = (va1*125)
temp = temp.Highbyte
'volt = (va2 */500) >> 2
volt = (va2*125)
volt = volt.Highbyte
high portb.7
lcdout $fe,2,"VOLTAGE..",dec (volt/100),".",dec2 volt,"V"
lcdout $fe,$c0,"TEMP.....",dec (temp/100),".",dec2 volt,"V"
pause 250
Goto loop
End
as you can see it ....no great change to what you did ...
IT IS FORBIDDEN TO YOU TO PASTE THAT CODE ... before having understood YOU MUST CONFIGURE the registers and ports by YOURSELF !!!
PbP cares for some ... yes, but only some "general use" ones.
Also try to show a "readable" listing where you ( mostly ! ) and others can find if you've programmed the "good" registers or not ...
And for the end ... remember to separate the "config zone" and the "working zone" ... setting registers in the "working zone" must be kept ONLY if changes have to be made while running ...
Here we are ... PbP doesn't do everything for you ...that's it
Especially read those F...manual and Datasheet !!!
Keep on ... thinking you're good at pics ... you'll become really good one day !!!
Alain
Bookmarks