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
Agenda
Review
Agenda
Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari
9-2
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
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
Decimal to ASCII
9-5
Decimal to ASCII
9-6
Decimal to ASCII
9-7
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
Recursive Solution (EE319H)
9-9
Recursive Solution (EE319H)
9-10
Recursive Solution (EE319H)
9-11
Input/Output Synchronization
Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari
9-12
Input/Output Sync. (cont.)
INPUT
OUTPUT
Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari
9-13
What to do while the peripheral is BUSY?
I/O Sync Options (1)
Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari
9-14
What to do while the peripheral is BUSY?
I/O Sync Options (2)
Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari
9-15
What to do while the peripheral is BUSY?
I/O Sync Options (3)
Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari
9-16
Latency (EE319H)
Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari
9-17
Real-Time System (EE319H)
Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari
9-18
I/O Sync Options (EE319H)
What to do while the peripheral is BUSY?
Our TM4C123 supports DMA (but EE319K doesn’t use it)
Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari
9-19
Sitronix ST7735 LCD
Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari
9-20
// 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
Module Call Graph
ST7735
LCD
Low-level
main
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
LCD Programming
writecommand: Involves 6 steps performed to send 8-bit Commands to the LCD
Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari
Think about what happens when you output multiple commands one right after another?
9-23
LCD Programming
writedata: Involves 4 steps performed to send 8-bit data to the LCD:
Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari
Think about what happens when you output multiple data one right after another?
9-24
LCD – Lab7
Bard, Cuevas, Erez, Gerstlauer, Holt, Valvano, Yerraballi, Telang, Tiwari
9-25