PDA

View Full Version : Simple question about "Sound" command



fratello
- 10th July 2012, 07:33
Hi !
I made one thermostat, with PIC16F628A and LCD display, for using as thermo-regulator. All works fine, but ... I want to have an audible "mark" when temperature is bigger/smaller than setting.
I wrote this :

If Temperature > Temp_Up then ' Above Target temperature
PORTA.2=0 ' Deactivate Warm output
PORTA.3=1 ' Activate Cold Output
SOUND PortA.7, [107,50]
EndIf
But in this way the buzzer sound WHILE Temperature > Temp_Up :( ... How can be setting to sound just 5 seconds, for example ?
Thanks in advance !

tasmod
- 10th July 2012, 09:26
I'm thinking this must be in a larger loop structure to keep returning to the routine.

How about this as an idea only:



If Temperature > Temp_Up then ' Above Target temperature
PORTA.2=0 ' Deactivate Warm output
PORTA.3=1 ' Activate Cold Output
SOUND PortA.7, [107,50]
temp_up = temp_up +5 'or 10 or whatever
endif 'as long as reset elsewhere

HenrikOlsson
- 10th July 2012, 09:51
You need a flag to remember that you've already sounded the alarm.



AlarmDone VAR BIT

IF Temperature > TempUp THEN
PortA.2 = 0
PortA.3 = 1
IF AlarmDone = 0 THEN ' Only activate alarm if not already activated.
SOUND PortA.7, [107, 50]
AlarmDone = 1 ' Alarm has been activated.
ENDIF
ELSE
AlarmDone = 0 ' Temperature is not over the limit, rearm the alarm.
ENDIF

fratello
- 10th July 2012, 11:03
Thanks for reply !
The second variant work verry fine. THANK YOU, Mr.Henrik ! As usual, You're a Great Gentleman !