Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

IO Port Programming

Uploaded by

tekiyagaming
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

IO Port Programming

Uploaded by

tekiyagaming
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

I/O Port

Programming

Thareendhra Keerthi Wijayasiriwardhane


Department of Industrial Management
Faculty of Science
University of Kelaniya
thareen@kln.ac.lk
Learning Outcomes
 On completion of this session, you should be able to
 Explain the functionality of I/O registers
 Construct a microcontroller-based system and program it
to drive an actuator
 Compare hardwired vs. software-based approaches
 Discuss the pros and cons of different firmware
implementations
 Construct a microcontroller-based system and program it
to read a digital input and then drive an actuator

2
I/O Ports
 Used to get the state of physical world with sensors
 Also used to
drive actuators
and thereby
change the
state of
physical world

3
I/O Registers
 Registers associated with an I/O Port
 Data Direction Register (DDR)
 Determines data direction
 Set to configure port pins as outputs
 Cleared to configure port pins as inputs
 Port Output RegisTer (PORT)
 Used to specify the state of port pins

4
DDR and PORT Registers

5
System 1
blinkerAsm - Blinks an LED every ½
a second using Assembly

6
Electricity
 Current
 Voltage

7
Resistor

8
Diode

9
ATmega328P I/O Ports

10
Hardware
 Schematic
Diagram

11
Breadboard

12
Hardware
 Wiring Diagram

13
Firmware
 Algorithm

14
Configuring an I/O Pin
 Configure Pin 0 of Port B as an output
 Use Set Bit in I/o register instruction

15
Making an I/O Pin High
 Change the state of Pin 0 of Port B high
 Use Set Bit in I/o register instruction

16
Delaying
 Engage CPU by running a loop and delay half a second
 Use LoaD Immediate, DECrement and BRanch if Not
Equal instructions

17
Delay Calculation
 Calculate clock cycle time

 Calculate number of clock cycles starting from the most


inner loop

18
Calling a Subroutine
 Execute the instructions for delaying half a second as a
subroutine
 Use CALL instruction

 Use RETurn instruction to return from subroutine

19
Making an I/O Pin Low
 Change the state of Pin 0 of Port B low
 Use Clear Bit in I/o register instruction

20
Performing Tasks Indefinitely
 Perform the tasks such as change the state of Pin 0 of
Port B high, delay 500ms, change the state of Pin 0 of
Port B low and again delay 500ms, indefinitely
 Use JuMP instruction

 Infinite loop

21
Assembly Program

22
Microchip Studio

23
Creating an Assembler Project

24
Device Selection

25
Assembly Program

26
Building HEX File

27
Programming Options
 COTS programmer from
manufacturer
 Aftermarket/home made
programmers
 USB
 Serial
 Self-programming

28
Self-Programming
 Bootloader

 Host Application

 AVRDUDE (AVR Downloader UploaDEr)

29
Configuring Host Application

30
Configuring Host Application
 Settings
 Title - menu item for Atmel Studio’s Tools menu
Arduino &Uno Programmer
 Command - path to AVRDUDE
Drive:\...\avrdude.exe
 Arguments - arguments passed to AVRDUDE
‐C "Drive:\...\avrdude.conf" ‐v ‐v ‐p atmega328p
‐c arduino ‐P Port ‐b 115200
‐U flash:w:"$(TargetName).hex":i
 Initial Directory - directory to read the HEX file
$(TargetDir)
 Use Output window - whether to display processing
information in output window

31
Uploading HEX File

32
Hardwired Alternatives
 Using Transistors
 Using an IC
 Problems?

33
Modified Assembly Program

34
System 2
blinkerC - Blinks an LED every 200
milliseconds using C

35
Firmware
 Algorithm

36
Creating a C Project

37
C Program

38
Using Bit-wise Logical Operators

39
Uploading HEX File

40
System 3
blinker - Blinks an LED every 200
millisecond using Arduino

41
Arduino IDE
 Integrates a
code editor,
compiler,
debugger,
uploader, text
terminal and
other tools
 Freely
available to
download
from
https://www.arduino.cc/en/software

42
Arduino IDE
Upload Board & Port select Serial plotter

Serial
Verify
monitor
Sketch book Sketch name

Board
manager
Library Code editor
manager
Debugger
Bottom panel
Search

Message area
Arduino cloud
Toggle bottom
panel
Board & Port connected Notifications

43
Firmware
 Algorithm
 setup function
 loop function

44
Firmware
 Source Code

45
Compiling and Uploading

46
Comparison
 Assembly
 Highly efficient, difficult to code, not portable
 C
 Efficient, easier to code, libraries available, portable
 Data type misuse possible
 Arduino
 Very easier to code, libraries available
 Inefficient, not portable
 How come Arduino becomes inefficient, if it also uses
GCC and AVRDUDE?

47
I/O Registers
 Port INput register (PIN)
 Used to read
the state present
at port pins
 Set the bits of
PORT register
to activate
internal pull-up
resistors

48
DDR and PIN Registers

49
System 4
dualRateBlinker - Blinks an LED
every 500ms if no input, otherwise
blinks it every 200ms

50
Micro Pushbutton Switch
 Connects two points in a circuit when
pressed
 Normally open and closed when pressed

51
Hardware
 Schematic
Diagram

52
Hardware
 Wiring Diagram

53
Firmware
 Algorithm

54
C Program

55
Using Bit-wise Shift Operators

56
Using Labeled Constants

57
Firmware
 Algorithm for Arduino

58
Firmware
 Source Code (using Arduino Wrapper Functions)

59
Questions

60

You might also like