اطلاعیه

Collapse
No announcement yet.

ارتباط کیپد 4*4 با LPC1768 هدر برد....

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    ارتباط کیپد 4*4 با LPC1768 هدر برد....

    سلام..
    یک برنامه نوشتم برای اینکه بدون آی سی واسط 8 پین مربوط به کیپد رو به هدر برد LPC1768 وصل کنم و با فشردن یک کلید نتیجه رو روی LCD 2*16 نشون بدم...
    ولی چیزی نشون نمیده فقط مکان 1و1 چشمک می زنه....
    کیپد متصل به P2 (0...7( است....
    این برنامه است....

    کد:
    #include "LPC17xx.H"
    
    #define LCD_PORT_0
    #define LCD_RS 4
    #define LCD_E 5
    #define LCD_DB4 7
    #define LCD_DB5 8
    #define LCD_DB6 9
    #define LCD_DB7 10
    #include "lcd2.h"
    
    void delay (unsigned long tick) {    /* Delay Function           */
    unsigned long dly = tick*300;
    	while(dly--);
    }
    
    int main()
    {
    unsigned int keystatus;
    unsigned int ScanKeypad(void);
    
    
     	LPC_GPIO2->FIODIR = 0x000000F0;   // COLUMNS ARE INPUT & rows are output
    
    	lcd_init(); 
     	lcd_clear();
     cursor_off();
    
    
    while(1)
      {
        keystatus=ScanKeypad();
        if(keystatus!=0) 
        {   // atleast one key pressed so debounce. 
          
          delay(1000); //wait 
          keystatus=keystatus&ScanKeypad(); // get verified key presses after debounce
          switch(keystatus)
          {
            case 0x0001:lcd_clear(); lcd_gotoxy(1,1);lcd_puts(0);break;
            case 0x0002: lcd_clear();lcd_gotoxy(1,1);lcd_puts(1);break;
            case 0x0004: lcd_clear();lcd_gotoxy(1,1);lcd_puts(2);break;  
            case 0x0008: lcd_clear();lcd_gotoxy(1,1);lcd_puts(3);break;
            case 0x0010: lcd_clear();lcd_gotoxy(1,1);lcd_puts(4);break;
            case 0x0020: lcd_clear();lcd_gotoxy(1,1);lcd_puts(5);break;
            case 0x0040: lcd_clear();lcd_gotoxy(1,1);lcd_puts(6);break;  
            case 0x0080: lcd_clear();lcd_gotoxy(1,1);lcd_puts(7);break;  
            case 0x0100: lcd_clear();lcd_gotoxy(1,1);lcd_puts(8);break;
            case 0x0200: lcd_clear();lcd_gotoxy(1,1);lcd_puts(9);break;
            case 0x0400: lcd_clear();lcd_gotoxy(1,1);lcd_puts(10);break;  
            case 0x0800: lcd_clear();lcd_gotoxy(1,1);lcd_puts(11);break;
            case 0x1000: lcd_clear();lcd_gotoxy(1,1);lcd_puts(12);break;
            case 0x2000: lcd_clear();lcd_gotoxy(1,1);lcd_puts(13);break;
            case 0x4000: lcd_clear();lcd_gotoxy(1,1);lcd_puts(14);break;  
            case 0x8000: lcd_clear();lcd_gotoxy(1,1);lcd_puts(15);break;
            default:   lcd_clear();lcd_gotoxy(1,1);lcd_puts(16);break; // display H if more than one key pressed at a time        
          }
        }
      }
    }
    
    //****************************************************************************************
    //Function ScanKeypad()
    
    unsigned int ScanKeypad(void)
    {
      unsigned int keys,keys_tmp;
    
      LPC_GPIO2->FIOCLR = 0x000000f0; // make sure P2(4:7) pins are LOW without changing other P2 pins
    
      LPC_GPIO2->FIOSET |= 0x00000010; // ebable ROW1 of keypad( make RD4 pin 1)
      delay(20);
    
      keys=(LPC_GPIO2->FIOPIN)&(0x0000000F); // read column1 of keypad (we need to read only PORTB0:3)
      keys=keys<<12;  // put column1 values in keys15:12 bits
      
      LPC_GPIO2->FIOCLR = 0x000000f0;// make sure P2(4:7) pins are LOW without changing other P2 pins
      LPC_GPIO2->FIOSET |=0x00000020; // enable ROW2 of keypad
      delay(20);
    
      keys_tmp=(LPC_GPIO2->FIOPIN)&(0x0000000F); // read column2 of keypad
      keys_tmp=keys_tmp<<8; // place column 2 key values in keys_tmp8:11
      keys=keys|keys_tmp; //combine comomn 1 and 2 data in to keys
    
      LPC_GPIO2->FIOCLR = 0x000000f0;// make sure P2(4:7) pins are LOW without changing other P2 pins
      LPC_GPIO2->FIOSET |=0x00000040; // enable ROW3 of keypad
      delay(20);
    
    
      keys_tmp=(LPC_GPIO2->FIOPIN)&(0x0000000F); // read column3 of keypad
      keys_tmp=keys_tmp<<4; // place column 3 key values in keys_tmp4:7
      keys=keys|keys_tmp; //combine comomn 1 and 2 nad 3 data in to keys
      
      LPC_GPIO2->FIOCLR = 0x000000f0; // make sure P2(4:7) pins are LOW without changing other P2 pins
      LPC_GPIO2->FIOSET |=0x00000080;  // enable ROW2 of keypad
      delay(20);
    
      keys_tmp=(LPC_GPIO2->FIOPIN)&(0x0000000F); // read column2 of keypad
      keys=keys|keys_tmp; //combine comumn 1,2,3,4 data in to keys
    
      return keys;
       
    }

    ask One Question

    #2
    پاسخ : ارتباط کیپد 4*4 با LPC1768 هدر برد....

    اصراری بر اینکار ندارم... یعنی چون آی سی واسط برای این کیپد موجود است ولی من نداشتم
    گفتم بدون این آی سی اینکار رو بکنم ولی خب نشد.... راهنمایی نمی کنید؟؟؟ برنامه چه ایرادی داره...؟ :bye
    ask One Question

    دیدگاه


      #3
      پاسخ : ارتباط کیپد 4*4 با LPC1768 هدر برد....

      سلام
      ای سی واسط این کی پد ها اسمشون چیه؟
      ممنونم
      [glow=red,2,300]برنامه هاي آموزشي تست شده براي NXP LPC1768 با توابع CMSIS[/glow]
      http://www.eca.ir/forum2/index.php?topic=76623.0

      دیدگاه

      لطفا صبر کنید...
      X