Difference between revisions of "Arduino/C3/Assembly-programming-through-Arduino/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with " {| style="border-spacing:0;" | style="background-color:#c0c0c0;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| '''Vi...")
 
 
(3 intermediate revisions by 2 users not shown)
Line 7: Line 7:
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Slide 1:
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Slide 1:
  
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Welcome to the''' '''spoken tutorial on''' Assembly programming through Arduino.'''
+
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Welcome to the spoken tutorial on''' Assembly programming through Arduino.'''
  
 
|-
 
|-
Line 16: Line 16:
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| In this tutorial, we will learn to:
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| In this tutorial, we will learn to:
  
* Interface a''' seven-segment Display''' to''' Arduino''' board
+
* Interface a''' seven-segment Display''' to''' Arduino board'''  
* Write an assembly program to display a digit on '''seven-segment display '''and
+
* Write an '''assembly program''' to display a digit on '''seven-segment display '''and
 
* Display a digit on the '''seven segment display''' using '''7447 IC.'''
 
* Display a digit on the '''seven segment display''' using '''7447 IC.'''
  
Line 68: Line 68:
  
 
Please refer to the basic level tutorial of this series to know more about '''seven segment display'''.
 
Please refer to the basic level tutorial of this series to know more about '''seven segment display'''.
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"|
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Refer the pin mapping for '''Arduino '''and '''microcontroller.'''
 
  
 
|-
 
|-
Line 77: Line 73:
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Let us see the connection circuit details.
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Let us see the connection circuit details.
  
The '''Dot''' pin of the '''Seven Segment Display''' is connected to the '''pin 13''' of '''Arduino'''.  
+
The '''Dot pin''' of the '''Seven Segment Display''' is connected to the '''pin 13''' of '''Arduino'''.  
  
 
Any one of the '''COM pins '''is connected to the +5V through a 220 '''ohm resistor'''.
 
Any one of the '''COM pins '''is connected to the +5V through a 220 '''ohm resistor'''.
 +
 +
|-
 +
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"|
 +
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Refer the '''pin mapping''' for '''Arduino '''and '''microcontroller.'''
  
 
|-
 
|-
Line 87: Line 87:
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Point to the Dot in the diagram
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Point to the Dot in the diagram
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Now we will write an assembly program to turn on the '''dot''' led on the '''seven segment display'''.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Now we will write an '''assembly program''' to turn on the '''Dot LED''' on the '''seven segment display'''.
  
 
|-
 
|-
Line 108: Line 108:
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| To install '''avra''' and '''avrdude''', type
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| To install '''avra''' and '''avrdude''', type
  
'''sudo apt-get install avra avrdude'''
+
'''sudo space apt hyphen get space install space avra space avrdude'''
  
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"|  
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"|  
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Enter the '''administrative '''password if prompted and press '''Enter.'''
+
| style="background-color:#ffffff; :1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Enter the '''administrative password''' if prompted and press '''Enter.'''
  
 
|-
 
|-
Line 134: Line 134:
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Installing AVRA
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Installing AVRA
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| To check the port number of '''Arduino''', I'll type  
+
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| To check the '''port''' number of '''Arduino''', I'll type  
  
'''ls forward slash dev forward slash ttyACM asterisk'''
+
'''ls space forward slash dev forward slash ttyACM asterisk'''
  
 
|-
 
|-
Line 144: Line 144:
 
'''forward slash dev forward slash ttyACM0'''
 
'''forward slash dev forward slash ttyACM0'''
  
Here''' ttyACM0''' represents the port number of '''Arduino'''.
+
Here''' ttyACM0''' represents the '''port''' number of '''Arduino'''.
  
You may get a different port number. Make a note of your port number.
+
You may get a different '''port''' number. Make a note of your '''port''' number.
  
 
|-
 
|-
Line 153: Line 153:
 
Def files for ATmega328P
 
Def files for ATmega328P
  
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Download '''m328Pdef.inc '''file''' '''from the '''Code files''' link of this tutorial.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Download '''m328Pdef.inc '''file from the '''Code files''' link of this tutorial.
  
 
We need to include this '''library''' file in the first line of the source code.
 
We need to include this '''library''' file in the first line of the source code.
Line 161: Line 161:
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"|  
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"|  
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Let us write the '''assembly program '''and upload it to the '''microcontroller'''.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Let us write an '''assembly program '''and upload it to the '''microcontroller'''.
  
 
|-
 
|-
Line 170: Line 170:
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| '''Highlight according to narration:'''
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| '''Highlight according to narration:'''
  
<nowiki>;program to turn on the dot LED</nowiki>
+
<nowiki>;program to turn on the Dot LED</nowiki>
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| '''Semicolon''' represents '''comment statements'''.  
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| '''Semicolon''' represents '''comment statements'''.  
  
Line 179: Line 179:
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| This line tells the '''assembler''' to include the '''m328Pdef.inc file.'''
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| This line tells the '''assembler''' to include the '''m328Pdef.inc file.'''
  
We had downloaded this file earlier and in my computer this is the path.
+
We had downloaded this file earlier and in my computer this is the '''path'''.
  
Note that we have to specify the entire file path.
+
Note that we have to specify the entire '''file path.'''
  
 
|-
 
|-
Line 191: Line 191:
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| '''ldi''' stands for '''"load immediate" '''
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| '''ldi''' stands for '''"load immediate" '''
  
This sets pin PB5, that is digital pin 13 as output.
+
This sets '''pin PB5''', that is digital '''pin 13''' as output.
  
 
It tells the '''assembler''' to take a working '''register r16''' and load a '''binary number '''into it.
 
It tells the '''assembler''' to take a working '''register r16''' and load a '''binary number '''into it.
Line 197: Line 197:
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| out DDRB, r16
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| out DDRB, r16
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| This line tells the compiler to copy the contents of the '''register r16 '''into the '''DDRB register.'''
+
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| This line tells the '''compiler''' to copy the contents of the '''register r16 '''into the '''DDRB register.'''
  
 
|-
 
|-
Line 203: Line 203:
  
 
ldi r17, 0b00000000
 
ldi r17, 0b00000000
 
 
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| This sets all the pins to '''0 volts '''except '''pin PB5''', (i.e '''digital pin 13''') which is set to '''5 volts. '''
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| This sets all the pins to '''0 volts '''except '''pin PB5''', (i.e '''digital pin 13''') which is set to '''5 volts. '''
  
Line 215: Line 213:
  
 
Rjmp Start
 
Rjmp Start
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| '''Relative jump statement''' executes the program in an infinite loop.  
+
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| '''Relative jump statement''' executes the '''program''' in an '''infinite loop.'''
  
 
The '''program''' has to just keep running, in order for the '''LED''' to remain '''ON'''.
 
The '''program''' has to just keep running, in order for the '''LED''' to remain '''ON'''.
Line 241: Line 239:
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Go to the folder where '''dot hyphen blink.asm '''file is saved.
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Go to the folder where '''dot hyphen blink.asm '''file is saved.
  
Type, '''avra dot hyphen blink.asm''' and press '''Enter'''.
+
Type, '''avra space dot hyphen blink.asm''' and press '''Enter'''.
  
 
|-
 
|-
Line 255: Line 253:
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"|  
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"|  
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| switch back to the terminal.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Switch back to the '''terminal'''.
  
 
|-
 
|-
Line 267: Line 265:
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| For this, type
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| For this, type
  
* '''avrdude space hyphen p space atmega328p space hyphen c arduino space hyphen b space 115200 space hyphen capital P space forward slash dev forward slash ttyACM0 space hyphen capital U space flash colon w colon dot hyphen blink.hex '''
+
'''avrdude space hyphen p space atmega328p space hyphen c arduino space hyphen b space 115200 space hyphen capital P space forward slash dev forward slash ttyACM0 space hyphen capital U space flash colon w colon dot hyphen blink dot hex '''
  
Here''' ttyACM0''' represents the port number of '''Arduino'''.
+
Here''' ttyACM0''' represents the '''port''' number of '''Arduino'''.
  
 
'''dot hyphen blink.hex''' is the file that is generated.
 
'''dot hyphen blink.hex''' is the file that is generated.
  
and press Enter.
+
And press '''Enter'''.
  
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Point to the output
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Point to the output
  
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Now you can see that''' '''the '''dot''' '''LED''' in the '''seven segment''' is glowing.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Now you can see that the '''Dot LED''' in the '''seven segment''' is glowing.
  
 
|-
 
|-
Line 286: Line 284:
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Pause the tutorial and do the below assignment.
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Pause the tutorial and do the below assignment.
  
* Modify the same code to turn off the '''dot LED.'''
+
* Modify the same code to turn off the '''Dot LED.'''
  
 
|-
 
|-
Line 296: Line 294:
  
  
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| To display '2', '''a''','''b,d,e,g segments '''should be high and the other '''LEDS''' should be low.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| To display '2', '''a,b,d,e,g segments '''should be high and the other '''LEDS''' should be low.
  
 
|-
 
|-
Line 302: Line 300:
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Connect '''Pins a, b, c, d, e, f '''and '''g''' of the '''seven-segment display''' to '''pins 2, 3, 4, 5, 6, 7''' and '''8''' of '''Arduino'''.
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Connect '''Pins a, b, c, d, e, f '''and '''g''' of the '''seven-segment display''' to '''pins 2, 3, 4, 5, 6, 7''' and '''8''' of '''Arduino'''.
  
The two common '''pins''' are connected to +5V through '''resistors'''.
+
The two '''common pins''' are connected to +5V through '''resistors'''.
 
+
  
 
|-
 
|-
Line 343: Line 340:
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| These two lines makes '''bit 0''' on '''PORT B '''as output.
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| These two lines makes '''bit 0''' on '''PORT B '''as output.
  
These bits corresponds to the '''digital pins 2 to 8 '''on '''Arduino'''.  
+
These '''bits''' corresponds to the '''digital pins 2 to 8 '''on '''Arduino'''.  
  
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| <nowiki>;Writing number 2 on Seven Segment Display</nowiki>
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| <nowiki>;Writing number 2 on Seven Segment Display</nowiki>
  
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Here, we are making the pins as high or low corresponding to whatever number we want to display.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Here, we are making the '''pins''' as high or low corresponding to whatever number we want to display.
  
 
In our case, it is digit two.
 
In our case, it is digit two.
Line 367: Line 364:
  
 
Rjmp Start
 
Rjmp Start
 
 
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Here, we are writing '''0100100''' to digital '''pins 2 '''to '''8 '''of '''Arduino'''.
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Here, we are writing '''0100100''' to digital '''pins 2 '''to '''8 '''of '''Arduino'''.
  
Line 391: Line 386:
  
 
'''avrdude -p atmega328p -c arduino -b 115200 -P /dev/ttyACM0 -U flash:w:two.hex'''
 
'''avrdude -p atmega328p -c arduino -b 115200 -P /dev/ttyACM0 -U flash:w:two.hex'''
 
 
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| To upload, press the up arrow to get the previous command.  
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| To upload, press the up arrow to get the previous command.  
  
Now change the filename as shown and press Enter.
+
Now change the filename as shown and press '''Enter'''.
  
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Point to the output
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Point to the output
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Now you can see that''' '''the digit 2 in the '''seven segment''' is glowing.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Now you can see that the digit 2 in the '''seven segment''' is glowing.
  
 
|-
 
|-
Line 426: Line 419:
 
Show the pin image of 7447 IC
 
Show the pin image of 7447 IC
  
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| The '''ā (a complement) '''to''' ¯f (f complement) pins''' of the '''decoder''' connect to the '''a f pins''' of '''Seven Segment Display'''.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| The '''a complement '''to''' f complement pins''' of the '''decoder''' connect to the '''a''' to '''f pins''' of '''Seven Segment Display'''.
  
 
'''Vcc''' and the '''GND pins '''of the '''decoder''' are connected to '''+5V''' and the '''GND pins '''of '''Arduino.'''
 
'''Vcc''' and the '''GND pins '''of the '''decoder''' are connected to '''+5V''' and the '''GND pins '''of '''Arduino.'''
Line 432: Line 425:
 
Connect the''' A, B,C,D pins''' of the '''Decoder''' to '''pins 2,3,4,5''' of '''Arduino.'''
 
Connect the''' A, B,C,D pins''' of the '''Decoder''' to '''pins 2,3,4,5''' of '''Arduino.'''
  
Note that this decoder is compatible only with common anode seven segment display.
+
Note that this '''decoder''' is compatible only with '''common anode seven segment display.'''
  
 
|-
 
|-
Line 468: Line 461:
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| The first two lines makes the '''bits 2''' to '''5''' on '''PORT D''' as output.
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| The first two lines makes the '''bits 2''' to '''5''' on '''PORT D''' as output.
  
This means we are making digital '''pins 2 to 5 '''in '''Arduino '''as '''output pins.'''
+
This means we are making digital '''pins 2''' to '''5 '''in '''Arduino '''as '''output pins.'''
  
 
'''2 to 5 pins '''in the '''Arduino '''are connected to '''A, B, C, D pins '''of '''decoder.'''
 
'''2 to 5 pins '''in the '''Arduino '''are connected to '''A, B, C, D pins '''of '''decoder.'''
Line 481: Line 474:
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| The next two lines are giving input of '''0101''' to decoder inputs.
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| The next two lines are giving input of '''0101''' to decoder inputs.
  
This will then be decoded as 5 in the seven segment display.
+
This will then be decoded as 5 in the '''seven segment display'''.
  
 
|-
 
|-
Line 508: Line 501:
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| To upload, press the up arrow to get the previous command.  
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| To upload, press the up arrow to get the previous command.  
  
Now change the filename as shown and press enter.
+
Now change the filename as shown and press '''Enter'''.
  
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Point to the output
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Point to the output
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Now we can see that the digit five in the seven segment is glowing.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Now we can see that the digit five in the '''seven segment''' is glowing.
  
 
|-
 
|-
Line 560: Line 553:
 
| style="background-color:#ffffff;border-top:0.75pt solid #000001;border-bottom:1pt solid #000001;border-left:1pt solid #000001;border-right:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Spoken Tutorial project is funded by NMEICT, MHRD, Government of India.
 
| style="background-color:#ffffff;border-top:0.75pt solid #000001;border-bottom:1pt solid #000001;border-left:1pt solid #000001;border-right:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Spoken Tutorial project is funded by NMEICT, MHRD, Government of India.
  
More information on this mission is available at
+
More information on this mission is available at this link.
 
+
this link.
+
  
 
|-
 
|-
Line 570: Line 561:
 
This is Priya from IIT Bombay signing off.
 
This is Priya from IIT Bombay signing off.
  
Thanks for watching.
+
Thanks for joining.
  
 
|}
 
|}

Latest revision as of 08:34, 12 April 2018

Visual Cue Narration
Slide 1: Welcome to the spoken tutorial on Assembly programming through Arduino.
Slide 2:

Learning objectives

In this tutorial, we will learn to:
  • Interface a seven-segment Display to Arduino board
  • Write an assembly program to display a digit on seven-segment display and
  • Display a digit on the seven segment display using 7447 IC.
Slide 3:

Pre-requisites


To follow this tutorial, you should have basic knowledge of :
  • Electronics and
  • Assembly language

Refer to the Additional reading material link of this tutorial to know more about:

  • Arduino - Assembly code reference and
  • Arduino ATmega328 Pin mapping.
Slide 4:

System Requirement

To record this tutorial, I am using:
  • Arduino UNO Board
  • Ubuntu Linux operating system version 14.04
Slide 5:

External Devices

We also require some external devices such as:
  • Breadboard
  • Arduino UNO Board
  • Common Anode Seven-Segment Display
  • 220 ohm Resistor
  • Decoder 7447 IC
  • Jumper Wires
Show the image:

Seven-segment display

In this experiment we will use the common anode seven segment display.

Please refer to the basic level tutorial of this series to know more about seven segment display.

Let us see the connection circuit details.

The Dot pin of the Seven Segment Display is connected to the pin 13 of Arduino.

Any one of the COM pins is connected to the +5V through a 220 ohm resistor.

Refer the pin mapping for Arduino and microcontroller.
Show the live connection This is the live setup of the connection.
Point to the Dot in the diagram Now we will write an assembly program to turn on the Dot LED on the seven segment display.
Slide: Software Setup We need to install an assembler AVRA and AVRDUDE.

AVRA is an assembler that will generate a hex file.

AVRDUDE is used to upload any hex file to the Arduino board.

Press Ctrl + Alt + T keys Open the terminal by pressing Ctrl + Alt + T keys together.
Type

> sudo apt-get install avra dude

To install avra and avrdude, type

sudo space apt hyphen get space install space avra space avrdude

Enter the administrative password if prompted and press Enter.
Press ‘Y’ We can see the installation process has begun.

Press 'Y' wherever there is a prompt during the installation, to confirm the configuration.

Installation will take some time to complete depending upon the internet speed.

Point to the prompt We can see that the installation has been completed successfully.

Let us clear the screen.

Now let us connect the Arduino board to the computer.
Installing AVRA To check the port number of Arduino, I'll type

ls space forward slash dev forward slash ttyACM asterisk

Highlight ttyACM0 We can see the output as

forward slash dev forward slash ttyACM0

Here ttyACM0 represents the port number of Arduino.

You may get a different port number. Make a note of your port number.

Slide 6:

Def files for ATmega328P

Download m328Pdef.inc file from the Code files link of this tutorial.

We need to include this library file in the first line of the source code.

This allows the user to use Register and Bit name when writing assembly programs.

Let us write an assembly program and upload it to the microcontroller.
Open gedit text editor Open any text editor and type the following.
Highlight according to narration:

;program to turn on the Dot LED

Semicolon represents comment statements.

These statements are ignored by the assembler and are not executed.

.include "/home/spoken/Assembly/m328Pdef.inc" This line tells the assembler to include the m328Pdef.inc file.

We had downloaded this file earlier and in my computer this is the path.

Note that we have to specify the entire file path.

; Configure pin 13 on Arduino as Output 5:10 ,8:18

ldi r16, 0b00100000


ldi stands for "load immediate"

This sets pin PB5, that is digital pin 13 as output.

It tells the assembler to take a working register r16 and load a binary number into it.

out DDRB, r16 This line tells the compiler to copy the contents of the register r16 into the DDRB register.
; Making pin 13 LOW

ldi r17, 0b00000000

This sets all the pins to 0 volts except pin PB5, (i.e digital pin 13) which is set to 5 volts.
out PortB, r17 This line copies the same binary number from our storage register r17 to PortB.
Start:

Rjmp Start

Relative jump statement executes the program in an infinite loop.

The program has to just keep running, in order for the LED to remain ON.

Save the code as dot hyphen blink.asm file in the home slash spoken slash Assembly folder.
This code is available in the Code files link of this tutorial, as well.

You can download and use it.

Switch to the terminal. Switch to the terminal.
Type,

> cd /home/spoken/Assembly

> avra dot-blink.asm

Go to the folder where dot hyphen blink.asm file is saved.

Type, avra space dot hyphen blink.asm and press Enter.

Point to the /home/spoken/Assembly folder This will assemble the code and create a file dot hyphen blink.hex.

Let us see the dot hyphen blink.hex file that is generated in the same folder.

Next we need to upload the code to Arduino.
Switch back to the terminal.
Type,

avrdude -p atmega328p -c arduino -b 115200 -P /dev/ttyACM0 -U flash:w:dot-blink.hex

3:45

7:06,2:00,6:22

For this, type

avrdude space hyphen p space atmega328p space hyphen c arduino space hyphen b space 115200 space hyphen capital P space forward slash dev forward slash ttyACM0 space hyphen capital U space flash colon w colon dot hyphen blink dot hex

Here ttyACM0 represents the port number of Arduino.

dot hyphen blink.hex is the file that is generated.

And press Enter.

Point to the output Now you can see that the Dot LED in the seven segment is glowing.
Slide 7:

Assignment 1

Pause the tutorial and do the below assignment.
  • Modify the same code to turn off the Dot LED.
Next, we will display the digit 2 on the seven segment display.
Point to the diagram


To display '2', a,b,d,e,g segments should be high and the other LEDS should be low.
Connect Pins a, b, c, d, e, f and g of the seven-segment display to pins 2, 3, 4, 5, 6, 7 and 8 of Arduino.

The two common pins are connected to +5V through resistors.

show the connection Let us see the live connection setup.
Let us see the source code for this program.
open gedit Open any text editor and type the following code.
.include "/home/spoken/Assembly

/m328Pdef.inc"

Highlight 4 lines

As seen earlier, we should first configure the pins as output first.

Then make it as high or low according to our requirement.

;Configure pins 2-7 on Arduino as Output

ldi r16, 0b11111100

out DDRD, r16

These two lines makes the bits 2 to 7 on PORT D as output.
; Configure pin 8 on Arduino as Output

ldi r16, 0b00000001

out DDRB, r16

These two lines makes bit 0 on PORT B as output.

These bits corresponds to the digital pins 2 to 8 on Arduino.

;Writing number 2 on Seven Segment Display Here, we are making the pins as high or low corresponding to whatever number we want to display.

In our case, it is digit two.

Highlight the code

ldi r17, 0b10010000

out PortD, r17

ldi r17, 0b00000000

out PortB, r17


Start:

Rjmp Start

Here, we are writing 0100100 to digital pins 2 to 8 of Arduino.

This will make all the segments of SSD low, except c and g.

save the file as two.asm Let us save this as two.asm file.
Switch back to the terminal. Switch back to the terminal.

Let us clear the screen.

Type, avra two.asm and press Enter. Type, avra space two.asm and press Enter.
type

avrdude -p atmega328p -c arduino -b 115200 -P /dev/ttyACM0 -U flash:w:two.hex

To upload, press the up arrow to get the previous command.

Now change the filename as shown and press Enter.

Point to the output Now you can see that the digit 2 in the seven segment is glowing.
Slide 8:

Assignment 2

Pause the tutorial and do the below assignment.
  • Modify the above code to display any other digit from 0 to 9.
Next, we will use a Decoder to display the number 5 on the Seven Segment Display.
Slide 9:

Show the image of the decoder:

We are using 7447 IC.

Slide 10:

Show the pin image of 7447 IC

The a complement to f complement pins of the decoder connect to the a to f pins of Seven Segment Display.

Vcc and the GND pins of the decoder are connected to +5V and the GND pins of Arduino.

Connect the A, B,C,D pins of the Decoder to pins 2,3,4,5 of Arduino.

Note that this decoder is compatible only with common anode seven segment display.

Show the setup Let us see the live connection setup.
Show the image of the table:

D C B A Decimal

0 1 0 1 5

The input pins of the decoder are A,B,C and D.

A being the lowest significant bit (LSB) and D being the most significant bit (MSB).

For example, the number 5 is visible on the display when the A,B,C and D inputs are as shown here.

open gedit Let us see the source code for this program.

Open any text editor and type the following code.

.include "/home/user/m328Pdef.inc"

;Configure pins 2,3,4 and 5 on Arduino as Output

ldi r16, 0b00111100

out DDRD, r16

The first two lines makes the bits 2 to 5 on PORT D as output.

This means we are making digital pins 2 to 5 in Arduino as output pins.

2 to 5 pins in the Arduino are connected to A, B, C, D pins of decoder.

;Writing number 5 on Seven Segment Display

ldi r16, 0b00010100

out PORTD, r16

The next two lines are giving input of 0101 to decoder inputs.

This will then be decoded as 5 in the seven segment display.

Start:

Rjmp Start

Save it as decoder.asm file. Save it as decoder.asm file.
Switch back to the terminal. Switch back to the terminal.
Type, avra decoder.asm and press Enter. Type, avra space decoder.asm and press Enter.


type

avrdude -p atmega328p -c arduino -b 115200 -P /dev/ttyACM0 -U flash:w:decoder.hex

To upload, press the up arrow to get the previous command.

Now change the filename as shown and press Enter.

Point to the output Now we can see that the digit five in the seven segment is glowing.
This brings us to the end of this tutorial. Let us summarize.
Slide 11:

Summary

In this tutorial, we learnt to:
  • Interface a Seven-segment Display to Arduino board and
  • Write an assembly program to display a digit on seven-segment display.
  • Display a digit on the seven segment display using 7447 IC.
Slide 12:

About Spoken Tutorial project

The video at the following link summarizes the Spoken Tutorial project.

Please download and watch it.

Slide 13:

Spoken Tutorial workshops

The Spoken Tutorial Project Team:
  • conducts workshops and gives certificates.

For more details, please write to us.

Slide 14:

Forum for specific questions

Please post your timed queries in this forum.
Slide 15:

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 signing off.

Thanks for joining.

Contributors and Content Editors

Nancyvarkey, Nirmala Venkat