1 of 25

EE 319K�Introduction to Embedded Systems

Lecture 9b: Decimal to ASCII conversion, Recursion, Busy-wait, and LCD interfacing

Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari

9-1

2 of 25

Agenda

Review

  • Local variables with binding
  • Stack frames

Agenda

  • Decimal to ASCII conversion
  • Recursion (EE319H)
  • Busy-wait
  • LCD Interfacing

Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari

9-2

3 of 25

Output

Output an integer.

Assume integer, n, is between 0 and 9999.

1) LCD_OutChar(0x30+n/1000) ;thousand’s digit

2) n = n%1000�3) LCD_OutChar(0x30+n/100) ;hundred’s digit

4) n = n%100�5) LCD_OutChar(0x30+n/10) ;ten’s digit

6) LCD_OutChar(0x30+n%10) ;one’s digit

Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari

This is not the solution to Lab 7 because 42 is output as “0042”

9-3

4 of 25

Output Fixed point

Output a fixed-point decimal number.

Assume the integer part of the fixed-point number, n, is between 0 and 999, and resolution is 0.01.

1) LCD_OutChar(0x30+n/100) //one’s digit

2) n = n%100�3) LCD_OutChar(0x2E) //decimal point

4) LCD_OutChar(0x30+n/10) //tenth’s digit

5) n = n%10�6) LCD_OutChar(0x30+n) //hundredth’s digit

Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari

This is not the solution to Lab 7 because 42 is output as “0.042”

9-4

5 of 25

Decimal to ASCII

9-5

6 of 25

Decimal to ASCII

9-6

7 of 25

Decimal to ASCII

9-7

8 of 25

Recursion using the stack (EE319H)

; Input R0 is n

; Output R0 is return value

n EQU 0 ;input parameter

Fact PUSH {R0,LR}

CMP R0,#1

BLS base

SUB R0,#1 ;n-1

BL Fact ;Fact(n-1)

LDR R1,[SP,#n]

MUL R0,R0,R1 ;n*Fact(n-1)

B done

base MOV R0,#1

done ADD SP,#4 ;deallocate

POP {PC}

uint32_t Fact(uint32_t n) {

if(n<=1) return 1;

return n*fact(n-1);

}

Recursion requires putting parameters and locals on the stack

Bard, Cuevas, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Tiwari

9-8

9 of 25

Recursive Solution (EE319H)

9-9

10 of 25

Recursive Solution (EE319H)

9-10

11 of 25

Recursive Solution (EE319H)

9-11

12 of 25

Input/Output Synchronization

  • 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

Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari

9-12

13 of 25

Input/Output Sync. (cont.)

INPUT

OUTPUT

Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari

9-13

14 of 25

What to do while the peripheral is BUSY?

    • BLIND CYCLE TRANSFER
      • Suppose that a BUSY control signal is not available
      • Perform I/O operation
      • Wait for a period of time that is guaranteed to be sufficient for operation to complete
      • Initiate next operation

I/O Sync Options (1)

Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari

9-14

15 of 25

What to do while the peripheral is BUSY?

    • BUSY-WAIT (e.g., ready-busy, test-transfer)
      • Poll peripheral status – wait for READY/NOT BUSY
      • Perform other tasks between polls
      • Unless timed correctly, under/over run possible
        • One solution: POLL CONTINUOUSLY

I/O Sync Options (2)

Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari

9-15

16 of 25

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 changes context when current transfer complete
        • Requires program structure to process context change

I/O Sync Options (3)

Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari

9-16

17 of 25

Latency (EE319H)

  • Software latency or interface latency
    • Time from when new input is ready until time software reads data.
    • Time from when output is idle until time software writes new data.
    • Execute tasks at periodic intervals, latency is delay from when it should run until it does run
  • Interrupts guarantee an upper bound on the software response time
    • Count maximum time running with I=1, plus
    • Time to process the interrupt.

Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari

9-17

18 of 25

Real-Time System (EE319H)

  • Real-time system
    • a system that can guarantee a worst case latency
  • Throughput/bandwidth
    • maximum data flow (bytes/s) that can be processed by the system
  • Priority
    • determines the order of service among two or more requests

Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari

9-18

19 of 25

I/O Sync Options (EE319H)

What to do while the peripheral is BUSY?

    • DIRECT MEMORY ACCESS TRANSFER
      • Special purpose hardware logic monitors status of BUSY signal and maintains addresses of data to be communicated
        • Requires address and block size initialization
      • On the condition of NOT BUSY logic communicates next data element and increments address
      • When transfer is complete, logic provides COMPLETE INTERRUPT

Our TM4C123 supports DMA (but EE319K doesn’t use it)

Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari

9-19

20 of 25

Sitronix ST7735 LCD

  • Resolution: widthxheight of 128x160 pixels
  • 1.8” TFT LCD display with 18-bits per pixel
  • On-chip Display Data RAM 128x160x18bits
  • Device driver library ST7735.c provided to you – Implements the SPI protocol
  • Interfaced using the SPI protocol with 8 wires
  • Built-in micro-SD card for storage with 2 more wires

Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari

9-20

21 of 25

// pin 10 Backlight +3.3 V

// pin 9 MISO unconnected

// pin 8 SCK PA2 (SSI0Clk)

// pin 7 MOSI PA5 (SSI0Tx)

// pin 6 TFT_CS PA3 (SSI0Fss)

// pin 5 CARD_CS unconnected

// pin 4 D/C PA6 (GPIO)

// pin 3 RESET PA7 (GPIO)

// pin 2 VCC +3.3 V

// pin 1 Gnd ground

Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari

Interface to Launchpad

Note: if your ST7735 display doesn’t look exactly like this,

see the comments in ST7735.c to find how to connect it to the TM4C123.

D/C High for Data , Low for Command

9-21

22 of 25

Module Call Graph

ST7735

LCD

Low-level

main

Print

IO

writedata

writecommand

LCD_OutDec

LCD_OutFix

ST7735_OutChar

ST7735_OutString

Lab7Main.s

Print.s

ST7735.c

LCD.s

IO.s

IO_Init

IO_Touch

IO_Heartbeat

Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari

9-22

23 of 25

LCD Programming

writecommand: Involves 6 steps performed to send 8-bit Commands to the LCD

  1. Read SSI0_SR_R and check bit 4,
  2. If bit 4 is high, loop back to step 1
    • wait for BUSY bit to be low
  3. Clear D/C=PA6 to zero
    • (D/C pin configured for COMMAND)
  4. Write the command to SSI0_DR_R
  5. Read SSI0_SR_R and check bit 4,
  6. If bit 4 is high loop back to step 5
    • (wait for BUSY bit to be low)

Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari

Think about what happens when you output multiple commands one right after another?

9-23

24 of 25

LCD Programming

writedata: Involves 4 steps performed to send 8-bit data to the LCD:

  1. Read SSI0_SR_R and check bit 1,
  2. If bit 1 is low, loop back to step 1
    • (wait for TNF bit to be one)
  3. Set D/C=PA6 to one
    • (D/C pin configured for DATA)
  4. Write the 8-bit data to SSI0_DR_R

Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari

Think about what happens when you output multiple data one right after another?

9-24

25 of 25

LCD – Lab7

  • Lab assignment
    • Interface LCD to TI board
    • Develop device driver to serve as interface between TM4C123 and ST7735R display
    • Write the modules you are responsible for
    • Test on Simulator first
    • Build circuit and test on real board

Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari

9-25