Home

Input Switches

image

Contents

1. Microprocessors amp Interfacing Input Output Devices Lecturer Dr Annie Guo S2 2008 COMP9032 Week8 amp Lecture Overview e Input devices Input switches e Basics of switches Keypads e Output devices LCD S2 2008 COMP9032 Week8 2 Input Switches e Most basic binary input devices e The switch output is high or low depending on the switch position e Pull up resistors are necessary in each switch to provide a high logic level when the switch is Open e Problem with switches Switch bounce e When a switch makes contact its mechanical springiness will cause the contact to bounce or contact and break for a few milliseconds typically 5 to 10 ms S2 2008 COMP9032 Week8 amp Input Switches cont Vcc Vcc R Typically 1K Ohm Logic high with switch open gt Logic low with switch closed Ya k 74LS244 Data Bus O Octal Buffer a Single pole single throw b Multiple pole switch SPST logic switch Data Bus S2 2008 COMP9032 Week8 4 NAND Latch Debouncer Vcc S2 2008 COMP9032 Week8 Logic high with switch up Logic low with switch down Software Debouncing Basic idea wait until the switch is stable e For example Wait and see e If the software detects a low logic level indicating that switch has closed it sim
2. The cursor or the blink moves to the upper left edge of the display Text on the display remains unchanged S2 2008 COMP9032 Week8 32 Instructions e Entry Mode Set RS R W DB7 DB6 DB5 BD4 DB3 DB2 DB1 DBO Code 0 0 0 0 0 0 0 1 ID S amp S Sets the Increment Decrement and Shift modes to the desired settings I D Increments I D 1 or decrements ID 0 the DD RAM address by 1 when a character code is written into or read from the DD RAM The cursor or blink moves to the right when incremented by 1 The same applies to writing and reading the CG RAM e S Shifts the entire display either to the right or to the left when S 1 shift to the left when I D 1 and to the right when I D 0 S2 2008 COMP9032 Week8 amp 33 Instructions e Display ON OFF Control RS R W DB7 DB6 DB5 BD4 DB3 DB2 DB1 DBO Code 0 0 0 0 0 0 1 D C B Controls the display ON OFF status Cursor ON OFF and Cursor Blink function e D The display is ON when D 1 and OFF when D 0 e C The cursor displays when C 1 and does not display when C 0 e B The character indicated by the cursor blinks when B i S2 2008 COMP9032 Week8 34 Instructions e Cursor or Display Shift RS R W DB7 DB6 DB5 BD4 DB3 DB2 DB1 DBO Code 0 0 0 0 0 1 SC RL x x Shifts the cursor position or display to the right or left without writing or reading display data S C R L 0 0 S
3. 8 to 1 y4 A Input f 7 v Multiplexer ey o on Coal 06 07 o L shy n 10 T 12 17 Scanned Switch Data Keyboard Matrix of Switches cont e A keyboard is an array of switches arranged in a two dimensional matrix e A switch is connected at each intersection of vertical and horizontal lines w 2p e Closing the switch connects the horizontal line to the vertical line a e 8 8 keyboard can be interfaced directly into B 70 71 77 mie 8 bit output and input ports at point A and B oo 01 02 03 04 05 O6 07 E3 E2 E1 A2 A1 A0 Select Input From a 3 of 8 iki S2 2008 ig COMP9032 Weeks ee 9 S2 2008 COMP9032 Week8 amp 10 Keyboard Matrix of Switches Ghosting cont e Software can scan the key board by T outputting a three bit code to the decoder and then scanning the multiplexer to find the closed switch or switches The combination of the two 3 bit scan codes A2A1A0 and S2S1S0 identifies which switch is closed For example the code 000000 scan switch 00 in the upper left hand corner e The diode prevents a problem called ghosting S2 2008 COMP9032 Week8 amp 11 R3 R2 R1 Colo Colt Col2 Row 0 Pulled low error Row 1 Pulled low OK Row 2 High OK Scanned column S2 2008 COMP9032 Week8 12 Ghosting cont e Ghosting occu
4. def temp2 r21 equ PORTDDIR 0xF0 PD7 4 output PD3 0 input equ INITCOLMASK 0xEF scan from the leftmost column equ INITROWMASK 0x01 scan from the top row equ ROWMASK 0x0F for obtaining input from Port D S2 2008 COMP9032 Week8 16 Code Implementation Code Implementation colloop RESET cpi col 4 Idi temp1 low RAMEND __ initialize the stack breq main if all keys are scanned repeat jout SPL temp1 out PORTD cmask otherwise scan a column sldi temp1 high RAMEND out SPH temp1 Idi temp1 OxFF slow down the scan operation delay dec temp1 Idi temp1 PORTDDIR PD7 4 PD3 0 out in brne delay out DDRD temp1 ser temp1 PORTC is output in temp1 PIND read PORTD out DDRC temp1 andi temp1 ROWMASK get the keypad output value out PORTC temp1 cpi temp1 0xF check if any row is low breq nextcol main if yes find which row is low Idi cmask INITCOLMASK _ initial column mask Idi rmask INITROWMASK _ initialize for row check clr col initial column clr row S2 2008 COMP9032 Week8 17 S2 2008 COMP9032 Week8 18 Code Implementation Code Implementation rowloop cpi row 4 convert i o breq nextcol the row scan is over cpi col 3 if the pressed key is in col 3 mov temp2 temp1 breq letters we have a letter and temp2 rmask check un masked bit breq convert if bit is clear the key is pressed if the key is not in co
5. delay to meet timing Enable cycle time nop nop nop nop ENDMACRO ENDMACHO Examples ME AP LCD Initialization e Check LCD and wait until LCD is not busy comments are same as in the previous slide initiali e Roe e LCD should be initialized before use clr temp ie out DDRD temp Make PORTD be an input port for now j Internal Reset Circuit can be used but It IS out PORTD temp f si ce a related to power supply loading may not out PORTA temp RS 0 RW 1 for a command port read work pro perly busy_loop oa nop delay to meet set up time e Therefore software initialization is sbi PORTA LCD_E turn on the enable pin nop delay to meet timing Data delay time recommended nop nop in temp PIND read value from LCD cbi PORTA LCD_E turn off the enable pin sbrc temp LCD_BF if the busy flag is set rjmp busy_loop repeat command read clr temp else out PORTA temp turn off read mode ser temp out DDRD temp make PORTD an output port again ENDMACRO S2 2008 COMP9032 Week8 44 Software Initialization 8 Bit Initialization Wait more than 15ms after Vee 4 5V RS R W DB DB DB DB DB DB DB DB 0 0 0 O 1 1 x x x No data should be transferred to or from the display during this time Function Set Command 8 Bit interface x BF cannot be checked before this command y i No data should be transferred to or from Wait more tian 4 Inis the display during this tim
6. 00 delay Icd_write_com Function set command with N 1 and F 0 for 2 line display and 5 7 font The 1t command Idi data LCD_FUNC_SET 1 lt lt LCD_N 2nd Function set command delay gt 15ms delay gt 4 1 ms continued S2 2008 COMP9032 Week8 48 Example of Initialization Code Idi del_lo low 100 Idi del_hi high 100 delay delay gt 100 ns Icd_write_com Icd_write_com 3rd Function set command Final Function set command Icd_wait_busy Idi data LCD_DISP_OFF Icd_write_com Wait until the LCD is ready Turn Display off Icd_wait_busy Idi data LCD_DISP_CLR Wait until the LCD is ready Example of Initialization Code Icd_wait_busy Entry set command with I D 1 and S 0 Set Entry mode Increment yes and Shift no Idi data LCD_ENTRY_SET 1 lt lt LCD_ID Icd_write_com Icd_wait_busy Display On command with C 1 and B 0 Idi data LCD_DISP_ON 1 lt lt LCD_C Icd_write_com Wait until the LCD is ready Wait until the LCD is ready Icd_write_com Clear Display continued S2 2008 COMP9032 Week8 49 S2 2008 COMP9032 Week8 amp 50 Reading Material Homework e Chapter 7 Computer Buses and Parallel Input and Output Microcontrollers and Microcomputers by Fredrick M Cady Simple I O Devices e DOT Matrix LCD User s Manual Available on the course website S2 2008 COMP9032 Week8 amp 5
7. 1 1 Write an assembly program to initialize LCD panel to display characters in one line with 5x7 font S2 2008 COMP9032 Week8 52
8. CG RAM Data Register DR To temporarily store data to be read written to from the DD RAM of the display controller S2 2008 COMP9032 Week8 amp 27 Operations cont The register select RS signal determines which of these two register is selected IR write internal operation Display Clear etc DR Write Internal Operation DR DD RAM or CG RAM O0 o o Busy flag DB and Address Counter DBp DBs read ee ee i 1 DR Read Internal Operation DD RAM or CG RAM S2 2008 COMP9032 Week8 28 Operations cont e When the busy flag is high or 1 the LCD module is busy with internal operation e The next instruction must not be written until the busy flag is low or 0 e For details refer to the LCD USER S MANUAL S2 2008 COMP9032 Week8 amp 29 LCD Instructions e A list of binary instructions are available for LCD operations e Some typical ones are explained in the next slides S2 2008 COMP9032 Week8 30 Instructions e Clear Display RS R W DB7 DB6 DB5 BD4 DB3 DB2 DB1 DBO Code 0 0 0 0 0 0 0 0 0 1 The display clears and the cursor or blink moves to the upper left edge of the display The execution of clear display instruction sets entry mode to increment mode S2 2008 COMP9032 Week8 amp 31 Instructions e Return Home RS R W DB7 DB6 DB5 BD4 DB3 DB2 DB1 DBO Code 0 0 0 0 0 0 0 0 1 Xx
9. e RS R W DB DB DB DB DB DB DB DBo oo 0 0 1 1 x x x Wait more than 1001s Function Set Command 8 Bit interface x BF cannot be checked before this command No data should be transferred to or from the display during this time Software Initialization Wait more than 100us RS R W DB DB DB DB DB DB DB DBo o o0 o o0 1 ee x x RS R W DB DB DB DB DB DB DB DBo o 1 1 N 3 x o o o 1 0 Initialization Complete Display Ready No data should be transferred to or from the display during this time Function Set Command 8 Bit interface After this command is written BF can be checked Function Set Interface 8 bits Set No of lines and display font Display OFF Clear Display Entry Mode Set Display ON Set C and B for cursor Blink options Note BF should be checked before each of the instructions starting with Display OFF Example of Initialization Code include m64def inc MACRO delay loop subi del_lo 1 sbci del_hi 0 nop nop nop nop brne loop ENDMACRO The del_hi del_lo register pair store the loop counts each loop generates about 1 us delay taken branch takes two cycles one loop time is 8 cycles 1 08us continued S2 2008 COMP9032 Week8 amp 47 Example of Initialization Code Idi del_lo low 15000 Idi del_hi high 15000 delay Icd_write_com Idi del_lo low 4100 Idi del_hi high 41
10. hifts cursor position to the left AC is decremented by one Shifts cursor position to the right AC is incremented by one Shifts the entire display to the left The cursor follows the display shift k Shifts the entire display to the right The cursor follows the display shift S2 2008 COMP9032 Week8 35 Instructions e Function Set RS R W DB7 DB6 DB5 BD4 DB3 DB2 DB1 DBO Code 0 0 0 0 1 DL N F x x Sets the interface data length the number of lines and character font e DL 1 8 bits otherwise 4 bits e N Sets the number of lines N 0 1 line display N 1 2 line display e F Sets character font F 1 5x 10 dots F 0 5 x 7 dots S2 2008 COMP9032 Week8 36 Instructions e Read Busy Flag and Address RS R W DB7 DB6 DB5 BD4 DB3 DB2 DB1 DBO Code 0 1 BF A A A A A A A Reads the busy flag BF and value of the address counter AC BF 1 indicates that on internal operation is in progress and the next instruction will not be accepted until BF is set to O If the display is written while BF 1 abnormal operation will occur S2 2008 COMP9032 Week8 amp 37 Instructions Write Data to CG or DD RAM RS R W DB7 DB6 DB5 BD4 DB3 DB2 DB1 DBO Code 1 0 DB D D D D D D D Writes binary 8 bit data DDDDDDDD to the CG or DD RAM The previous designation determines whether the CG or DD RAM is
11. iptions Lines to DB4 DB7 4 Input Output MPU 4 lines of high order data bus Bi directional transfer of data between MPU and module is done through these lines Also DB can be used as a busy flag These lines are used as data in 4 bit operation DBO DB3 4 Input Output MPU 4 lines of low order data bus Bi directional transfer of data between MPU and module is done through these lines In 4 bit operation these are not used and should be grounded MPU Enable Operation start signal for data read write RW 1 Input MPU Signal to select Read or Write 0 Write 1 Read RS 1 Input MPU Register Select 0 Instruction register Write i Busy flag Address counter Read 1 Data register Write Read E a Fe Terminal for LCD drive power source Suppl ee een Suppl AE T E Supply S2 2008 COMP9032 Week8 25 Dot Matrix LCD Diagram Common DB Var piali l Dot matrix LCD panel v Controller RS amp Driver Segment 40 4i 41 4 IC RW Serial data Segment Segment Segment Drive O Driver Driver gl ZN Timing E z 3 22 S2 2008 COMP9032 Week8 26 Operations e MPU communicates with LCD through two registers Instruction Register IR To store instruction code like Display clear or Cursor Shift as well as addresses for the Display Data RAM DD RAM or the Character Generator RAM
12. l 3 and inc row else move to the next row Isl rmask cpi row 3 if the key is in row3 imp rowloop breq symbols we have a symbol or 0 nextcol if row scan is over mov temp1 row otherwise we have a number in 1 9 Isl cmask Isl temp1 inc col increase column value add temp1 row jmp colloop go to the next column add temp1 col temp1 row 3 col subi temp1 1 add the value of character 1 jmp convert_end S2 2008 COMP9032 Week8 19 S2 2008 COMP9032 Week8 20 Code Implementation letters Idi temp1 A add temp1 row Get the ASCII value for the key jmp convert_end symbols cpi col 0 check if we have a star breq star cpi col 1 or if we have zero breq zero Idi temp1 if not we have hash jmp convert_end star Idi temp1 set to star jmp convert_end zero Idi temp1 0 set to zero convert_end out PORTC temp1 write value to PORTC jmp main restart main loop s 21 LCD e Liquid Crystal Display e Programmable output device S2 2008 COMP9032 Week8 22 Dot Matrix LCD Characters are displayed using a dot matrix 5x7 5x8 and 5x11 A controller is used for communication between the LCD and other devices e g MPU The controller has an internal character generator ROM All display functions are controllable by instructions S2 2008 COMP9032 Week8 23 Pin Assignments S2 2008 COMP9032 Week8 24 Pin Descr
13. ply waits for some time say 20 to 100ms and then test if the switch is still low Counter based approach Initialize a counter to 10 e Poll the switch every millisecond until the counter is either 0 or 20 If the switch output is low decrease the counter otherwise increment the counter e If the counter is 0 we know that switch output has been low closed for at least 10 ms If on the other hand the counter reaches 20 we know that the switch has been open for at least 10 ms S2 2008 COMP9032 Week8 One Dimensional Array of me Switches J r 10 741151 8 to 1 K 11 Multiplexer Scanned Q 12 Switch Data To 13 To Input Port y Z fo 14 il EE 5 15 y a 16 y ay 17 E S2 S1 S0 S2 2008 COMP9032 Week8 Selected Input From Output Port One Dimensional Array of Switches e Switch bouncing problem must be solved Either using software or hardware e The array of switches must be scanned to find out which switches are closed or open Software is required to scan the array As the software outputs a 3 bit sequence from 000 to 111 the multiplexer selects each of the switch inputs The output of switch array could be interfaced directly to an eight bit port at point A S2 2008 COMP9032 Week8 Vece Keyboard Matrix of Switches 12 74LS151
14. rs when several keys are pushed at once e Consider the case shown in the figure where three switches 01 10 and 11 are all closed Column 0 is selected with a logic low and assume that the circuit does not contain the diodes As the rows are scanned a low is sensed on Row 1 which is acceptable because switch 10 is closed In addition Row 0 is seen to be low indicating switch 00 is closed which is NOT true The diodes in the switches eliminate this problem by preventing current flow from R1 through switches 01 and 11 Thus Row 0 will not be low when it is scanned S2 2008 COMP9032 Week8 amp 13 Example e Get an input from 4 4 keypad HBA pro BEB rR HEB r HO HD R CO C1 C2 C3 S2 2008 COMP9032 Week8 14 Example solution e Algorithm Scan columns from left to right for each column scan rows from top to bottom for each key being scanned if it is pressed display wait endif endfor endfor Repeat the scan process Acolumn is selected its related Cx value is set to 0 A mask is used to read one row at a time S2 2008 COMP9032 Week8 amp 15 Code Implementation The program gets input from keypad and displays its ascii value on the LED bar include m64def inc def row r16 current row number def col r17 current column number def rmask r18 mask for current row during scan def cmask r19 mask for current column during scan def temp1 r20
15. to be written CG RAM address set or DD RAM address set After a write the entry mode will automatically increase or decrease the address by 1 Display shift will also follow the entry mode S2 2008 COMP9032 Week8 38 Timing Characteristics e For write operation RS Ls 2 0V 20V lt effective data S Osv gt DB DB Timing Characteristics For read operation RS LS DB DB effective data teycle Examples Examples e Send a command to LCD Send data to display Register data stores value to be written to the LCD Port D is output and connects to LCD Port A controls the LCD comments are same as in previous slide Assume all other labels are pre defined g MACRO Icd_write_data MACRO IEA nom F out PORTD data set the data port s value up out PORTD data set the data port s value up Idi temp 1 lt lt LCD_RS clr temp 7 RS 1 RW 0f i out PORTA temp RS 0 RW 0 for a command write zech temp a A aide re ese ae nop ae delay to iba pris Set up time sbi PORTA LCD_E turn on the enable pin sbi PORTA LCD turn on the enable pin ries E l l idth nop delay to meet timing Enable pulse width Aon delay to meet timing Enable pulse width nop nop NOP cbi PORTA LCD_E turn off the enable pin CDI PORTA ECD_E tur onine enable pin nop delay to meet timing Enable cycle time nop

Download Pdf Manuals

image

Related Search

Related Contents

Samsung Galaxy Tab 2 (10.1) Užívateľská príručka  SOL 25 Plus Flat Plate Collector Installation Manual  Analog radios from Hytera  Eignungsprüfbericht für Gaskomponenten  Samsung SPH-B3000 User Manual  Diamond Multimedia R9280XD53GXOC AMD Radeon R9 280X 3GB graphics card  PowerTraveller Powermonkey Discovery  IM 660-3.book - McQuay International Home Page  TAC4 DG-DM + MODBUS RTU    

Copyright © All rights reserved.
Failed to retrieve file