Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

reading a 4x4 switch matrix

Status
Not open for further replies.
Cheers jon got it now. So its a routine more than anything. I thought he was describing a module that set up the port. I dont do sword fish, i nearly went that way but stuck with C. Maybe one day i will give SF a try
 
Still not sure why he didnt go the resistor route and ADC, just two pins and read the voltage to tell the key....
 
Still not sure why he didn't go the resistor route and ADC, just two pins and read the voltage to tell the key....
This is a lot harder to get working when making more than one device. There are many article on selecting good values for all 8 resistors. Then there is the wake from sleep that can require some clever pin selections so the ADC peripheral and the comparator peripheral can share the same pin. You need the comparator to do the wake from sleep.

For these reasons MrDEB may find that this kind of implementation is too complex in firmware and hardware for his tastes.
 
This is a lot harder to get working when making more than one device. There are many article on selecting good values for all 8 resistors. Then there is the wake from sleep that can require some clever pin selections so the ADC peripheral and the comparator peripheral can share the same pin. You need the comparator to do the wake from sleep.

For these reasons MrDEB may find that this kind of implementation is too complex in firmware and hardware for his tastes.
Sorry i forgot he was making it sleep to save 1uA so he can have 2KW for the backlight!.

Honestly though I have never had problems just using the keypad like a resistor divider. Havnt used pics in ages but got used to using cap touch on sil labs or the ultra cool light sensor to do gestures.

I might download SF and take a look, i hate the mplabX ide. I like C18 as well. I know XC8 is supposed to be hitech C but seems different to me, also the old hitech IDE was way better.
 
You got any idea why he moved from port B?
Why would he need capture compare? i am sure it can wake from change. If I find proteus I will mock up what i mean.
 
The Special Edition of Swordfish is free and has generous limitations on the size of programs made. I believe some of the well-known users here use the free version.
 
I am so used to C I am not sure i would get on with basic now.
 
You wouldn't have any problems. Much of the formating of Swordfish is based on C anyway.
 
For testing I am using a 18f4321 on a perf board.
I first need to map out the pins on the new keypad.
Reason I swaped the matrix to portC is based on a suggestion made by Jon concerning the ICSP.
 
Reason I swaped the matrix to portC is based on a suggestion made by Jon concerning the ICSP.

Back the truck up and read the words I wrote. I made no such recommendation.

I said you can't have the PICkit 2 connected to the ICSP connector when trying to read the keypad. Period.

I think it's foolish to change something you should be able to make work in 10 minutes because you can't be bothered to unplug the ICSP connector. If you can't make it work aa designed don't go adding parts (which you have put in the wrong place) and go mucking about in code you don't understand.

Piece of advice: make no changes to the keyboard module. If you think you need to change it to use a different port, you are wrong.
 
Hang on why am i reading a 18fK part when your working on another chip?? it might help if you tell us which chip you have pulled out the lucky dip box!

I would leave on port B, its designed for switches and keypads. Its got all the goodies to make that easy, with pics they put certain functions on certain ports, yes you swap about but you end up making things harder. Normally its something like Port A is ADC/cap sense etc , portB inputs etc. the ICSP is redundant once the circuit is programed, as Jonsea says just unplug it when you run, if you check the hardware first (sound familiar?) then code.....Then mistakes are code. Your way it makes it all guess work, it becomes a case of well it could be X Y Z in hardware thats wrong or it could Be ABC in software depend if its X or Y or Z you got wrong on the board.

Swapping chips is like swapping women, a new one is exciting right upto the point it nags for the first time or does something you dont like, better the devil you know ;).
 
Decided to use Jons suggestion and code then use a Tap 28 board with keypad on portb
using the usart, a fresh copy of keypad16 and use the usart.
tried different baud rates and all I get are ????????????????????????? When I compile it says KEYVALUE is declared but never used
DEVICE=18f2420
CLOCK = 8 ' Tell the compiler what we will be setting the clock to (Mhz)
CONFIG MCLRE = OFF
'CONFIG fOSC = INTIO67 ' Internal oscillator, IO on pins 6 and 7
'INCLUDE "INTOSC8.bas"
'config "InternalOscillator.bas"
'#option LCD_DATA = PORTC.4
'#option LCD_RS = PORTC.0
'#option LCD_EN = PORTC.1
INCLUDE "SetDigitalIO.bas" // Include this file when we compile so that we can use keywords like 'setalldigital'
INCLUDE "utils.bas"
INCLUDE "convert.bas" //xxxxx
'INCLUDE "LCD.bas"
INCLUDE "keypad16pullup.bas"
INCLUDE "usart.bas"
DIM Keypressed AS BYTE
DIM Keyvalue AS BYTE
SetBaudrate(br4800)
DELAYMS(5000)
USART.Write ("Test program",13, 10, 10)
WHILE 1 = 1
Keypressed = keypad16.Value
IF Keypressed <> 0 THEN
USART.Write ("Key pressed = ", HexToStr(Keypressed), 13, 10)
END IF
WEND
 
Again, I didn't tell you to do anything except use port B. Use a pic on a breadboard, a TAP-28....tgat is irrelevant. I promised I was done helping you and I mean that, but I guess I have to help unfuckerate the mess you've made of my code.

You are using a TAP-28 board which has a location for a crystal and you've commented out the internal oscillator bs, so it is apparent that you are using a crystal.

Your clock = 8 statement means the chip is running at 8MHz. Chances you're using an 8MHz crystal are virtually ZERO. The CLOCK statement must match the crystal frequency.

Baudrate is a function of bits per second. PER SECOND. If you've told the micro it's running at a different speed, all the TIMING functions are screwed up. You know, like bits per SECOND.

Make the clock statement match the crystal frequency. Set the baud rate to 9600.

In the PICkit 2 GUI, use the UART tool, and set its baud rate to match the baud rate on the board. The BIT PER SECOND must match.

Someone else can explain what "Keyvalue not used" means. Geez oh grief, how long have you been doing this?

I'm done.
 
Got it to finally work! with a few differences in code. WHY ?? I am going to investigate and yes I doubled checked baude rate etc. Only reason Ipulled out the tap28 was I wanted to eliminate any circuit issues.
DEVICE = 18F2420
CLOCK = 20
DIM Key AS BYTE
#option KEYPAD_PORT = PORTB
INCLUDE "Keypad16Pullup.bas"
INCLUDE "USART.bas"
INCLUDE "convert.bas"
SetBaudrate(br9600) //19200
WHILE True
REPEAT
Key = Keypad16.Value
UNTIL Key <> 0

USART.Write(DecToStr(Key),13,10)
WEND
 
MrDEB has earned this. Have fun without me from here on.

Wow. Only TWO HUNDRED MESSAGES AFTER THE WORKING CODE WAS POSTED. Incredible the knowledge exchange that occurs here!

participation award.jpg
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top