PDA

View Full Version : Buttons



WarPony
- 15th May 2008, 02:58
I know this seems like a simple question, but I want to make sure my code is in the right ball park. The section of code should add 1 or minus 1 to a setpoint that another part of code will interpret and output to and lcd and turn on a red led or a green led

ADCON1 = 7 ' Set PORTD and PORTE to digital

Setpoint Var word
Temp_Down Var PortB.3 'Temp down button input port
Temp_Up VAR PortB.2 'Temp up button input port
R_LED VAR PortB.0 ' Red LED output
G_LED VAR PortB.1 ' Green LED output
DQ VAR PortC.0 ' One-wire Data-Pin "DQ" on PortC.0
Busy VAR BIT ' Busy Status-Bit
Sign VAR BYTE ' +/- sign for temp display
Dummy VAR BYTE ' Dummy for Div32
R_Temp VAR WORD ' RAW Temperature readings
TempC VAR WORD ' Temp in deg C
TempF VAR WORD ' Temp in deg F
Float VAR WORD ' Holds remainder for + temp C display
Cold_Bit VAR R_Temp.Bit11' Sign-Bit for +/- Temp. 1 = Below 0 deg C
Real_Cold CON 1 ' Define Real_Cold = 1
DS18B20_9bit CON %00011111 ' 93.75ms, 0.5°C
DS18B20_10bit CON %00111111 ' 187.5ms, 0.25°C <-- My favorite
DS18B20_11bit CON %01011111 ' 375ms, 0.125°C
DS18B20_12bit CON %01111111 ' 750ms, 0.0625°C (default)

OPTION_REG = $7f


OWOUT DQ, 1, [$CC, $4E, 0, 0, DS18B20_10bit] 'Skip ROM search and write 10bit resolution to scratch pad
Pause 500
LCDOut $FE 'Clear LCD
Setpoint = 22

Start_Convert:
OWOUT DQ, 1, [$CC, $44] ' Skip ROM search & do temp conversion
PortB = 0
If Temp_Up = 0 Then
Setpoint = Setpoint + 1
Endif
If Temp_Down = 0 Then
Setpoint = Setpoint - 1
Endif
lcdout $fe, 1, "Setpoint = ", #Setpoint
If TempC < Setpoint Then
high R_LED ' Turn on Red LED and turn off Green LED
low G_LED
Else
High G_LED ' Turn on Green LED and turn off Red LED
low R_LED
EndIf

Darrel Taylor
- 15th May 2008, 03:19
You can run, but you can't hide.

Equally, you can create a new thread, but I can still reply.<hr>
OK, resolution looks good.
Start temp conversions OK,
And the setpoint via buttons probably work too. (But a bit bouncy)

Only thing left is to actually read the temperature from the DS18B20.

ruthlessly,

WarPony
- 15th May 2008, 15:24
One step ahead of you good sir

I was able to read temp and actually write in a setpoint that turned on a green LED when temp was over setpoint and a red one when below.

so maybe two steps

You think I should use the button command to send the program to a subroutine that loops as long as the button is pushed? This way if you want to increase the temp by say ten you can just hold it down.

Later
Bryan

Acetronics2
- 15th May 2008, 16:04
You think I should use the button command to send the program to a subroutine that loops as long as the button is pushed? This way if you want to increase the temp by say ten you can just hold it down.


Hi, Bryan

looks pretty good that way ...

and also works pretty good with the BUTTON command which is really ideal for such use ...

Alain

WarPony
- 15th May 2008, 17:13
Thanks Alain

I am just starting to wrap my head around this stuff

Acetronics2
- 15th May 2008, 20:12
Hi,

I knew there was an example in my projects ...




'************************************************* ****************************
mainloop:

Writeok = 0

delay = 0

button Up, 0, 255, 0, delay, 1, upbutton
button Down, 0, 255, 0, delay, 1, dwnbutton
button Prog, 0, 255, 0, delay, 1, Program

Gosub Outsig
PAUSE 18
compte = 0

Goto Mainloop


'************************************************* ****************************
upbutton:

IF Down = 0 THEN

Pos = posn
Goto Jump1

Endif

Compte = compte + 1

Select Case Compte

Case 255
Compte = Compte-1
N = 10

Case is > 50
N = 10

Case is > 15
N = 3

Case else
N = 1

End Select

pos = pos + 2*N

if pos > 2250 then pos = 2250

Jump1:

For delay = 1 to 9

Gosub Outsig
Pause 18

Next delay

Gosub Outsig

Goto mainloop


'************************************************* ****************************
dwnbutton:

IF Up = 0 THEN

Pos = posn
Goto Jump2

Endif

Compte = compte + 1

Select Case Compte

Case 255
Compte = Compte - 1
N = 10

Case is > 50
N = 10

Case is > 10
N = 3

Case else
N = 1

End Select

pos = pos - 2*N

if pos < 750 then pos = 750

Jump2:

For delay = 1 to 9

Gosub Outsig
Pause 18

Next delay

Gosub Outsig

Goto mainloop


'************************************************* ****************************
Program:

Compte = 0

Test:

IF Prog = 0 Then

compte = compte + 1
Gosub Outsig
Pause 18

IF Compte > 250 THEN Compte = 250: Goto Test
IF Compte >= 80 THEN WriteoK = Compte .4 : Goto Test
IF Compte >= 20 THEN WriteoK = Compte .2

Goto Test 'Attendre relāchement bouton ...

Endif

IF Compte > 250 OR Compte < 20 Then mainloop

IF Compte >= 80 Then

pos = 1500
Goto Save 'remise au Neutre

Endif



NB : WriteOk is the led that shows where you are ...
Outsig is generating a servo pulse ...

Alain

WarPony
- 16th May 2008, 01:47
ty alain

I am going to use your example instead of pbp manual on this one. I am almost there

Bryan