• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
:::


Browsing this Thread:   1 Anonymous Users






Re: 單 on 雙 off 的開關問題~~(按一下 on 再按一下就 off)
#5
初級會員
初級會員


查看用戶資訊
1. GET Key with debounce 
;=====================================================================================
;
; Function     : 
GetPowerKey 
;             : To get the power with debounce function is the power key is pressed 
;              not long enough then return the carry bit
;               And 
can set the key noise level to avoid the noise happens at 
;              key pressed interval.
;
Algorithm Step 1: if the GPIO at this moment retutn STATUS.C clear
;              Step 2Setting the value for counting the loop for key pressed.
;              
Step 3Delay every 560uS to check one time for key pressed
;                      
check about keycountloop time 
;              Step 4Every time (under Keycountloop) if read a power key pressed 
;                      increase keyreceiveno
;              Step 5check the keyreceiveno is over key_level or not
;                      if 
yesthat means the power key is really be pressed
;                      if 
no, return the clear STATUS.C by Sub function. 
;
;=====================================================================================
GetPowerKey
    bcf        STATUS
,    C                Step 1. 
    btfss    GPIO
Powerkey            ;
    
retlw    zero                    ;

    
clrf    keyreceiveno            Step 2.
    movlw    keycountloop            
;
    
movwf    keyloop                    ;

Debounce        
    movlw    delay560us                
Step 3 Step 4
    call    DelaywithW                

    
btfsc    GPIOPowerkey            ;
    
incf    keyreceivenoF            ;
    
decfsz    keyloopF                ;
    goto    
Debounce                ;

    
movlw    key_level                Step 5. 
    subwf    keyreceiveno
F            ;
    
movlw    0x1                        ;
    
btfsc    STATUS,    C                ;
    
xorwf    MPV800_statusF        ;
    
retlw    zero                    ; return the status carry bit back directly


2. Main function

start
    movlw    PowerOnSetting            
Step 2 check the initial status --> power on or Power
    andlw    PowerOnSetting            
off.
    
btfsc    STATUS,     Z            
    goto     
Power_off_stage_setting    ;
Power_on_stage_setting                
    bsf        Power_status
,     powerkeyon    ;
    goto    
Power_on_stage            ;
Power_off_stage_setting    
    bcf        Power_status
,    powerkeyon    ;
    goto     
Power_off_stage            ;

發表於: 2006/10/20 23:30
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 單 on 雙 off 的開關問題~~(按一下 on 再按一下就 off)
#4
版主
版主


查看用戶資訊
其實C或組合語言寫程式,其流程架構都是一樣的,先研究ㄧ下彈跳處理的流程再轉寫成組合語言。
或著你可以參考市面上有很多有關PIC16F877的中文書多多少少都會寫道如何處理彈跳的問題。

發表於: 2006/10/18 14:37
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 單 on 雙 off 的開關問題~~(按一下 on 再按一下就 off)
#3
新會員
新會員


查看用戶資訊
非常感謝板主的解答~~~~~~~~~~~~~~
但我只會用組合語言的寫法....C的寫法 看不懂
真是不好意思,有小範例或者大概要怎麼樣的寫法才可以克服這個問題



謝謝參照:

Ryang 寫到:
像你這種按鍵竟需考慮按鍵彈跳的問題,模擬下是不會有彈跳的所以很正常,但實際接上硬體就亂了。
底下是用C寫用延遲方式處理彈跳的例子:
void Press_Key(void)
{
    
unsigned int i;

    while (
1)
    {    
        if (
debounce==0)                    // Check the dubounce time is over?
        
{
            if (!
SW5)                       // debounce is completed, now checking the SW5 ststus
            
{
                
SW_Input '5';                // The SW5 has been Press, Set the Key buffer = '5'
                
debounce 30;                 // Set the debounce loop = 30    
                
break;
            }
    
             if (!
SW6)                         // Check the SW6 status
            
{
                
SW_Input '6';                // The SW5 has been Press, Set the Key buffer = '5'
                
debounce 30;                // Set the debounce loop = 30
                
break;
            }
        }
        else                                
// Process the debounce procedure
        
{
            if (
SW5 SW6)                     // Bothe SW5 & SW6 ahve released ?
                    
{
                    
debounce--;                // Yes, decrement debounce loop once
                    
for (i=0;i<500;i++);    // Basic debounce delay time
                    
}
                else                         
// Still have key press done
                    
debounce=30;            // Re-set the debounce loop = 30
        
}             
    }

}


發表於: 2006/10/17 17:30
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 單 on 雙 off 的開關問題~~(按一下 on 再按一下就 off)
#2
版主
版主


查看用戶資訊
像你這種按鍵竟需考慮按鍵彈跳的問題,模擬下是不會有彈跳的所以很正常,但實際接上硬體就亂了。
底下是用C寫用延遲方式處理彈跳的例子:
void Press_Key(void)
{
    
unsigned int i;

    while (
1)
    {    
        if (
debounce==0)                    // Check the dubounce time is over?
        
{
            if (!
SW5)                       // debounce is completed, now checking the SW5 ststus
            
{
                
SW_Input '5';                // The SW5 has been Press, Set the Key buffer = '5'
                
debounce 30;                 // Set the debounce loop = 30    
                
break;
            }
    
             if (!
SW6)                         // Check the SW6 status
            
{
                
SW_Input '6';                // The SW5 has been Press, Set the Key buffer = '5'
                
debounce 30;                // Set the debounce loop = 30
                
break;
            }
        }
        else                                
// Process the debounce procedure
        
{
            if (
SW5 SW6)                     // Bothe SW5 & SW6 ahve released ?
                    
{
                    
debounce--;                // Yes, decrement debounce loop once
                    
for (i=0;i<500;i++);    // Basic debounce delay time
                    
}
                else                         
// Still have key press done
                    
debounce=30;            // Re-set the debounce loop = 30
        
}             
    }

}


發表於: 2006/10/17 15:33
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


單 on 雙 off 的開關問題~~(按一下 on 再按一下就 off)
#1
新會員
新會員


查看用戶資訊
麻煩各位先進了~~~
--------------------------------------------------------
我要做一個單 on 雙 off 的按鍵控制
就是按一下 on 再按一下就 off
單 on 時沒有問題,可是 雙 off 時就沒辦法回去了
,程式在 MPLAB IDE 上模擬時都很正常.
可是在實際上操作時就不行了
---------------------------------------------------------
以下是我的程式


right

incf right_counter,f
movlw b'00000011'
andwf right_counter,f
btfss right_counter,1
goto right1
goto clearright
right1:
movlw b'00000111'
movwf 06h
delaybig
movlw b'00111111'
movwf 06h
delaybig
btfsc 05h,3
goto right1 goto right
clearright:
movlw 00h
movwf right_counter
movlw b'11111111'
movwf 06h
goto scan
--------------------------------------------------------------------


發表於: 2006/10/16 16:28
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------