Close
0%
0%

8051 Interface

8051 LCD, Serial Port and KeyBoard

Similar projects worth following
The main objective of this practice is to build a connection between the microprocessor and other devices such as an LCD screen, which works with an Japanese ascii code. At the same time, the serial port must be used to send it to other devices through a Bluetooth module or through the Rs-232 module.
This program must obtain the data of a matrix keyboard. To avoid many possible errors we use a matrix keyboard decoder. With this, the micro should process the information received and send it to the screen. It must also have a reset button, a button that serves as Alt, to enter characters in ascii and another to send information through the serial.
The screen is served by codes that can be separated between instructions for the screen and data for the screen, that is by means of a configuration that must be taken into account both in the wiring and in the code.

THEORY

LCD SCREEN

A LCD of two lines of 16 characters of matrix of 5x7 points. The driver includes a character generator in ROM with 192 characters and the possibility of defining another 8 in RAM. It also has a RAM of display data where the message to be displayed is stored of 80 bytes, of which 32 (2x16) are displayed.

Pins:

SIGNAL

PIN

FUNCTION

DB0-3

8-5

Low data nibble

DB4-7

4-1

High data nible

E

9

LCD Enable

R/W

10

Read / Write selector

1 Leer | 0 Escribir

RS

11

Data or Instruction selector

0 IR | 0 DR

VLS

12

LCD contrast, connect to potentiometer

VDD

14

Power, 5v

VSS

13

GND

Operations:

The controller has two registers, the instruction (IR) and the data (DR), which are selected by the RS signal. These records can be read or written as indicated by the R / W signal, so that 4 different operations are possible:

RS

R/W

OPERATION

0

0

Write IR: Clean Display, etc., or modify AC.

0

1

Read IR: Read the AC(DB0-6) & the Busy Flag (DB7).

1

0

Write DR: Write on DD RAM or CG RAM

1

1

Read DR: Read from DD RAM or CG RAM

Write to the IR: Instructions are sent and also to write a new address in the AC (Address Counter) register, which is the register in charge of pointing, both to the DD RAM (RAM of Display Data) and to the CG RAM ( Character Generator RAM)

Read from the IR: It allows the reading of the AC record, of which only the 7 least weight bits DB0-6 are valid, the May weight bit, the DB7, informs of the status of the Busy Flag or Occupied Display indicator.

Write in the DR: It allows writing in DD RAM or CG RAM where the AC record is pointed.

Read from the DR: It allows reading of DD RAM or CG RAM where the AC points.

Busy Flag (BF): A "1" indicates that the LCD is busy performing internal operations and can not accept new instructions. You have to wait for the Busy Flag to be "0" to send you the next instruction.

Direction Counter (AC): Indicates the address where the data on DD RAM or CG RAM will be read or written. This record can be modified by writing to the IR.

In addition, when writing or reading data in DD / RAM or CG RAM, the AC is incremented or decremented automatically according to the Entry Mode Set.

Display Data RAM (DD RAM): It has a capacity of 80 bytes, 40 for each line; Logically, only 32 of the 80 bytes can be displayed at the same time, although by moving the display you can display all the written characters.

Generator of characters in ROM (CG ROM): It has 192 characters, in matrices of 5x7 points.

Character generator in RAM (CG RAM): It allows to define 8 characters, whose codes go from 00 to 08, or from 09 to 0f.


MATRIX KEYBOARD

A matrix keyboard is one that has organized the connections of the keys in the form of n columns and m rows, such as a matrix.

They are done in this way, since with n + m connection lines you can read n x m keys. For example, a 16-button keyboard can be read with only 8 lines. However, this increases a little the complexity of the reading algorithm since it is necessary to do up to n readings m times to find the key pressed, that is, one reading per key. To facilitate reading we use an encoder MM74C922.

Encoder MM74C922: The keyboard encoders MM74C922 and MM74C923 CMOS provide the logic necessary to completely encode a matrix keyboard.

It has an internal bounce suppression circuit so the data output at high level, when a valid keyboard input has been made, is "clean". The available output data returns to a low level when the entered key has been released, even if another key is pressed. The available data will return to stop to indicate acceptance of the new key after a period of normal bounce suppression.

CODE IN HEX80

:03000000020040BB

:02000300211FBB

:02001300216E5C

:1000400075892175A885759840758DFD758BFDD2D4

:100050008E119811EB7590007D007E0078007C6019

:100060007A607B6079407530307531317532327528

:1000700033337534347535357536367537377538ED

:1000800038753939753A41753B42753C43753D4485

:10009000753E45753F4680FE11B3743811C1743802

:1000A00011C1743811C1740111C1740F11C1748070

:1000B00011C122758AB6758C3CD28C308DFDC28DF3...

Read more »

P4.pdf

Spanish Documentation

Adobe Portable Document Format - 916.56 kB - 10/15/2018 at 02:31

Preview
Download

8051 interface.txt

Assembly language code

plain - 7.39 kB - 10/15/2018 at 02:23

Download

  • 1 × AT89S52 Microprocessors, Microcontrollers, DSPs / Microcontrollers (MCUs)
  • 1 × LCD Display 16x2
  • 1 × Matrix Keyboard
  • 1 × Encoder MM79C922
  • 1 × Quartz cristal 11.059 Mhz

View all 9 components

  • Principal Problems

    Lilia Lobato10/15/2018 at 02:30 0 comments

    It is an error in theoretical concepts that stopped us for a few hours. When printing a hexadecimal value on the screen, sending this by bluetooth and printing it on the screen of a cell phone, the ASCII characters vary but the hexadecimal code was maintained.

    To understand this problem we started to investigate and we found that the ASCII code is divided into "printable characters" and "Extended alphabet". Next we explain each one:

    Printable Characters:

    It is a character code based on the Latin alphabet, as it is used in modern English. It was created in 1963 by the American Standards Committee as a recasting or evolution of the code sets then used in telegraphy. Later, in 1967, lowercase letters were included, and some control codes were redefined.

    Currently it defines codes for 32 non-printable characters, of which most are control characters that have an effect on how the text is processed, plus another 95 printable characters that follow them in the numbering (starting with the space character).

    The ASCII code uses 7 bits to represent the characters, although initially it used an additional bit (parity bit) that was used to detect errors in the transmission. It is often incorrectly called ASCII to several 8-bit character codes that extend the ASCII with characters from languages other than English, such as the ISO / IEC 8859-1 standard. This is just the error we found. The screen works with a Japanese ASCII while the cell phone works on a Mexican ASCII, theoretically, if the language of the cell is changed to Japanese, the same characters would be seen.

    Extended ASCII:

    As computer technology spread throughout the world, different standards were developed and companies developed many variations of the ASCII code to facilitate the writing of languages other than English that use Latin alphabets.

    So, any 8-bit character set, in which the codes 32 to 126 (0x20 to 0x7E) match the printable ASCII characters, as well as the control codes from 8 to 13 but with characters from 127 onwards , they are called "Extended Alphabet"

    The extended ASCII encodings also use part or all of the codes greater than 128 to encode additional characters to the printable ASCII characters.

View project log

  • 1
    Code

    ;P2.0 --------------- Enable LCD

    ;P2.1 --------------- RS LCD (0 Instrucción, 1 Dato)

    ;P3.4 --------------- ALTBTN (0 Si no está presionaldo alt, 1 si es que si)

    E EQU P2.0

    RS EQU P2.1

    ALTBTN EQU P3.4

    DATAAV EQU P3.2

    ORG 0000H

    LJMP INICIO

    ORG 0003H

    JMP TECLADO

    ORG 0013H

    JMP SEND ;NUDES

    ORG 0040H

    INICIO: MOV TMOD,#21H ; MODO 0 TMP 1

    MOV IE,#85H ; HABILITA INTERRUPCIÓN EXT0

    MOV SCON,#40H

    MOV TH1,#0FDH

    MOV TL1,#-3D

    SETB TR1

    ACALL INIT ; LLAMA A INICIALIZAR LCD

    ACALL EQUIPO9 ; PRESENTACIÓN DEL EQUIPO

    MOV P1,#0H ; PUERTO 1 EN 0 DESPUES DE EQUIPO9

    MOV R5,#0H ; CONTADOR DE CARACTERES EN LCD EN 0

    MOV R6,#0H ; CONTADOR DE DOS NUMEROS EN ALT EN 0

    MOV R0,#0H ; VARIABLE DONDE SE ALMACENA DATO A IMPRIMIR EN 0

    MOV R4,#60H

    MOV R2,#60H

    MOV R3,#60H

    MOV R1,#40H

    ////////////////////////////////////////////////////////////////////////////////////////////

    ; TABLA DE VALORES DE ASCII A HEXADECIMAL

    ////////////////////////////////////////////////////////////////////////////////////////////

    MOV 30H, #48D ;1

    MOV 31H, #49D ;2

    MOV 32H, #50D ;3

    MOV 33H, #51D ;A

    MOV 34H, #52D ;4  

    MOV 35H, #53D ;5

    MOV 36H, #54D ;6

    MOV 37H, #55D ;B

    MOV 38H, #56D ;7

    MOV 39H, #57D ;8

    MOV 3AH, #65D ;9

    MOV 3BH, #66D ;C

    MOV 3CH, #67D ;F

    MOV 3DH, #68D ;0

    MOV 3EH, #69D ;E

    MOV 3FH, #70D ;D

    SJMP $

    INIT: ACALL WAIT ; TIEMPO DE ESPERA TÍPICO

    MOV A, #38H ; 2 LÍNEAS, MATRÍZ DE 5*8

    ACALL MANDAR ; ENVÍA LA INSTRUCCIÓN A LA LCD

    MOV A, #38H ; 2 LÍNEAS, MATRÍZ DE 5*8

    ACALL MANDAR ; ENVÍA LA INSTRUCCIÓN A LA LCD

    MOV A, #38H ; 2 LÍNEAS, MATRÍZ DE 5*8

    ACALL MANDAR ; ENVÍA LA INSTRUCCIÓN A LA LCD

    REINICIO: MOV A, #01H ; LIMPIA LA LCD

    ACALL MANDAR ; ENVÍA LA INSTRUCCIÓN A LA LCD

    MOV A, #0FH ; DISPLAY, CURSOR Y PARPADEO PRENDIDOS

    ACALL MANDAR ; ENVÍA LA INSTRUCCIÓN A LA LCD

    MOV A, #80H ; CURSOR LÍNEA 1, POSICIÓN 1 (DDRAM DIRECCIÓN EN 0)

    ACALL MANDAR ; ENVÍA LA INSTRUCCIÓN A LA LCD

    RET ; RETORNA A DONDE SE LLAMÓ

    /////////////////////////////////////////////////////////////////////////////////////////////

    WAIT: MOV TL0, #0B6H  ; PARTE INFERIOR (057 PARA 25ms)

    MOV TH0, #03CH ; PARTE SUPERIOR (09E PARA 25ms

    SETB TR0 ; INICIALIZA EN 1 PARA INICIAR CONTEO

    JNB TF0,$ ; 50ms

    CLR TF0 ; LIMPIA BANDERA DE DESBORDE

    RET ; RETORNA A DONDE SE LLAMÓ

    ////////////////////////////////////////////////////////////////////////////////////////////

    MANDAR: CLR RS ; RS MODO INSTRUCCIÓN

    ACALL WAIT ; TIEMPO DE ESPERA TÍPICO

    CLR E ; PREPARANDO EL...

    ACALL WAIT ; TIEMPO DE ESPERA TÍPICO

    SETB E ; ...ENABLE

    ACALL WAIT ; TIEMPO DE ESPERA TÍPICO

    MOV P1, A ; ACUMILADOR A PUERTO 1 (LCD)

    ACALL WAIT ; TIEMPO DE ESPERA TÍPICO

    CLR E ; FLANCO DE BAJADA ENABLE (MANDA INSTRUCCIÓN)

    ACALL WAIT ; ESPERA TÍPICA

    RET ; RETORNA A DONDE SE LLAMÓ

    ////////////////////////////////////////////////////////////////////////////////////////////

    ESCRIBE: SETB RS ; RS EN MODO DE DATO

    ACALL WAIT ; TIEMPO DE ESPERA TÍPICO

    CLR E ; PREPARANDO EL...

    ACALL WAIT ; TIEMPO DE ESPERA TÍPICO

    SETB E ; ...ENABLE

    ACALL WAIT ; ESPERA TÍPICA

    MOV P1, A ; ACUMULADOR A PUERTO 1 (LCD)

    ACALL WAIT ; ESPERA TÍPICA

    CLR E ; FLANCO DE BAJADA ENABLE (MANDA INSTRUCCIÓN)

    ACALL WAIT ; ESPERA TÍPICA

    RET ; RETORNA A DONDE SE LLAMÓ

    ////////////////////////////////////////////////////////////////////////////////////////////

    EQUIPO9: MOV A,#69D ; E

    ACALL ESCRIBE ; ESCRIBE EN LCD

    MOV A,#81D ; Q

    ACALL ESCRIBE ; ESCRIBE EN LCD

    MOV A,#85D ; U

    ACALL ESCRIBE ; ESCRIBE EN LCD

    MOV A,#73D ; I

    ACALL ESCRIBE ; ESCRIBE EN LCD

    MOV A,#80D ; P

    ACALL ESCRIBE ; ESCRIBE EN LCD

    MOV A,#79D ; O

    ACALL ESCRIBE ; ESCRIBE EN LCD

    MOV A,#32D ; " "

    ACALL ESCRIBE ; ESCRIBE EN LCD

    MOV A,#57D ; 9

    ACALL ESCRIBE ; ESCRIBE EN LCD

    MOV R7,#20D ; REPETICIONES DE 50ms

    LGK: MOV TL0, #0H ; PARTE INFERIOR

    MOV TH0, #0H ; PARTE SUPERIOR

    SETB TR0 ; INICIALIZA EN 1 PARA INICIAR CONTEO

    JNB TF0,$ ; 50ms

    CLR TF0 ; LIMPIA BANDERA DESBORDAMIENTO

    DJNZ R7, LGK ; EJECUTA 20 VECES

    ACALL REINICIO ; REINICIA PANTALLA

    RET ; RETORNA A DONDE SE LLAMÓ

    /////////////////////////////////////////////////////////////////////////////////////////////

    TECLADO: CJNE R5,#10H,PLLENA ; COMPARA QUE LA PRIMERIA LÍNEA NO ESTE LLENA  

    MOV  A,#0C0H ; SI SE LLENA SE CAMBIA A LA SIGUIENTE LÍNEA

    ACALL MANDAR ; MANDA INSTRUCCIÓN A LCD

    PLLENA: CJNE R5,#20H,ELCD ; COMPARA QUE LA SEGUNDA LÍNEA NO ESTE LLENA

    MOV A,#01H ; CUANDO ESTA LLENA BORRA TODO

    ACALL MANDAR ; MANDA INSTRUCCIÓN A LCD

    MOV R5,#0H ; LIMPIA CONTADOR DE CARACTERES

    RETI ; SALE DE LA INTERRUPCIÓN DEL TECLADO

    /////////////////////////////////////////////////////////////////////////////////////////////

    ELCD: JB ALTBTN,ALT ; VERIFICA QUE NO ESTÉ PRESIONADO EL PUSHBTN ALT

    MOV A,P0 ; MUEVE DATOS DEL TECLADO AL ACUMULADOR

    ADD A,#30H ; LO POSICIONA EN SU DECODIFICACIÓN CORRESPONDIENTE

    MOV R0,A ; GUARDA ACUMULADOR EN R0 PARA USARLO COMO APUNTADOR

    MOV A,@R0 ; APUNTA AL VALOR EN LA DIRECCION DONDE ESTÁ R0

    ACALL TLCD ; LLAMA A TECLADO LCD (TLCD)

    MOV @R1,A

    INC R1

    RETI ; SALE DE LA INTERRUPCIÓN DEL TECLADO

    /////////////////////////////////////////////////////////////////////////////////////////////

    TLCD: SETB RS ; RS EN MODO DE DATO

    ACALL WAIT ; ESPERA TÍPICA

    CLR E ; PREPARANDO EL...

    ACALL WAIT ; ESPERA TÍPICA

    SETB E ; ...ENABLE

    ACALL WAIT ; ESPERA TÍPICA

    MOV P1,A ; ACUMULADOR A PUERTO 1 (LCD)

    ACALL WAIT ; ESPERA TÍPICA

    CLR E ; FLANCO DE BAJADA ENABLE (MANDA INSTRUCCIÓN)

    ACALL WAIT ; ESPERA TÍPICA

    CLR RS ; RS EN MODO INSTRUCCIÓN  

    ACALL WAIT ; ESPERA TÍPICA

    INC R5 ; INCREMENTA CONTADOR DE CARACTERES

    RET ; RETORNA A DONDE SE LLAMÓ

    /////////////////////////////////////////////////////////////////////////////////////////////

    ALT: JNB DATAAV,ALT

    MOV A,P0 ; MUEVE DATOS DEL TECLADO AL ACUMULADOR

    CJNE R6,#01H,PD ; MANDA A RUTINA PARA GUARDAR LOS DOS VALORES PRESIONADOS

    ADD A,B ; SUMA PRIMER VALOR (PARTE ALTA) CON SEGUNDO (PARTE BAJA)

    MOV R6,#0H ; PONE EN 0 EL COMPARADOR

    ACALL TLCD ; LLAMA A TECLADO LCD (TLCD)

    MOV @R1,A

    INC R1

    RETI ; SALE DE LA INTERRUPCIÓN DEL TECLADO

    /////////////////////////////////////////////////////////////////////////////////////////////

    PD: SWAP A ; MANDA LA PARTE BAJA DE "A" A LA PARTE ALTA

    MOV B,A ; MUEVE "A" A LA VARIABLE "B"

    INC R6 ; PONE EN 1 EL COMPARADOR

    RETI ; SALE DE LA INTERRUPCIÓN DEL TECLADO

    //////////////////////////////////////////////////////////////////////////////////////////////

    SEND: MOV A,R1

    SUBB A,#40H

    JZ SALIR

    MOV R0,#40H

    MOV 60H,A

    SETB TR1

    SER: MOV SBUF,@R0

    ACALL WAIT

    JNB TI,$

    ACALL WAIT

    CLR TI

    ACALL WAIT

    INC R0

    DJNZ 60H,SER

    CLR TR1

    MOV R1,#40H

    ACALL REINICIO

    SALIR: RETI

    ////////////////////////////////////////////////////////////////////////////////////////////////

    END

View all instructions

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates