0

キーパッド モジュールには残念な問題があり、そのキーのいずれかを押すと、通常は LCD モジュールで押されたキーが表示されます。問題は、キーを押すたびに行のスキャンが停止し、たとえばアプリケーションがパスワードを受信して​​ LCD に表示されるシステムの場合、LCD に表示される他のキーを押すことができないことです。LCD にリストを表示したいときに、画面の別のページをめくってリストの表示を再開したい場合、現在直面している別の問題があります。どうすればこれを実装できますか?! 回路図のスクリーンショットを添付し、キーパッドと LCD の両方をチェックするためのコードを提供します。とにかく私を助けてくれてありがとう。 ここに画像の説明を入力

私のアプリケーションコード:

#define F_CPU 8000000UL
#include <util/delay.h>
#include <avr/io.h>
#include "LCD.h"
#include "Keypad.h"

int main(void)
{
    /* Replace with your application code */
    uint8_t keypadPress = 0;
    Keypad_vInit();
    LCD_vInit();

    while( !Keypad_u8Scan() )
    {
        keypadPress = Keypad_u8Scan();
        if( keypadPress == '8' )
        {
            LCD_vPrintChar( '8' );
            while( keypadPress == '8' );
        }
    }
}

私のLCDライブラリ:

#if defined MODE_4

static void sendFallingEdge( void ); /* This prototype is declared static       to avoid modifying it. */

static void sendFallingEdge( void )
{
    /* Initializing the EN pin of the LCD when detecting a falling edge. */
    /* The following code is the representation of falling edge using the   system clock. */
    PORTB |= ( 1 << EN );
    _delay_ms( 1 );
    PORTB &= ( ~ ( 1 << EN ) );
    _delay_ms( 1 );
}

void LCD_vSendCmd( char cmd )
{
    /* Transferring the first nibble. */
    PORTA &= 0x0F;
    PORTA |= ( cmd & 0xF0 );
    CLR_BIT( PORTB, RS ); /* Transferring instructions data. */
    sendFallingEdge( );

    /* Transferring the second nibble. */
    PORTA &= 0x0F;
    PORTA |= ( cmd << 4 );
    CLR_BIT( PORTB, RS ); /* Transferring instructions data. */
    sendFallingEdge( );
}

void LCD_vInit( void )
{
    DDRA |= 0xF0; /* DDRA |= 0b11110000; */
    DDRB |= 0x0E; /* DDRB |= 0b00001110; */ /* Those three HIGH bits are the RS, RW and EN respectively. */
    CLR_BIT( PORTB, RW ); /* Write mode enabled according to the LCD's datasheet. */

    LCD_vSendCmd( 0x33 );
    _delay_ms( 1 );

    LCD_vSendCmd( 0x32 );
    _delay_ms( 1 );

    LCD_vSendCmd( 0x28 );
    _delay_ms( 1 );

    LCD_vSendCmd( 0x01 );
    _delay_ms( 1 );

    LCD_vSendCmd( 0x0F );
    _delay_ms( 1 );
}

void LCD_vPrintChar( char data )
{
    PORTA &= 0x0F;
    PORTA |= ( data & 0xF0 );
    SET_BIT( PORTB, RS ); /* Transferring display data. */
    sendFallingEdge( );

    PORTA &= 0x0F;
    PORTA |= ( data << 4 ); 
    SET_BIT( PORTB, RS ); /* Transferring display data. */
    sendFallingEdge( );
}

void LCD_vPrintString( char * str )
{
    uint8_t counter;
    for( counter = 0; str[ counter ] != '\0'; counter ++ )
    {
        LCD_vPrintChar( str[ counter ] );
    }
}

void LCD_vPrintNumbers( uint8_t str[ ], uint8_t size )
{
    uint8_t counter;
    for( counter = 0; str[ counter ] < size; counter ++ )
    {
        LCD_vPrintChar( str[ counter ] );
    }
}

void LCD_vClrScreen( void )
{
    LCD_vSendCmd( CLR_SCRN );
}

void LCD_vMoveCursor( char row, char column )
{
    char cmd;
    if( row == 1 )
    {
        cmd = STARTROW0 + column - 1;
        LCD_vSendCmd( cmd );
    }
    else if( row == 2 )
    {
        cmd = STARTROW1 + column - 1;
        LCD_vSendCmd( cmd );
    }
}

#endif

私のキーパッド ライブラリ:

#include <avr/io.h>
#include "std_macros.h"

void Keypad_vInit( void )
{
    DDRC = 0x0F; 
    CLR_BIT( SFIOR, PUD ); 
    PORTC = 0xFF;          
}
unsigned char Keypad_u8Scan( void )
{
    unsigned char row, column, scan, buttonPressed = 0;
    unsigned char KP[ 4 ][ 4 ] = { { '7', '8', '9', '/' },
                                   { '4', '5', '6', '*' },
                                   { '1', '2', '3', '-' },
                                   { ' ', '0', '=', '+' }           
                                 };
    for( row = 0; row < 4; row ++ )
    {
        PORTC |= 0x0F;
        CLR_BIT( PORTC, row );
        for( column = 4; column < 8; column ++ )
        {
            scan = READ_BIT( PINC, column );
            if( scan == 0 )
            {
                buttonPressed = KP[ row ][ column - 4 ];
            }
        }
    }
    return buttonPressed;
}

そして最後に私の標準マクロ:

#define SET_BIT( REGISTER, BIT_NUM ) ( REGISTER = REGISTER | ( 1 << BIT_NUM ) )
#define CLR_BIT( REGISTER, BIT_NUM ) ( REGISTER = REGISTER & ( ~( 1 << BIT_NUM ) ) )
4

2 に答える 2