19 Ekim 2021, 12:08:46

Haberler:

Forum kuralları güncellendi LÜTFEN  okuyunuz:  https://bit.ly/2IjR3ME


buton kontrol fonksiyonu

Başlatan selvi, 04 Aralık 2014, 00:19:07

selvi

04 Aralık 2014, 00:19:07 Son düzenlenme: 04 Aralık 2014, 00:22:20 selvi
asagidaki kodlarda iki butonun kontolunu fonksiyonla yapilmis.ben inceledim kodlari takip ettim farkli sonuclara gidiyorum.ozellikle for dongusu kismini  tam anlayamadim.bazi kosullarin yanina takildigim yerleri yazdim.tam nerde yanlis yaptigimi anlayamadim.

#define     KEY1            RC1
#define     KEY2            RC2
#define     LED1            RC5
#define     LED2            RC6/code]

[code]void scankey(void)//
{
    
U8 now_key,temp,i;
    
key_value=0;
    
now_key=PORTC&0x06;
    if(
now_key!=key_last)
        {
            
Flag.debounce_start=1;
            
key_debouncems=0;
            
key_last=now_key&PORTC&0x06;

        }
    else if(
Flag.debounce_start==1)
        {
            if(
key_debouncems>=40)
                 {

                     
Flag.debounce_start=0;
                     
//now_key=PORTC&0x06;
                     
key_image=key_image&0x06;
                     if(
now_key!=key_image)
                          {
                              
temp=now_key;
                              
now_key=now_key^key_image;//
                              
key_image=temp;//
                              
if(now_key!=0x00)
                                  {
                                     
temp=0x01;
                                     for(
i=0;i<4;i++)
                                         {
                                             if(
temp&now_key)  //portc.1 e bagli butonuna basildigini dusunelim now_key=4 esit olmaz mi. bu kosulun bir kere gerceklesmis olur.
                                                  
{
                                                      
key_value=i+1;
                                                      if(
temp&key_image)// bu kosulda bir kez gerceklesir.
                                                          
{
                                                              
Flag.KEY_UP_DOWN=KEY_UPUP;

                                                          }
                                                      else
                                                          {
                                                              
Flag.KEY_UP_DOWN=KEY_DOWNDOWN;
                                                              
waitforreturn=1;delayms=0;
                                                              if(
key_value==2//key 2 is pressed down  //programin akisi  sanki buraya hic gelmiyor.
                                                                 
{
                                                                     
sendkey='1'//save the key value
                                                                     
send_buf[0]='s';
                                                                     
send_buf[1]='e';
                                                                     
send_buf[2]='n';
                                                                     
send_buf[3]='d';
                                                                     
send_buf[4]='1';
                                                                     
send_p=0;
                                                                     
send_len=4;
                                                                     
TXREG=send_buf[0];//start to send data
                                                                     
while(send_p<send_len)
                                                                        {
                                                                            while(!
TXIF);
                                                                            
send_p++;
                                                                            
TXREG=send_buf[send_p];
                                                                        }
//waiting for sending end

                                                                  
}
                                                              else if(
key_value==3)//key 3 is pressed down
                                                                 
{
                                                                     
sendkey='2'//save the key value
                                                                     
send_buf[0]='s';
                                                                     
send_buf[1]='e';
                                                                     
send_buf[2]='n';
                                                                     
send_buf[3]='d';
                                                                     
send_buf[4]='2';
                                                                     
send_p=0;
                                                                     
send_len=4;
                                                                     
TXREG=send_buf[0];//start to send data
                                                                     
while(send_p<send_len)
                                                                        {
                                                                            while(!
TXIF);
                                                                            
send_p++;
                                                                            
TXREG=send_buf[send_p];
                                                                        }
//waiting for sending end

                                                                 
}
                                                          }
                                                 }
                                             
temp=temp<<1;
                                         }
                                 }
                          }
                 }
        }
}/
code]
Yaşam anlamlandırıldıkça kutsaldır....

Yasal Uyarı: Picproje.org sitemizde 5651 sayılı kanunun 8. maddesine ve T.C.Knın 125. maddesine göre tüm üyelerimiz yaptıkları paylaşımlardan kendileri sorumludur. Picproje.org hakkında yapılacak tüm hukuksal şikayetleri İletişim sayfamızdan bize bildirdikten en geç 3 (üç) iş günü içerisinde ilgili kanunlar ve yönetmelikler çerçevesinde tarafımızca incelenerek gereken işlemler yapılacak ve site yöneticilerimiz tarafından bilgi verilecektir.