Shinnster
Member level 4
- Joined
- Sep 15, 2009
- Messages
- 70
- Helped
- 1
- Reputation
- 2
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- Malaysia
- Activity points
- 1,800
Yeah I think I can change .asm files to .bas since I can write both and yes it is fairly easy to do.betwixt said:I can't help you with a BASIC program, I never use it but what you are asking for sounds fairly easy to do in assembly language so it might be translatable to BASIC.
The 16F84A has 12 I/O pins. You can use 4 pins to drive the LCD data lines and the keypad columns, 1 pin for the LCD RS, 1 pin for the LCD E and 4 pins to read the LCD rows. That gives you a full 4x4 keypad and 2 pins spare.
It sounds like your problem at the moment is the LCD is not configured properly though.
Brian.
betwixt said:You connect the data lines to the LCD to the keypad as well.
The LCD will ignore the port being used to send the scan signals unless you also toggle to 'E' signal. To scan the keypad, don't change the 'E' signal so the LCD doesn't update. When writing to the LCD, ignore the signals back from the keypad.
So you use the four data lines for two purposes to save pins.
Brian.
Nice. I didn't think about that. *I mean the LCD with Keypad.*betwixt said:The more I see BASIC, the more I realize how deficient it is!
Yes, you are right about PORTB feeding the 4 data lines to the LCD and the keypad as well.
There are several ways to read a keypad but the most common way is to 'scan' it, the procedure is:
1 Set the port data bits to output mode. Set the row pins to be inputs.
2. You have 4 data bits connected to the columns, think in binary and set the data lines to 0001.
3. Read the row inputs (could be the other half of port B or it could be port A)
4. If 0000 is read back, no keys in the column with '1' on it were pressed, if any bit is '1', it corresponds with the key at the intersection of that row and column so you can tell what it was.
5. Change the column output to 0010 and repeat step 4.
6. Change the column output to 0100 and repeat step 4.
7. Change the column output to 1000 and repeat step 4.
So you are walking a '1' across the columns and then reading the rows. When a key is pressed, it shorts one row to one column so at some point that '1' will appear on the row inputs. For example, on a standard 4x3 telephone keypad, pressing the '5' key would give an output on row 2 when column 2 was driven.
If a key was pressed, your next step is to feed the appropriate data for the LCD on to the data lines, ignore anything on the row inputs, and toggle the LCD 'E' line to write the data to the LCD module. You can then go back to scanning the keypad again.
Make sense?
Brian.
addwf PCL,f ;add the value in W to the program counter.
retlw '0' ;key in row 1 found
retlw '8' ;key in row 2 found
retlw 'x'
retlw '5' ;key in row 3 found
retlw 'x'
retlw 'x'
retlw 'x'
retlw '2' ;key in row 4 found
movf PORTB,w ;read the whole port B
movwf KeyPadIn ;save the value read in
swapf KeyPadIn,w ;swap top and bottom bits so b7:4 is now b3:0
andlw h'0F' ;zero the top bits so only the row data is now in W register
movlw h'0F' ;this will be used to mask the top bits of the reading
andwf PORTB,w ;read and mask PORT B with the result put in W
since you are the walking '1', should W not contain 1 or can be any value? 1 2 3 4?betwixt said:For example if W contained the value 5 and the subroutine was called, it would return with the value in the 5th retlw instruction. So you have a quick and easy look-up table, enter with the position in W and return with the value for that position in W.
The only thing to be careful of is that your look-up table doesn't cross a page boundary in memory as the addwf PCL instruction only works on the PCL register, it doesn't switch to the next memory page if PCL is made to count beyond h'FF'.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?