AT89C51AC2 Interface 16 digit keypad and lcd

Thread Starter

Chris-Pap

Joined Mar 15, 2010
6
Hello my name is Chris and i have a problem interfacing a 16 digit keypad with AT89C51AC2 and a 2*16 LCD.

Here's the thing:

I want to appear on the LCD the message "alarm off" and if i press the " * " button to appear on LCD the message " ENTER NEW PASS1 " and if i press the " # " button to appear the message " ENTER NEW PASS2 " .

i have made 3 .a51 files and added the to my project. I attach the assembly code i used and the schematic diagram to connect the lcd with 8051. The 16 digit keypad is connected to P2 port withoun any pull down or up resistors.

I use the AT89C51AC2 microcontroller and the Archimedes μVision2 compiler. The 16 digit keypad is the same with the one on this picture
http://images.quickblogcast.com/0/7/...adbd_small.JPG


I connected the keypad to P2 port as in the attached screenshot.


If no key is pressed the reading of Px.0 to Px.3 gives 1, due to the pull up resistors that are connected internally to Vcc in all ports except P0. If we give 1 to columns Px.4 to Px.7, the reading of the lines will give 1 either the keys are pressed or not. But we can scan the keys of a column by reading the lines (rows), if we send 0 to that column and 1 to theo other columns. From the junction of the column that we have send 0 with the row that it has been scanned the 0, we can locate the pressed key.

The programm appears on the lcd the text "ALARM OFF" and does nothing when i press any buton of the keypad.

I believe that it is a problem either in the keypad scan routine or the main program.

I' d also like to ask if we connect the 17-32 pins of the LCD as we would connect the pin 1-16, what will happen. What are there for these pins since we need only 1-16 to interface lcd with a microcontroller?

Can anyone help?
 

Attachments

Thread Starter

Chris-Pap

Joined Mar 15, 2010
6
I' ve asked a teacher of mine and he told that the code should have this structure.

1. Initial statements
2.Initializers
a)CPU
b)Keypad
c)LCD
d)Program variables
3. Main program
a) Call subroutine to print on the lcd " alarm off "
b) Call subroutine of keypad
c) Check the key that was pressed and if it is *, print on screen " ENTER NEW PASS1 "
d)Check the key that was pressed and if it is *, print on screen " ENTER NEW PASS2 "
e) Branch to (a)
4. Subroutines
5. Data (DB)

Can anyone help?
 

retched

Joined Dec 5, 2009
5,197
Are you sure your ports are set as inputs?

Have you checked for proper response withOUT the keypad? just sending a logic(1) to the pins responsible for the '*' key?
 

Thread Starter

Chris-Pap

Joined Mar 15, 2010
6
I've written a simplier code that appears after the reset of the controller the character A at the middle of the upper line of the lcd and if i press * of my keypad, it appear the character ! at the middle of the upper line of the lcd. If i press # it appears the character " at the middle of the upper line of the lcd.

Now i want when i press the # key to appear the character " at the middle of the upper line of the lcd and also when i press an other key, to appear the character * at the middle of the second line of the lcd.

So i compare the A accumulator with FF, which is the number that i get from my keypad scan routine if no key is pressed.

But when i press the # key it appears on the lcd the " character at the middle of the upper line of the lcd and the * character at the middle of the second line of the lcd. I suppose this happens because the program runs faster than i take my hand of the # key and understands it as a pressed key for a second time and so it appears the * on the lcd.


Could someone tell me a delay routine for about 2 seconds that i can use after the
CALL LCDCHAR ; show on lcd character "

to gain some time????????????


Here is the main program

XTRN CODE (lcdinit,lcdchar,POSIT_CURSOR,LCDCLS,SCAN2)

CURSPOS data 50h

CSEG AT 0H

CALL LCDINIT ;initialisation of the lcd
MOV CURSPOS,#8 ;move cursor at the middle of the upper line
CALL POSIT_CURSOR ; of the lcd
MOV A,# 41h
CALL LCDCHAR; show on lcd character A

MAIN:

CALL SCAN2 ;a full scan of the keypad
MOV A,R5 ;code of key
CJNE A,#03h,ACTION2 ;if * wasn't pressed go to action2 and check if # has been pressed


CALL LCDCLS ;clear screen
MOV CURSPOS,#8 ;move cursor at the middle of the upper line
CALL POSIT_CURSOR ; of lcd
MOV A,# 21h
CALL LCDCHAR; show on lcd character !

JMP HALT
ACTION2:
mov A, R5
CJNE A,#0Bh,MAIN
CALL LCDCLS ;clear screenς
MOV CURSPOS,#8 ;move cursor at the middle of the upper line
CALL POSIT_CURSOR ; of lcd
MOV A,# 22h
CALL LCDCHAR; show on lcd character "



PROTOPSIFIO:

call SCAN2

MOV A,R5
CJNE A,#0FFh,GRAPSE ; check if any key has been pressed, if yes go to Grapse
jMP EPANELABE ;else go to epanelabe


GRAPSE:
MOV CURSPOS,#22 ;move cursor at the bottom line
CALL POSIT_CURSOR ; of lcd
MOV A,# 2Ah
CALL LCDCHAR; show on lcd character *
JMP HALT

EPANELABE : ; go to protopsifio and scan again the keypad
JMP PROTOPSIFIO

HALT: JMP HALT

END


 

Thread Starter

Chris-Pap

Joined Mar 15, 2010
6
've achieved to show a character on the lcd ann if i press the * of my keypad to show another and if i press the # button to show another.

Now I want to show a phrase at the beginning and when i press the * sto show another. I declared two test strings in the end of my program but it appears both these phrases on my lcd (one on each row) and when i press the * button it shows the second string in the upper row and it "blackens" the boxes of the second row.

Why does it read both strings? How do i declare text strings?

Here is the program


EXTRN CODE (lcdinit,lcdchar,POSIT_CURSOR,LCDCLS,SCAN2,LCDSTR)

CURSPOS data 50h

CSEG AT 0H

CALL LCDINIT ;Áñ÷éêïðïéçóç ôçò ïèïíçò
MOV CURSPOS,#4 ;Ìåôáêéíïõìå ôïí êåñóïñá óôçí ìåóç ôçò ðáíù ãñáììçò
CALL POSIT_CURSOR ; ôçò ïèïíçò
MOV DPTR,#STRING1 ;Åããñáöç óôçí ïèïíç ôïõ ðñùôïõ string
CALL LCDSTR


MAIN:

CALL SCAN2 ;ìéá ðëÞñçò óÜñùóç
MOV A,R5 ;êùäéêüò ðëÞêôñïõ
CJNE A,#03h,ACTION2 ; ÁÍ ÄÅÍ ÐÁÔÇÈÇÊÅ ÔÏ * ÐÁÍÅ ÓÔÇÍ ACTION2 ÄÅò ÁÍ ÐÁÔÇÈÇÊÅ ÔÏ #

CALL LCDCLS ;êáèáñéóìïò ïèïíçò
MOV CURSPOS,#0 ;Ìåôáêéíïõìå ôïí êåñóïñá óôçí ìåóç ôçò ðáíù ãñáììçò
CALL POSIT_CURSOR ; ôçò ïèïíçò
MOV DPTR,#STRING2 ;Åããñáöç óôçí ïèïíç ôïõ ðñùôïõ string
CALL LCDSTR

...........
.........
..........

HALT: JMP HALT




STRING1:
DB ' minima1 '

STRING2:
DB ' minima2 '

END
 
Top