Arduino/C3/Mixing-Assembly-and-C-programming/English
Visual Cue | Narration |
Slide 1: | Welcome to the Spoken Tutorial on Mixing Assembly and C programming. |
Slide 2:
Learning objectives |
In this tutorial, we will learn to:
|
Slide 3:
Pre-requisites |
To follow this tutorial, you should have basic knowledge of :
|
Slide 4:
System Requirement |
To record this tutorial, I am using:
|
Slide 5:
External Devices |
We also require some external devices such as:
|
Circuit Connections (new-dot-blink.jpg) | The Dot pin of the Seven Segment Display is connected to the pin 13 of the Arduino.
Any one of the common pins is connected to the +5Volts through a resistor. |
Show the real connection
dot-blink-setup.jpeg |
This is the live setup of the connection. |
Now we will write an Assembly routine to perform the initialisation. | |
Open any text editor and type the following. | |
Open text editor | This assembly routine program initialises and sets pin 13 of Arduino as output. |
Highlight according to narration:
#define __SFR_OFFSET 0 #include <avr/io.h> |
Let me explain the code line by line.
This line sets the Special Function Register offset to zero. |
.global init
.section .text |
These two lines make this assembly routine globally accessible.
It enables other programs to use it. |
init:
LDI R16, 0b00100000 OUT DDRB, R16 RET |
Here init is the subroutine name.
These two lines sets pin 13 of Arduino as output. |
Save the file | Save the code as initasm.S in capital in the Downloads folder.
Since this is the subroutine, it is saved as .S extension. |
All codes used in this tutorial are available in the Code Files link of this tutorial.
You can download and use it. | |
Now we will write an AVR-GCC program to call this subroutine and blink the Dot LED. | |
Open text editor | Open any text editor and type the following. |
This code will blink the Dot LED continuously. | |
Highlight according to narration:
#include <avr/io.h> #include <util/delay.h> int main (void) { init (); while(1) { PORTB = ((0 << PB5)); _delay_ms (10000L); PORTB = ((1 << PB5)); _delay_ms (10000L); } return 0; } |
The first line,”init()” calls the Assembly subroutine.
These lines of code alternatively turn the Dot LED on and off causing it to blink. |
Save the code | Save the code as blink.c in the Downloads folder. |
Point to the Makefile | Download the Makefile from the code files link of this tutorial.
Place it in the same folder where blink.c file is saved. |
Open the Makefile | I’ll open the Makefile in text editor. |
Note that this Makefile is different from the one previously used. | |
Highlight the lines in the Makefile | In the Makefile, ensure that “TARGET = blink” and ASRC = “initasm.S”
Here “blink” is the main program and “initasm” is the subroutine. You need to change the filename and subroutine name if you have given a different name. Then save the Makefile. |
Switch to the terminal. | |
Type,
> cd /home/spoken/Downloads > make FNAME = blink |
Go to the folder where blink.c file is saved.
Type, make space FNAME in capital =blink and press Enter. |
Point to the output
dot-blink.mov |
Now you can see that the Dot LED is blinking. |
This brings us to the end of this tutorial. Let us summarize. | |
Slide 6:
Summary |
In this tutorial, we learnt to:
|
Assignment | As an assignment-
|
Slide 7:
About Spoken Tutorial project |
The video at the following link summarizes the Spoken Tutorial project.
Please download and watch it. |
Slide 8:
Spoken Tutorial workshops |
The Spoken Tutorial Project Team:
For more details, please write to us. |
Slide 9:
Forum for specific questions |
Please post your timed queries in this forum. |
Slide 10:
Acknowledgement |
Spoken Tutorial project is funded by NMEICT, MHRD, Government of India.
More information on this mission is available at this link. |
This tutorial has been contributed by FOSSEE and Spoken Tutorial Project, IIT Bombay.
This is Priya from IIT Bombay. Thanks for watching. |