PDA

View Full Version : Comparison problem



ngeronikolos
- 10th March 2006, 08:31
Hello boys and girls,

I have a problem with my code.I measure themperature using DS1820 and display it on an LCD.I want to hear a buzzer if the temurature reach 90 degrees C.My comparison is not working.
PLEASE HAVE A LOOK


-------------------------------------------
@ DEVICE pic16F628, INTRC_OSC_NOCLKOUT ' system clock options
@ DEVICE pic16F628, WDT_ON ' watchdog timer
@ DEVICE pic16F628, PWRT_ON ' power-on timer
@ DEVICE pic16F628, MCLR_OFF ' master clear options (internal)
@ DEVICE pic16F628, BOD_ON ' brown-out detect
@ DEVICE pic16F628, LVP_OFF ' low-voltage programming
@ DEVICE pic16F628, CPD_OFF ' data memory code Protect
@ DEVICE pic16F628, PROTECT_OFF ' program code protection


Define LCD_BITS 4 ' 4-bit interface
Define LCD_LINES 2 ' 2 line LCD


Define LCD_DREG PORTA
Define LCD_DBIT 0

Define LCD_RSREG PORTA
Define LCD_RSBIT 4

Define LCD_EREG PORTB
Define LCD_EBIT 3


Define LCD_COMMANDUS 2000 ' Adjust for slower LCD modules
Define LCD_DATAUS 50

INCLUDE "MODEDEFS.BAS"
INTCON = 0 ' Disable interrupts
CMCON = 7
Pause 500 ' Wait for LCD to startup

Lcdout $fe, 1 ' Clear LCD screen
Lcdout "By:Geronikolos" ' Display Hello

Lcdout $fe,$c0,"FW-05T" ' Clear LCD screen
PAUSE 5000 ' Wait 5 second

DQ var PortB.4
temp var word

loop:
owout DQ,1,[$cc]
owout DQ,0,[$44]
Pause 2000
owout DQ,1,[$cc]
owout DQ,0,[$be]
owin DQ,0,[temp.byte0,temp.byte1]
lcdout $FE,1
temp=temp*5
lcdout $fe, 1,"Temp = ",DEC2 temp/10,".", dec1 temp," ",$DF,"C"
lcdout $fe, $C0,"Temp = ",dec temp
pause 2000
IF temp > 90 THEN ;--this comparison is not working FOR 90 DEGREES
portb.0 = 1
endif
goto loop
end
---------------------------------------------------------------


Regards
Nikos

sougata
- 10th March 2006, 14:57
Hi,

Add this line to the top of your code:

TRISB = %xxxxxxx0

Hope this helps.

ngeronikolos
- 10th March 2006, 15:02
My friend sougata,

I do not think this is the problem!!!But I will try to do it now.

The problem is the the comparison.
temp is binary or not?
How can I do a comparison with temp and 90?

Thanks
Regards

ngeronikolos
- 10th March 2006, 15:51
Thanks
You are right.I should have cofigured the portb.o as input.

Do you have an idea how can I reduce my consuption?
I have 16f627 internal osc+lcd module+ds1820
When the pic do a mesurment for the ds1820 my current is 4.5mA and when it do not it is 3mA.

Any idea to reduce the curent?
Thanks
Best regards

paul borgmeier
- 10th March 2006, 21:08
Most of the time your program appears to be “PAUSE”ing. The first thing to do would be to use the NAP or SLEEP command instead of PAUSE. (Make sure and enable the WDT - See the manual)

Good Luck,

Paul Borgmeier
Salt Lake City, Utah
USA