PSoC + TECLADO + LCD

Software e Hardware para uC PSoC

Moderadores: andre_luis, 51

PSoC + TECLADO + LCD

Mensagempor Iran » 09 Jun 2007 17:01

Um programinha simples para guiar os que como eu estão iniciando no PSoC. Pode servir de base para algum projeto. Não garanto ser o melhor programa do mundo não. ACEITO CRÍTICAS E SUGESTÔES.

Um teclado telefônico de 12 teclas foi ligado na porta P1 da seguinte forma:

P1_0 -> Coluna 3,6,9,#
P1_1 -> Coluna 2,5,8,0
P1_2 -> Coluna 1,4,7,*
P1_3 -> Linha 1,2,3
P1_4 -> Linha 4,5,6
P1_5 -> Linha 7,8,9
P1_6 -> Linha *,0,#

Na porta P2 foi ligado um display LCD 16x2 usando o componente LCD_1 (renomeado para LCD) do PSoC Designer.

O número da tecla digitada e mostrado no LCD quando a tecla é liberada

//----------------------------------------------------------------------------
// C main line
//----------------------------------------------------------------------------

#include <m8c.h> // part specific constants and macros
#include "PSoCAPI.h" // PSoC API definitions for all User Modules


unsigned int delay;
unsigned char tecla[2]= {'X',0x00};

#pragma interrupt_handler teclado

void teclado(void)
{
while(PRT1DR != 0xF8) //
{
do
{
PRT1DR = 0x88; // Excita Linha 0 do teclado, teclas 1,2,3
switch(PRT1DR)

{
case 0x8c:
tecla[0] = '1'; // Tecla 1
break;
case 0x8a:
tecla[0] = '2'; // Tecla 2
break;
case 0x89:
tecla[0] = '3'; // Tecla 3
break;
default:
break;
}
PRT1DR = 0x90; // Excita Linha 1 do teclado, teclas 4,5,6
switch(PRT1DR)

{
case 0x94:
tecla[0] = '4'; // Tecla 4
break;
case 0x92:
tecla[0] = '5'; // Tecla 5
break;
case 0x91:
tecla[0] = '6'; // Tecla 6
break;
default:
break;
}
PRT1DR = 0xa0; // Excita Linha 2 do teclado, teclas 7,8,9
switch(PRT1DR)

{
case 0xa4:
tecla[0] = '7'; // Tecla 7
break;
case 0xa2:
tecla[0] = '8'; // Tecla 8
break;
case 0xa1:
tecla[0] = '9'; // Tecla 9
break;
default:
break;
}
PRT1DR = 0xc0; // Excita Linha 3 do teclado, teclas *,0,#
switch(PRT1DR)

{
case 0xc4:
tecla[0] = '*'; // Tecla *
break;
case 0xc2:
tecla[0] = '0'; // Tecla 0
break;
case 0xc1:
tecla[0] = '#'; // Tecla #
break;
default:
break;
}
PRT1DR = 0xf8; //
}while(PRT1DR != 0xf8); //
}
LCD_Position(1,8); // Posiciona o cursor na segunda linha coluna 6
LCD_PrString(tecla); // Escreve o valor atual da contagem
delay = 5000; // Carrega variável delay
while(delay--); // Atraso de tempo
INT_CLR0 =0x20; // Limpa interrupções pendentes
}

void main()
{
PRT1DM2 = 0x00; // Define porta P1_0,P1_1 e P1_2 como pull down demais strong
PRT1DM1 = 0x00; // Define porta P1_0,P1_1 e P1_2 como pull down demais strong
PRT1DM0 = 0xf8; // Define porta P1_0,P1_1 e P1_2 como pull down demais strong
PRT1IC1 = 0x07; // Interrupção em nível alto em P1_0, P1_1 e P1_2
PRT1IC0 = 0x00; // Interrupção em nível alto em P1_0, P1_1 e P1_2
PRT1IE = 0x07; // Habilita interrupção em P1_0, P1_1 e P1_2
M8C_EnableIntMask(INT_MSK0, INT_MSK0_GPIO); // Habilita interupção GPIO
M8C_EnableGInt; // Habilita globalmente interrupções
LCD_Start(); // Inicializa o display
LCD_Position(0,1); // Posiciona o cursor na primeira linha coluna 1
LCD_PrCString("PSoC - TECLA"); // Escreve PSoC - TECLA na primeira linha
LCD_Position(1,7); // Posiciona o cursor na segunda linha coluna 7
LCD_PrString(tecla); // Escreve X antes da primeira tecla ser pressionada
PRT1DR = 0xf8;
while(1);

}



Zé Iran.

PS. Uma carinha que apareceu aí pelo meio não sei pq é o numero 8, alguns comentários não tem nada a ver com a estória.
Avatar do usuário
Iran
Word
 
Mensagens: 558
Registrado em: 16 Out 2006 18:10
Localização: Imperatriz - MA

Voltar para Cypress

Quem está online

Usuários navegando neste fórum: Nenhum usuário registrado e 1 visitante

x