OK, i missread the thing. Well at least you'd understand the core of the code. Now here's the modified version that will DO a routine if a button is pressed for more than TimeoutDelay on the pins 0, 2, 4 and 5. Kill me if i'm still wrong.. well try to
Code:' PIC12f629 ' Push-button attach to GPIO 0, 2, 4 and 5 between i/o and VCC ' ' it assume you'd previously disable all analog stuff and MCLR pin ' aPushButton var byte PushButton var byte Delay var Word TimeoutDelay con 100 ' Here you select Your own delay (100=1 Second) Start: clear ' reset all variable to 0 apushbutton=GPIO & %00110101 ' read all GPIO pins ' keep only GPIO 0,2,4,5 bits ' ----- HOW? ----- ' By masking the unused bits with ' a bitwise AND ' if apushbutton=0 then start ' no push button pressed, sit and spin pushbutton=apushbutton ' Store the push button press ' while (apushbutton!=0) or (delay!=TimeoutDelay) ' Wait untill the timeout happen ' or push Button release apushbutton=GPIO & %00110101 pause 10 delay=delay+1 wend pause 50 ' debounce delay if DELAY=timeoutdelay then ' if push button is press for 1 second ' ' PushButton handling section ' =========================== ' We'd read the whole GPIO and set the un-assign bit to 0 ' Push button are attach to GPIO 0,2,4,5. Result is store in ' PushButton variable ' Select case PushButton case %00000001 gosub PushButtonGPIO_0 case %00000100 gosub PushButtonGPIO_2 case %00010000 gosub PushButtonGPIO_4 case %00100000 gosub PushButtonGPIO_5 end select endif goto start





Bookmarks