Interfacing keypad and LCD with 8051

Discussion in 'Embedded Systems and Microcontrollers' started by PY01A0080, Mar 27, 2013.

  1. PY01A0080

    PY01A0080 Thread Starter Member

    Joined:
    Mar 7, 2013
    42
    3
    Hello,

    i'm trying to send data to LCD with a Keypad (3x4) like a phone keypad.
    so i know how to send data one by one, like when i click 1 it displays 1 in the LCD and so on.
    This is ok for me.

    But now i want to type a word for example "ABC" then when i will click on "#" button it will send the word "ABC" to the LCD and only after i clicked the "#" button not one by one letter.

    how do i have to modify my asm code.

    The LCD is connected to P2.

    here is the code :
    KEYPAD:
    Code ( (Unknown Language)):
    1. mov p1,#0ffh  ; MAKE P3 as input for keypad
    2. lcall Line0
    3. lcall delay
    4.  
    5. mov p1,#0ffh
    6. lcall Line1
    7. lcall delay
    8.  
    9. mov p1,#0ffh
    10. lcall Line2
    11. lcall delay
    12. Line0:
    13. clr p1.0
    14. jb p1.1,L1
    15. lcall Col1
    16. jnb p1.1,$
    17. ret
    18.  
    19. L1:
    20. jb p1.4,L2
    21. lcall Col2  
    22. jnb p1.4,$
    23. ret
    24.  
    25. L2:
    26. jb p1.5,L3
    27. lcall Col3  
    28. jnb p1.5,$
    29. ret
    30.  
    31. L3:
    32. jb p1.6,L4
    33. lcall Col4  
    34. jnb p1.6,$
    35. l4:ret
    36. ;---------------
    37. Col1:
    38. lcall lcdtrans
    39. mov a,#'A'; display 1
    40. mov p2,a
    41. lcall LCDdata
    42. ret
    43. Col2:
    44. lcall lcdtrans
    45. mov a,#'D'; display 4    
    46. mov p2,a
    47. lcall LCDdata
    48. ret
    49. Col3:
    50. lcall lcdtrans
    51. mov a,#'G'; display 7  
    52. mov p2,a
    53. lcall LCDdata
    54. ret
    55. Col4:
    56. lcall lcdtrans
    57. mov a,#'J'; dipslay *
    58. mov p2,a
    59. lcall LCDdata
    60. ret
    61.  
    62. Line1:
    63. clr p1.1
    64. jb p1.3,L11
    65. lcall Col11
    66. lcall lcdtrans  
    67. jnb p1.3,$
    68. ret
    69.  
    70. L11:
    71. jb p1.4,L22
    72. lcall Col22
    73. lcall lcdtrans  
    74. jnb p1.4,$
    75. ret
    76. L22:
    77. jb p1.5,L33
    78. lcall Col33
    79. lcall lcdtrans  
    80. jnb p1.5,$
    81. ret
    82.  
    83. L33:
    84. jb p1.6,L44
    85. lcall Col44
    86. lcall lcdtrans
    87. jnb p1.6,$
    88. L44:ret
    89. ;----------------
    90. Col11:
    91. lcall lcdtrans
    92. mov a,#'B'; display 2
    93. mov p2,a
    94. lcall LCDdata
    95. ret
    96. Col22:
    97. lcall lcdtrans
    98. mov a,#'E'; display 5    
    99. mov p2,a
    100. lcall LCDdata
    101. ret
    102. Col33:
    103. lcall lcdtrans
    104. mov a,#'H'; display 8  
    105. mov p2,a
    106. lcall LCDdata
    107. ret
    108. Col44:
    109. lcall lcdtrans
    110. mov a,#'K'; dipslay 0
    111. mov p2,a
    112. lcall LCDdata
    113. ret
    114. ;---------------
    115. Line2:
    116. clr p1.2
    117. jb p1.3,LA
    118. lcall ColA
    119. lcall lcdtrans
    120. jnb p1.3,$
    121. ret
    122.  
    123. LA:
    124. jb p1.4,LB
    125. lcall ColB
    126. lcall lcdtrans
    127. jnb p1.4,$
    128. ret
    129. LB:
    130. jb p1.5,LC
    131. lcall ColC
    132. lcall lcdtrans
    133. jnb p1.5,$
    134. ret
    135. LC:
    136. jb p1.6,LD
    137. lcall ColD
    138. lcall lcdtrans
    139. jnb p1.6,$
    140. LD:ret
    141. ;-----------------
    142. ColA:
    143. lcall lcdtrans
    144. mov a,#'C'; display 3
    145. mov p2,a
    146. lcall LCDdata
    147. ret
    148. ColB:
    149. lcall lcdtrans
    150. mov a,#'F'; display 6    
    151. mov p2,a
    152. lcall LCDdata
    153. ret
    154. ColC:
    155. lcall lcdtrans
    156. mov a,#'I'; display 9  
    157. mov p2,a
    158. lcall LCDdata
    159. ret
    160. ColD:
    161. lcall lcdtrans
    162. mov a,#'L'; dipslay #
    163. mov p2,a
    164. lcall LCDdata
    165. ret
    Thank you
    PS: there is one problem with my code, the letter A is never displayed, i tried to understand, for me the code is good maybe there is a problem with xtal frequencey or i don't know what.
     
    #1
  2. MrChips

    MrChips Moderator

    Joined:
    Oct 2, 2009
    11,752
    3,010
    There are some essential steps required to design a successful program, even before you start writing code. This is called Top-Down Design.

    1) Define and identify the problem.
    2) Create an algorithm that solves the problem.
    3) Write out the steps of the algorithm in plain language.
    4) Draw a flow chart to show the flow of the algorithm.

    Only after those steps are taken do you begin to write code.
    Learn to comment all your code with appropriate and meaningful comments.
     
    #2
  3. PY01A0080

    PY01A0080 Thread Starter Member

    Joined:
    Mar 7, 2013
    42
    3
    Hello Ms Chips,
    thank you for your advice.
    Here i'm doing some exercise by myself to learn asm.
    I'm trying to understand how the keypad have to be coded to send a word to LCd using 8051 µc.
    So first, i did the first example with a keypad and a 7 segment led with 8051 and it was working fine.
    Second i tried to connect two 8051 in serial communication and use interrupt function to send data to LCD through a Keypad between the two 8051, and it was working fine, each time a pressed a button in the keypad that data is displayed in the LCD nad i can do it from one 8051 to another 8051 and vice et versa.

    But now i tried to send a word to the LCD with the keypad. so i tried many times to modify the above code but it did not work.

    Yes for the algorythm, i used many papers and i didn't find any solution.

    So can you give me clue not the solution, but only a guidance.
    do i have to use DPTR function or anything else?

    i want to do it in asm, i did not start the Embedded C yet.
    Do u want the above code fully commented?


    Thank you for your support.
     
    #3
Loading...