I use just :
"Include "Elapsed.bas"" ; for counting seconds
without other interrupts...
Thanks and Regards;
Gadelhas
I think I made some mistakes ......
Can you attache the files? ( your code and elapsed.bas)
Thanks and Regards;
Gadelhas
The code is in post #1 ; this is the "header" :
More about "Elapsed.bas" (credits to Mr.Darrel !) here : http://www.picbasic.co.uk/forum/show...7473#post17473Code:@ DEVICE PIC16F684, INTRC_OSC_NOCLKOUT, WDT_OFF, PWRT_ON, BOD_OFF, MCLR_ON, PROTECT_ON DEFINE OSC 4 TRISA= %00010000 TRISC= %00110000 CMCON0 = %00000111 ' Disable analog comparators. VRCON = %00000000 ' Disable Comparator Voltage Reference ANSEL = %00010000 ' Set pin (AN2) to analog input, the rest to digital ADCON0 = %10001101 ' Set up A/D converter - Right Just., VDD REF., CH 3, ON ADCON1 = %00110000 ' Set up A/D Converter clock source to internal RC DEFINE ADC_BITS 10 DEFINE ADC_CLOCK 3 DEFINE ADC_SAMPLEUS 50 DEFINE LCD_DREG PORTC ' LCD on port c DEFINE LCD_DBIT 0 ' Data bits C0..C3 DEFINE LCD_RSREG PORTA ' RS on PORTA DEFINE LCD_RSBIT 1 ' RS on A1 DEFINE LCD_EREG PORTA ' E on PORTA DEFINE LCD_EBIT 2 ' E on A2 DEFINE LCD_BITS 4 ' LCD 4 bit mode DEFINE LCD_LINES 2 ' 2 line LCD display Define LCD_COMMANDUS 2000 ' Command Delay (uS) Define LCD_DATAUS 50 ' Data Delay (uS) Temperature1 Var Word Temperature2 Var Word TempC1 Var Word TempC2 Var Word Float1 Var Word Float2 Var Word Sign1 Var Byte Sign2 Var Byte DQ1 Var PORTC.5 ' OUT SENSOR DQ2 Var PORTC.4 ' IN SENSOR Twist1 Var Bit Dummy1 Var Byte V1 Var Word Twist2 Var Bit Dummy2 Var Byte V2 Var Word symb Var Byte Vfs con 20480 ' 20,480v K16 con 61441 ' coefficiente filtro 15/16 Vbatt Var Word ' Vbatt filtrato TmpW Var Word Acc_Vbatt Var Word ' accumulatore Vbatt filtrato * 16 batt Var Word DS18B20_1_12bit CON %01111111 ' 750ms, 0.0625°C (default) DS18B20_2_12bit CON %01111111 ' 750ms, 0.0625°C (default) LCDOUT 254,64,4,10,4,0,0,0,0,0 ' Cust Char #0 ; http://www.darreltaylor.com/files/CustChar.htm LCDOUT 254,72,10,31,17,17,17,17,31,0 ' Cust Char #1 LCDOUT 254,80,10,31,17,17,17,31,31,0 ' Cust Char #2 LCDOUT 254,88,10,31,17,17,31,31,31,0 ' Cust Char #3 LCDOUT 254,96,10,31,17,31,31,31,31,0 ' Cust Char #4 LCDOUT 254,104,10,31,31,31,31,31,31,0 ' Cust Char #5 LCDOUT 254,112,15,3,5,9,16,16,16,0 ' Cust Char #6 LCDOUT 254,120,1,1,1,18,20,24,30,0 ' Cust Char #7 include "Elapsed.bas" Twist1 = 0 Twist2 = 0 Pause 5000 LcdOut $FE, $80," TERMO " LcdOut $FE, $C0," VOLT " PAUSE 3000 LCDOUT $FE, 1, $FE, $0C ' Clear display, cursor off Pause 200 ;Init Sensor 1 OWOUT DQ1, 1, [$CC, $4E, 0, 0, DS18B20_1_12bit] OWOut DQ1, 1, [$CC, $48] ' Start temperature conversion OWOut DQ1, 1, [$CC, $B8] OWOut DQ1, 1, [$CC, $BE] Pause 50 OWIn DQ1, 2, [temperature1.byte0, temperature1.byte1] Pause 50 ;Init Sensor 2 OWOUT DQ2, 1, [$CC, $4E, 0, 0, DS18B20_2_12bit] OWOut DQ2, 1, [$CC, $48] ' Start temperature conversion OWOut DQ2, 1, [$CC, $B8] OWOut DQ2, 1, [$CC, $BE] Pause 50 OWIn DQ2, 2, [temperature2.byte0, temperature2.byte1] Pause 50
Thanks again for support !
fratello,
Try this hex file.
It uses elapsed.bas, adds CRC checking and error correction, while only using 1375 WORDs.
Yours was 1871 WORDs, so it also saves ~500 WORDs (~1/4 of total memory.)
It should run on your .dsn, but the voltage will be off because I changed the circuit a little.
I didn't have your code, so the battery icon is different.
DT
Thank You so much ! I will try soon Your hardware ... I must (re) build the PCB.
In Proteus I have some messages ... It's something wrong ?
...and the temperature on display don't follow the variation of sensor(s)-the new temperature is on display NEXT time when the temperature is show !
Last edited by fratello; - 23rd February 2012 at 06:34.
Oh, OK.
I din't see that your's kept up with changes during each period.
I will fix that.
I wasn't seeing the ADC clock error, but I'll take a look.
DT
Thank You again for helping me !
The code for batterie is this :
...post #16.Code:LCDOUT 254,64,4,10,4,0,0,0,0,0 ' Cust Char #0 ; http://www.darreltaylor.com/files/CustChar.htm LCDOUT 254,72,10,31,17,17,17,17,31,0 ' Cust Char #1 LCDOUT 254,80,10,31,17,17,17,31,31,0 ' Cust Char #2 LCDOUT 254,88,10,31,17,17,31,31,31,0 ' Cust Char #3 LCDOUT 254,96,10,31,17,31,31,31,31,0 ' Cust Char #4 LCDOUT 254,104,10,31,31,31,31,31,31,0 ' Cust Char #5 LCDOUT 254,112,15,3,5,9,16,16,16,0 ' Cust Char #6 LCDOUT 254,120,1,1,1,18,20,24,30,0 ' Cust Char #7
Sorry, sometimes I get carried away ...
Code:'*************************************************************************** '* Name : DT18x20_Fratello.pbp '* Author : Darrel Taylor '* Date : 2/19/2012 '* Version : 1.1 (2/24/2012) '* Target : 16F684 @ 4 mhz '*************************************************************************** DEFINE OSC 4 CLEAR ;----[Main Options]--------------------------------------------------------- TimeToShow CON 5 ; Seconds to show each temperature ;----[Battery Options]------------------------------------------------------ Res1 CON 20000 ; Top Resistor of Voltage Divider Res2 CON 10000 ; Bottom Resistor of Divider VDD CON 50 ; VDD voltage MaxBat CON 140 ; 14.0V ; Batt indicator Max MinBat CON 98 ; 9.8V ; Batt indicator Min ;----[DS1820 Options]----Value----Default----------------------------------- DEFINE DS1820_DECIMALS 1 ; 1 DEFINE DS18B20_ONLY YES ; NO DEFINE DS1820_VERIFYCRC YES ; NO DEFINE DS1820_USETIMEOUT NO ; YES MaxRetries CON 4 INCLUDE "DT18x20.pbp" ; Include DT18x20 module ; --- To get the include file, Register at http://darreltaylor.com/whatsup/ Inside VAR PORTC.5 ; Pin assigned to Inside Sensor Outside VAR PORTC.4 ; Pin assigned to Outside Sensor ;----[Elapsed Timer]-------------------------------------------------------- INCLUDE "Elapsed.bas" ; --- To get the include file ... Go to ... ; --- http://www.pbpgroup.com/modules/wfsection/article.php?article GOSUB ResetTime ;----[LCD definitions]------------------------------------------------------ DEFINE LCD_DREG PORTC ; LCD Data port DEFINE LCD_DBIT 0 ; starting Data bit (0 or 4) DEFINE LCD_EREG PORTA ; LCD Enable port DEFINE LCD_EBIT 2 ; Enable bit DEFINE LCD_RSREG PORTA ; LCD Register Select port DEFINE LCD_RSBIT 1 ; Register Select bit DEFINE LCD_BITS 4 ; LCD bus size (4 or 8 bits) DEFINE LCD_LINES 2 ; number of lines on LCD DEFINE LCD_COMMANDUS 2000 ; Command delay time in us DEFINE LCD_DATAUS 50 ; Data delay time in us ;----[Analog options]------------------------------------------------------- DEFINE ADC_BITS 10 DEFINE ADC_CLOCK 3 ADCON0.7=1 ; Right Justify A/D results ;----[Program Variables]---------------------------------------------------- BattLevel VAR BYTE ; 0 - 10, 0=Empty 10=Full RawBattery VAR WORD Volts VAR WORD LastVolts VAR WORD : LastVolts=0 Sensor VAR BIT : Sensor=1 Char VAR BYTE y VAR BYTE Retries VAR BYTE TempW VAR WORD GIE VAR INTCON.7 ;----[Initialization]------------------------------------------------------- CMCON0=7 ; disable Comparators ANSEL=0 ; All Digital ADCON1=$30 ; ADC_CLOCK is FRC LCDOUT $FE,1:PAUSE 250:LCDOUT $FE,1 ' Initialize LCD LCDOUT " TERMO- ",$FE,$C0," VOLT " GOSUB StartConversions ; get the first reading started PAUSE 4000 GOSUB StartTimer ; Start the Elapsed Timer Seconds=TimeToShow ; Force 1st display on start-up SecondsChanged=1 ;----[Main Program Loop]---------------------------------------------------- Main: IF SecondsChanged THEN SecondsChanged=0 IF Seconds !=0 AND Seconds != TimeToShow THEN GOSUB StartConversions IF Seconds=TimeToShow THEN ; on each period Seconds=0 Sensor=!Sensor ; Toggle sensors LCDOUT $FE,$80 IF Sensor=0 THEN LCDOUT "I: " ; Indicate Inside sensor ELSE LCDOUT "O: " ; Indicate Outside sensor ENDIF ENDIF ENDIF ;--------------------------------- IF Sensor=0 THEN @ DS1820_Select _Inside ; Select Inside DS18x20 pin ELSE @ DS1820_Select _Outside ; Select Outside DS18x20 pin ENDIF DS1820_Flags=0 ; clear flags before Stat GIE=0 ; disable interrupts @ DS1820_Stat ; get sensor status GIE=1 ; enable interrupts IF DS1820_Done THEN ; if conversion finished @ DS1820_Read ; try to read the temp Retries=0 RetryRead: IF DS1820_Error=0 THEN ; if there were no errors GOSUB TempToLCD ; display TempC ELSE ;--- Error reading Sensor -------- IF Retries < MaxRetries THEN Retries=Retries + 1 @ DS1820_Read ; try to read it again (no Conv) GOTO RetryRead ENDIF LCDOUT $FE,$82,"Error " ENDIF ENDIF GOSUB ReadVoltage PAUSE 100 GOTO Main ;----[Start conversion on both sensors]------------------------------------- StartConversions: @ DS1820_Select _Inside ; Select Inside DS18x20 pin @ DS1820_Convert ; start conversion @ DS1820_Select _Outside ; Select Outside DS18x20 pin @ DS1820_Convert ; start conversion RETURN ;----[Display TempC on LCD]------------------------------------------------- TempToLCD: TempW=TempC LCDOUT $FE,$82 IF ABS(TempW)/DS1820_DIG < 10 THEN LCDOUT " " IF TempW.15 THEN LCDOUT "-" ; if negative, display minus sign ELSE LCDOUT "+" ENDIF TempW=ABS(TempW) ; get the positive value LCDOUT DEC TempW/DS1820_DIG ; Display the Integer portion LCDOUT "." ; display decimal point TempW=TempW//DS1820_DIG ; get decimal portion LCDOUT DEC1 TempW DIG 0 IF ABS(TempC) < 1000 THEN LCDOUT $DF ENDIF RETURN ;----[Read battery voltage]------------------------------------------------- RT CON Res1 + Res2 ; Total Divider Resistance ReadVoltage: ADCIN 3, RawBattery Volts=RawBattery * Rt Volts=DIV32 Res2 Volts=Volts * VDD Volts=DIV32 1023 IF Volts != LastVolts THEN LastVolts=Volts LCDOUT $FE,$C1 IF Volts/10 < 10 THEN LCDOUT " " LCDOUT " ",DEC Volts/10,",",DEC1 Volts Dig 0," V" IF Volts >= MaxBat THEN BattLevel=12 ELSE IF Volts <= MinBat THEN BattLevel=0 ELSE BattLevel=(Volts - MinBat +1) * 12 / (MaxBat - MinBat +1) ENDIF ENDIF GOSUB ShowBattery ENDIF RETURN ;----[Show Battery Icon 0 - 12, 0=Empty 12=Full]-------------------------- ShowBattery: lcdout $FE,$C0,1,$FE,$48,$0A,$1F for y=4 to 1 step -1 if BattLevel >= (y * 3) then Char=$1F else if BattLevel >= (y * 3 - 1) then Char=$17 else if BattLevel >= (y * 3 - 2) then Char=$13 else Char=$11 endif endif endif lcdout Char next y lcdout $1F return
Last edited by Darrel Taylor; - 24th February 2012 at 08:16.
DT
A GREAT piece of code ! A VERRY GOOD EXAMPLE !!!
As usual, I'm speechless...Thank YOU, Mr. Darrel !
![]()
Bookmarks