Beruflich Dokumente
Kultur Dokumente
B. Furman
19MAR2011
Learning Objectives
User
Interface
ME 106
ME 120
Controller
ME 106
Power
Interface
INTEGRATION
ME 106
ME 154
ME 157
ME 195
Signal
Conditioning
ME 106
ME 190
ME 187
ME 106
ME 120
Actuator
Sensor
System to
Control ME 110
ME 182
ME 136 ME 189
ME 154 ME 195
ME 157
ME 120
ME 297A
BJ Furman 22JAN11
8-bit register
7
a 1 in DDRx means?
a 0 in DDRx means?
DDRD = 0xFF;
DDRD = 0b11111111;
DDRD = 255;
Arduino style
pinMode(0, OUTPUT);
pinMode(7, OUTPUT);
DDRD = 0b00101010;
DDRD = 0x2A;
Arduino style
pinMode(1, OUTPUT);
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
setup()
setup()
loop()
configures pin modes and
registers
loop()
like while(1) {}
Where is main() ?
Programmers block
At a minimum:
Program name
Description of what
the program does
Author
Revision number
Revision date/time
Even better:
Creation date
Inputs
Outputs
Method/algorithm
Why?
ATmega328
D3
D2
VTG= +5V
D0, D1
0
Challenge:
Make bits 5 and 3 of PORTB high and the rest low
1.
2.
1.
2.
Pull-up Resistors
How is it done?
When the pin is configured as an input, SET the
corresponding bit in PORTxn
Undone by clearing the bit
#define LATCHED 0
#define ENGAGED 0
DDRD | = _BV(2) | _BV(3); // D2 and D3 are OUTPUTs
PORTD | = _BV(0) | _BV(1); // turn on pull-ups for D0 and D1
current_state = ~PIND; // invert for active-low switches
key_state=current_state & ( _BV(0) )
belt_state=current_state & ( _BV(1) )
if(key_state==ENGAGED)
if(belt_state==LATCHED)
PORTD & = ~( _BV(2) | _BV(3) ); // buzzer and lamp off
else
PORTD | = ( _BV(2) | _BV(3) ); // buzzer and lamp on
else
PORTD & = ~( _BV(2) | _BV(3) ); // buzzer and lamp off
ATmega328
D3
D2
VTG= +5V
D0, D1
0
Key on D0
Belt on D1
If configured as output:
Ex. To make Port D pins 7, 3, and 4 low, and the rest high
PORTD=___________; (write in binary, then in hex)
uint8_t a_pins;
a_pins=PIND;
What is the content of a_pins:
binary:__________
hex:_____
PD6
PD5
PD4
PD3
PD2
PD1
PD0
VTG
PD7
PD6
PD5
PD4
PD3
PD2
PD1
PD0
VTG
PD7
DDRD=0;
PD6
testD=PIND;
PD5
PD3
PD4
binary: 11111001
PD2
hex: F9
PD0
PD1
VTG
ATmega328 Features
http://www.atmel.com/dyn/resources/prod_documents/doc8271.pdf
PORT Pin
Schematics
DDRx
PORTxn
PINxn