PDA

View Full Version : Button subfunction 16F628



Jųan
- 10th August 2005, 15:47
Here I go again :-)

I am trying to display some values on an lcd. One that counts from 10 to 20 using up\down buttons. And when I press RB1 the lcd counts from 80 - 90 using the same up\down. I created the dummy functions because I found that having these allowed me to hold the button and have continous incrementation\decrementation (see code below). Ive connected RA4 and RA1 to ground.

My problem is that I want to solely increment\decrement num2 without interfering with num1. The other problem is that when I press RB1 to go num2 mode, the lcd counts up on its own. If anyone has a look at my grubby code and sees what Im trying to do and where Im doin wrong, can you shead some light please?

Muchas Gracias


Juan






************************************************** ******
Include "modedefs.bas" ' Include serial modes
DEFINE BUTTON_PAUSE 75 ' button debounce delay is 75ms

I con 254 '254h = 1111 1110 (Sets LCD to command mode)
ClrScr con 1 '01h = 0000 00001 (Clears Screen & goes to position 1)
Line2 con 192 'COh = 1100 0000B (sets address to positionn 40 on LCD)
DispCur con 12 '12h = 0000 1100 (activates display & cursor mode)
'Commands obtained from LCD article in epemag.com

B0 var byte
B1 var byte
B2 var byte
B3 var byte
B4 var byte
number var word
number2 var word

B0 = 0
B1 = 0
B2 = 0
B3 = 0
B4 = 0

number = 15
number2 = 85

serout PORTB.0,T9600,[i,clrScr] ' Clearscreen
pause 400

numSetup:
serout PORTB.0,T9600,[I,128,"Display num1"] ' Setup display
serout PORTB.0,T9600,[I,line2," Press button"] ' Setup display
numMain:
pause 25
Button PORTA.7,1,200,255,B0,1,incNum
Button PORTA.6,1,200,255,B1,1,decNum
Button PORTA.4,1,200,255,B0,1,dummy1
Button PORTA.1,1,200,255,B1,1,dummy2
Button PORTB.1,1,200,255,B2,1,number2Setup
Serout PORTB.0,T9600,[i,line2,#number]
goto numMain

incNum:
if number > 19 then numMain
number = number + 1
pause 100
Goto numMain ' goes back to main function

decNum:
if number < 11 then numMain
number = number - 1
pause 100
Goto nummain ' goes back to main function

dummy1:
PAUSE 1000
GOTO nummain
dummy2:
PAUSE 1000
GOTO nummain

number2Setup:
serout PORTB.0,T9600,[i,clrScr] ' Clearscreen
serout PORTB.0,T9600,[I,128,"Display num2"] ' Setup display
number2Main:
pause 25
Button PORTB.7,1,200,255,B3,1,incNumber2
Button PORTA.6,1,200,255,B4,1,decNumber2
Button PORTB.1,1,200,255,B2,1,numsetup
serout PORTB.0,T9600,[I,line2,#number2]
goto number2Main

incNumber2:
if number2 > 89 then number2Main
number2 = number2 + 1
pause 100
Goto number2main

decNumber2:
if number2 < 81 then number2main
number2 = number2 - 1
pause 100
Goto number2main

Darrel Taylor
- 10th August 2005, 18:24
Hi Jųan,

The problem might be related to re-using variables in the BUTTON commands.

Button PORTA.7,1,200,255,B0,1,incNum
Button PORTA.6,1,200,255,B1,1,decNum
Button PORTA.4,1,200,255,B0,1,dummy1
Button PORTA.1,1,200,255,B1,1,dummy2
Button PORTB.1,1,200,255,B2,1,number2Setup

Within any single loop each BUTTON command must have it's own variable to count the passes, and that variable can't be used anywhere else in the program.<br><br>

Jųan
- 11th August 2005, 01:22
Thanks for your reply Darrel, I tried that but the auto repeat function didnt work when using unique Bvariables. Also the displayNum2 still counted on its own. I have attached a diagram of how I've connected the switch.

Juan

Darrel Taylor
- 11th August 2005, 05:05
Did you make ALL of the button commands use a separate variable? There are 8 button commands, you should have B0-7 variables.

Also, try putting a CLEAR statement at the top of the program. According to the manual... The variable must be initialized to 0 prior to use.<br><br>

Jųan
- 11th August 2005, 13:13
Bingo Bango!

Yes I placed the Bvariables inside the corresponding loop. This allowed me to get rid of the dummy file call. Thanks Darrel, much appreciated!

Leonardo
- 19th August 2005, 16:44
Hola Juan,

Veo que hablas espaņol, que bueno encontrar a alguien del mismo idioma me gustaria que me escribieras y me dieras tu mail para comunicarnos en este fabuloso foro mi mail es [email protected]

Saludos

Leonardo




Here I go again :-)

I am trying to display some values on an lcd. One that counts from 10 to 20 using up\down buttons. And when I press RB1 the lcd counts from 80 - 90 using the same up\down. I created the dummy functions because I found that having these allowed me to hold the button and have continous incrementation\decrementation (see code below). Ive connected RA4 and RA1 to ground.

My problem is that I want to solely increment\decrement num2 without interfering with num1. The other problem is that when I press RB1 to go num2 mode, the lcd counts up on its own. If anyone has a look at my grubby code and sees what Im trying to do and where Im doin wrong, can you shead some light please?

Muchas Gracias


Juan






************************************************** ******
Include "modedefs.bas" ' Include serial modes
DEFINE BUTTON_PAUSE 75 ' button debounce delay is 75ms

I con 254 '254h = 1111 1110 (Sets LCD to command mode)
ClrScr con 1 '01h = 0000 00001 (Clears Screen & goes to position 1)
Line2 con 192 'COh = 1100 0000B (sets address to positionn 40 on LCD)
DispCur con 12 '12h = 0000 1100 (activates display & cursor mode)
'Commands obtained from LCD article in epemag.com

B0 var byte
B1 var byte
B2 var byte
B3 var byte
B4 var byte
number var word
number2 var word

B0 = 0
B1 = 0
B2 = 0
B3 = 0
B4 = 0

number = 15
number2 = 85

serout PORTB.0,T9600,[i,clrScr] ' Clearscreen
pause 400

numSetup:
serout PORTB.0,T9600,[I,128,"Display num1"] ' Setup display
serout PORTB.0,T9600,[I,line2," Press button"] ' Setup display
numMain:
pause 25
Button PORTA.7,1,200,255,B0,1,incNum
Button PORTA.6,1,200,255,B1,1,decNum
Button PORTA.4,1,200,255,B0,1,dummy1
Button PORTA.1,1,200,255,B1,1,dummy2
Button PORTB.1,1,200,255,B2,1,number2Setup
Serout PORTB.0,T9600,[i,line2,#number]
goto numMain

incNum:
if number > 19 then numMain
number = number + 1
pause 100
Goto numMain ' goes back to main function

decNum:
if number < 11 then numMain
number = number - 1
pause 100
Goto nummain ' goes back to main function

dummy1:
PAUSE 1000
GOTO nummain
dummy2:
PAUSE 1000
GOTO nummain

number2Setup:
serout PORTB.0,T9600,[i,clrScr] ' Clearscreen
serout PORTB.0,T9600,[I,128,"Display num2"] ' Setup display
number2Main:
pause 25
Button PORTB.7,1,200,255,B3,1,incNumber2
Button PORTA.6,1,200,255,B4,1,decNumber2
Button PORTB.1,1,200,255,B2,1,numsetup
serout PORTB.0,T9600,[I,line2,#number2]
goto number2Main

incNumber2:
if number2 > 89 then number2Main
number2 = number2 + 1
pause 100
Goto number2main

decNumber2:
if number2 < 81 then number2main
number2 = number2 - 1
pause 100
Goto number2main