EET 203 MICROCONTROLLER SYSTEMS DESIGN LECTURE 5 INPUT

  • Slides: 39
Download presentation
EET 203 MICROCONTROLLER SYSTEMS DESIGN LECTURE 5: INPUT AND OUPUT INTERFACING

EET 203 MICROCONTROLLER SYSTEMS DESIGN LECTURE 5: INPUT AND OUPUT INTERFACING

Interfacing and Programming with Input/Output Device: LCD (liquid crystal display) is specifically manufactured to

Interfacing and Programming with Input/Output Device: LCD (liquid crystal display) is specifically manufactured to be used with microcontrollers, which means that it cannot be activated by standard IC circuits. It is used for displaying different messages on a miniature liquid crystal display. It is based on the HD 44780 microcontroller (Hitachi) and can display messages in two lines with 16 characters each. It can display all the letters of alphabet, Greek letters, punctuation marks, mathematical symbols etc. It is also possible to display symbols made up by the user. Other useful features include automatic message shift (left and right), cursor appearance, LED backlight etc.

Interfacing and Programming with Input/Output Device: LCD

Interfacing and Programming with Input/Output Device: LCD

Interfacing and Programming with Input/Output Device: LCD

Interfacing and Programming with Input/Output Device: LCD

Interfacing and Programming with Input/Output Device: LCD Pins Description DB 0 - DB 7

Interfacing and Programming with Input/Output Device: LCD Pins Description DB 0 - DB 7 8 -bit data pins, used to send information to LCD or read the contents of the LCD’s internal registers. Vss, Vdd Voltage supply pins; ground and 5 V, respectively. R/W*: Allows the user to read/write information from/to the LCD. R/W*=1 when reading, R/W*=0 when writing. RS Pin selects registers between Instruction Register and Data Register RS=0: the instruction command code register is selected, allowing the user to send a command such as clear display, cursor at home etc. RS=1: the data register is selected, allowing the user to send data to be displayed on the LCD. E Enable pin is used by LCD to latch information presented to its data pins. When data is supplied to data pins, a high-to-low pulse must be applied to the E pin in order for the LCD to latch in the data present at the data pins. This pulse must be a

Interfacing and Programming with Input/Output Device: LCD registers The HD 44780 U controller has

Interfacing and Programming with Input/Output Device: LCD registers The HD 44780 U controller has two 8 -bit registers: instruction register (IR) - the IR stores instruction codes, such as display clear and cursor shift, and address information for display data RAM (DDRAM) and character generator RAM (CGRAM). data register (DR) - the DR temporarily stores data to be written into DDRAM or CGRAM and temporarily stores data to be read from DDRAM or CGRAM. The DR is also used for data storage when reading data from DDRAM or CGRAM.

Interfacing and Programming with Input/Output Device: LCD The choice between the two registers is

Interfacing and Programming with Input/Output Device: LCD The choice between the two registers is made by the register selector (RS) signal as detailed the following table: Register Selector (RS) RS R/W* 0 0 Sends a command to LCD 0 1 Read busy flag (DB 7) and address counter (DB 0 to DB 6) 1 0 Sends information to LCD 1 1 Reads information from LCD Busy Flag (BF) BF gives an indication whether the LCD is finished the previous instruction and ready with the next.

Interfacing and Programming with Input/Output Device: LCD Address Counter (AC) The address counter (AC)

Interfacing and Programming with Input/Output Device: LCD Address Counter (AC) The address counter (AC) assigns addresses to both DDRAM and CGRAM. When an address of an instruction is written into the IR, the address information is sent from the IR to the AC. Selection of either DDRAM or CGRAM is also determined concurrently by the instruction. After writing into (reading from) DDRAM or CGRAM, the AC is automatically incremented by 1(decremented by 1). The AC contents are then output to DB 0 to DB 6 when RS = 0 and R/W* = 1.

Interfacing and Programming with Input/Output Device: LCD display contains three memory blocks: 1. DDRAM

Interfacing and Programming with Input/Output Device: LCD display contains three memory blocks: 1. DDRAM Display Data RAM; 2. CGRAM Character Generator RAM; and 3. CGROM Character Generator ROM.

Interfacing and Programming with Input/Output Device: LCD DDRAM Memory DDRAM memory is used for

Interfacing and Programming with Input/Output Device: LCD DDRAM Memory DDRAM memory is used for storing characters to be displayed. The size of this memory is capable of storing 80 characters. Some memory locations are directly connected to the characters on display.

Interfacing and Programming with Input/Output Device: LCD CGROM Memory CGROM memory contains a standard

Interfacing and Programming with Input/Output Device: LCD CGROM Memory CGROM memory contains a standard character map with all characters that can be displayed on the screen. Each character is assigned to one memory location:

The ASCII code table is shown in Table 4. 4. A 250 ms delay

The ASCII code table is shown in Table 4. 4. A 250 ms delay is executed between each output to make the count visible.

Interfacing and Programming with Input/Output Device: LCD CGRAM Memory Apart from standard characters, the

Interfacing and Programming with Input/Output Device: LCD CGRAM Memory Apart from standard characters, the LCD display can also display symbols defined by the user itself. It can be any symbol in the size of 5 x 8 pixels. RAM memory called CGRAM in the size of 64 bytes enables it. Memory registers are 8 bits wide, but only 5 lower bits are used. Logic one (1) in every register represents a dimmed dot, while 8 locations grouped together represent one character. It is best illustrated in figure below:

Interfacing and Programming with Input/Output Device: LCD

Interfacing and Programming with Input/Output Device: LCD

Interfacing and Programming with Input/Output Device: LCD Writing a letter/character to the LCD display

Interfacing and Programming with Input/Output Device: LCD Writing a letter/character to the LCD display To write a letter/character on the LCD display we have to do the following: 1. Perform an initialization. 2. Send the desired position to IR (DDRAM Address). 3. Send ASCII code of the letter to DR. LCD display will show the letter that matches the code that was sent and the address counter AC will be updated (increment or decrement, depending on how it was initialized). You can write strings by sending characters in sequence.

Interfacing and Programming with Input/Output Device: LCD Before using the LCD for display purpose,

Interfacing and Programming with Input/Output Device: LCD Before using the LCD for display purpose, LCD has to be initialized either by the internal reset circuit or sending the commands to initialize the LCD. Given is a flowchart that describes the step to follow to initialize the LCD. When you send out an instruction (command or information) to the LCD it takes some time to execute it, so it is important to make sure that the LCD is "ready" for the next instruction/operation. There are two ways to send characters (command/data) to the LCD: Create a delay subroutine to accommodate the minimum execution time. Scanning BF (busy flag) bit – this bit gives an

Interfacing and Programming with Input/Output Device: LCD instruction set The LCD instruction set consists

Interfacing and Programming with Input/Output Device: LCD instruction set The LCD instruction set consists of the commands you can send to LCD. Remember that the RS line needs to be set to zero (RS = 0) to send instruction to the LCD. When the RS line is set to one (RS = 1), you are sending data to display memory or the character graphics (CG) memory. An “X” in any position means it does not matter what you enter there.

Interfacing and Programming with Input/Output Device: LCD Clear Display: This command clears the display

Interfacing and Programming with Input/Output Device: LCD Clear Display: This command clears the display and returns the cursor to the home position (address 0) and sets I/D to 1 in order to increment the cursor. Its line settings are as follows: RS R/ W D 7 D 6 D 5 D 4 D 3 D 2 D 1 D 0 0 0 0 0 1 Home Cursor: This returns the cursor to the home position, returns a shifted display to the correct position, and sets the display data (DD) RAM address to 0. Its line settings are as follows: RS R/ W D 7 D 6 D 5 D 4 D 3 D 2 D 1 D 0 0 0 0 0 1 X

Interfacing and Programming with Input/Output Device: LCD Entry Mode Set: This command sets the

Interfacing and Programming with Input/Output Device: LCD Entry Mode Set: This command sets the cursor move direction and specifies whether to shift the display or not. These operations are performed during the data write/read of the CG or DD RAM. Its line settings are as follows: RS R/ W D 7 D 6 D 5 D 4 D 3 D 2 D 1 D 0 0 0 0 1 I/D S I/D=0 means the cursor position is decremented (moves right to left). I/D=1 means the cursor position is incremented (moves left to right). S=0 means normal operation, the display remains still, and the cursor moves. S=1 means the display moves with the cursor.

Interfacing and Programming with Input/Output Device: LCD Display On/Off Control: This command sets the

Interfacing and Programming with Input/Output Device: LCD Display On/Off Control: This command sets the ON/OFF display as well as the cursor and blinking capabilities (0 equals OFF; 1 equals ON). D controls whether the display is ON or OFF, C controls whether the cursor is ON or OFF, B controls whether the blinking is ON or OFF. The line settings are as follows: RS R/ W D 7 D 6 D 5 D 4 D 3 D 2 D 1 D 0 0 0 0 1 D C B Cursor or Display Shift: This moves the cursor and shifts the display without changing DD RAM contents. The line settings are as follows: S/C=0 means move the cursor. S/C=1 means shift display. R/L= 0 means shift to the left. R/L= 1 means shift to the right. RS R/ W D 7 D 6 D 5 D 4 D 3 D 2 D 1 D 0 0 0 1 S/C R/L X X

Interfacing and Programming with Input/Output Device: LCD Function Set: This sets the interface data

Interfacing and Programming with Input/Output Device: LCD Function Set: This sets the interface data length (DL), the number of display lines (N), and character font (F). The line settings are as follows: RS R/ W D 7 D 6 D 5 D 4 D 3 D 2 D 1 D 0 0 0 1 DL N F X X DL=0 means 4 bits are being used (the standard) DL=1 means a full 8 bits being utilized N=0 means 1 line N=1 means 2 lines or more F=0 means that 5 x 7 dot characters are used (which is how 99% of all LCDs are set up) F=1 means 5 x 10 dot characters are used

Interfacing and Programming with Input/Output Device: LCD Set CG RAM Address: This command sets

Interfacing and Programming with Input/Output Device: LCD Set CG RAM Address: This command sets the custom graphics (CG) RAM address. Setting RS to 1 sends data to CG RAM instead of the DD RAM. Eight CG characters are available, and they reside in the ASCII codes 0 through 7. The is sent in the 8 -bit bytes from the top row to the bottom row and is left justified, meaning that only the bottom 5 bits matter (it is a 5 x 7 dot matrix). The line settings are as follows: RS R/ W D 7 D 6 0 0 0 1 D 5 MSB D 4 CG D 3 RAM LSB D 2 D 1 ADDRESS D 0

Interfacing and Programming with Input/Output Device: LCD Set DD RAM Address: This sets the

Interfacing and Programming with Input/Output Device: LCD Set DD RAM Address: This sets the DD RAM address. Setting RS to 1 sends data to the display RAM, and the cursor advances in the direction where the I/D bit was set to. The line settings are as follows: RS R/ W D 7 0 0 1 D 6 D 5 D 4 MSB D 3 D 2 D 1 D 0 DD RAM ADDRESS LSB Read Busy Flag and Address: This reads the busy flag (BF). If BF equals to 1, the LCD is busy and displays the location of the cursor. With the R/W line grounded, this command can not be used. The line settings are as follows: RS R/ W D 7 D 6 D 5 D 4 D 3 D 2 D 1 D 0 0 1 0 0 0 0 1

Interfacing and Programming with Input/Output Device: LCD Write Data to CG or DD RAM:

Interfacing and Programming with Input/Output Device: LCD Write Data to CG or DD RAM: This command’s line settings are as follows: RS R/ W 1 0 D 7 MSB D 6 D 5 D 4 D 3 D 2 D 1 D 0 ASCII code or CG bit pattern data LSB Read Data from CG or DD RAM: This command’s line settings are as follows: RS 1 R/ W 1 D 7 MSB D 6 D 5 D 4 D 3 D 2 D 1 D 0 ASCII code or CG bit pattern data LSB

Interfacing and Programming with Input/Output Device: LCD Example 1: LCD initialization command code sequence

Interfacing and Programming with Input/Output Device: LCD Example 1: LCD initialization command code sequence

Interfacing and Programming with Input/Output Device: LCD Example 2: LCD command code To send

Interfacing and Programming with Input/Output Device: LCD Example 2: LCD command code To send any of the command codes listed in Table 12 -2 to the LCD, make pin RS = 0. For data, make RS = 1. Then send a high-to-low pulse to the E pin to enable the internal latch of the LCD.

Interfacing and Programming with Input/Output Device: LCD Connection of a 2 x 16 character

Interfacing and Programming with Input/Output Device: LCD Connection of a 2 x 16 character LCD to PIC 16 F 877 A

Interfacing and Programming with Input/Output Device: LCD Example 1: Write a program and create

Interfacing and Programming with Input/Output Device: LCD Example 1: Write a program and create a circuit to display sentences below for condition: a. When the microcontroller on, LCD will display “ Welcome to Electrical Sys. Eng. ” for 1000 ms and followed “ Please Visit www. unimap. edu. my” for 1000 ms. The sentences will be repeated. b. The sentences will be stopped if the power off.

Interfacing and Programming with Input/Output Device: LCD Example 1: Solution

Interfacing and Programming with Input/Output Device: LCD Example 1: Solution

Interfacing and Programming with Input/Output Device: LCD

Interfacing and Programming with Input/Output Device: LCD

Interfacing and Programming with Input/Output Device: LCD

Interfacing and Programming with Input/Output Device: LCD

Interfacing and Programming with Input/Output Device: LCD Example 2: Write a program and create

Interfacing and Programming with Input/Output Device: LCD Example 2: Write a program and create a circuit to display “Door Close!” or “Door Open!” to inform a door condition, following below: a. If the door is closed, the LCD will display “Door Close!”. b. If the door is opened, the LCD will display “Door Open!”. Connect a switch to RC 1 for the door condition.

Interfacing and Programming with Input/Output Device: LCD Example 2: Solution

Interfacing and Programming with Input/Output Device: LCD Example 2: Solution

Interfacing and Programming with Input/Output Device: LCD

Interfacing and Programming with Input/Output Device: LCD

Interfacing and Programming with Input/Output Device: LCD

Interfacing and Programming with Input/Output Device: LCD

Interfacing and Programming with Input/Output Device: LCD Example 3: Design an alarm system with

Interfacing and Programming with Input/Output Device: LCD Example 3: Design an alarm system with LCD message output: a. Connect C 1 to push button 1, connect C 2 to push button 2. b. Connect buzzer to C 7 c. d. e. f. When C 1=1, C 2=0, it will turn ON buzzer and display “Zone 1 ON” on LCD. When C 1=0, C 2=1, it will turn ON buzzer and display “Zone 2 ON” on LCD. When C 1=1, C 2=1, it will turn ON buzzer and display “Zone 1, 2 ON” on LCD. When C 1=0, C 2=0, it will turn OFF buzzer and display “Safety” on LCD.

Interfacing and Programming with Input/Output Device: LCD Example 3: Solution

Interfacing and Programming with Input/Output Device: LCD Example 3: Solution

Interfacing and Programming with Input/Output Device: LCD

Interfacing and Programming with Input/Output Device: LCD

Interfacing and Programming with Input/Output Device: LCD

Interfacing and Programming with Input/Output Device: LCD