Instructor: Nachiket M' Kharalkar - PowerPoint PPT Presentation

1 / 48
About This Presentation
Title:

Instructor: Nachiket M' Kharalkar

Description:

LCD Liquid Crystal Display. Operation (cont.) Interface to HD44780. Employ 4-bit data mode ... Develop device driver to serve as interface between 6812 and HD 44780 ... – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 49
Provided by: nachiketk
Category:

less

Transcript and Presenter's Notes

Title: Instructor: Nachiket M' Kharalkar


1
Introduction to Microcontrollers
  • Instructor Nachiket M. Kharalkar
  •  
  • Lecture 13
  • Date 07/02/2007
  • E-mail knachike_at_ece.utexas.edu
  •  

2
Todays Agenda
  • No class on 7/4/2007 7/6/2007
  • Recap
  • LCD demo
  • ADC
  • Output compare interrupt

3
LCD Liquid Crystal DisplayOperation (cont.)
  • Interface to HD44780
  • Employ 4-bit data mode
  • Port M0-5
  • Character addresses
  • Left 00 07
  • Right 40 - 47

4
LCD 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

5
LCD 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.

6
LCD 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

7
LCD 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

8
LCD 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

9
LCD 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

10
(No Transcript)
11
(No Transcript)
12
(No Transcript)
13
  • 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

14
LCD_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

15
LCD_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

16
LCD_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

17
LCD_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)
  • 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

18
OutFix
  • 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 ?. ?

19
outCsr
  • 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

20
LCD 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

21
Dialog box for interfacing a simple LCD display
22
(No Transcript)
23
  • 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

24
LCD demo
25
ADC
26
  • ATDCTL20x80 set bit 7 to enable ADC
  • ATDCTL30x08 sequence length1
  • ATDCTL40x01 10-bit, divide by 2
  • ATDCTL5 write channel number to start ADC
  • channel number 80 to 87
  • ATDSTAT bit 7 SCF
  • cleared by write to ATDCTL5
  • set when ADC finished
  • ATDDR0 first 10-bit ADC result

27
(No Transcript)
28
(No Transcript)
29
(No Transcript)
30
(No Transcript)
31
(No Transcript)
32
(No Transcript)
33
  • ATDCTL20x80 set bit 7 to enable ADC
  • ATDCTL30x08 sequence length1
  • ATDCTL40x01 10-bit, divide by 2
  • ATDCTL5 write channel number to start ADC
  • channel number 80 to 87
  • ATDSTAT bit 7 SCF
  • cleared by write to ATDCTL5
  • set when ADC finished
  • ATDDR0 first 10-bit ADC result

34
  • Position resolution is the smallest change in
    position that your system can reliably detect. In
    other words, if the resolution were 0.01 cm and
    the position were to change from 1.00 to 1.01 cm.
    Resolution will depend on the amount of
    electrical noise, the number of ADC bits, and the
    resolution of the output display software.
  • Accuracy is defined as the absolute difference
    between the true position and the value measured
    by your device.

35
  • precision 10-bit, 1024 alternatives
  • range 0 to 5V
  • resolution (5-0)/1024 5 mV
  • Digital Output 1024Vin/5

36
Interrupt
  • An interrupt is the automatic transfer of
    software execution in response to a hardware
    event that is asynchronous with the current
    software execution.
  • The hardware could be external I/O device like
    the SCI input/output or an internal event like
    periodic interrupt

37
Thread
  • A thread is defined as the path of action of
    software as it executes. The execution of the
    interrupt service handler is called a background
    thread.
  • The thread is created by the hardware interrupt
    request and is killed when the interrupt service
    routine executes the rti instruction.
  • A new thread is created for each interrupt
    request.

38
  • sei instruction disables interrupts
  • cli instruction enables interrupts
  • To arm a device means to enable the source of
    interrupts
  • In order for an interrupt to be requested, the
    appropriate flag bit must be armed (ex TIOS for
    OC interrupt)
  • Whenever an interrupt occurs corresponding flag
    is set in the I/O status register (ex C1F for OC
    interrupt)
  • The interrupt service routine must acknowledge or
    disarm the interrupt (ex setting the TFLG1 flag)

39
Interrupts
  • Why
  • Reduce latency in complex system
  • Increase bandwidth in complex system
  • Handle errors, infrequent but important
  • Multithreaded many software functions
  • When
  • Input when new data received
  • Output when device is idle
  • Periodic at a fixed-time interval

40
Types of interrupts
  • Hardware calling software
  • RTI clock (periodic) cause RTIhandler
  • Output compare interrupts
  • RDRF flag call SCIhandler
  • TDRE flag call SCIhandler
  • Key typed -gt run key handler

41
Periodic interrupts
  • Real time interrupt
  • Timer over flow interrupt
  • Output compare interrupt

42
Decreasing order of priority
43
before interrupt after interrupt
44
Registers used to configure periodic interrupts
45
OC interrupt
  • Enable Set TIOS register bits
  • When TCx (x 07) matches TCNT register
    corresponding interrupt occurs
  • TxF flag is set when interrupt occurs
  • Interrupt period defined by TCNT period delay
    added in ISR
  • ISR Acknowledge Set TxF bit
  • Set time for next interrupt

46
Implementation of OC
47
Typical OC handler
  • interrupts every 1000 TCNT cycles
  • every 1ms
  • TC0handler
  • ldd TC0
  • addd 1000
  • std TC0 setp time for next
    interrupt
  • movb 01,TFLG1 acknowledge, clear C0F
  • rti

48
  • RTI.RTF
  • Jonathan W. Valvano 5/1/06
  • test of the RTI system, 6812
  • base clock is OSCCLK250nsec
  • RTR64 Real Time Interrupt Prescale Rate
    Select Bits
  • 000 off
  • 001 divide by 1024
  • 010 divide by 2048
  • 011 divide by 4096
  • 100 divide by 8192
  • 101 divide by 16384
  • 110 divide by 32768
  • 111 divide by 65536
  • RTR30 Real Time Interrupt Modulus Counter
    Select Bits
  • 0000 divide by 1
  • 0001 divide by 2
  • 0010 divide by 3
  • 0011 divide by 4
  • 0100 divide by 5
Write a Comment
User Comments (0)
About PowerShow.com