I/O Ports I/O I/O Ports, I/O Mechanism: Microprocessor Interfacing
I/O Ports I/O I/O Ports, I/O Mechanism: Microprocessor Interfacing
PORTS I/O
MECHANISM
Lecture 05 Microprocessor Interfacing
Review
; Add R1:R0 to R3:R2
ADD r2,r0 ; Add low byte
ADC r3,r1 ; Add with carry high byte
CISC & RISC
Von Neumann Architecture & Harvard Architecture
Register Set
I t ti SSett
Instruction
ATMEL AVR ATMega16 Overview
Non-Volatile and Data Memory
PORT System
Peripheral Features
Lecture Objectives
j
I/O Ports
/
Pull Up Circuit
] // [[Switch On Pull‐UP]
[[Default] ] // [[Output],
p ], Configuration
g
Synchronization when Reading an Externally /Software
Applied Pin Value
I/O Code Examples
RESET Logic
I/O
/ Ports
I/O
/ Ports
Pull Up
p Resistors
If PORTxn is written logic one when the pin is configured as an input pin,
the pull‐up resistor is activated.
To switch the pull‐up resistor off, PORTxn has to be written logic zero or
the pin has to be configured as an output pin.
The port pins are tri‐stated when a reset condition becomes active, even
if no clocks are running
Default Configuration
g
Switch On Pull-Up
p
Port set as Output
p
SFIOR: Special
p Function I/O
/ Register
g
Synchronization when Reading an
E t
Externally
ll AApplied
li d Pi
Pin V
Value
l
Synchronization when Reading a
S ft
Software Assigned
A i d Pi Pin Value
V l
CODE: 01
#include <mega16.h> void main(void)
#include <delay.h> {
unsigned char led=VLED;
#define VLED 0xFE; DDRB = VPOUT ;
PORTB = VPIN ;
#define VRESET 0x00; delay_ms(VDELAY);
#define VSET 0xFF; STEP - 02 while (1)
{
#d f VDELAY
#define 5000
5000; PORTB = led ;
delay_ms(VDELAY);
#define SHFT_BITS 0x01; led << = SHIFT_BITS ;
#define SET_LSB 0x01;; led |= SET_LSB
SET LSB ;
if (led == VPOUT)
led = VLED ;
}
STEP - 01 } STEP - 03
CODE: 02
#include <mega16.h> void main(void)
# l d <delay.h>
#include d l h { while (1)
unsigned char led = VLED ; {
#define VLED 0xFE; DDRB = VSET ; do
PORTB = VRESET ; {
#define
#d fi EOEO_L2R
L2R 0xFE;
0 FE delay_ms(VDELAY); PORTB = led ;
#define EO_R2L 0x7F; delay_ms(VDELAY); delay_ms(VDELAY);
delay_ms(VDELAY); led << = SHIFT_BITS ;
#define VRESET 0x00; led |= SET_LSB ;
#d fi VSET
#define 0 FF
0xFF; STEP - 02 } while (led != EO_R2L) ;
#define VDELAY 1000; do
{
#define
#d fi SHFT_BITS
SHFT BITS 0x01;
0 01 PORTB = led ;
#define SET_LSB 0x01; delay_ms(VDELAY) ;
#define SET_MSB 0x80; led >>= SHIFT_BITS ;
led |= SET_MSB ;
} while (led != EO_L2R) ;
STEP - 01 }
} STEP - 03
Reset Logic
g