What if you comment the DS1820 logic, set temperature and sign to -20 and test only the display logic?
Robert
Printable View
What if you comment the DS1820 logic, set temperature and sign to -20 and test only the display logic?
Robert
Near the top of the program you set up a config line but it's commented out. I think for that chip to need to set the HS osc since you're using a 20Meg unit.
Do you also need to set the CONFIG register to set for oscillator speed and type?
I'm looking over the data sheet but have to catch it in fits and starts. More questions later.
Thanks for advice ....
Indeed I commented this : ";@ __config _HS_OSC & _WDT_ON & _PWRTE_ON & _LVP_OFF"
But in Proteus I set the freq to 20 MHz.
If I write "temperature=123", the display show "12.3" ; so, it's work ...but the reading of sensor not work / or the temperature is wrong calculated ...
So the LCD logic works, that's a start.
Are you doing this only in proteus?
Robert
No, I have builded the hardware too ...
Note : the code for temperature sensor is for DS1820 ; I use DS18B20 - maybe this is the problem ?!
Hello Fratello,
your code
Best I remember and for reasons I don't you cannot assign a port value just that way. Something about BLA = bla being a T/F comparason rather than assignment, don't remember just fuzzy . . . I believe PORTA=_7seg1 is a comparason operator and putting ! or ~ ahead of it converts it to a "Bitwise" operationCode:PORTA=_7seg1 ' enable hundreds 7 segment
displayport = digit_1 ' display
GoSub DelayBetweenEachDigit
Try this
As I have not really studied your code I may have misread where your port display is, in any event use not or 2 nots before that port assignment.Code:PORTA=~_7seg1 ' enable hundreds 7 segment
displayport = digit_1 ' display
GoSub DelayBetweenEachDigit
and if that inverts your display then use 2 nots
PORTA=~~_7seg1 ' enable hundreds 7 segment
displayport = digit_1 ' display
GoSub DelayBetweenEachDigit
A couple of other things I question:Please bear in mind I'm not a real programmer just a poor hacker!
You say you set a rate in Protues but don't you have to have those configs to set the chip up to work at that speed even in Proteus?
Once you go through the mainloop you never go back to it. I don't see a line in your code where you have goto mainloop anywhere.
On the write1820 sub, and some others, you write either a 0 or a1 then shift if right 1 digit. Won't that constantly shift in a zero? And in same sub there are 8 bits to a byte but I think they shouldstart at 0 not 1. I don't really understand how that works so if I'm wrong I'll look up the 1820 and get schooled up.
A couple of other things I question:Please bear in mind I'm not a real programmer just a poor hacker!
You say you set a rate in Protues but don't you have to have those configs to set the chip up to work at that speed even in Proteus?
Once you go through the mainloop you never go back to it. I don't see a line in your code where you have goto mainloop anywhere.
On the write1820 sub, and some others, you write either a 0 or a1 then shift if right 1 digit. Won't that constantly shift in a zero? And in same sub there are 8 bits to a byte but I think they shouldstart at 0 not 1. I don't really understand how that works so if I'm wrong I'll look up the 1820 and get schooled up.
Thank you all for support !
1. The code (last version, from previous page) work fine - at least show a clear, flicker-free suite of "0" , if I comment all references to temperature ...
The "copyright code" belong to Mr.Monfette (' File name : Count_Display.bas ' Company : Mister E ' Programmer : Steve Monfette) so it's a WORKING code for LED display. Me, I just attempted to adapt to my project - reading DS18B20 sensor !
2.If I write in code this line "temperature=123" (instead "calculated" value of temperature), the display show "12.3" ; so, it's work ...but the reading of sensor not work / or the temperature is wrong calculated ...
3.Indeed, the return in loop was to "DisplayRefresh:", not to "Mainloop:". I've changed that, but not results !
...
Me, again ...
I have some good results ! I used example from "EXPERIMENTING WITH THE PICBASIC PRO COMPILER", by Les.Johnson.
Main code :
and the include file :Code:' Program Thermo-LED, mod. of DISP_TST.BAS
' *************************************************************
' * For use with EXPERIMENTING WITH THE PICBASIC PRO COMPILER *
' * *
' * This source code may be freely used within your own *
' * programs. However, if it is used for profitable reasons, *
' * please give credit where credit is due. *
' * And make a reference to myself or Rosetta Technologies *
' * *
' * Les. Johnson *
' *************************************************************
'
' Demonstrate the use of the 7-segment display multiplexing include files.
'
' Upon the programs start a TMR0 interrupt is automatically started
' using the compilers ON INTERRUPT command
' To display a value on the leds,
' Place the value to display into the variable D_NUMBER
' and the decimal point location into the variable DP.
' A value of 0 in DP will disable the decimal point
' ***********************************************************************
@ DEVICE pic16F628A, intOSC_osc_noclkout, WDT_OFF, PWRT_ON, MCLR_OFF, LVP_OFF, CPD_OFF, PROTECT_OFF
Include "Modedefs.Bas"
Include "d:\PBP\3CC_DAN.Inc" ' Load the 3-digit display multiplexor, modified for my hw
' ** Setup the Crystal Frequency, in mHz **
Define OSC 4 ' Set Xtal Frequency
CMCON=7 ' Disable comparators
TRISB = %00000000 ' Set segment pins to output
TRISA = $F0 ' Set digit pins to output
Temp Var Byte
Temperature Var Word
TempC Var Word
I Var Byte
Float Var Word
V Var Word
Dummy Var Byte
n Var Byte
value Var Word
DQ VAR PORTA.4
' ** Declare the Variables **
Counter Var Word ' General purpose counter
Del Var Word ' General purpose delay loop variable
DS18B20_12bit CON %01111111 ' 750ms, 0.0625°C
Init_sensor:
OWOUT DQ, 1, [$CC, $4E, 0, 0, DS18B20_12bit]
OWOut DQ, 1, [$CC, $48]
OWOut DQ, 1, [$CC, $B8]
OWOut DQ, 1, [$CC, $BE]
Pause 50
OWIn DQ, 2, [temperature.byte0, temperature.byte1]
' ** THE MAIN PROGRAM STARTS HERE **
Main:
OWOut DQ, 1, [$CC, $44]
OWOut DQ, 1, [$CC, $BE]
OWIn DQ, 2, [temperature.byte0, temperature.byte1]
If Temperature.15 then
Temperature= ~Temperature +1
Sign = 1
Endif
Dummy = 625 * Temperature
TempC = DIV32 10
TempC = (Temperature & $7FF) >> 4
Float = ((Temperature.Lowbyte & $0F ) * 25 )>>2
Temperature = TempC*100 + Float
If Sign=1 then
V= 10000 - Temperature
else
V= 10000 + Temperature
EndIf
If V >= 10000 then
Temperature=V-10000
sign = 0
else
Temperature=10000-V
sign = 1
EndIf
value=temperature/10
D_Number=value ' Place the value to display into D_NUMBER
DP=2 ' Enable the decimal point
Gosub Display ' Display the value
For Del=0 to 8000 ' Pause 10ms
Pauseus 100 ' using smaller delays
Next
Inf: Goto Main ' Do it forever
I have now a sharp display (sharper by decreasing this value : For Del=0 to 8000 ) with a verry, verry little flicker, almost imperceptible ! It is by far the best option until now !Code:' Program 3CC.DISP.INC
' *************************************************************
' * For use with EXPERIMENTING WITH THE PICBASIC PRO COMPILER *
' * *
' * This source code may be freely used within your own *
' * programs. However, if it is used for profitable reasons, *
' * please give credit where credit is due. *
' * And make a reference to myself or Rosetta Technologies *
' * *
' * Les. Johnson *
' *************************************************************
'
' Common Anode (Cathode) seven segment display multiplexer Include file
' Displays the contents of the variable D_NUMBER on THREE common anode (cathode) displays
' using a TMR0 interrupt every 6.5ms (assuming a 20mHz oscillator)
' ***********************************************************************
' ** Declare the Variables **
LEDS Var Byte ' The amount of LEDs in the display
O_C Var Byte ' Used by the interrupt for time sharing
D_Number Var Word ' The number to display on the LEDS
DP Var Byte ' Position of the decimal point
Disp_Patt Var Byte ' Pattern to output to PortC
Num Var Byte[3] ' Array to hold each digits value
Digit0 Var PortA.0 ' Controls the first DIGIT on the LED
Digit1 Var PortA.1 ' Controls the second DIGIT on the LED
Digit2 Var PortA.2 ' Controls the third DIGIT on the LED
sign var word
' ** Declare the bits and flags of the various registers **
T0IE Var INTCON.5 ' Timer0 Overflow Interrupt Enable
T0IF Var INTCON.2 ' Timer0 Overflow Interrupt Flag
GIE Var INTCON.7 ' Global Interrupt Enable
PS0 Var OPTION_REG.0 ' Prescaler division bit-0
PS1 Var OPTION_REG.1 ' Prescaler division bit-0
PS2 Var OPTION_REG.2 ' Prescaler division bit-0
PSA Var OPTION_REG.3 ' Prescaler Assignment (1= assigned to WDT)
' (0= assigned to oscillator)
T0CS Var OPTION_REG.5 ' Timer0 Clock Source Select (0=Internal clock)
' (1=External PORTA.4)
' ** THE MAIN PROGRAM STARTS HERE **
' Set TMR0 to interrupt
GIE=0 ' Turn off global interrupts
While GIE=1:GIE=0:Wend ' Make sure they are off
PSA=0 ' Assign the prescaler to external oscillator
PS0=0 '0 ' Set the prescaler
PS1=1 '1 ' to increment TMR0
PS2=0 '0 ' every 128th instruction cycle ' settings for 4 MHz oscillator
T0CS=0 ' Assign TMR0 clock to internal source
TMR0=0 ' Clear TMR0 initially
T0IE=1 ' Enable TMR0 overflow interrupt
GIE=1 ' Enable global interrupts
On Interrupt Goto Mult_Int ' Point to the interrupt handler
TrisB=0 ' Make PortB outputs
TrisA.0=0:TrisA.1=0:TrisA.2=0 ' Make only the specific bits of PortA outputs
PortA=0:PortB=0 ' Clear PortA and PortB
O_C=0 ' Clear the time share variable
Goto Over_MULTIPLEXER ' Jump over the subroutines
' Build up the seperate digits of variable D_NUMBER
' into the array NUM. Each LED is assigned to each array variable.
' LED-0 (right) displays the value of NUM[0]
' LED-1 (middle) displays the value of NUM[1]
' LED-2 (lef) displays the value of NUM[2]
' The decimal point is placed by loading the variable DP
' with the LED of choice to place the point (0..3). where 1 is the farthest right LED,
' and 0 disables the decimal point.
Display:
For LEDS=2 to 0 step -1 ' Loop for 3 digits (0-999)
Disable ' Disable the interrupt while we calculate
Num[LEDS]=D_Number dig LEDS ' Extract the seperate digits into the array
;If D_Number<10 and LEDS=1 then Num[LEDS]=10 ' Zero Suppression for the second digit ; not used in my program
If D_Number<100 and LEDS=2 then Num[LEDS]=10 ' Zero Suppression for the Third digit
Enable ' Re-enable the interrupt
Next
Return
' INTERRUPT HANDLER
' Multiplexes the 4-digits
'
Disable ' Disable all interupts during the interrupt handler
Mult_Int:
' Lookup Num[O_C],[63,6,91,79,102,109,124,7,127,103,0],Disp_Patt ' Decode the segments for the LED
Lookup Num[O_C],[192,249,164,176,153,146,130,248,128,144,255],Disp_Patt
' Process the first display (farthest right)
If O_C=0 then ' If it is our turn then
Digit2=0 ' Turn OFF the third LED
PortB=Disp_Patt ' Place the digit pattern on portC
If DP=1 then PortB.7=0 ' Check the value of DP and Turn ON the decimal point
Digit0=1 ' Turn ON the first LED
Endif
' Process the second display
If O_C=1 then ' If it is our turn then
Digit0=0 ' Turn OFF the first LED
PortB=Disp_Patt ' Place the digit pattern on portC
If DP=2 then PortB.7=0 ' Check the value of DP and Turn ON the decimal point
Digit1=1 ' Turn ON the second LED
Endif
' Process the third display
If O_C=2 then ' If it is our turn then
Digit1=0 ' Turn OFF the second LED
PortB=Disp_Patt ' Place the digit pattern on portC
If DP=3 then PortB.7=0 ' Check the value of DP and Turn ON the decimal point
if sign = 1 then portb.6 = 0
Digit2=1 ' Turn ON the third LED
Endif
O_C=O_C+1 ' Increment the time share counter
If O_C>=3 then O_C=0 ' If it reaches 4 or over then clear it
T0IF=0 ' Reset TMR0 interrupt flag
Resume ' Exit the interrupt
Enable ' Allow more interrupts
Over_MULTIPLEXER: