SlideShare a Scribd company logo
1 of 7
Download to read offline
AENG 505 – INTRO TO EMBEDDED SYSTEMS
Dr. Jaerock Kwon
Experiment-2
GPIO, LED Interface, Functions
Nipun Kumar – 31440148
Objectives:
● To gain experience with the ARM Assembly and the TI TIVA C Launchpad Development
Board.
● To gain experience the CCS ARM development environment and debugging features.
● To gain experience writing subroutines and passing parameters.
● To gain experience with software delay loops and generating square waves, flashing LED.
● To gain experience with general purpose input/output (GPIO) subsystem initialization.
Experiment Result:
Q1) After installation of CCS, Exp1 starter project is imported and built for any errors.
Later it is flashed to the controller and observed that blue LED starts blinking and turns
off after 1 second. By changing the code in LoopBlue, it is observed that blinking pattern
can be delayed by adding more delay functions.
Ans: To set Pin0 off in Port D, first bit in GPIO_PORTD_DATA_R has to be set to 0. AND
Op code is used to perform bit wise AND operation for GPIO_PORTD_DATA_R value and
0xFE ( first bit is 0 and remaining all are ones). All other seven-bit values are restored except
for first bit which becomes 0. Subroutine PortD_Pin0_Off is exported from Port D.asm file
and imported in main.asm file before accessing.
;------------PortD_Pin0_Off------
; Turn off the Port D Pin 0 without changing other pin values
; Input: None
; Output: None
; Modifies: R0, R1
PortD_Pin0_Off: .asmfunc
LDR R1, GPIO_PORTD_DATA_R ; R1 = &GPIO_PORTD_DATA_R
LDR R0, [R1] ; R0 = [R1]
AND R0, R0, #0xFE ; R0 = R0 & 0xFE set pin_0 to 0
STR R0, [R1] ; [R1] = R0
BX LR
.endasmfunc
• After subroutine PortD_Pin0_On:
• After subroutine PortD_Pin0_Off:
Q2) Show and discuss your green_led_toggle function. This function should only
manipulate the green LED pin and leave other Port F pins as they were.
Ans: Green LED is hardwired to fourth pin in port F. To toggle the LED on and off, fourth bit
value in GPIO_PORTF_DATA_R address must be changed from 0 to 1 and vice versa. So, bit
wise XOR operation is done with Port F data and 0x08 (fourth bit is 1) as operand to change
the fourth bit value. Subroutine code is shown below. R1 register stores the address of
GPIO_PORTF_DATA_R and R0 register is used to store its value and perform XOR operation.
Register bit Operand bit After XOR operation
1 1 0(~ Register bit=1)
0 1 1(~ Register bit=0)
;------------green_led_toggle------
; Change the green Led light from on to off and vice versa
; Input: None
; Output: None
; Modifies: R0, R1
green_led_toggle: .asmfunc
LDR R1, GPIO_PORTF_DATA_R ; R1 = &GPIO_PORTF_DATA_R
LDR R0, [R1] ; R0 = [R1]
EOR R0, R0, #0x08 ; R0 = R0 XOR 0x08 changes the
4th bit(Green LED) value from 0 to 1 and vice versa
STR R0, [R1] ; [R1] = R0
BX LR
.endasmfunc
Q3) Show and describe how you implemented your subroutine and the mechanism you
used to pass the input parameters to it. Also describe how the CPU registers are affected
by your subroutine.
Ans:
• Firstly, the address in LR, which is the next line after calling timed_green_led_toggle
subroutine in main code, must be stored in stack to remember the address. This is needed
as there are multiple functions called inside a function using BL Op code. R13 register
(Stack pointer) is modified by using push operation code.
• Green LED is toggled by calling the function green_led_toggle, which acts as an on/off
switch for green LED. R0 and R1 registers are modified to perform the toggle operation
as explained above.
• By calling the delay function, green LED condition is retained for stored delay time in R10
register. At the end of delay function, R10 register value becomes 0.
• Address stored in the stack is popped back into the Link register using POP op code to
execute the next code in main block. R13 register( Stack pointer) is modified.
;------------timed_green_led_toggle------
; Toggles the green Led light based on inputted delay time in R10 register
; Input: R10 in delay subroutine
; Output: None
; Modifies: None
timed_green_led_toggle: .asmfunc
PUSH {LR} ; Push the next address in LR into stack
BL green_led_toggle ; Toggles the green LED on or off
BL delay ; Delays the green LED in on or off
condition for time stored in R10
POP {LR} ; Restores the initially saved address
back to LR from stack
BX LR ; Go to the address in LR i.e., the
B Mainloop in main
.endasmfunc
Q3) Next, write a program in main that calls your subroutine to flash the green LED at
two different rates based on whether switch 1 pressed or not:
- Left button (SW1) not pressed: green LED flashes at a rate of once per second. On for
one second off for one second then the sequence repeats as long as the button is not
pressed.
- LEFT button pressed: green LED flashes at a rate of 10 times per second. On for one
0.1 second off for 0.1 second then the sequence repeats as long as the button is pressed.
Ans:
• SW1 is hardwired to pin 5 of port F. Switches are connected using negative logic which
sets the fifth bit to 0 when pressed, else to 1.
• So, to check whether SW1 is pressed or not AND op code is used to perform bit wise
AND with port F data and 0x10. The result will set the Z bit when switch is pressed
else no.
When SW1 is pressed When SW1 is not pressed
Port F data (first 8 bits) ---0---- ---1----
0x10 00010000 00010000
AND operation result 00000000 00010000
Z bit 1 0
• BEQ op code is used to go to else loop when Z bit is set, or else next set of code is
executed.
• R10 value is set to ONESEC when Z bit is not set i.e., when SW1 is not pressed. Then
timed_green_led_toggle subroutine is executed with saved R10 value.
• R10 value is set to POINTONESEC in Else loop when Z bit is set i.e., when SW1 is
pressed. Then timed_green_led_toggle subroutine is executed with saved R10 value.
MainLoop
LDR R1, GPIO_PORTF_DATA_R ; R1 = &GPIO_PORTF_DATA_R
LDR R0, [R1] ;R0 = [R1]
MOV R3, #0x10 ; R3 = #0x10
ANDS R3, R0 ; R3 = R3 & #0x10 which sets all other bits to
zero except the fifth and sets the Z bit when
switch is pressed else not
BEQ Else ;Go to else loop if Z bit is set
LDR R10, ONESEC ; R10 = 5333333,32 value for 1 sec delay
BL timed_green_led_toggle ; Go to timed_green_led_toggle subroutine
B MainLoop ; Go to MainLoop and repeat
;Else block to be executed when SW1 is pressed i.e., when Z bit is set
Else
LDR R10, POINTONESEC ; R10 = 533333,32 value for 0.1 sec delay
BL timed_green_led_toggle ; Go to timed_green_led_toggle subroutine
B MainLoop ; Go to MainLoop and repeat
.endasmfunc
Q4) Record a brief video demonstrating this program.
https://youtu.be/8B6D2RfFwzo
Conclusion:
• In this experiment, initialization of GPIO port D and F is done and specific pins inside
a GPIO can be set as on or off using subroutines written in different assembly files by
import and export. With this, we can connect the specific ports after initialization as
above, to external components either as input or output.
• By using conditional branching based on SW1 input, blinking pattern of green LED
output is varied with the help of nested subroutines and stack pointer. The similar
function is achieved using If else logic in high level languages.
• The importance of Link register and stack pointer is understood with the usage of
multiple BL op codes inside a single subroutine. Initial address in LR, while calling
first subroutine, is stored inside stack pointer to return to the same address at the end of
subroutine.
• In this experiment, it is not possible to call delay subroutine multiple times without
restoring the R10 register value. This is because delay function takes R10 as input and
makes it 0 when it is completed.
• When multiple push is done inside the stack pointer, program seems to enter an infinite
loop after the second push operation.

More Related Content

What's hot

What's hot (20)

Curso Formacion Apache Solr
Curso Formacion Apache SolrCurso Formacion Apache Solr
Curso Formacion Apache Solr
 
Std 10 computer chapter 9 Problems and Problem Solving
Std 10 computer chapter 9 Problems and Problem SolvingStd 10 computer chapter 9 Problems and Problem Solving
Std 10 computer chapter 9 Problems and Problem Solving
 
Back patching
Back patchingBack patching
Back patching
 
Lex & yacc
Lex & yaccLex & yacc
Lex & yacc
 
Understanding storage class using nm
Understanding storage class using nmUnderstanding storage class using nm
Understanding storage class using nm
 
Lecture Note-1: Algorithm and Its Properties
Lecture Note-1: Algorithm and Its PropertiesLecture Note-1: Algorithm and Its Properties
Lecture Note-1: Algorithm and Its Properties
 
Advanced Programming C++
Advanced Programming C++Advanced Programming C++
Advanced Programming C++
 
Spr ch-02
Spr ch-02Spr ch-02
Spr ch-02
 
Big omega
Big omegaBig omega
Big omega
 
Programming Methodology
Programming MethodologyProgramming Methodology
Programming Methodology
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
debugging - system software
debugging - system softwaredebugging - system software
debugging - system software
 
C# Lab Programs.pdf
C# Lab Programs.pdfC# Lab Programs.pdf
C# Lab Programs.pdf
 
PL SQL Quiz | PL SQL Examples
PL SQL Quiz |  PL SQL ExamplesPL SQL Quiz |  PL SQL Examples
PL SQL Quiz | PL SQL Examples
 
Algorithm and c language
Algorithm and c languageAlgorithm and c language
Algorithm and c language
 
Print input-presentation
Print input-presentationPrint input-presentation
Print input-presentation
 
Buttons In .net Visual Basic
Buttons In .net Visual BasicButtons In .net Visual Basic
Buttons In .net Visual Basic
 
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdfMANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
 
358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
 

Similar to Gain Experience with GPIO, LED Interface and Functions in TI TIVA C Launchpad Development Board.

EMBEDDED SYSTEMS 5
EMBEDDED SYSTEMS 5EMBEDDED SYSTEMS 5
EMBEDDED SYSTEMS 5
PRADEEP
 
Digital Alarm Clock 446 project report
Digital Alarm Clock 446 project reportDigital Alarm Clock 446 project report
Digital Alarm Clock 446 project report
Akash Mhankale
 
Applications of microcontroller(8051)
Applications of microcontroller(8051) Applications of microcontroller(8051)
Applications of microcontroller(8051)
vijaydeepakg
 

Similar to Gain Experience with GPIO, LED Interface and Functions in TI TIVA C Launchpad Development Board. (20)

Input-Output Interfacing for LED and Switch
Input-Output Interfacing for LED and SwitchInput-Output Interfacing for LED and Switch
Input-Output Interfacing for LED and Switch
 
8051 MMD Chapter 1.ppt
8051 MMD Chapter 1.ppt8051 MMD Chapter 1.ppt
8051 MMD Chapter 1.ppt
 
COA Module 3 PART 2.pptx
COA Module 3 PART 2.pptxCOA Module 3 PART 2.pptx
COA Module 3 PART 2.pptx
 
Vlsi es-lab-manual
Vlsi es-lab-manualVlsi es-lab-manual
Vlsi es-lab-manual
 
ESD Lab1
ESD Lab1ESD Lab1
ESD Lab1
 
8051.pdf
8051.pdf8051.pdf
8051.pdf
 
Hardware interfacing basics using AVR
Hardware interfacing basics using AVRHardware interfacing basics using AVR
Hardware interfacing basics using AVR
 
input
inputinput
input
 
EMBEDDED SYSTEMS 5
EMBEDDED SYSTEMS 5EMBEDDED SYSTEMS 5
EMBEDDED SYSTEMS 5
 
Anup2
Anup2Anup2
Anup2
 
Interfacing with Atmega 16
Interfacing with Atmega 16Interfacing with Atmega 16
Interfacing with Atmega 16
 
Dsp Datapath
Dsp DatapathDsp Datapath
Dsp Datapath
 
SE PAI Unit 5_IO programming in 8051
SE PAI Unit 5_IO programming in 8051SE PAI Unit 5_IO programming in 8051
SE PAI Unit 5_IO programming in 8051
 
Instruction set
Instruction setInstruction set
Instruction set
 
8051 FINIAL
8051 FINIAL8051 FINIAL
8051 FINIAL
 
Analog to Digital Converter
Analog to Digital ConverterAnalog to Digital Converter
Analog to Digital Converter
 
Basic computer organisation design
Basic computer organisation designBasic computer organisation design
Basic computer organisation design
 
Digital Alarm Clock 446 project report
Digital Alarm Clock 446 project reportDigital Alarm Clock 446 project report
Digital Alarm Clock 446 project report
 
Dee2034 chapter 6 register
Dee2034 chapter 6 registerDee2034 chapter 6 register
Dee2034 chapter 6 register
 
Applications of microcontroller(8051)
Applications of microcontroller(8051) Applications of microcontroller(8051)
Applications of microcontroller(8051)
 

Recently uploaded

Top profile Call Girls In Thrissur [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Thrissur [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Thrissur [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Thrissur [ 7014168258 ] Call Me For Genuine Models ...
nirzagarg
 
John Deere Tractors 5415 Diagnostic Repair Service Manual.pdf
John Deere Tractors 5415 Diagnostic Repair Service Manual.pdfJohn Deere Tractors 5415 Diagnostic Repair Service Manual.pdf
John Deere Tractors 5415 Diagnostic Repair Service Manual.pdf
Excavator
 
+97470301568>>buy vape oil,thc oil weed,hash and cannabis oil in qatar doha}}
+97470301568>>buy vape oil,thc oil weed,hash and cannabis oil in qatar doha}}+97470301568>>buy vape oil,thc oil weed,hash and cannabis oil in qatar doha}}
+97470301568>>buy vape oil,thc oil weed,hash and cannabis oil in qatar doha}}
Health
 
一比一原版(Greenwich毕业证书)格林威治大学毕业证如何办理
一比一原版(Greenwich毕业证书)格林威治大学毕业证如何办理一比一原版(Greenwich毕业证书)格林威治大学毕业证如何办理
一比一原版(Greenwich毕业证书)格林威治大学毕业证如何办理
bd2c5966a56d
 
如何办理伦敦商学院毕业证(LBS毕业证)毕业证成绩单原版一比一
如何办理伦敦商学院毕业证(LBS毕业证)毕业证成绩单原版一比一如何办理伦敦商学院毕业证(LBS毕业证)毕业证成绩单原版一比一
如何办理伦敦商学院毕业证(LBS毕业证)毕业证成绩单原版一比一
avy6anjnd
 
如何办理莱斯大学毕业证(Rice毕业证)毕业证成绩单原版一比一
如何办理莱斯大学毕业证(Rice毕业证)毕业证成绩单原版一比一如何办理莱斯大学毕业证(Rice毕业证)毕业证成绩单原版一比一
如何办理莱斯大学毕业证(Rice毕业证)毕业证成绩单原版一比一
avy6anjnd
 
如何办理多伦多大学毕业证(UofT毕业证书)成绩单原版一比一
如何办理多伦多大学毕业证(UofT毕业证书)成绩单原版一比一如何办理多伦多大学毕业证(UofT毕业证书)成绩单原版一比一
如何办理多伦多大学毕业证(UofT毕业证书)成绩单原版一比一
opyff
 
如何办理新西兰林肯大学毕业证(Lincoln毕业证书)成绩单原版一比一
如何办理新西兰林肯大学毕业证(Lincoln毕业证书)成绩单原版一比一如何办理新西兰林肯大学毕业证(Lincoln毕业证书)成绩单原版一比一
如何办理新西兰林肯大学毕业证(Lincoln毕业证书)成绩单原版一比一
opyff
 
Top profile Call Girls In Ranchi [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Ranchi [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Ranchi [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Ranchi [ 7014168258 ] Call Me For Genuine Models We...
gajnagarg
 
Top profile Call Girls In Darbhanga [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Darbhanga [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Darbhanga [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Darbhanga [ 7014168258 ] Call Me For Genuine Models...
nirzagarg
 
Abortion pills Dubai (+918133066128) Cytotec 200mg pills UAE Abudhabi
Abortion pills Dubai (+918133066128) Cytotec 200mg pills UAE AbudhabiAbortion pills Dubai (+918133066128) Cytotec 200mg pills UAE Abudhabi
Abortion pills Dubai (+918133066128) Cytotec 200mg pills UAE Abudhabi
Abortion pills in Kuwait Cytotec pills in Kuwait
 

Recently uploaded (20)

Top profile Call Girls In Thrissur [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Thrissur [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Thrissur [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Thrissur [ 7014168258 ] Call Me For Genuine Models ...
 
Electronic Stability Program. (ESP).pptx
Electronic Stability Program. (ESP).pptxElectronic Stability Program. (ESP).pptx
Electronic Stability Program. (ESP).pptx
 
Nangloi Jat Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nangloi Jat
Nangloi Jat Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nangloi JatNangloi Jat Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nangloi Jat
Nangloi Jat Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nangloi Jat
 
JOHN DEERE 7200R 7215R 7230R 7260R 7280R TECHNICAL SERVICE PDF MANUAL 2680PGS...
JOHN DEERE 7200R 7215R 7230R 7260R 7280R TECHNICAL SERVICE PDF MANUAL 2680PGS...JOHN DEERE 7200R 7215R 7230R 7260R 7280R TECHNICAL SERVICE PDF MANUAL 2680PGS...
JOHN DEERE 7200R 7215R 7230R 7260R 7280R TECHNICAL SERVICE PDF MANUAL 2680PGS...
 
John Deere Tractors 5415 Diagnostic Repair Service Manual.pdf
John Deere Tractors 5415 Diagnostic Repair Service Manual.pdfJohn Deere Tractors 5415 Diagnostic Repair Service Manual.pdf
John Deere Tractors 5415 Diagnostic Repair Service Manual.pdf
 
+97470301568>>buy vape oil,thc oil weed,hash and cannabis oil in qatar doha}}
+97470301568>>buy vape oil,thc oil weed,hash and cannabis oil in qatar doha}}+97470301568>>buy vape oil,thc oil weed,hash and cannabis oil in qatar doha}}
+97470301568>>buy vape oil,thc oil weed,hash and cannabis oil in qatar doha}}
 
Washim Call Girls 📞9332606886 Call Girls in Washim Escorts service book now C...
Washim Call Girls 📞9332606886 Call Girls in Washim Escorts service book now C...Washim Call Girls 📞9332606886 Call Girls in Washim Escorts service book now C...
Washim Call Girls 📞9332606886 Call Girls in Washim Escorts service book now C...
 
Muslim Call Girls Churchgate WhatsApp +91-9930687706, Best Service
Muslim Call Girls Churchgate WhatsApp +91-9930687706, Best ServiceMuslim Call Girls Churchgate WhatsApp +91-9930687706, Best Service
Muslim Call Girls Churchgate WhatsApp +91-9930687706, Best Service
 
一比一原版(Greenwich毕业证书)格林威治大学毕业证如何办理
一比一原版(Greenwich毕业证书)格林威治大学毕业证如何办理一比一原版(Greenwich毕业证书)格林威治大学毕业证如何办理
一比一原版(Greenwich毕业证书)格林威治大学毕业证如何办理
 
如何办理伦敦商学院毕业证(LBS毕业证)毕业证成绩单原版一比一
如何办理伦敦商学院毕业证(LBS毕业证)毕业证成绩单原版一比一如何办理伦敦商学院毕业证(LBS毕业证)毕业证成绩单原版一比一
如何办理伦敦商学院毕业证(LBS毕业证)毕业证成绩单原版一比一
 
Effortless Driving Experience Premier Mercedes Sprinter Suspension Service
Effortless Driving Experience Premier Mercedes Sprinter Suspension ServiceEffortless Driving Experience Premier Mercedes Sprinter Suspension Service
Effortless Driving Experience Premier Mercedes Sprinter Suspension Service
 
Vip Begusarai Escorts Service Girl ^ 9332606886, WhatsApp Anytime Begusarai
Vip Begusarai Escorts Service Girl ^ 9332606886, WhatsApp Anytime BegusaraiVip Begusarai Escorts Service Girl ^ 9332606886, WhatsApp Anytime Begusarai
Vip Begusarai Escorts Service Girl ^ 9332606886, WhatsApp Anytime Begusarai
 
如何办理莱斯大学毕业证(Rice毕业证)毕业证成绩单原版一比一
如何办理莱斯大学毕业证(Rice毕业证)毕业证成绩单原版一比一如何办理莱斯大学毕业证(Rice毕业证)毕业证成绩单原版一比一
如何办理莱斯大学毕业证(Rice毕业证)毕业证成绩单原版一比一
 
如何办理多伦多大学毕业证(UofT毕业证书)成绩单原版一比一
如何办理多伦多大学毕业证(UofT毕业证书)成绩单原版一比一如何办理多伦多大学毕业证(UofT毕业证书)成绩单原版一比一
如何办理多伦多大学毕业证(UofT毕业证书)成绩单原版一比一
 
Bhilai Escorts Service Girl ^ 8250092165, WhatsApp Anytime Bhilai
Bhilai Escorts Service Girl ^ 8250092165, WhatsApp Anytime BhilaiBhilai Escorts Service Girl ^ 8250092165, WhatsApp Anytime Bhilai
Bhilai Escorts Service Girl ^ 8250092165, WhatsApp Anytime Bhilai
 
SEM 922 MOTOR GRADER PARTS LIST, ALL WHEEL DRIVE
SEM 922 MOTOR GRADER PARTS LIST, ALL WHEEL DRIVESEM 922 MOTOR GRADER PARTS LIST, ALL WHEEL DRIVE
SEM 922 MOTOR GRADER PARTS LIST, ALL WHEEL DRIVE
 
如何办理新西兰林肯大学毕业证(Lincoln毕业证书)成绩单原版一比一
如何办理新西兰林肯大学毕业证(Lincoln毕业证书)成绩单原版一比一如何办理新西兰林肯大学毕业证(Lincoln毕业证书)成绩单原版一比一
如何办理新西兰林肯大学毕业证(Lincoln毕业证书)成绩单原版一比一
 
Top profile Call Girls In Ranchi [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Ranchi [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Ranchi [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Ranchi [ 7014168258 ] Call Me For Genuine Models We...
 
Top profile Call Girls In Darbhanga [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Darbhanga [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Darbhanga [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Darbhanga [ 7014168258 ] Call Me For Genuine Models...
 
Abortion pills Dubai (+918133066128) Cytotec 200mg pills UAE Abudhabi
Abortion pills Dubai (+918133066128) Cytotec 200mg pills UAE AbudhabiAbortion pills Dubai (+918133066128) Cytotec 200mg pills UAE Abudhabi
Abortion pills Dubai (+918133066128) Cytotec 200mg pills UAE Abudhabi
 

Gain Experience with GPIO, LED Interface and Functions in TI TIVA C Launchpad Development Board.

  • 1. AENG 505 – INTRO TO EMBEDDED SYSTEMS Dr. Jaerock Kwon Experiment-2 GPIO, LED Interface, Functions Nipun Kumar – 31440148
  • 2. Objectives: ● To gain experience with the ARM Assembly and the TI TIVA C Launchpad Development Board. ● To gain experience the CCS ARM development environment and debugging features. ● To gain experience writing subroutines and passing parameters. ● To gain experience with software delay loops and generating square waves, flashing LED. ● To gain experience with general purpose input/output (GPIO) subsystem initialization. Experiment Result: Q1) After installation of CCS, Exp1 starter project is imported and built for any errors. Later it is flashed to the controller and observed that blue LED starts blinking and turns off after 1 second. By changing the code in LoopBlue, it is observed that blinking pattern can be delayed by adding more delay functions. Ans: To set Pin0 off in Port D, first bit in GPIO_PORTD_DATA_R has to be set to 0. AND Op code is used to perform bit wise AND operation for GPIO_PORTD_DATA_R value and 0xFE ( first bit is 0 and remaining all are ones). All other seven-bit values are restored except for first bit which becomes 0. Subroutine PortD_Pin0_Off is exported from Port D.asm file and imported in main.asm file before accessing. ;------------PortD_Pin0_Off------ ; Turn off the Port D Pin 0 without changing other pin values ; Input: None ; Output: None ; Modifies: R0, R1 PortD_Pin0_Off: .asmfunc LDR R1, GPIO_PORTD_DATA_R ; R1 = &GPIO_PORTD_DATA_R LDR R0, [R1] ; R0 = [R1] AND R0, R0, #0xFE ; R0 = R0 & 0xFE set pin_0 to 0 STR R0, [R1] ; [R1] = R0 BX LR .endasmfunc
  • 3. • After subroutine PortD_Pin0_On: • After subroutine PortD_Pin0_Off: Q2) Show and discuss your green_led_toggle function. This function should only manipulate the green LED pin and leave other Port F pins as they were. Ans: Green LED is hardwired to fourth pin in port F. To toggle the LED on and off, fourth bit value in GPIO_PORTF_DATA_R address must be changed from 0 to 1 and vice versa. So, bit wise XOR operation is done with Port F data and 0x08 (fourth bit is 1) as operand to change
  • 4. the fourth bit value. Subroutine code is shown below. R1 register stores the address of GPIO_PORTF_DATA_R and R0 register is used to store its value and perform XOR operation. Register bit Operand bit After XOR operation 1 1 0(~ Register bit=1) 0 1 1(~ Register bit=0) ;------------green_led_toggle------ ; Change the green Led light from on to off and vice versa ; Input: None ; Output: None ; Modifies: R0, R1 green_led_toggle: .asmfunc LDR R1, GPIO_PORTF_DATA_R ; R1 = &GPIO_PORTF_DATA_R LDR R0, [R1] ; R0 = [R1] EOR R0, R0, #0x08 ; R0 = R0 XOR 0x08 changes the 4th bit(Green LED) value from 0 to 1 and vice versa STR R0, [R1] ; [R1] = R0 BX LR .endasmfunc Q3) Show and describe how you implemented your subroutine and the mechanism you used to pass the input parameters to it. Also describe how the CPU registers are affected by your subroutine. Ans: • Firstly, the address in LR, which is the next line after calling timed_green_led_toggle subroutine in main code, must be stored in stack to remember the address. This is needed as there are multiple functions called inside a function using BL Op code. R13 register (Stack pointer) is modified by using push operation code. • Green LED is toggled by calling the function green_led_toggle, which acts as an on/off switch for green LED. R0 and R1 registers are modified to perform the toggle operation as explained above.
  • 5. • By calling the delay function, green LED condition is retained for stored delay time in R10 register. At the end of delay function, R10 register value becomes 0. • Address stored in the stack is popped back into the Link register using POP op code to execute the next code in main block. R13 register( Stack pointer) is modified. ;------------timed_green_led_toggle------ ; Toggles the green Led light based on inputted delay time in R10 register ; Input: R10 in delay subroutine ; Output: None ; Modifies: None timed_green_led_toggle: .asmfunc PUSH {LR} ; Push the next address in LR into stack BL green_led_toggle ; Toggles the green LED on or off BL delay ; Delays the green LED in on or off condition for time stored in R10 POP {LR} ; Restores the initially saved address back to LR from stack BX LR ; Go to the address in LR i.e., the B Mainloop in main .endasmfunc Q3) Next, write a program in main that calls your subroutine to flash the green LED at two different rates based on whether switch 1 pressed or not: - Left button (SW1) not pressed: green LED flashes at a rate of once per second. On for one second off for one second then the sequence repeats as long as the button is not pressed. - LEFT button pressed: green LED flashes at a rate of 10 times per second. On for one 0.1 second off for 0.1 second then the sequence repeats as long as the button is pressed. Ans: • SW1 is hardwired to pin 5 of port F. Switches are connected using negative logic which sets the fifth bit to 0 when pressed, else to 1. • So, to check whether SW1 is pressed or not AND op code is used to perform bit wise AND with port F data and 0x10. The result will set the Z bit when switch is pressed else no.
  • 6. When SW1 is pressed When SW1 is not pressed Port F data (first 8 bits) ---0---- ---1---- 0x10 00010000 00010000 AND operation result 00000000 00010000 Z bit 1 0 • BEQ op code is used to go to else loop when Z bit is set, or else next set of code is executed. • R10 value is set to ONESEC when Z bit is not set i.e., when SW1 is not pressed. Then timed_green_led_toggle subroutine is executed with saved R10 value. • R10 value is set to POINTONESEC in Else loop when Z bit is set i.e., when SW1 is pressed. Then timed_green_led_toggle subroutine is executed with saved R10 value. MainLoop LDR R1, GPIO_PORTF_DATA_R ; R1 = &GPIO_PORTF_DATA_R LDR R0, [R1] ;R0 = [R1] MOV R3, #0x10 ; R3 = #0x10 ANDS R3, R0 ; R3 = R3 & #0x10 which sets all other bits to zero except the fifth and sets the Z bit when switch is pressed else not BEQ Else ;Go to else loop if Z bit is set LDR R10, ONESEC ; R10 = 5333333,32 value for 1 sec delay BL timed_green_led_toggle ; Go to timed_green_led_toggle subroutine B MainLoop ; Go to MainLoop and repeat ;Else block to be executed when SW1 is pressed i.e., when Z bit is set Else LDR R10, POINTONESEC ; R10 = 533333,32 value for 0.1 sec delay BL timed_green_led_toggle ; Go to timed_green_led_toggle subroutine B MainLoop ; Go to MainLoop and repeat .endasmfunc Q4) Record a brief video demonstrating this program. https://youtu.be/8B6D2RfFwzo
  • 7. Conclusion: • In this experiment, initialization of GPIO port D and F is done and specific pins inside a GPIO can be set as on or off using subroutines written in different assembly files by import and export. With this, we can connect the specific ports after initialization as above, to external components either as input or output. • By using conditional branching based on SW1 input, blinking pattern of green LED output is varied with the help of nested subroutines and stack pointer. The similar function is achieved using If else logic in high level languages. • The importance of Link register and stack pointer is understood with the usage of multiple BL op codes inside a single subroutine. Initial address in LR, while calling first subroutine, is stored inside stack pointer to return to the same address at the end of subroutine. • In this experiment, it is not possible to call delay subroutine multiple times without restoring the R10 register value. This is because delay function takes R10 as input and makes it 0 when it is completed. • When multiple push is done inside the stack pointer, program seems to enter an infinite loop after the second push operation.