and What about this one, using the Button command ?
AlainCode:'******************************************************************************* ' Name : BUTTONTEST2.pbp ' Compiler : PICBASIC PRO Compiler 3.0 ' Assembler : PM ' Target PIC : 8-pin PIC12F675 or similar type ' Hardware : Kee ' Oscillator : 4MHz internal ' Keywords : HIGH, LOW ' Description : use a push button to toggle two LEDs. THere are two push buttons. 'each push button toggles a separate set of LEDs. Program also debounces '******************************************************************************* #config __CONFIG _CP_OFF & _WDT_ON & _BODEN_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _CPD_OFF #endconfig DEFINE OSCCAL_1K 1 ' PIC12F675, Calibrate internal oscillatordefine MCLRE_OFF DEFINE BUTTON_PAUSE 255 Delay VAR Byte Button1 VAR GPIO.2 Button2 VAR GPIO.3 LED1 VAR GPIO.0 'Alias GPIO.0 to LED LED2 VAR GPIO.1 'Alias GPIO.1 to LED2 LED3 VAR GPIO.4 'Alias GPIO.4 to LED3 LED4 VAR GPIO.5 'Alias GPIO.5 to LED4 CMCON = 7 ANSEL = 0 ADCON0 = 0 GPIO = %00001100 TRISIO = %00001100 CLEAR '******************************************************************************* Main: '******************************************************************************* WHILE 1 FIRST:' let's check Button1 ... Delay = 0 button Button1, 0, 255, 0, Delay, 1,yes1 no1: Pause 20 ; pace the scanning ... not compulsory goto Second yes1: toggle LED1 ' Stop until Button1 released WHILE !Button1 WEND SECOND:' let's check Button2 Delay = 0 button Button2, 0, 255, 0, Delay, 1,yes2 no2: Pause 20 ; pace the scanning ... not compulsory goto Update yes2: toggle LED3 'Stop until Button2 released WHILE !Button2 WEND Update: led2 = ! LED1 : LED4 = !LED3 WEND END




Bookmarks