PDA

View Full Version : Need help Temp and 7segment led display



mastero
- 11th August 2006, 13:26
Hello all,

I am having difficulty in a project which i am working on.

I require temperature reading on two 7 segement LED display.

Using 16f72 and LM34 as sensor

Does anyone know of a program which will read the temp from LM34 and display it on two LED segment display something like this

h**p://www.geocities.com/hagtronics/thermometer.html

I can program the LM34 to read temp and display on LCD but not 7 segment LED display.

Anyhelp is good

Cheers
Mastero

Darrel Taylor
- 11th August 2006, 17:40
Check out the 7segment.pbp sample program at meLabs

http://www.melabs.com/resources/samples.htm

HTH,
  Darrel

mastero
- 11th August 2006, 18:37
I have already checked it out and others.. the problem is putting the temp reading on LED :(

************************************************** ******
DEVICE 16F72
DEFINE osc 4 ' 4 MHz oscillator
DEFINE ADC_BITS 8 ' Set A/D for 8-bit operation
DEFINE ADC_CLOCK 1 ' Set A/D clock Fosc/8
DEFINE ADC_SAMPLEUS 50 ' Set A/D sampling time @ 50 uS
Dim digit As Byte 'input variable for GETMASK subroutine
Dim digit1 As Byte 'current digit1
Dim digit2 As Byte 'current digit2
Dim mask As Byte 'output variable from GETMASK subroutine
Dim mask1 As Byte 'current digit1 mask
Dim mask2 As Byte 'current digit2 mask
Dim temp As Word 'Temperature storage

Dim samples As WORD ' Multiple A/D sample accumulator
Dim sample As BYTE ' Holds number of samples to take

Symbol d1enable = PORTC.7 'enable line for display1
Symbol d2enable = PORTC.6 'enable line for display2

TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %00000011 ' Set PORTA.0,1,2,5 = A/D, PortA.3 = +Vref
TRISB = %00000000 'set PORTB pins as outputs
TRISC.7 = 0 'set RD4 pin as output
TRISC.6 = 0 'set RD5 pin as output

LOW d1enable
LOW d2enable
mask1 = 0 ' Clear samples accumulator on power-up
mask2 = 0 ' Clear samples accumulator on power-up
samples = 0 ' Clear samples accumulator on power-up

PAUSE 250 ' Wait .5 second

loop:

FOR sample = 1 TO 20 ' Take 20 samples
ADCIN 0, temp ' Read channel 0 into temp variable
samples = samples + temp ' Accumulate 20 samples
PAUSE 250 ' Wait approximately 1/4 seconds per loop
NEXT sample
temp = samples/20

digit1 = temp / 10 'get current digit1
temp = temp // 10
digit2 = temp 'get current digit2
digit = digit1

Gosub getmask 'get mask for digit1
mask1 = mask
digit = digit2

Gosub getmask 'get mask for digit2
mask2 = mask

Gosub show1 'display new mask
Gosub show2 'display new mask

pause 500
samples = 0 ' Clear old sample accumulator

Goto loop

End

getmask: 'get appropriate 7-segment mask for input digit
mask = Lookupl digit,[$40,$79,$24,$30,$19,$12,$02,$78,$00,$18], digit
Return

show1: 'show digit1 on its display
LOW d1enable
LOW d2enable
PORTB = mask1
HIGH d1enable
Return

show2: 'show digit2 on its display
LOW d1enable
LOW d2enable
PORTB = mask2
HIGH d2enable
Return
************************************************** *******

Someone please check the above and let me know if there is any errors...?

Cheers
Mastero

Darrel Taylor
- 11th August 2006, 18:45
Well, this is a problem

mask = Lookupl digit,[$40,$79,$24,$30,$19,$12,$02,$78,$00,$18], digit

Try this instead ...

Lookup digit,[$40,$79,$24,$30,$19,$12,$02,$78,$00,$18], mask

HTH

P.S. You'll need to speed up the loop for it to display properly.

mastero
- 11th August 2006, 23:47
Is there a way i can have this whole process of reading the temp and displaying on the LEDs working in the background ? and the PIC is executing other commands.

Will HPWM work here as i have one ccp pin on 16f72

Thanks for your help

Mastero

Darrel Taylor
- 12th August 2006, 03:17
That's what I get for making a quick reply from work.

After looking again, it appears that your program is written for Proton.

Are you sure you're using PicBasic Pro?

If so then yes to your interrupt question.

If not, then you might want to try this forum.
http://www.picbasic.org/forum/
<br>

mastero
- 12th August 2006, 05:33
That's what I get for making a quick reply from work.

After looking again, it appears that your program is written for Proton.

Are you sure you're using PicBasic Pro?

If so then yes to your interrupt question.

If not, then you might want to try this forum.
http://www.picbasic.org/forum/
<br>

Now i am confused here :(

Will check and let you know

mister_e
- 12th August 2006, 11:04
Don't worry Darrel.. there's a mix of 2 PICBASIC compiler in there...


DEVICE 16F72

not valid in PBP neither in PROTON



DEFINE osc 4 ' 4 MHz oscillator
DEFINE ADC_BITS 8 ' Set A/D for 8-bit operation
DEFINE ADC_CLOCK 1 ' Set A/D clock Fosc/8
DEFINE ADC_SAMPLEUS 50 ' Set A/D sampling time @ 50 uS

PBP



Dim digit As Byte 'input variable for GETMASK subroutine
.
.
.
.

Proton



PAUSE 250 ' Wait .5 second

PBP native but now accepted by PROTON with a warning... well the last time i used it

Now Mastero is on PROTON forum with the same code...

mastero
- 12th August 2006, 14:04
Don't worry Darrel.. there's a mix of 2 PICBASIC compiler in there...


DEVICE 16F72

not valid in PBP neither in PROTON



DEFINE osc 4 ' 4 MHz oscillator
DEFINE ADC_BITS 8 ' Set A/D for 8-bit operation
DEFINE ADC_CLOCK 1 ' Set A/D clock Fosc/8
DEFINE ADC_SAMPLEUS 50 ' Set A/D sampling time @ 50 uS

PBP



Dim digit As Byte 'input variable for GETMASK subroutine
.
.
.
.

Proton



PAUSE 250 ' Wait .5 second

PBP native but now accepted by PROTON with a warning... well the last time i used it

Now Mastero is on PROTON forum with the same code...


Yes its proton i am using.

Cheers
Mastero