搜索
bottom↓
回复: 41

用ad口做按键检测,25个按键,电压分辨幅度为0.2v。大家看看如何来滤波,如何来做。

[复制链接]

出0入0汤圆

发表于 2006-12-21 08:29:47 | 显示全部楼层 |阅读模式
用ad口做按键检测,基准电压5v,25个按键,电压构建等差数列,电压分辨幅度为0.2v。大家看看如何来滤波,如何来做。这个滤波调了好几天没有出来。

大家帮帮忙。

阿莫论坛20周年了!感谢大家的支持与爱护!!

曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……

出0入0汤圆

 楼主| 发表于 2006-12-21 11:11:01 | 显示全部楼层
大家说说啊

出0入0汤圆

发表于 2006-12-21 11:47:08 | 显示全部楼层
在论坛里有见过相关的贴,通过不同的电阻进行分压,AD口得到不同的ADC值,某个范围内的ADC值对应某个按键,不过我没试过,呵呵

出0入0汤圆

发表于 2006-12-21 13:25:43 | 显示全部楼层
上传一张文件给你看看。

出0入0汤圆

 楼主| 发表于 2006-12-21 13:52:44 | 显示全部楼层
我采用的方法跟上面的差不多,但是按键会出现错误,采用那种滤波方式来消除按键抖动的问题。

出0入0汤圆

发表于 2006-12-21 14:57:35 | 显示全部楼层
ZT

Robs-Projects MP3 Player V2

//                                                                   V2.6

//                                                                   Rob Riglar

//                                                        Copyright 2003,2004

//

//                                                Web:   http://www.robs-projects.com

//                                             Email: admin@robs-projects.com

//

//                            Compiled with Imagecraft C Compiler for the AVR series

//                                                                (set stack to 50)

//-----------------------------------------------------------------------------

//

// This file is part of Robs-Projects MP3 Player V2.

//

// Robs-Projects MP3 Player V2 is free software; you can redistribute it and/or

// modify it under the terms of the GNU General Public License as published by

// the Free Software Foundation; either version 2 of the License, or

// (at your option) any later version.

//

// Robs-Projects MP3 Player V2 is distributed in the hope that it will be useful,

// but WITHOUT ANY WARRANTY; without even the implied warranty of

// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

// GNU General Public License for more details.

//

// You should have received a copy of the GNU General Public License

// along with Robs-Projects MP3 Player V2; if not, write to the Free Software

// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------



//-----------------------------------------------------------------------------

// Prototypes

//-----------------------------------------------------------------------------

void InitADC( void);

int ReadADC( unsigned char);

int CheckSonyInput(void);

void CalibrateSonyStick(void);

void FindButtonPress(word adcvalue);

word MakeCalibrate(void);

void UpdateCalibration(void);



//-----------------------------------------------------------------------------

// Structures

//-----------------------------------------------------------------------------

struct

{

          byte Detect;

          word values[10];

          word keyvalue[10];          

} SonyStick;







byte recievedbyte;

//-----------------------------------------------------------------------------

// InitADC: Initialise ADC Channel

//-----------------------------------------------------------------------------

void InitADC( void)

{

        PORTF|= 0b01111111;

        DDRF|= 0b01111111;

    ADMUX = 7;          // Select channel 7 = 0000 0111

    ADCSR = 0xC0;       // Enable ADC & start 1:st dummy conversion

}



//-----------------------------------------------------------------------------

// ReadADC: Read ADC value

//-----------------------------------------------------------------------------

int ReadADC( byte channel)

{

    int i;



        // Select channel

    ADMUX = channel;                        



    // Start conversion

    ADCSR |= 0x40;                        

   

        // Check if converstion is ready

    while (!(ADCSR & 0x10));               

   

        // Clear Conversion ready flag by setting the bit

    ADCSR |= 0x10;                          



        // Read 8 low bits first (important)

    i = ADCL;                              

       

        // Read 2 high bits and multiply with 256

    i += (int)ADCH << 8;                    



        // Return value read

    return i;

}



//-----------------------------------------------------------------------------

// CheckSonyInput: Does a threshold check and then samples ADC 10 times to

//                                    see which button is pressed.

//                                    Return 0 for no button pressed, 1 if detected.

//-----------------------------------------------------------------------------

int CheckSonyInput(void)

{

  word adcvalue;

  int i;

  int medium=0;



  // Read ADC for Sony Stick Input

  adcvalue = ReadADC(7);

  

  // Check threshold button

  if (adcvalue<100)

       return 0;

  

  // If button detected

  else

             {

           // Sample 10 times

           for (i=0;i<10;i++)

           {

                      SonyStick.values = ReadADC(7);

                  // printf("\r
ADC Value is %d", SonyStick.values);

           }

       

           // Calculate mean value

           for (i=0;i<10;i++)

                      medium = medium + SonyStick.values;

           medium = medium / 10;



           //printf("\r
Average value is %d", medium);

           // Decode input

           FindButtonPress(medium);

printf("\r
Button was %d", medium);          

           printf("\r
Button was %c", recievedbyte);



           return 1;

           }

}



//-----------------------------------------------------------------------------

// FindButtonPress: Match ADC read value with calibrations for buttons

//-----------------------------------------------------------------------------

void FindButtonPress(word adcvalue)

{

        // Reset buffer

        recievedbyte = 0;

       

        // Check for Volume Up

        if ( (SonyStick.keyvalue[0]-7<adcvalue) && (SonyStick.keyvalue[0]+7>adcvalue) )

           {

           recievedbyte = '*';                                                       

           printf("\r
Volume Up");

           }

        else

        // Check for Volume Down

        if ( (SonyStick.keyvalue[1]-7<adcvalue) && (SonyStick.keyvalue[1]+7>adcvalue) )

           {

           recievedbyte = '/';

           printf("\r
Volume Down");

           }

        else

        // Check for Track Up

        if ( (SonyStick.keyvalue[2]-7<adcvalue) && (SonyStick.keyvalue[2]+12>adcvalue) )

           {

           recievedbyte = '>';

           printf("\r
Track Up");

           }

        else

        // Check for Track Down

        if ( (SonyStick.keyvalue[3]-12<adcvalue) && (SonyStick.keyvalue[3]+7>adcvalue) )

           {

           recievedbyte = '<';

           printf("\r
Track Down");

           }

        else

        // Check for album up

        if ( (SonyStick.keyvalue[9]-15<adcvalue) && (SonyStick.keyvalue[9]+15>adcvalue) )

           {

           recievedbyte = 'S';

           printf("\r
Album Forward Pressed");

           }          

        else

        // Check for album down

        if ( (SonyStick.keyvalue[4]-15<adcvalue) && (SonyStick.keyvalue[4]+15>adcvalue) )

           {

           printf("\r
Album Backward Pressed");

           recievedbyte = 'A';

           }

        else

        // Check for 'Play'

        if ( (SonyStick.keyvalue[5]-20<adcvalue) && (SonyStick.keyvalue[5]+20>adcvalue) )

           {

           printf("\r
Play Pressed");

           recievedbyte = 'P';

           }       

        else

        // Check for 'Pause'

        if ( (SonyStick.keyvalue[6]-10<adcvalue) && (SonyStick.keyvalue[6]+10>adcvalue) )

           {

           printf("\r
Pause Pressed");

           recievedbyte = 'U';

           }                                                

}



//-----------------------------------------------------------------------------

// Load Calibration Values

//-----------------------------------------------------------------------------

void CalibrateSonyStick(void)

{

         SonyStick.keyvalue[0] = 999; // Volume Up

         SonyStick.keyvalue[1] = 999; // Volume Down

         SonyStick.keyvalue[2] = 847; // Track Up

         SonyStick.keyvalue[3] = 872; // Track Down

         SonyStick.keyvalue[4] = 771; // Album Back

         SonyStick.keyvalue[5] = 527; // Play Button

         SonyStick.keyvalue[6] = 639; // Pause

         SonyStick.keyvalue[7] = 999; // Sound

         SonyStick.keyvalue[8] = 1000; // Mode

         SonyStick.keyvalue[9] = 608; // Album Fwd

}
-----此内容被back于2006-12-21,14:59:41编辑过

出0入0汤圆

发表于 2006-12-21 19:06:33 | 显示全部楼层
有启发,留名,下载,刻盘,备份~~~呵呵~~~~

出0入0汤圆

发表于 2006-12-22 08:03:09 | 显示全部楼层
对应3楼的源代码

/***********************************************************************/

/*                                                                     */

/*  PROJECT                :Atmel AVR Design Contest 2006: AT3244                           */

/*  FILE        :KeyPad.c                                              */

/*  DATE        :April 27, 2006                                               */

/*  DESCRIPTION :This file contains the basic set of functions to            */

/*               input data from the keypad.                                 */

/*                                                                                                                                           */

/***********************************************************************/





#include <avr/interrupt.h>

#include <avr/pgmspace.h>

#include "usbdrv.h"

#include "KeyPad.h"

#include "LCD.h"

#include "ADC.h"

#include "ISO7816.h"





const char KeyPad[10][10] PROGMEM = {

    {'@', '0', '#', '_', '&', '$', '.', '(', ')', '\0'},    // Keypad '0'

    {' ', '1', '*', '+', '-', '/', '?', '!', '%', '\0'},    // Keypad '1'

    {'a', 'b', 'c', '2', 'A', 'B', 'C', '\0', '\0', '\0'},  // Keypad '2'

    {'d', 'e', 'f', '3', 'D', 'E', 'F', '\0', '\0', '\0'},  // Keypad '3'

    {'g', 'h', 'i', '4', 'G', 'H', 'I', '\0', '\0', '\0'},  // Keypad '4'

    {'j', 'k', 'l', '5', 'J', 'K', 'L', '\0', '\0', '\0'},  // Keypad '5'   

    {'m', 'n', 'o', '6', 'M', 'N', 'O', '\0', '\0', '\0'},  // Keypad '6'

    {'p', 'q', 'r', 's', '7', 'P', 'Q', 'R', 'S', '\0'},    // Keypad '7'

    {'t', 'u', 'v', '8', 'T', 'U', 'V', '\0', '\0', '\0'},  // Keypad '8'   

    {'w', 'x', 'y', 'z', '9', 'W', 'X', 'Y', 'Z', '\0'},    // Keypad '9'

};  





/*****************************************************************************

Name:            KeyPad_GetKey

Parameters:  None

Returns:     Key pressed coded in BCD (16 keys)

Description: This function gets a key from a 16-key keypad using the ADC

                         converter. To improve the reliability it takes two samples

                         before deciding on the key value   

*****************************************************************************/

unsigned char KeyPad_GetKey (void)

{

        unsigned char i;

        unsigned short raw[KEYPAD_MAX_SAMPLES];





        do {

                for (i = 0; i < KEYPAD_MAX_SAMPLES; i++) {

                        raw = ADC_Read (KBD);                            // Get raw ADC converter value       



                        if (raw >= KEYPAD_RAW_NO_KEY) {            // Lower digital Limit for checking the

                                                                                                   // corresponding digital value of 'NO KEY'

                                return KEYPAD_NO_KEY;                              // Return 'NO KEY' pressed code

                        }

                        else if (raw >= KEYPAD_RAW_D) {             // Lower digital Limit for checking the

                                                                                                  // corresponding digital value of 'D' key

                                raw = KEYPAD_D;                                // Key 'D' code in BCD

                                continue;                                                    // Try again

                        }

                        else if (raw >= KEYPAD_RAW_C) {             // Lower digital Limit for checking the

                                                                                                  // corresponding digital value of 'C' key

                                raw = KEYPAD_C;                                 // Key 'C' code in BCD

                                continue;                                                    // Try again

                        }

                        else if (raw >= KEYPAD_RAW_B) {             // Lower digital Limit for checking the

                                                                                                  // corresponding digital value of 'B' key

                               raw = KEYPAD_B;                                 // Key 'B' code in BCD

                                continue;                                                    // Try again

                        }

                    else if (raw >= KEYPAD_RAW_A) {             // Lower digital Limit for checking the

                                                                                                  // corresponding digital value of 'A' key

                               raw = KEYPAD_A;                                 // Key 'A' code in BCD

                                continue;                                                    // Try again

                        }

                    else if (raw >= KEYPAD_RAW_ENTER) {  // Lower digital Limit for checking the

                                                                                                      // corresponding digital value of 'ENTER' key

                               raw = KEYPAD_ENTER;                           // Key 'ENTER' code in BCD

                                continue;                                                    // Try again

                        }

                    else if (raw >= KEYPAD_RAW_9) {      // Lower digital Limit for checking the

                                                                                                  // corresponding digital value of '9' key

                               raw = KEYPAD_9;                               // Key '9' code in BCD

                                continue;                                                    // Try again

                        }

                    else if (raw >= KEYPAD_RAW_6) {             // Lower digital Limit for checking the

                                                                                                  // corresponding digital value of '6' key

                               raw = KEYPAD_6;                                 // Key '6' code in BCD

                                continue;                                                    // Try again

                        }

                    else if (raw >= KEYPAD_RAW_3) {             // Lower digital Limit for checking the

                                                                                                    // corresponding digital value of '3' key

                               raw = KEYPAD_3;                                 // Key '3' code in BCD

                                continue;                                                    // Try again

                    }

                        else if (raw >= KEYPAD_RAW_0) {             // Lower digital Limit for checking the

                                                                                                  // corresponding digital value of '0' key

                               raw = KEYPAD_0;                                 // Key '0' code in BCD

                                continue;                                                    // Try again

                        }

                    else if (raw >= KEYPAD_RAW_8) {             // Lower digital Limit for checking the

                                                                                                  // corresponding digital value of '8' key

                               raw = KEYPAD_8;                          // Key '8' code in BCD

                                continue;                                                    // Try again

                        }

                    else if (raw >= KEYPAD_RAW_5) {             // Lower digital Limit for checking the

                                                                                                    // corresponding digital value of '5' key

                               raw = KEYPAD_5;                                 // Key '5' code in BCD

                                continue;                                                    // Try again

                        }

                        else if (raw >= KEYPAD_RAW_2) {             // Lower digital Limit for checking the

                                                                                                  // corresponding digital value of '2' key

                                raw = KEYPAD_2;                                 // Key '2' code in BCD

                                continue;                                                    // Try again

                        }

                    else if (raw >= KEYPAD_RAW_ESC) {    // Lower digital Limit for checking the

                                                                                                  // corresponding digital value of 'ESC' key

                               raw = KEYPAD_ESC;                               // Key 'ESC' code in BCD

                                continue;                                                    // Try again

                        }                                   

                    else if (raw >= KEYPAD_RAW_7) {             // Lower digital Limit for checking the

                                                                                                  // corresponding digital value of '7' key

                               raw = KEYPAD_7;                                 // Key '7' code in BCD

                                continue;                                                    // Try again

                        }

                        else if (raw >= KEYPAD_RAW_4) {             // Lower digital Limit for checking the

                                                                                                  // corresponding digital value of '4' key

                                raw = KEYPAD_4;                                 // Key '4' code in BCD

                                continue;                                                    // Try again

                        }                                    

                    else {                                             // Lower digital Limit for checking the

                                                                                                  // corresponding digital value of '1' key

                                   raw = KEYPAD_1;                                 // Key '1' code in BCD

                        }

                }

        } while (raw[0] != raw[1]);                                            // Repeat until both samples are equal



        return raw[1];                                                                    // Return key code in BCD

}





/*****************************************************************************

Name:            KeyPad_WaitKeyRelease

Parameters:  None

Returns:     None

Description: This function waits for a key release   

*****************************************************************************/

void KeyPad_WaitKeyRelease (void)

{

    unsigned char key = KEYPAD_NO_KEY;





    do {                                            // Wait until the key has been released

        key = KeyPad_GetKey();                      // Sample keypad

    } while ((key < KEYPAD_NO_KEY) && ISO7816_SmartCardReady());

}





/*****************************************************************************

Name:            KeyPad_GetDigit

Parameters:  key_buff -> keys pressed string in ASCII

             digits -> number of digits to read

                         mode -> KEY_HIDE (1): show asterisks instead of digits

                                          KEY_SHOW (0): show the entered numbers

Returns:     None

Description: This function waits for a numeric input from the keypad and

                         at the same time displays the key pressed on the LCD. Depending

                         on the mode (HIDE / SHOW) the key is masked or not with '*'   

*****************************************************************************/

void KeyPad_GetDigit (unsigned char *digit_buff, unsigned char digits, unsigned char mode)

{

        unsigned char i = 0;

    unsigned char state = KEYPAD_WAIT_STATE;

        unsigned char key = KEYPAD_NO_KEY;

    unsigned char last_key = KEYPAD_NO_KEY;

        unsigned char lcd_buff [LCD_CHARS_PER_LINE + 1];





    *digit_buff = '\0';                                 // Initialize display buffers

    *lcd_buff = '\0';



    if (mode)

                LCD_String (LCD_LINE2, lcd_buff);                        // Display value masked with asterisks or

        else

                LCD_String (LCD_LINE2, digit_buff);                        // Display plain value

        

    LCD_Cursor (LCD_CURSOR_ON);                         // Show cursor



    while (ISO7816_SmartCardReady() && (i < LCD_CHARS_PER_LINE)) {



        switch (state) {

            case KEYPAD_WAIT_STATE:                     // Wait for a numeric key press         

                do {

                    usbPoll();                          // Refresh USB connection

                    key = KeyPad_GetKey();              // Sample keypad

                } while ((key > KEYPAD_ENTER) && ISO7816_SmartCardReady());               



                if (!ISO7816_SmartCardReady()) {        // If the smart card is removed

                    *digit_buff = '\0';                 // Clear display buffers

                    *lcd_buff = '\0';

                    LCD_Cursor (LCD_CURSOR_OFF);        // Hide cursor

                    return;                             // Exit

                }

                state = KEYPAD_HANDLING_STATE;          // Set next keypad state

                break;



            case KEYPAD_HANDLING_STATE:                 // Key handling

                switch (key) {

                    case KEYPAD_ESC:                    // Delete previous number

                        if (i > 0) {                    // If cursor position other than first

                                        i--;                                        

                                    }

                        

                        *(digit_buff + i) = ' ';

                        *(digit_buff + i + 1) = '\0';

                        *(lcd_buff + i) = ' ';

                        *(lcd_buff + i + 1) = '\0';

                                                

                        break;



                    case KEYPAD_ENTER:                  // Enter key

                        *(digit_buff + i) = '\0';       // Finish the input string

                        *(lcd_buff + i) = '\0';

                        LCD_Cursor (LCD_CURSOR_OFF);    // Hide cursor

                        return;



                    default:                            // Numeric key: 0 to 9

                        if (i < digits) {               // Convert to ASCII

                            *(digit_buff + i) = (char)(key + '0');

                            *(digit_buff + i + 1) = '\0';

                            *(lcd_buff + i) = '*';      // Display asterisk

                            *(lcd_buff + i + 1) = '\0';

                            i++;

                        }



                        break;

                }



                last_key = key;                         // Save the last key pressed value



                if (mode)

                    LCD_String (LCD_LINE2, lcd_buff);   // Display value masked with asterisk

                else

                    LCD_String (LCD_LINE2, digit_buff); // Display plain value

               

                if (key == KEYPAD_ESC)                  // If the DEL/ESC key was pressed

                    LCD_Cursor (LCD_CURSOR_LEFT);       // Move cursor to the left



                state = KEYPAD_PRESSED_STATE;           // Set next keypad state

               

                break;



            case KEYPAD_PRESSED_STATE:                        // Wait for numeric key release         

                do {

                    key = KeyPad_GetKey();              // Sample keypad  

                } while ((key <= KEYPAD_ENTER) && ISO7816_SmartCardReady());

               

                if (!ISO7816_SmartCardReady()) {        // If smart card withdrawal

                    *digit_buff = '\0';                 // Discard buffer contents

                    *lcd_buff = '\0';

                    LCD_Cursor (LCD_CURSOR_OFF);        // Hide cursor

                    return;                             // Exit

                }



                state = KEYPAD_WAIT_STATE;              // Re-initialize state machine

               

                break;

        }

    }



    LCD_Cursor (LCD_CURSOR_OFF);                        // Hide cursor

}





/*****************************************************************************

Name:            KeyPad_GetAlpha

Parameters:  alpha_buff -> keys pressed string in ASCII

                         letters -> number of alphanumeric characters to read

Returns:     None

Description: This function waits for an alphanumeric input from the keypad and

                         at the same time displays the key pressed on the LCD. The

             alphanumeric data is entered using a multiple keystroke algorithm

             similar to the input mechanism found on a cellular phone.

*****************************************************************************/

void KeyPad_GetAlpha (unsigned char *alpha_buff, unsigned char letters)

{

        unsigned char i = 0;

    unsigned char j = 0;

        unsigned char key = KEYPAD_NO_KEY;

    unsigned char last_key = KEYPAD_NO_KEY;

    unsigned long int timeout = 1000;

    unsigned char state = KEYPAD_WAIT_STATE;



     

    *alpha_buff = '\0';                                 // Initialize display buffer



    LCD_String (LCD_LINE2, alpha_buff);                            // Display string

    LCD_Cursor (LCD_CURSOR_ON);                         // Show cursor



    while (ISO7816_SmartCardReady() && (i < LCD_CHARS_PER_LINE)) {



        switch (state) {

            case KEYPAD_WAIT_STATE:                     // Wait for a numeric key press

                do {

                    key = KeyPad_GetKey();              // Sample keypad

                } while ((key > KEYPAD_ENTER) && ISO7816_SmartCardReady());

               

                if (!ISO7816_SmartCardReady()) {        // If the smart card is removed

                    *alpha_buff = '\0';                 // Clear display buffers

                    LCD_Cursor (LCD_CURSOR_OFF);        // Hide cursor

                    return;                             // Exit

                }

                state = KEYPAD_HANDLING_STATE;          // Set next keypad state

                break;



            case KEYPAD_HANDLING_STATE:                 // Key handling

                switch (key) {

                    case KEYPAD_ESC:                    // If DEL/ESC key pressed

                        if (i > 0) {

                                        i--;                        // Clear previous character                                        

                                    }

                        

                        *(alpha_buff + i) = ' ';        // Delete with white space

                        *(alpha_buff + i + 1) = '\0';   

                        LCD_Cursor (LCD_CURSOR_LEFT);   // Move cursor to the left

                                                

                        break;



                    case KEYPAD_ENTER:  

                        *(alpha_buff + i) = '\0';       // Finish the input string

                        LCD_Cursor (LCD_CURSOR_OFF);    // Hide cursor

                        return;                         // Exit



                    default:

                        if (i < letters) {              // Get first character of the key

                            *(alpha_buff + i) = pgm_read_byte (&KeyPad[key][0]);

                            *(alpha_buff + i + 1) = '\0';

                            j = 0;

                        }



                        break;

                }

               

                if (i < letters) {

                    last_key = key;                     // Save value of last key pressed

                    LCD_String (LCD_LINE2, alpha_buff);        // Display letter

                    LCD_Cursor (LCD_CURSOR_LEFT);       // Move cursor to the left

                }

                state = KEYPAD_PRESSED_STATE;           // Set next keypad state

               

                break;



            case KEYPAD_PRESSED_STATE:                  // Key release

                timeout = 1000;                         // Set timeout

                   

                do {                                    // Do until key is released or timeout

                    key = KeyPad_GetKey();              // Sample keypad  

                } while ((key <= KEYPAD_ENTER) && (--timeout) && ISO7816_SmartCardReady());         // Release

               

                if (!ISO7816_SmartCardReady()) {        // If the smart card is removed

                    *alpha_buff = '\0';                 // Clear display

                    LCD_Cursor (LCD_CURSOR_OFF);        // Hide cursor

                    return;                             // Exit

                }

                state = KEYPAD_PRESSED_TIMEOUT_STATE;   // Set next keypad state

               

                break;



            case KEYPAD_PRESSED_TIMEOUT_STATE:

                if (timeout == 0) {                     // If key is still pressed

                    if (key == KEYPAD_ESC) {            // And the key pressed is ESC key

                        *alpha_buff = '\0';             // Clear the LCD display

                        LCD_String (LCD_LINE2, "                ");

                        LCD_String (LCD_LINE2, alpha_buff);

                        i = 0;

                    }

                    else {

                        if (i < letters) {              // Display numeric value of the key pressed

                            *(alpha_buff + i) = (char)(key + '0');  // Convert to ASCII

                            *(alpha_buff + i + 1) = '\0';

                            LCD_String (LCD_LINE2, alpha_buff);                // Display value

                            i++;

                        }

                    }



                    do {                                // Wait until key is released

                        key = KeyPad_GetKey();          // Sample keypad

                    } while ((key <= KEYPAD_ENTER) && ISO7816_SmartCardReady());

                    

                    if (!ISO7816_SmartCardReady()) {    // If the smart card is removed

                        *alpha_buff = '\0';             // Clear display

                        LCD_Cursor (LCD_CURSOR_OFF);    // Hide cursor

                        return;                         // Exit

                    }

                    state = KEYPAD_WAIT_STATE;          // Set next keypad state

                }

                else {

                    if ((last_key == KEYPAD_ESC) || (i >= letters)) {

                        state = KEYPAD_WAIT_STATE;      // Set next keypad state

                    }

                    else {

                        state = KEYPAD_RELEASE_STATE;   // Set next keypad state

                    }

                }



                break;



            case KEYPAD_RELEASE_STATE:

                timeout = 1000;                         // Set timeout

               

                do {                                    // Wait for a key press or timeout

                    key = KeyPad_GetKey();              // Sample keypad

                } while ((key > KEYPAD_ENTER) && (--timeout) && ISO7816_SmartCardReady());

               

                if (!ISO7816_SmartCardReady()) {        // If the smart card is removed

                    *alpha_buff = '\0';                 // Clear display

                    LCD_Cursor (LCD_CURSOR_OFF);        // Hide cursor

                    return;                             // Exit

                }

                state = KEYPAD_RELEASE_TIMEOUT_STATE;   // Set next keypad state

               

                break;



            case KEYPAD_RELEASE_TIMEOUT_STATE:

                if (timeout == 0) {                     // If no key is pressed

                    i++;                                // Increment display index

                    state = KEYPAD_WAIT_STATE;          // Set next keypad state

                    LCD_Cursor (LCD_CURSOR_RIGHT);      // Move cursor to the right

                }

                else {                                  // If a key pressed within timeout

                    j++;                                // Select next character of key

                    state = KEYPAD_NEXT_CHAR_STATE;     // Set next keypad state

                }

                break;



            case KEYPAD_NEXT_CHAR_STATE:

                if (key == last_key) {                  // If key pressed is the same key

                    *(alpha_buff + i) = pgm_read_byte (&KeyPad[key][j % strlen_P (KeyPad[key])]);//KeyPad[key][j % strlen (KeyPad[key])];

                    *(alpha_buff + i + 1) = '\0';

                    LCD_String (LCD_LINE2, alpha_buff);        // Display value

                    LCD_Cursor (LCD_CURSOR_LEFT);       // Move cursor to the left

                    state = KEYPAD_PRESSED_STATE;       // Set next keypad state

                }

                else {                                  // If key different from previous key

                    i++;

                    state = KEYPAD_HANDLING_STATE;      // Set next keypad state

                    LCD_Cursor (LCD_CURSOR_RIGHT);      // Move cursor to the right

                }



                break;

        }

    }



    LCD_Cursor (LCD_CURSOR_OFF);                        // Hide cursor

}

出0入0汤圆

发表于 2006-12-22 08:43:09 | 显示全部楼层
就类似触摸屏的原理。

出0入0汤圆

发表于 2008-7-14 16:56:16 | 显示全部楼层
MAKE

出0入0汤圆

发表于 2008-7-14 17:00:00 | 显示全部楼层
MAKE

出0入46汤圆

发表于 2008-7-14 17:35:42 | 显示全部楼层
mark!

出0入0汤圆

发表于 2008-7-14 20:22:13 | 显示全部楼层
第一次采集到的值 在延时20ms 再采集一次
如果误差范围之类 就算是一次稳定的按键
不过用AD做按键,很怕多个按键同时按下
不知道你的那个不能区分的出来

出0入0汤圆

发表于 2008-9-9 09:51:11 | 显示全部楼层
mark

出0入0汤圆

发表于 2008-9-9 10:03:20 | 显示全部楼层
用电容的话,一定要小,不然有响应问题!

出0入0汤圆

发表于 2008-9-9 10:46:02 | 显示全部楼层
0.2v 应该可以分别吧!

5/1024=5mv啊

设置采样计算值 最小偏差< <最大偏差

出0入0汤圆

发表于 2008-9-9 11:09:43 | 显示全部楼层
先读出AD的值,同一按键 多次按是不是一样,

出0入0汤圆

发表于 2008-9-9 11:16:54 | 显示全部楼层
我试过ad按键,10位ad读出来的值非常稳,基本不会变,最多有+-1的变化,根本不需要滤波。用的vcc做基准,vcc是从7805出来的。楼主还是用示波器量一下按键时的电平,以及基准是否稳定。

出0入0汤圆

发表于 2009-4-5 22:48:33 | 显示全部楼层
mark

出0入0汤圆

发表于 2009-4-7 20:23:35 | 显示全部楼层
好像多个按键同时按下时就不太好处理了吧

出0入0汤圆

发表于 2009-4-7 22:48:35 | 显示全部楼层
记号

出0入0汤圆

发表于 2009-4-8 18:30:35 | 显示全部楼层
标记

出0入0汤圆

发表于 2009-4-8 18:37:59 | 显示全部楼层
好图

出0入0汤圆

发表于 2009-4-25 20:40:39 | 显示全部楼层
参考一下!

出0入0汤圆

发表于 2009-9-8 08:54:39 | 显示全部楼层
let me mark it

出0入0汤圆

发表于 2010-1-5 22:40:23 | 显示全部楼层
好方法  支持下

出0入0汤圆

发表于 2010-1-6 09:39:24 | 显示全部楼层
mark

出0入0汤圆

发表于 2010-11-15 20:58:17 | 显示全部楼层
mark

出0入0汤圆

发表于 2010-12-7 15:13:58 | 显示全部楼层
mark

出0入0汤圆

发表于 2011-9-2 10:47:49 | 显示全部楼层
mark 可以参考一下。

出0入0汤圆

发表于 2011-9-28 15:13:53 | 显示全部楼层
mark,学习下

出0入0汤圆

发表于 2011-12-2 16:33:21 | 显示全部楼层
mark..

出20入118汤圆

发表于 2013-5-5 11:47:18 | 显示全部楼层
mark 好东西

出0入0汤圆

发表于 2013-5-5 12:51:27 | 显示全部楼层
cool !
有启发,留名,下载,刻盘,备份~~~呵呵~~~~

出0入0汤圆

发表于 2013-5-6 22:37:18 | 显示全部楼层
以前 有些 CRT彩电不就是用电阻分压做的按键,使用时间久了之后按键识别就不准了;学习用可以的;做产品还是算了吧

出0入0汤圆

发表于 2013-5-7 08:58:30 | 显示全部楼层
太棒了!!!

出0入0汤圆

发表于 2013-6-24 08:45:09 | 显示全部楼层
好方法,收藏了~

出0入0汤圆

发表于 2013-6-24 09:26:06 | 显示全部楼层
ZLG7290,还是很好用的

出0入0汤圆

发表于 2013-6-24 09:48:42 | 显示全部楼层
这个论题很好,值得收藏
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-8-26 23:24

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表