Yeah, I think I might have a go at the BUTTON statement...
Let me go away and RTFM first, have a play, try and get something together before bailing be out
Before I start though, any comments on configuring PORTA (inc MCLR) for in/outputs ??
Malc
Yeah, I think I might have a go at the BUTTON statement...
Let me go away and RTFM first, have a play, try and get something together before bailing be out
Before I start though, any comments on configuring PORTA (inc MCLR) for in/outputs ??
Malc
Here a cutout ...
PORTA = 0 ' declare port level BEFORE port direction = safe power-on
PORTB = 0
'Pour 16F628
CMCON = 7 ' PortA Digital inputs
CCP1CON = 0 ' PWM off
' DATA @1,word 625,0,word 545,word 750 ' pre-setting EEPROM
'************************************************* *****************************
' Initialisation commutation : Vérification batterie
'************************************************* *****************************
init:
battok = 1 ' setting critical variables ...
dejavu = 0
bougie = 0
error = 0
Servo = 0
TRISA = %00000011 ' Port Direction
TRISB = %00000001
Pause 400 ' Stabilisation au branchement
GoSub verbatt ' beginning of real program ...batt testing i.e.
Cheers
Alain
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
Ok, trying to get my head round the BUTTON statement, and failing.. bu I just love the line
which was what I was originally doing .....In general, it is easier to simply read the state of the pin in an IF..THEN
than to use the BUTTON command as follows:
If PORTB.2 = 1 Then notpressed
Oh well ... I'll keep trying
Ok after a lot of tries I finally have something that works. Here's the centre section of the code with the initialisation parts ommited for clarity
Basically rather than try and compare a condition of swset1 and swset2 and SW0, I simply used SWFLAG1 as a counter to count the number of times the switches are activated, and if it is greater than 2 reset the couter and swset 1 and 2 to 0.Code:LED1 var PORTB.4 'LED1 (green) on pin 10 (RB4) LED2 var PORTB.5 'LED1 (red) on pin 11 (RB5) SW0 var PORTB.0 'switch input pin 6 (RB0) SW1 var PORTB.1 'switch input pin 7 (RB1) SWFLAG1 var Byte ' counter for track 1 Swset1 var bit Swset2 var bit low led1 low led2 Swset1=0 Swset2=0 SWFLAG1=0 Main: if SWFLAG1 >2 then ' if the counter is >2 then reset all swset1=0 swset2=0 SWFLAG1=0 endif If SW0=0 Then swflag1 = swflag1 +1 ' increase count by 1 swset1=1 pause 500 endif If SW1=0 Then swflag1 = swflag1 +1 'increase count by 1 swset2=1 pause 500 endif if swset1=1 then high led1 'then turn on RB4 (and hence the LED) else low led1 'else, LED is off endif If Swset2=1 then high led2 'then turn on RB5 (and hence the LED) else low led2 'else, LED is off endif
Now when sw0 goes low for the first time SWFLAG1 is = 1, when sw1 goes low SWFLAG1 =2 then when the loco is placed at the front of the train andis driven over SW0 for the second time SWFLAG1 =3. As the "IF SWFLAG1 > 2" condition is reached, SWFLAG1 is reset to 0, as is swset1 and swset2.
Now just have to replicate this for the other 6 inputs and outputs
I know this may seem trivial to the more experienced programmers, but its my first real program with PBP that is beyond the simple flash a LED, and I'm really pleased that I managed to figure something out, after some guidance from you guys here.
Thanks
Malcolm
Oh, and seeing that I RTFM and did my homework... do I qualify for a dozen lashes form Mel (alias Ms Whippy![]()
)
Hi,MalcOriginally Posted by malc-c
The IF THEN Statement implies your switch is an ideal switch and debouncing not tricky ...
BUTTON is more complicated and slow ... but works in very difficult situations.
The state of art is to verify the button has not changed its state BEFORE debouncing time has ended ...
Multiple IF ... THEN ... ELSE following each others reach that GOAL ...
Alain
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
Bookmarks