Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Để de-trả lại bấm phím chúng ta trì hoãn một thời gian ngắn, sau đó kiểm tra xem nút vẫn còn ép, sự chậm trễ thời gian được thiết lập bởi SWDel biến, được định nghĩa là Del50 trong định nghĩa phần bắt đầu của chương trình. Những hướng dẫn này yêu cầu Hội đồng quản trị chính, Ban LCD, | Del0 retlw 0x00 delay 0mS - return immediately Dell movlw d 1 delay 1mS goto Delay Del5 movlw d 5 delay 5mS goto Delay Dello movlw d 10 delay 10mS goto Delay Del20 movlw d 20 delay 2 0mS goto Delay Del50 movlw d 50 delay 50mS goto Delay Del100 movlw d 100 delay 100mS goto Delay Del250 movlw d 250 delay 250 ms Delay movwf count1 d1 movlw 0xC7 delay 1mS movwf counta movlw 0x01 movwf countb Delay_0 decfsz counta f goto 2 decfsz countb f goto Delay_0 decfsz count1 f goto d1 retlw 0x00 end In order to de-bounce the keypresses we delay for a short time then check that the button is still pressed the time delay is set by the variable SWDel which is defined as Del50 in the defines section at the start of the program. I ve extended the Delay routine to provide a selection of different delays from 0mS to 250mS called by simple call instructions the Delay routine itself can also be called directly - simply load the required delay into the W register and call Delay . We then check to see if the corresponding LED is lit with btfss SWPORT LEDx and jump to either LEDxON or LEDxOFF these routines are almost identical the only difference being that the first turns the LED on and the second turns it off. They first switch the LED on or off depending on which routine it is and then delay again calling SWDel as before next they check to see if the button is still pressed looping back around if it is. Once the key has been released the routine exits via the usual retlw and returns to waiting for a keypress. I ve used the variable SWDel and provided the various delay times so that you can easily try the effect of different delay times - in particular try setting SWDel to Del0 and see how the button pressing isn t reliable you will probably find one of the buttons is worse than the others - particularly if you use old switches wear makes them bounce more. Tutorial 2.3 - requires Main Board Switch Board and LED Board. Now for a more realistic example - this combines Tutorial 2.1 with .