ok it's not 4am (it's 8:15am)
i see what the dcd command is doing (common anode as you noted).
For the digit you want to have the dp on try
Sements.7 = 0 (provided your PORT.7 pin is tied to the DP via wire or trace
Good Luck
ok it's not 4am (it's 8:15am)
i see what the dcd command is doing (common anode as you noted).
For the digit you want to have the dp on try
Sements.7 = 0 (provided your PORT.7 pin is tied to the DP via wire or trace
Good Luck
Last edited by paul borgmeier; - 23rd December 2006 at 15:19.
Paul Borgmeier
Salt Lake City, UT
USA
__________________
One more time - after a proper days rest, I have no clue what your code does; it looks to me to be partly written for common anode displays ($3F=1) and partly written for common cathode displays (Digits = ~DCD i). The Segments.7=0 should work (right after your lookup table) for the digit you want the DP to be on. Please post full code or schematic for more definite help.
Again, Good Luck
Paul Borgmeier
Salt Lake City, UT
USA
__________________
Hi paul borgmeier
Now I try to show temp with DS1820 on 7 seg 4 digit
Below is code , I can read data temp from ds1820 and send to RS232 -->OK but canot to diplay to 7 Seg. Ex 29.05C
Code :
Define LOADER_USED 1
DEFINE OSC 4
@ Device pic16F877, xt_OSC, BOD_OFF, PWRT_ON, WDT_OFF, PROTECT_OFF,WRT_ON
Segments Var PORTC
Digits Var PORTD
i Var Byte
n Var Byte
Value Var Word
TRISc = $00 ' Set segment pins to output
TRISd = $f0 ' Set digit pins to output
' Allocate variables
command var byte ' Storage for command
J var byte ' Storage for loop counter
temp var word ' Storage for temperature
DQ var PORTd.4 ' Alias DS1820 data pin
DQ_DIR var TRISd.4 ' Alias DS1820 data direction pin
TRISc = $00 ' Set segment pins to output
TRISd = $f0 ' Set digit pins to output
TrisB = $00
Portb = $00
OPTION_REG = $55 ' Set TMR0 configuration 1:64
INTCON = $A0 ' Enable TMR0 interrupts
On Interrupt Goto display
ADCON1 = 7 ' Set PORTA and PORTE to digital
' Lcdout $fe, 1, "Temp in degrees C" ' Display sign-on message
'debug ====
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_SPBRG 12 ' 19200 Bauds ,4 m
'debug ====
' Mainloop to read the temperature and display on LCD
mainloop:
Gosub init1820 ' Init the DS1820
command = $cc ' Issue Skip ROM command
Gosub write1820
command = $44 ' Start temperature conversion
Gosub write1820
Pause 2000 ' Wait 2 seconds for conversion to complete
Gosub init1820 ' Do another init
command = $cc ' Issue Skip ROM command
Gosub write1820
command = $be ' Read the temperature
Gosub write1820
Gosub read1820
'Display the decimal temperature
'Lcdout $fe, 1, dec (temp >> 1), ".", dec (temp.0 * 5), " degrees C"
'HSEROUT ["Temp = ",dec (temp>>1),".", dec (temp.0*5)," C",13,10]
Goto mainloop ' Do it forever
' Initialize DS1820 and check for presence
init1820:
Low DQ ' Set the data pin low to init
Pauseus 500 ' Wait > 480us
DQ_DIR = 1 ' Release data pin (set to input for high)
Pauseus 100 ' Wait > 60us
If DQ = 1 Then
'Lcdout $fe, 1, "DS1820 not present"
Pause 500
Goto mainloop ' Try again
Endif
Pauseus 400 ' Wait for end of presence pulse
Return
' Write "command" byte to the DS1820
write1820:
For j = 1 to 8 ' 8 bits to a byte
If command.0 = 0 Then
Gosub write0 ' Write a 0 bit
Else
Gosub write1 ' Write a 1 bit
Endif
command = command >> 1 ' Shift to next bit
Next j
Return
' Write a 0 bit to the DS1820
write0:
Low DQ
Pauseus 60 ' Low for > 60us for 0
DQ_DIR = 1 ' Release data pin (set to input for high)
Return
' Write a 1 bit to the DS1820
write1:
Low DQ ' Low for < 15us for 1
@ nop ' Delay 1us at 4MHz
DQ_DIR = 1 ' Release data pin (set to input for high)
Pauseus 60 ' Use up rest of time slot
Return
' Read temperature from the DS1820
read1820:
For J = 1 to 16 ' 16 bits to a word
temp = temp >> 1 ' Shift down bits
Gosub readbit ' Get the bit to the top of temp
Next J
Return
' Read a bit from the DS1820
readbit:
temp.15 = 1 ' Preset read bit to 1
Low DQ ' Start the time slot
@ nop ' Delay 1us at 4MHz
DQ_DIR = 1 ' Release data pin (set to input for high)
If DQ = 0 Then
temp.15 = 0 ' Set bit to 0
Endif
Pauseus 60 ' Wait out rest of time slot
Return
'================== 7 seg ment display ==============================
disable
display:
INTCON.2 = 0 'clear the interrupt flag
VALUE = (temp >>1)+(temp.0 * 5)
For i = 0 To 3 ' Loop through 4 digits
n = Value Dig i ' Get digit to display
Gosub display1 ' Display the value
NEXT I
goto mainloop
display1:
Digits = $ff ' All digits off to prevent ghosting
' Convert binary number in n to segments for LED
' COM ANODE 1234567890
Lookup n, [$3F,$06, $5B, $4F, $66, $6D, $7D, $07, $7F, $6F, $77, $7C, $39, $5E, $79, $71], Segments
' Set digit pin i to 0 (on) and the rest of the pins to 1 (off)
Digits = ~Dcd i
Return
enable
End
[QUOTE=chai98a;30011]Hi paul borgmeier
Now I try to show temp with DS1820 on 7 seg 4 digit
Below is code , I can read data temp from ds1820 and send to RS232 -->OK but canot to diplay to 7 Seg. Ex 29.5C
How to show number , dot and character on display ??
Code :
Define LOADER_USED 1
DEFINE OSC 4
@ Device pic16F877, xt_OSC, BOD_OFF, PWRT_ON, WDT_OFF, PROTECT_OFF,WRT_ON
Segments Var PORTC
Digits Var PORTD
i Var Byte
n Var Byte
Value Var Word
TRISc = $00 ' Set segment pins to output
TRISd = $f0 ' Set digit pins to output
' Allocate variables
command var byte ' Storage for command
J var byte ' Storage for loop counter
temp var word ' Storage for temperature
DQ var PORTd.4 ' Alias DS1820 data pin
DQ_DIR var TRISd.4 ' Alias DS1820 data direction pin
TRISc = $00 ' Set segment pins to output
TRISd = $f0 ' Set digit pins to output
TrisB = $00
Portb = $00
OPTION_REG = $55 ' Set TMR0 configuration 1:64
INTCON = $A0 ' Enable TMR0 interrupts
On Interrupt Goto display
ADCON1 = 7 ' Set PORTA and PORTE to digital
' Lcdout $fe, 1, "Temp in degrees C" ' Display sign-on message
'debug ====
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_SPBRG 12 ' 19200 Bauds ,4 m
'debug ====
' Mainloop to read the temperature and display on LCD
mainloop:
Gosub init1820 ' Init the DS1820
command = $cc ' Issue Skip ROM command
Gosub write1820
command = $44 ' Start temperature conversion
Gosub write1820
Pause 2000 ' Wait 2 seconds for conversion to complete
Gosub init1820 ' Do another init
command = $cc ' Issue Skip ROM command
Gosub write1820
command = $be ' Read the temperature
Gosub write1820
Gosub read1820
'Display the decimal temperature
'Lcdout $fe, 1, dec (temp >> 1), ".", dec (temp.0 * 5), " degrees C"
'HSEROUT ["Temp = ",dec (temp>>1),".", dec (temp.0*5)," C",13,10]
Goto mainloop ' Do it forever
' Initialize DS1820 and check for presence
init1820:
Low DQ ' Set the data pin low to init
Pauseus 500 ' Wait > 480us
DQ_DIR = 1 ' Release data pin (set to input for high)
Pauseus 100 ' Wait > 60us
If DQ = 1 Then
'Lcdout $fe, 1, "DS1820 not present"
Pause 500
Goto mainloop ' Try again
Endif
Pauseus 400 ' Wait for end of presence pulse
Return
' Write "command" byte to the DS1820
write1820:
For j = 1 to 8 ' 8 bits to a byte
If command.0 = 0 Then
Gosub write0 ' Write a 0 bit
Else
Gosub write1 ' Write a 1 bit
Endif
command = command >> 1 ' Shift to next bit
Next j
Return
' Write a 0 bit to the DS1820
write0:
Low DQ
Pauseus 60 ' Low for > 60us for 0
DQ_DIR = 1 ' Release data pin (set to input for high)
Return
' Write a 1 bit to the DS1820
write1:
Low DQ ' Low for < 15us for 1
@ nop ' Delay 1us at 4MHz
DQ_DIR = 1 ' Release data pin (set to input for high)
Pauseus 60 ' Use up rest of time slot
Return
' Read temperature from the DS1820
read1820:
For J = 1 to 16 ' 16 bits to a word
temp = temp >> 1 ' Shift down bits
Gosub readbit ' Get the bit to the top of temp
Next J
Return
' Read a bit from the DS1820
readbit:
temp.15 = 1 ' Preset read bit to 1
Low DQ ' Start the time slot
@ nop ' Delay 1us at 4MHz
DQ_DIR = 1 ' Release data pin (set to input for high)
If DQ = 0 Then
temp.15 = 0 ' Set bit to 0
Endif
Pauseus 60 ' Wait out rest of time slot
Return
'================== 7 seg ment display ==============================
disable
display:
INTCON.2 = 0 'clear the interrupt flag
VALUE = (temp >>1)+(temp.0 * 5)
For i = 0 To 3 ' Loop through 4 digits
n = Value Dig i ' Get digit to display
Gosub display1 ' Display the value
NEXT I
goto mainloop
display1:
Digits = $ff ' All digits off to prevent ghosting
' Convert binary number in n to segments for LED
' COM ANODE 1234567890
Lookup n, [$3F,$06, $5B, $4F, $66, $6D, $7D, $07, $7F, $6F, $77, $7C, $39, $5E, $79, $71], Segments
' Set digit pin i to 0 (on) and the rest of the pins to 1 (off)
Digits = ~Dcd i
Return
enable
End
I see - the PNPs (which I did not know about) threw me off. It appears proper for Common Anode.
Try this:
1) On your buffer, tie 1 and 19 low so they do not float.
2) The 3rd from last line of your code - change "Return" to "Resume" (See manual section on On Interrupt for details).
Please report back progress so that others following this can get closure.
EDIT:
3) Your lookup values need to be inverted - as written they are for common cathode displays. Change to ($C0, $F9, $A4, etc) where the segments you want off are high and the segments you want on are low.
4) To turn on the decimal point on the second digit, insert right after the lookup table
if i = 1 then Segments.7 = 0 (or if the DP is always to be on you could do this in hardware by disconnecting RC7 from D7 on U2 and connecting RD1 to D7 on U2 (in addition to RD1 going to the Base of Q2))
Last edited by paul borgmeier; - 26th December 2006 at 07:15. Reason: add more info
Paul Borgmeier
Salt Lake City, UT
USA
__________________
Here is the full list of Common Cathode:
Starting from 0 to 9.
$c0, $F9, $A4, $B0, $99, $92, $82, $F8, $80, $90
------------------------------
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
Sayzer,
You bolded Common Cathode as if it is for sure - you must mean Common Anode. Common Cathode requires the segment to be high to be on while Common Anode requires Segments to be low to be on. His buffer is non-inverting. (Your set looks correct though - I left a little for the OP to work out as a learning exercise but now he is close to set).
EDIT:
Oh, for thoroughness, have you considered testing DT's suggested gif animator at 1/4 scale?![]()
![]()
Last edited by paul borgmeier; - 26th December 2006 at 19:35.
Paul Borgmeier
Salt Lake City, UT
USA
__________________
Bookmarks