Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

The keyboard

The keyboard

2005-02-18 by Eric

Hi what a failure the project is.

I was planning to put a 4*4 keyboard on portA of a ATmega32, sending F0 to the data direction register &
the data port.

this is the "test" plan, to put 1's on all the rows, the loop will look for a 1 on the columns,  when it
finds a 1 the beeper will beep, then I will continue to write the code so to put information on the LCD
from the keyboard after strobbing the rows one by one.


I got it to work alright on the studio program, it loops round looking for a 1 on the columns,  but it
fails when I download it to the micro,
I have got the port lines going direct to the keyboard,  should I put say 10K resistors on the input
ports? or use some other hardware ideas?



From Eric

Re: [AVR-Chat] The keyboard

2005-02-18 by Jesper Hansen

> Hi what a failure the project is.
>
> I was planning to put a 4*4 keyboard on portA of a ATmega32, sending F0 to 
> the data direction register &
> the data port.
>
> this is the "test" plan, to put 1's on all the rows, the loop will look 
> for a 1 on the columns,  when it
> finds a 1 the beeper will beep, then I will continue to write the code so 
> to put information on the LCD
> from the keyboard after strobbing the rows one by one.

Bad plan, the inputs are floating.

Assuming rows are on PA4..PA7 and columns on PA0..PA3 :
Write 0xF0 to DDRA to set PA0..PA3 as inputs and PA4..PA7 as outputs
Write 0x0F to PORTA to activate the pullups on PA0..PA3 and set all rows 
low.
Read PINA and AND with 0x0F, if the result is different from 0x0F, a key is 
pressed.
Set values 0xE0, 0xD0, 0xB0, 0x07 on PA4..7 and watch PA0..3 for a low to 
see which
key is was.
Show quoted textHide quoted text
>
> I got it to work alright on the studio program, it loops round looking for 
> a 1 on the columns,  but it
> fails when I download it to the micro,
> I have got the port lines going direct to the keyboard,  should I put say 
> 10K resistors on the input
> ports? or use some other hardware ideas?
>
>
>
> From Eric
>
>
>
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>

RE: [AVR-Chat] The keyboard

2005-02-18 by Javier Fiasche

i thing you should send a 1 to one row, scan the columns, and then send another 1 to the next row, not just send all the 4 1s to all the row at the same time
Here goes the code for a working 4*7 matrix keyboard
/*------------------------------------------------------------------------------------
RUTINAS DE UTILIZACION DEL TECLADO

Teclado matricial de 7 columnas x 4 filas. Las columnas se manejan con un decoder
74hc138 como salida y se leen los valores de las filas.
Para la conversion se utiliza un matriz.
El decoder esta conectado a la parte alta del puerto D y las filas a la parte baja del
puerto B.
COLUMNAS ---------> PUERTO DE LAS COLUMNAS
FILAS-------------> PUERTO DE LAS FILAS

-----------------------------------
| A | B | C | D | 1 | 2 | 3 |
-----------------------------------
| E | F | G | H | 4 | 5 | 6 |
-----------------------------------
| I | J | K | L | 7 | 8 | 9 |
-----------------------------------
| M | N | Ñ | O | P | 0 | Q |
-----------------------------------
;
/*-----------------------------------------------------------------------------------*/
#include "Keypad.h"
#include
flash char teclas[4][7]={{'A','B','C','D','1','2','3'},
{'E','F','G','H','4','5','6'},
{'I','J','K','L','7','8','9'},
; {'M','N','O','P','Q','0','R'}
};

/*------------------------------------------------------------------------------------
char Readkey(void)
Escanea la matriz de teclado, devuelve el valor de la tecla o nulo si no se presiono
-------------------------------------------------------------------------------------*/
char Readkey(void)
{ unsigned char i,col,fila,j;
for(i=0;i<7;i++)
{ col=COLUMNAS;
col&=0x1F; // limpio los bits del decoder
col|= ((i<<5)&0xE0);
COLUMNAS=col; // Escribo el puerto
fila=(~FILAS)&0x0F;
if(fila!=0x00) // Hay alguna tecla presionada??
{
for(j=0;j<4;j++)
{ if((fila>>j)&(0x01))
{ do
{fila=(~FILAS)&0x0F;}
while((fila>>j)&(0x01)); // Para q no se mantenga apretada
return(teclas[j][i]) ;
}
}
}
}
return('\0') ;
}
-----Mensaje original-----
De: Eric [mailto:erichards@clear.net.nz]
Enviado el: Viernes, 18 de Febrero de 2005 10:18 a.m.
Para: AVR-Chat@yahoogroups.com
Asunto: [AVR-Chat] The keyboard

Hi what a failure the project is.

I was planning to put a 4*4 keyboard on portA of a ATmega32, sending F0 to the data direction register &
the data port.

this is the "test" plan, to put 1's on all the rows, the loop will look for a 1 on the columns, when it
finds a 1 the beeper will beep, then I will continue to write the code so to put information on the LCD
from the keyboard after strobbing the rows one by one.


I got it to work alright on the studio program, it loops round looking for a 1 on the columns, but it
fails when I download it to the micro,
I have got the port lines going direct to the keyboard, should I put say 10K resistors on the input
ports? or use some other hardware ideas?



From Eric






Visita www.tutopia.com y comienza a navegar más rápido en Internet. Tutopia es Internet para todos.

Re: [AVR-Chat] The keyboard

2005-02-18 by Jose Fuentes

I recommend you to use at least 330 ohms resistors on
all the pins used for the keyboard.  Otherwise you
could unintentionally damage the ports, for instance
you could inadvertedly put all the pins as ouputs and
make a short-circuit with the switches.

I would scan the keyboard this way:

//PORTA.0:3 OUTPUTS
//PORTA.4:7 INPUTS

unsigned char i;
unsigned char result[4];
DDRA = 0x0F;//set direction (input/output)
PORTA = 0xFF;//activate pull-ups
for(i = 0; i < 4; i++)
{
  PORTA = ~(0x01 << i);//put 0s in PORTA.0:3
  result[i] = PINA;
}

If you want to save RAM memory (3 bytes) you can do
the following:
//PORTA.0:3 OUTPUTS
//PORTA.4:7 INPUTS

unsigned char result[2];
DDRA = 0x0F;//set direction (input/output)
PORTA = 0xFF;//activate pull-ups

PORTA = ~(0x01 );//put 0 in PORTA.0
result[0] = PINA | 0x0F;

PORTA = ~(0x01 << 1);//put 0 in PORTA.1
result[0] &= ((PINA >> 4) | 0xF0);

PORTA = ~(0x01 << 2);//put 0 in PORTA.2
result[1] = PINA | 0x0F;

PORTA = ~(0x01 << 3);//put 0 in PORTA.3
result[1] &= ((PINA >> 4) | 0xF0);

Then you have to check the bits in 'result' variable,
a 0 means a pressed switch.
This code is just an idea, I haven't tested it yet.


Regards

Jose

 --- Eric <erichards@clear.net.nz> escribió: 
> 
> Hi what a failure the project is.
> 
> I was planning to put a 4*4 keyboard on portA of a
> ATmega32, sending F0 to the data direction register
> &
> the data port.
> 
> this is the "test" plan, to put 1's on all the rows,
> the loop will look for a 1 on the columns,  when it
> finds a 1 the beeper will beep, then I will continue
> to write the code so to put information on the LCD
> from the keyboard after strobbing the rows one by
> one.
> 
> 
> I got it to work alright on the studio program, it
> loops round looking for a 1 on the columns,  but it
> fails when I download it to the micro,
> I have got the port lines going direct to the
> keyboard,  should I put say 10K resistors on the
> input
> ports? or use some other hardware ideas?
> 
> 
> 
> From Eric
> 
> 
> 
> 
> 
> 
> 
> 
>  
> Yahoo! Groups Links
> 
> 
>     AVR-Chat-unsubscribe@yahoogroups.com
> 
>  
> 
> 
> 
>  


	

	
		
___________________________________________________________ 
250MB gratis, Antivirus y Antispam 
Correo Yahoo!, el mejor correo web del mundo 
http://correo.yahoo.com.ar

Re: [AVR-Chat] The keyboard

2005-02-18 by Eric

Thanks Jesper
I know my circuit was a bit bare & rude, and could not get any ruder,
I did think about the short on the output lines killing a micro port, but mainly the port has the ADC on
them,

The read made module from http://www.futurlec.com/ has the buzzer on port D and the real time clock, Port
C has the LCD on it and the EEPROM, Port B is used for programming it.

Thank you for the advice, I quickly soldered the Keypad up before I went to work one morning, now the
weekend is here I will redo it properly adding in resistors.


Were you say "Set values 0xE0, 0xD0, 0xB0, 0x07 on PA4..7 and watch PA0..3 for a low to
see which key is was."
I think there is a typing error and 0x07 should be 0x70,

But I was thinking of
Setting values 0x10, 0x20, 0x40, 0x80 on PA4..7 and watch PA0..3 for a high to
see which key is was.

The keypad I have is a telephone type 3*4 alphanumeric with a 1*4 A to D column. what I program it for
could be numbered, I could do a long press for numbers short press for letters and two  and three short
presses for 2nd and 3rd letter, but one has to look at the cheap quality of the rubbish keypad and how
long before maximum key bounce, I might go better for a "two button" press to get the letters, press A
and another key to get the first letter, B and anther button to get the second button

From Eric
Show quoted textHide quoted text
----- Original Message -----
From: "Jesper Hansen" <jesperh@telia.com>
To: <AVR-Chat@yahoogroups.com>
Sent: Saturday, February 19, 2005 2:31 AM
Subject: Re: [AVR-Chat] The keyboard



> Hi what a failure the project is.
>
> I was planning to put a 4*4 keyboard on portA of a ATmega32, sending F0 to
> the data direction register &
> the data port.
>
> this is the "test" plan, to put 1's on all the rows, the loop will look
> for a 1 on the columns,  when it
> finds a 1 the beeper will beep, then I will continue to write the code so
> to put information on the LCD
> from the keyboard after strobbing the rows one by one.

Bad plan, the inputs are floating.

Assuming rows are on PA4..PA7 and columns on PA0..PA3 :
Write 0xF0 to DDRA to set PA0..PA3 as inputs and PA4..PA7 as outputs
Write 0x0F to PORTA to activate the pullups on PA0..PA3 and set all rows
low.
Read PINA and AND with 0x0F, if the result is different from 0x0F, a key is
pressed.
Set values 0xE0, 0xD0, 0xB0, 0x07 on PA4..7 and watch PA0..3 for a low to
see which
key is was.

>
> I got it to work alright on the studio program, it loops round looking for
> a 1 on the columns,  but it
> fails when I download it to the micro,
> I have got the port lines going direct to the keyboard,  should I put say
> 10K resistors on the input
> ports? or use some other hardware ideas?
>
>
>
> From Eric
>
>
>
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>





Yahoo! Groups Links

Amazon Re: [AVR-Chat] The keyboard

2005-02-18 by Eric

Thank you for your response I have that book

"Embedded C Programming and the Atmel AVR"
Barnett, Cox & O'Cull
                  A Thomson - Delmar Learning Publication
                              ISBN: 1401812066

coming from Amazon UK last night, I wanted two things, I stuffed the order up and could not cancel the
mess up I was going round and round in endless loops trying to find a way, I hope I don't have two books
coming or I will not purchase from them again, there is no direct feedback for such orders mess-ups, so
be it a lesson, it might of been better if I had of had my order come as two separate deliveries.


From Eric
Show quoted textHide quoted text
----- Original Message -----
From: "Jose Fuentes" <josecarlosfuentes@yahoo.com.ar>
To: <AVR-Chat@yahoogroups.com>
Sent: Saturday, February 19, 2005 4:03 AM
Subject: Re: [AVR-Chat] The keyboard



I recommend you to use at least 330 ohms resistors on
all the pins used for the keyboard.  Otherwise you
could unintentionally damage the ports, for instance
you could inadvertedly put all the pins as ouputs and
make a short-circuit with the switches.

I would scan the keyboard this way:

//PORTA.0:3 OUTPUTS
//PORTA.4:7 INPUTS

unsigned char i;
unsigned char result[4];
DDRA = 0x0F;//set direction (input/output)
PORTA = 0xFF;//activate pull-ups
for(i = 0; i < 4; i++)
{
  PORTA = ~(0x01 << i);//put 0s in PORTA.0:3
  result[i] = PINA;
}

If you want to save RAM memory (3 bytes) you can do
the following:
//PORTA.0:3 OUTPUTS
//PORTA.4:7 INPUTS

unsigned char result[2];
DDRA = 0x0F;//set direction (input/output)
PORTA = 0xFF;//activate pull-ups

PORTA = ~(0x01 );//put 0 in PORTA.0
result[0] = PINA | 0x0F;

PORTA = ~(0x01 << 1);//put 0 in PORTA.1
result[0] &= ((PINA >> 4) | 0xF0);

PORTA = ~(0x01 << 2);//put 0 in PORTA.2
result[1] = PINA | 0x0F;

PORTA = ~(0x01 << 3);//put 0 in PORTA.3
result[1] &= ((PINA >> 4) | 0xF0);

Then you have to check the bits in 'result' variable,
a 0 means a pressed switch.
This code is just an idea, I haven't tested it yet.


Regards

Jose

 --- Eric <erichards@clear.net.nz> escribió:
>
> Hi what a failure the project is.
>
> I was planning to put a 4*4 keyboard on portA of a
> ATmega32, sending F0 to the data direction register
> &
> the data port.
>
> this is the "test" plan, to put 1's on all the rows,
> the loop will look for a 1 on the columns,  when it
> finds a 1 the beeper will beep, then I will continue
> to write the code so to put information on the LCD
> from the keyboard after strobbing the rows one by
> one.
>
>
> I got it to work alright on the studio program, it
> loops round looking for a 1 on the columns,  but it
> fails when I download it to the micro,
> I have got the port lines going direct to the
> keyboard,  should I put say 10K resistors on the
> input
> ports? or use some other hardware ideas?
>
>
>
> From Eric
>
>
>
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>     AVR-Chat-unsubscribe@yahoogroups.com
>
>
>
>
>
>






___________________________________________________________
250MB gratis, Antivirus y Antispam
Correo Yahoo!, el mejor correo web del mundo
http://correo.yahoo.com.ar



Yahoo! Groups Links

Re: Amazon Re: [AVR-Chat] The keyboard

2005-02-18 by Eric

Oh-dam-it
I forgot to say I was going to focus on the assembly code for now, and try out my C coding after the book
comes, that Amazon stuff up really got me worked up, I just got a email to say one two piece order is on
the way. I hope they picked up the double order mistake.


From Eric
Show quoted textHide quoted text
----- Original Message -----
From: "Eric" <erichards@clear.net.nz>
To: <AVR-Chat@yahoogroups.com>
Sent: Saturday, February 19, 2005 8:32 AM
Subject: Amazon Re: [AVR-Chat] The keyboard



Thank you for your response I have that book

"Embedded C Programming and the Atmel AVR"
Barnett, Cox & O'Cull
                  A Thomson - Delmar Learning Publication
                              ISBN: 1401812066

coming from Amazon UK last night, I wanted two things, I stuffed the order up and could not cancel the
mess up I was going round and round in endless loops trying to find a way, I hope I don't have two books
coming or I will not purchase from them again, there is no direct feedback for such orders mess-ups, so
be it a lesson, it might of been better if I had of had my order come as two separate deliveries.


From Eric




----- Original Message -----
From: "Jose Fuentes" <josecarlosfuentes@yahoo.com.ar>
To: <AVR-Chat@yahoogroups.com>
Sent: Saturday, February 19, 2005 4:03 AM
Subject: Re: [AVR-Chat] The keyboard



I recommend you to use at least 330 ohms resistors on
all the pins used for the keyboard.  Otherwise you
could unintentionally damage the ports, for instance
you could inadvertedly put all the pins as ouputs and
make a short-circuit with the switches.

I would scan the keyboard this way:

//PORTA.0:3 OUTPUTS
//PORTA.4:7 INPUTS

unsigned char i;
unsigned char result[4];
DDRA = 0x0F;//set direction (input/output)
PORTA = 0xFF;//activate pull-ups
for(i = 0; i < 4; i++)
{
  PORTA = ~(0x01 << i);//put 0s in PORTA.0:3
  result[i] = PINA;
}

If you want to save RAM memory (3 bytes) you can do
the following:
//PORTA.0:3 OUTPUTS
//PORTA.4:7 INPUTS

unsigned char result[2];
DDRA = 0x0F;//set direction (input/output)
PORTA = 0xFF;//activate pull-ups

PORTA = ~(0x01 );//put 0 in PORTA.0
result[0] = PINA | 0x0F;

PORTA = ~(0x01 << 1);//put 0 in PORTA.1
result[0] &= ((PINA >> 4) | 0xF0);

PORTA = ~(0x01 << 2);//put 0 in PORTA.2
result[1] = PINA | 0x0F;

PORTA = ~(0x01 << 3);//put 0 in PORTA.3
result[1] &= ((PINA >> 4) | 0xF0);

Then you have to check the bits in 'result' variable,
a 0 means a pressed switch.
This code is just an idea, I haven't tested it yet.


Regards

Jose

 --- Eric <erichards@clear.net.nz> escribió:
>
> Hi what a failure the project is.
>
> I was planning to put a 4*4 keyboard on portA of a
> ATmega32, sending F0 to the data direction register
> &
> the data port.
>
> this is the "test" plan, to put 1's on all the rows,
> the loop will look for a 1 on the columns,  when it
> finds a 1 the beeper will beep, then I will continue
> to write the code so to put information on the LCD
> from the keyboard after strobbing the rows one by
> one.
>
>
> I got it to work alright on the studio program, it
> loops round looking for a 1 on the columns,  but it
> fails when I download it to the micro,
> I have got the port lines going direct to the
> keyboard,  should I put say 10K resistors on the
> input
> ports? or use some other hardware ideas?
>
>
>
> From Eric
>
>
>
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>     AVR-Chat-unsubscribe@yahoogroups.com
>
>
>
>
>
>






___________________________________________________________
250MB gratis, Antivirus y Antispam
Correo Yahoo!, el mejor correo web del mundo
http://correo.yahoo.com.ar



Yahoo! Groups Links










Yahoo! Groups Links

Re: Amazon Re: [AVR-Chat] The keyboard

2005-02-18 by Dave VanHorn

At 02:40 PM 2/18/2005, Eric wrote:

>Oh-dam-it
>I forgot to say I was going to focus on the assembly code for now, and try 
>out my C coding after the book
>comes, that Amazon stuff up really got me worked up, I just got a email to 
>say one two piece order is on
>the way. I hope they picked up the double order mistake.


The easy way to do a matrix keyboard, is to take rows (or columns) and make 
them inputs pulled up, and take the other side (col or row) and make them 
the scanned outputs, active low.

So, when you are seeing all highs, no keys are pressed.
When you see a low on any row, then you check what col you have set low, 
and now you know what key(s) are pressed.

Re: Amazon Re: [AVR-Chat] The keyboard

2005-02-18 by Stefan Trethan

On Fri, 18 Feb 2005 15:16:04 -0500, Dave VanHorn <dvanhorn@dvanhorn.org>  
wrote:

>
> The easy way to do a matrix keyboard, is to take rows (or columns) and  
> make
> them inputs pulled up, and take the other side (col or row) and make them
> the scanned outputs, active low.
> So, when you are seeing all highs, no keys are pressed.
> When you see a low on any row, then you check what col you have set low,
> and now you know what key(s) are pressed.
>


I am currently making something with a 3x4 keyboard.
I have connected the 3 columns to the 3 external iterrupts, and the 4 rows  
to I/O.
The plan is to set the column pins (interrupts) to pullup, and input, and  
the rows to output, low.
My hope is when someone presses a key the interrupt line goes low, causing  
a interrupt and in the ISR i switch the rows input and columns output to  
see which button it was.

Would be nice to know if this will actually work, i just guessed...

ST

Re: Amazon Re: [AVR-Chat] The keyboard

2005-02-18 by Dave VanHorn

>
>I am currently making something with a 3x4 keyboard.
>I have connected the 3 columns to the 3 external iterrupts, and the 4 rows
>to I/O.
>The plan is to set the column pins (interrupts) to pullup, and input, and
>the rows to output, low.
>My hope is when someone presses a key the interrupt line goes low, causing
>a interrupt and in the ISR i switch the rows input and columns output to
>see which button it was.
>
>Would be nice to know if this will actually work, i just guessed...

Sounds right to me, just set a timer to change the row outputs 
periodically, say every 100mS or so.

Re: Amazon Re: [AVR-Chat] The keyboard

2005-02-18 by Stefan Trethan

On Fri, 18 Feb 2005 15:34:36 -0500, Dave VanHorn <dvanhorn@dvanhorn.org>  
wrote:

>
>>
>> I am currently making something with a 3x4 keyboard.
>> I have connected the 3 columns to the 3 external iterrupts, and the 4  
>> rows
>> to I/O.
>> The plan is to set the column pins (interrupts) to pullup, and input,  
>> and
>> the rows to output, low.
>> My hope is when someone presses a key the interrupt line goes low,  
>> causing
>> a interrupt and in the ISR i switch the rows input and columns output to
>> see which button it was.
>>
>> Would be nice to know if this will actually work, i just guessed...

> Sounds right to me, just set a timer to change the row outputs
> periodically, say every 100mS or so.


Thanks,

but why should i change the row outputs?
I thought i let them all low, until there's a interrupt, and in the ISR i  
change the rows from out to in and make the colums low. The row input that  
goes low would show the pressed key?

ST

Re: Amazon Re: [AVR-Chat] The keyboard

2005-02-18 by Eric

I'm confused Stefan
why switch the rows from output to input & Columns from input to output? it just sounds like a waste of
software space for what it is worth.


From Eric
Show quoted textHide quoted text
----- Original Message -----
From: "Stefan Trethan" <stefan_trethan@gmx.at>
To: <AVR-Chat@yahoogroups.com>
Sent: Saturday, February 19, 2005 9:28 AM
Subject: Re: Amazon Re: [AVR-Chat] The keyboard



On Fri, 18 Feb 2005 15:16:04 -0500, Dave VanHorn <dvanhorn@dvanhorn.org>
wrote:

>
> The easy way to do a matrix keyboard, is to take rows (or columns) and
> make
> them inputs pulled up, and take the other side (col or row) and make them
> the scanned outputs, active low.
> So, when you are seeing all highs, no keys are pressed.
> When you see a low on any row, then you check what col you have set low,
> and now you know what key(s) are pressed.
>


I am currently making something with a 3x4 keyboard.
I have connected the 3 columns to the 3 external iterrupts, and the 4 rows
to I/O.
The plan is to set the column pins (interrupts) to pullup, and input, and
the rows to output, low.
My hope is when someone presses a key the interrupt line goes low, causing
a interrupt and in the ISR i switch the rows input and columns output to
see which button it was.

Would be nice to know if this will actually work, i just guessed...

ST



Yahoo! Groups Links

Re: Amazon Re: [AVR-Chat] The keyboard

2005-02-18 by Dave VanHorn

At 03:39 PM 2/18/2005, Stefan Trethan wrote:

>On Fri, 18 Feb 2005 15:34:36 -0500, Dave VanHorn <dvanhorn@dvanhorn.org>
>wrote:
>
> >
> >>
> >> I am currently making something with a 3x4 keyboard.
> >> I have connected the 3 columns to the 3 external iterrupts, and the 4
> >> rows
> >> to I/O.
> >> The plan is to set the column pins (interrupts) to pullup, and input,
> >> and
> >> the rows to output, low.
> >> My hope is when someone presses a key the interrupt line goes low,
> >> causing
> >> a interrupt and in the ISR i switch the rows input and columns output to
> >> see which button it was.
> >>
> >> Would be nice to know if this will actually work, i just guessed...
>
> > Sounds right to me, just set a timer to change the row outputs
> > periodically, say every 100mS or so.
>
>
>Thanks,
>
>but why should i change the row outputs?
>I thought i let them all low, until there's a interrupt, and in the ISR i
>change the rows from out to in and make the colums low. The row input that
>goes low would show the pressed key?

Well, let's just say inputs and outputs.
Assume a 4x4 matrix.
When I get a low, maybe I read 0xXE so bit 0 of the port is low.
That tells me that a key in a given row is pressed, but I need to know 
which col is low, to know which key that is.

So, have an event, probably on timer 0, that every so often, changes which 
col is low, and at the same time, writes new definitions into four bytes in 
ram.  So when Col0 is low, it writes A,B,C,D  A while later it takes Col0 
high and Col1 low, and writes E,F,G,H, and so on.

When you get the int, then you see 0x07, and you know that row 3 was 
pushed, so you load "H" from ram into TEMP, and return that "H" was pressed.

You could also just go look at the row and col inputs, and use them to look 
up a table, or handle it many other ways.

Re: Amazon Re: [AVR-Chat] The keyboard

2005-02-18 by Stefan Trethan

On Sat, 19 Feb 2005 09:41:45 +1300, Eric <erichards@clear.net.nz> wrote:

> I'm confused Stefan
> why switch the rows from output to input & Columns from input to output?  
> it just sounds like a waste of
> software space for what it is worth.
> From Eric


Well, i thought it is needed?
How would i know which button is pressed, it could be any on this column?

OH... you mean i should change the state of the row lines and see which is  
causing the column line to go low... oh well, that seems easier allright...

thanks

ST

Re: Amazon Re: [AVR-Chat] The keyboard

2005-02-18 by Eric

Hi again
By the way Application notes AVR242 on page 4 has a interesting four digit 7 segment LED, 4*4 keyboard
with a AT90S1200 but it uses two ports B & D.   not that I would use it, it is just food for thought.


From Eric
Show quoted textHide quoted text
----- Original Message -----
From: "Eric" <erichards@clear.net.nz>
To: <AVR-Chat@yahoogroups.com>
Sent: Saturday, February 19, 2005 9:41 AM
Subject: Re: Amazon Re: [AVR-Chat] The keyboard



I'm confused Stefan
why switch the rows from output to input & Columns from input to output? it just sounds like a waste of
software space for what it is worth.


From Eric





----- Original Message -----
From: "Stefan Trethan" <stefan_trethan@gmx.at>
To: <AVR-Chat@yahoogroups.com>
Sent: Saturday, February 19, 2005 9:28 AM
Subject: Re: Amazon Re: [AVR-Chat] The keyboard



On Fri, 18 Feb 2005 15:16:04 -0500, Dave VanHorn <dvanhorn@dvanhorn.org>
wrote:

>
> The easy way to do a matrix keyboard, is to take rows (or columns) and
> make
> them inputs pulled up, and take the other side (col or row) and make them
> the scanned outputs, active low.
> So, when you are seeing all highs, no keys are pressed.
> When you see a low on any row, then you check what col you have set low,
> and now you know what key(s) are pressed.
>


I am currently making something with a 3x4 keyboard.
I have connected the 3 columns to the 3 external iterrupts, and the 4 rows
to I/O.
The plan is to set the column pins (interrupts) to pullup, and input, and
the rows to output, low.
My hope is when someone presses a key the interrupt line goes low, causing
a interrupt and in the ISR i switch the rows input and columns output to
see which button it was.

Would be nice to know if this will actually work, i just guessed...

ST



Yahoo! Groups Links










Yahoo! Groups Links

Re: [AVR-Chat] The keyboard

2005-02-18 by Jesper Hansen

> Were you say "Set values 0xE0, 0xD0, 0xB0, 0x07 on PA4..7 and watch PA0..3 
> for a low to
> see which key is was."
> I think there is a typing error and 0x07 should be 0x70,

Oops, yes, it has to be 0x70 ofcourse. The idea is to just have a single row 
low.

> But I was thinking of
> Setting values 0x10, 0x20, 0x40, 0x80 on PA4..7 and watch PA0..3 for a 
> high to
> see which key is was.

The idea is the same, but then you would have to add pulldown resistors on 
the column lines.
Why not take advantage of the built in pullup resistors on the AVR port pins 
?

> The keypad I have is a telephone type 3*4 alphanumeric with a 1*4 A to D 
> column. what I program it for
> could be numbered, I could do a long press for numbers short press for 
> letters and two  and three short
> presses for 2nd and 3rd letter, but one has to look at the cheap quality 
> of the rubbish keypad and how
> long before maximum key bounce, I might go better for a "two button" press 
> to get the letters, press A
> and another key to get the first letter, B and anther button to get the 
> second button

Contact bounce is usually just a few mS. You'd have plenty of time to wait 
for debounce and still be able
to detect the various types of keypresses.

/Jesper
Show quoted textHide quoted text
> From Eric
>
>
>
>
> ----- Original Message -----
> From: "Jesper Hansen" <jesperh@telia.com>
> To: <AVR-Chat@yahoogroups.com>
> Sent: Saturday, February 19, 2005 2:31 AM
> Subject: Re: [AVR-Chat] The keyboard
>
>
>
>> Hi what a failure the project is.
>>
>> I was planning to put a 4*4 keyboard on portA of a ATmega32, sending F0 
>> to
>> the data direction register &
>> the data port.
>>
>> this is the "test" plan, to put 1's on all the rows, the loop will look
>> for a 1 on the columns,  when it
>> finds a 1 the beeper will beep, then I will continue to write the code so
>> to put information on the LCD
>> from the keyboard after strobbing the rows one by one.
>
> Bad plan, the inputs are floating.
>
> Assuming rows are on PA4..PA7 and columns on PA0..PA3 :
> Write 0xF0 to DDRA to set PA0..PA3 as inputs and PA4..PA7 as outputs
> Write 0x0F to PORTA to activate the pullups on PA0..PA3 and set all rows
> low.
> Read PINA and AND with 0x0F, if the result is different from 0x0F, a key 
> is
> pressed.
> Set values 0xE0, 0xD0, 0xB0, 0x07 on PA4..7 and watch PA0..3 for a low to
> see which
> key is was.
>
>>
>> I got it to work alright on the studio program, it loops round looking 
>> for
>> a 1 on the columns,  but it
>> fails when I download it to the micro,
>> I have got the port lines going direct to the keyboard,  should I put say
>> 10K resistors on the input
>> ports? or use some other hardware ideas?
>>
>>
>>
>> From Eric
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> Yahoo! Groups Links
>>
>>
>>
>>
>>
>>
>>
>>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>

Re: Amazon Re: [AVR-Chat] The keyboard

2005-02-19 by Russell Shaw

Eric wrote:
> Oh-dam-it
> I forgot to say I was going to focus on the assembly code for now, and try out my C coding after the book
> comes, that Amazon stuff up really got me worked up, I just got a email to say one two piece order is on
> the way. I hope they picked up the double order mistake.

You can return books even from overseas (like i did).

Send one book back in its original box, with the address clearly marked, and your own
address covered up. Put the return sticker on the box that comes with the receipt.

the Keyboard

2005-02-19 by Eric

Hi all

Just a note to say I am making good progress on the keyboard, not too sure if my code is "tidy" way of
doing it. but it is almost 2.30am on Sunday morning in "Kiwi" land and I must do some other Email to do
with work before I go to bed.

The other day I had a lot of "Instruction Set" problems, as this is the first time I have started coding
from square one, the LCD coding was written by the people who sold me the micro module, but I found a new
set of  "Instruction Set" and the old copy has been send to the recycle bin that gets collected at the
street each week.  in fact the old set I got off the internet somewhere never had any instruction that
started with 'B' like BREQ for example, strange as it might sound?

From Eric

Amazon Re: [AVR-Chat] The keyboard

2005-02-20 by brewski922

--- In AVR-Chat@yahoogroups.com, "Stefan Trethan" 
<stefan_trethan@g...> wrote:
> On Fri, 18 Feb 2005 15:16:04 -0500, Dave VanHorn <dvanhorn@d...>  
> wrote:
> 
> >
> > The easy way to do a matrix keyboard, is to take rows (or 
columns) and  
> > make
> > them inputs pulled up, and take the other side (col or row) and 
make them
> > the scanned outputs, active low.
> > So, when you are seeing all highs, no keys are pressed.
> > When you see a low on any row, then you check what col you have 
set low,
> > and now you know what key(s) are pressed.
> >
> 
> 
> I am currently making something with a 3x4 keyboard.
> I have connected the 3 columns to the 3 external iterrupts, and the 
4 rows  
> to I/O.
> The plan is to set the column pins (interrupts) to pullup, and 
input, and  
> the rows to output, low.
> My hope is when someone presses a key the interrupt line goes low, 
causing  
> a interrupt and in the ISR i switch the rows input and columns 
output to  
> see which button it was.
> 
> Would be nice to know if this will actually work, i just guessed...
> 
> ST

Haven't read messages in a day or so. Below is an interrupt driven 
program that scans a Grayhill Series 88 3x4 keypad. I completted it a 
week or so ago.
Mike

/*****************************************************
This program was produced by the
CodeWizardAVR V1.24.4a Standard
Automatic Program Generator
© Copyright 1998-2004 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
e-mail:office@hpinfotech.com

Project : 
Version : 
Date    : 1/31/2005
Author  : Mike Bronosky                   
Company : ICU LLC                         
Comments: 


Chip type           : ATmega8515
Program type        : Application
Clock frequency     : 4.000000 MHz
Memory model        : Small
External SRAM size  : 0
Data Stack size     : 128
*****************************************************

  PORTD.0..2 will be column outputs
  PIND.4..6 will be row inputs
  PORTD.3 Ext Int 1
  
  Connect the keypad matrix as follows:
   
 PORTD.3   D4
 Ext  -o--|>|-------   D4 - D7 = 1N4148
 Int1  |   D5       |
       o--|>|-----  |
       |   D6     | |
       o--|>|---  | |
       |   D7   | | |
        --|>|-  | | |
              | | | |
  PORTD      | | | |     [KEYS]
  5 PD4 ------------o---1----2----3
              | | |     |    |    |
  6 PD5 ----------o-----4----5----6
              | |       |    |    |
  7 PD6 --------o-------7----8----9
              |         |    |    |
  8 PD7 ------o---------10---11---12
                  D1    |    |    | 
  1 PD0 ----------|<|---     |    |   D1 - D3 = 1N4148  
                  D2         |    | 
  2 PD1 ----------|<|--------     |
                  D3              | 
  3 PD2 ----------|<|------------- 
   
  Use an 2x20 alphanumeric LCD connected
  to PORTC as follows:

  [LCD]   [STK500 PORTC HEADER]
   1 GND- 9  GND
   2 +5V- 10 VCC  
   3 VLC- LCD contrast control voltage 0..1V
   4 RS - 1  PC0
   5 RD - 2  PC1
   6 EN - 3  PC2
  BLite -    PC3
  11 D4 - 5  PC4
  12 D5 - 6  PC5
  13 D6 - 7  PC6
  14 D7 - 8  PC7
*/

#include <mega8515.h>

// Alphanumeric LCD Module functions
#asm
   .equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>
#include <stdlib.h>
#include <delay.h>

#define Enable 0
#define Disable 1
void Scan(int i);
void DoCase(int ii);

// External Interrupt 1 service routine
interrupt [EXT_INT1] void ext_int1_isr(void)
{
// Place your code here
//delay_ms(50);
if (PIND.3==0) {
PORTD=0xFF;
//delay_ms(50);
//Column 1
  PORTD.0=Enable;
  Scan(0);
  PORTD.0=Disable;
//Column 2
  PORTD.1=Enable;
  Scan(1);
  PORTD.1=Disable;
//Column 3
  PORTD.2=Enable;
  Scan(2);
  PORTD.2=Disable;
  }
PORTD=0xF8;
}

// Declare your global variables here

void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In 
Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T 
State0=T 
PORTA=0x00;
DDRA=0x00;

// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In 
Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T 
State0=T 
PORTB=0x00;
DDRB=0x00;

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In 
Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T 
State0=T 
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=Out Func1=Out 
Func0=Out 
// State7=T State6=T State5=T State4=T State3=T State2=0 State1=0 
State0=0 
PORTD=0xF8;
DDRD=0x07;

// Port E initialization
// Func2=In Func1=In Func0=In 
// State2=T State1=T State0=T 
PORTE=0x00;
DDRE=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: On
// INT1 Mode: Falling Edge
// INT2: Off
GICR|=0x80;
MCUCR=0x08;
EMCUCR=0x00;
GIFR=0x80;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;

// LCD module initialization
lcd_init(16);

// Global enable interrupts
#asm("sei")

while (1)
      {
      // Place your code here

      };
}
void Scan(int i)
{
if ((PIND & 0XF0) != 0xF0) {
  switch(PIND & 0xF0){
    case 0b11100000: DoCase(1 + i);
      break;
    case 0b11010000: DoCase(4 + i);
      break;
    case 0b10110000: DoCase(7 + i);
      break;
    case 0b01110000: DoCase(10 + i);
      break;
    default: DoCase(PIND);
    }
  }
}

void DoCase(int ii)
{
  char s[1];
  lcd_clear();
  itoa(ii, s);
  if (ii<=9) lcd_putsf(" ");
  lcd_puts(s);
}

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.