Title: Instructor: Nachiket M' Kharalkar
1Introduction to Microcontrollers
- Instructor Nachiket M. Kharalkar
-
- Lecture 12
- Date 06/29/2007
- E-mail knachike_at_ece.utexas.edu
-
2Todays Agenda
- Recap
- Fixed point numbers
- LCD interfacing
LCD slides Courtesy Prof. Bard
3Implementation
- Stack implementation of local variables has four
stages - binding
- allocation
- access, and
- deallocation.
4- Example of local variables on stack
- org 4000
- calculate sum of numbers
- Input RegD num
- Output RegD Sum of 1,2,3,...,num
- Errors may overflow
- 1) binding
- num set 2 loop counter 1,2,3
- sum set 0 running
- calc
- 2) allocation
- pshd allocate num
- movw 0,2,-sp sum0
- 3) access
- loop ldd sum,sp
- addd num,sp
- std sum,sp sum sumnum
- ldd num,sp
- subd 1
5Call by reference call by value
- call by reference
- how
- a pointer to the object is passed
- why
- fast for passing lots of data
- simple to implement input/output parameters
- both subroutine and calling routine assess same
data - call by value
- how
- a copy of the data is passed
- why
- simple for small numbers of parameters
- protection of the original data from the
subroutine
6- org 4000
- calculate sum of numbers
- Input RegD num
- Output RegD Sum of 1,2,3,...,num
- Errors may overflow
- 1) binding
- sum set -4 16-bit accumulator
- num set -2 loop counter 1,2,3
- calc
- 2) allocation
- pshx save old frame
- tsx create frame
- pshd allocate num
- movw 0,2,-sp sum0
- 3) access
- Draw a stack picture relative to frame
- X-4 -gt sum
- X-2 -gt num
- X -gt oldX
Example of local variables on stack, using a
stack frame Advantage you can use the stack for
other temporary Disadvantage slower ties up the
use of a register
7Parameters and locals on stack, using a stack
frame
- Advantage you can pass lots of data
- Disadvantage slower
- Strategy
- number of parameters?
- few use registers
- a lot use the stack
- size of the parameter
- 1 or 2 bytes call by value
- buffers call by reference
8Fixed point numbers
- Why
- express values with non-integer values
- no floating point hardware support
- When
- range of values is known
- range of values is small
- How
- 1) variable integer, called I.
- may be signed or unsigned
- may be 8, 16 or 32 bits (precision)
- 2) fixed constant, called ? (resolution)
- value is fixed, and can not be changed
- not stored in memory
- specify this fixed content using comments
9Fixed point numbers
- The value of the fixed-point number
- fixed-point number ? I?
- Decimal fixed-point, ?10m
- decimal fixed-point number I 10m
- nice for human input/output
- Binary fixed-point, ?2m
- binary fixed-point number I 2m
- easier for computers to perform calculations
10?0.01 V Vin 5N/255 how ADC works Vin I
0.01 definition of fixed point I
(5100N)/255 substitution I (100N)/51
simplify I (100N25)/51 round to closest
integer
11Fixed point conversion example
- Consider the following digital filter
calculation. - y x -0.0532672x1 x2 0.0506038y1-0.9025y2
- The variables y, y1, y2, x, x1, and x2 are all
- integers
- -0.0532672 -142-8
- 0.0506038 132-8
- -0.9025 -2312-8
- y x x2 (-14x113y1-231y2)gtgt8
12Input/Output Considerations
- Processor-Peripheral Timing Mismatch
- Peripherals, e.g., displays, sensors, switches,
generally operate MUCH slower than processor
instruction times - Processor MHz
- Peripheral KHz or Hz
- MANY instructions can be executed while
peripheral processes information
13Input/Output Considerations (cont.)
- Peripheral primitive states
- READY
- Peripheral is ready to initiate an I/O transfer
- BUSY
- READY peripheral becomes BUSY when I/O transfer
initiated - Peripheral remains BUSY for duration of I/O
transfer - Another transfer can NOT be initiated
- NOT READY
- Peripheral is unable to perform I/O transfer
14Input/Output Considerations (cont.)
- I/O options what to do while the peripheral is
BUSY - TEST/TRANSFER (aka, ready/busy, gadfly)
- Poll peripheral status wait for READY/NOT BUSY
- Perform other tasks between polls
- Unless timed correctly, under/over run possible
- One solution POLL CONTINUOUSLY
15Input/Output Considerations (cont.)
- I/O options what to do while the peripheral is
BUSY - INTERRUPT/TRANSFER
- Hardware INTERRUPTS processor on condition of
READY/NOT BUSY - Facilitates performing other background -
processing between I/O transfers - Processor informed (changes context) when current
transfer complete - Requires program structure to process context
change
16Input/Output Considerations (cont.)
- Simplified option
- Suppose that a BUSY control signal is not
available - Employ Blind Cycle approach
- Perform I/O operation
- Wait for a period of time that is guaranteed to
be sufficient for operation to complete - Initiate next operation
17LCD Liquid Crystal DisplayFeatures
- Low power consumption
- Appears to be a capacitor
- Charge changes reflectivity or transmittivity
- Read with ambient light contrast with LEDs
- Flexibility in size and shape
- LCD is a sandwich
- Transparent LCD material Active PCB
- Size and shape determined by PCB
- Contrast with LEDs
18LCD Liquid Crystal DisplayOperation
- MDL(S) 16166 LCD display
- Consider LCD display to be 1 X 16 matrix
- Each of the 16 character positions behaves as a 5
X 8 matrix - Any combination of the 40 picture elements
(pixel) per character position can be activated - Each of the 16 characters can be considered as an
independent display COMPLEX!
19LCD Liquid Crystal DisplayOperation (cont.)
- Simplification provided by
- Hitachi HD 44780U (LCD-II) Dot Matrix LCD
Controller/Driver - The HD 44780U will serve as an interface between
the 6812 and the LCD display - It will serve to generate the appropriate 5 X 8
bit patterns for the ASCII character set - It will handle display character positioning,
e.g., where next characters are added
20LCD Liquid Crystal DisplayOperation (cont.)
- Interface to HD44780
- Employ 4-bit data mode
- Port M0-5
- Character addresses
- Left 00 07
- Right 40 - 47
21LCD Liquid Crystal DisplayAssignment
- Laboratory assignment
- Interface LCD to Tech Arts board
- Develop device driver to serve as interface
between 6812 and HD 44780 - Develop main program that employs device driver
to display message, Welcome to 319K on LCD - Use EspressSCH to develop circuit diagram
22LCD Liquid Crystal DisplayDevice Driver
- A Device Driver is a set of software routines
that provide the basic I/O functions of a
peripheral to higher level programs - Device drivers encapsulate the specific
operational details of an I/O device and provide
the I/O function - For example, the fact that 42 might be required
to activate a read function on one type of
network interface while 80 is required on
another would only be known by the device driver
and NOT the program using the driver.
23LCD Liquid Crystal DisplayDevice Driver (cont.)
- Device drivers enable
- Simplified installation of new hardware
- Different algorithms to be employed for I/O
transfers and control - Error detection
- Changes in protocol timing
- Simplified implementation of higher level
software systems
24LCD Liquid Crystal DisplayDevice Driver
- LCD Device Driver functions
- LCD_Open
- Initializes timer, port M data direction
- LCD_OutChar
- Transfers one byte as two nibbles to the
display - LCD_Clear
- Clears the display and homes the cursor
25LCD Liquid Crystal DisplayDevice Driver (cont.)
- LCD Device Driver functions
- LCD_OutString
- Transfers a null terminated string of characters
to the display by calling LCD_OutChar - LCD_GoTo
- Moves the cursor to a particular display address
- LCD_OutDec
- Displays a 16-bit unsigned number in decimal
format - LCD_OutFix
- Displays fixed-point numbers with resolution
0.001 in unsigned decimal format, 0.000 to 9.999
26LCD Liquid Crystal DisplayDevice Driver (cont.)
- Device Driver Private Function
- outCsr transfers one byte of command to the
display - Available to the drivers public functions, e.g.,
LCD_xyz - Not available to higher level software
27(No Transcript)
28(No Transcript)
29(No Transcript)
30(No Transcript)
31- Entry Mode Set 0,0,0,0,0,1,I/D,S
- I/D1 for increment cursor move direction
- 0 for decrement cursor move direction
- S 1 for display shift
- 0 for no display shift
- Display On/Off Control 0,0,0,0,1,D,C,B
- D 1 for display on
- 0 for display off
- C 1 for cursor on
- 0 for cursor off
- B 1 for blink of cursor position
character - 0 for no blink
- Cursor/Display Shift 0,0,0,1,S/C,R/L,,
- S/C1 for display shift
- 0 for cursor movement
- R/L1 for shift to left
- 0 for shift to right
- Function Set 0,0,1,DL,N,F,,
- DL1 for 8 bit
32LCD_Open
- LCD_Open
- 0) save any registers that will be destroyed by
pushing on the stack - 1) initialize timer Timer_Init()
- 2) wait 100ms allowing the LCD to power up (can
skip this step in TExaS) - 3) set DDRM so that PM5-0 are output signals to
the LCD - 4) E0, RS0
- 5) 4-bit DB7,DB6,DB5,DB4 02 (DL0 4-bit mode)
- 6) E1
- 7) E0 (latch 4-bits into LCD)
- 8) blind cycle 90 us wait
- 9) outCsr(06) // I/D1 Increment, S0 no
displayshift - 10)outCsr(0C) // D1 displayon, C0 cursoroff,
B0 blink off - 11)outCsr(14) // S/C0 cursormove, R/L1
shiftright - 12)outCsr(28) // DL0 4bit, N1 2 line, F0 5by7
dots - 13)LCD_Clear() // clear display
- 14)restore the registers by pulling off the stack
33LCD_OutChar
- 0) save any registers that will be destroyed by
pushing on the stack - 1) E0, RS1
- 2) 4-bit DB7,DB6,DB5,DB4 most significant
nibble of data - 3) E1
- 4) E0 (latch 4-bits into LCD)
- 5) 4-bit DB7,DB6,DB5,DB4 least significant
nibble of data - 6) E1
- 7) E0 (latch 4-bits into LCD)
- 8) blind cycle 90 us wait
- 9) restore the registers by pulling off the stack
34LCD_Clear, LCD_OutString
- LCD_Clear
- 0) save any registers that will be destroyed by
pushing on the stack - 1) outCsr(01) // Clear Display
- 2) blind cycle 1.64ms wait
- 3) outCsr(02) // Cursor to home
- 4) blind cycle 1.64ms wait
- 5) restore the registers by pulling off the stack
- LCD_OutString
- 0) save any registers that will be destroyed by
pushing on the stack - 1) read one character from the string
- 2) increment the sting pointer to the next
character - 3) break out of loop (go to step 6) if the
character is NUL(0) - 4) output the character to the LCD by calling
LCD_OutChar - 5) loop back to step 1)
- 6) restore the registers by pulling off the stack
35LCD_GoTo, LCD_OutDec
- 0) save any registers that will be destroyed by
pushing on the stack - 1) verify proper values of DDaddr
- 2) outCsr(DDaddr80 11000000 C0)
- 3) restore the registers by pulling off the stack
- LCD_OutDec (recursive implementation)
- 1) allocate local variable n on the stack
- 2) set n with the input parameter passed in RegD
- 3) if(n gt 10)
- LCD_OutDec(n/10)
- n n10
-
- 4) LCD_OutChar(n30) / n is between 0 and 9 /
- 5) deallocate variable
36OutFix
- Output characters to LCD display in fixed-point
format - unsigned decimal, resolution 0.001, range 0.000
to 9.999 - Inputs RegD is an unsigned 16-bit number
- Outputs none
- Registers modified CCR
- E.g., RegD0, then output ?0.000 ?
- RegD3, then output ?0.003 ?
- RegD89, then output ?0.089 ?
- RegD123, then output ?0.123 ?
- RegD9999, then output ?9.999 ?
- RegDgt9999, then output ?. ?
37outCsr
- sends one command code to the LCD
control/status - Input RegA is 8-bit command to execute
- Output none
- 0) save any registers that will be destroyed by
pushing on the stack - 1) E0, RS0
- 2) 4-bit DB7,DB6,DB5,DB4 most significant
nibble of command - 3) E1
- 4) E0 (latch 4-bits into LCD)
- 5) 4-bit DB7,DB6,DB5,DB4 least significant
nibble of command - 6) E1
- 7) E0 (latch 4-bits into LCD)
- 8) blind cycle 90 us wait
- 9) restore the registers by pulling off the stack
38LCD interfacing
- The IO-gtHD44780 command allows you to connect an
integrated liquid crystal display (LCD) - PT4 means PT7,PT6,PT5,PT4
- LCD is physically 16 characters in 1 row, but
internally 8 characters in 2 rows
39Dialog box for interfacing a simple LCD display
40(No Transcript)
41- Entry lds 4000
- cli
-
- bset ATDDIEN,C0 PAD7, PAD6 digital
- bclr DDRAD,C0 PAD7, PAD6 inputs
- jsr LCD_Open Your function that
initializes the LCD - start jsr LCD_Clear Your function that
clears the display - ldx Welcome
- jsr LCD_OutString Your function
that outputs a string - ldx TestData
- loop brset PTAD,80, wait for switch
release - brclr PTAD,80, wait for switch touch
- jsr LCD_Clear Your function that clears
the display - ldd 0,x
- jsr LCD_OutDec Your function that
outputs an integer - jsr LCD_GoTo Your function that
moves the cursor - ldd 2,x
- jsr LCD_OutFix Your function that
outputs a fixed-point
42LCD demo