+ All Categories
Home > Documents > PORT(I/O) Configuration

PORT(I/O) Configuration

Date post: 08-Jan-2018
Category:
Upload: kevin-woods
View: 241 times
Download: 0 times
Share this document with a friend
Description:
Input/Output AVR CPU BUS TWI ADC SPI ISP PORTA PORTB PORTC PORTD SRAM Flash Memory SRAM EEPROM Counter USART TWI ADC MCU Control and Timing I/O Ports Interface Watchdog Timer SPI ISP Interrupt Unit PORTD PORTC PORTB PORTA Internal Calibrated Oscillator Crystal PORTA PORTB PORTC PORTD
17
PORT(I/O) Configuration Lecturer: Reza Arjmandi Autumn 2015 Lecture 2: Introduction Input/Output with PORT Configuration
Transcript
Page 1: PORT(I/O) Configuration

PORT(I/O)Configuration

Lecturer: Reza ArjmandiAutumn 2015

Lecture 2:Introduction Input/Output with PORT Configuration

Page 2: PORT(I/O) Configuration

Input/Output

AVR CPU BUS

Flash Memory SRAM EEPROM Counter USART TWI ADC

MCU Control and Timing

I/OPorts Interface

Watchdog Timer SPI ISP Interrupt

Unit

PORTD

PORTC

PORTB

PORTA

Internal Calibrated OscillatorOscillator

Crystal Oscillator

PORTAPORTB

PORTC

PORTD

Page 3: PORT(I/O) Configuration

Input/Output

AVR CPU

I/OPorts Interface

8 Bit Parallel Data(Output)

8 Bit Parallel Data(Input)

10110111

00111111

0x3F0xB7

0V

+5V

+5V0V

Example:

char a;a=PINB; //read data 0xB7 fromPORTA=0x3F; //write data 0x3F on PORTAPORTA_Bit7=0; //LED offPORTA_Bit7=1; //LED OnIf(PINB_Bit7==0) //read data from …

0 -> 0V1 -> +5V

10K

VCC

Page 4: PORT(I/O) Configuration

Input/Output-Registers

I/O

AVR CPU

DDRx

PINx

PORTx

x:A,B,C,D,…

Input/Output Registers:DDRAPORAPINBDDRCPINC….

DDRx_Bit0ex. DDRA_Bit0

PORTx_Bit3ex. PORTD_Bit3

Header file: ioavr.hEx. #include<ioavr.h>

Page 5: PORT(I/O) Configuration

Input/Output-Registers-DDRData Direction Register(Initial value for DDR=0)

0->for input1->for output

Example:

#include<ioavr.h> //include Header file…DDRA_Bit0=1;DDRA_Bit2=0;DDRB=0xB3; //binary:10110011DDRC=0b10110011; //Hex=0xB3…

Output

Input

Page 6: PORT(I/O) Configuration

Input/Output-Registers-PORTRegister for Output Direction

8 Bit Parallel Data(Output)

00111111

0x3F

Example:

#include<ioavr.h> //include Header file…DDRA=0xFF; //Config PORTA for outputPORTA=0x3F; //binary:00111111DDRC_Bit3=1 ; //Config PORTA Bit3 for outputPORTC_Bit3=0;…

0

00111111

PORTA

Page 7: PORT(I/O) Configuration

Input/Output-Registers-PINRegister for Input Direction

8 Bit Parallel Data(Input)

00111111

0x3F

Example:

#include<ioavr.h> //include Header file…DDRB=0x00; //Config PORTB for inputChar a=PINB; //read 0x3F from PINBLcd_putchar(a); //display lcd dataa=PINB_Bit5;…

Recieve:63

Initial Value for PIN Register =0 00111111

PINB

Page 8: PORT(I/O) Configuration

Input/Output-Pull Up/Down

00000000

PINB

Example: PIN B initial value=0

10K

VCC

How to capture push button?

Answer : with external Pull Up resistor

00001000

Page 9: PORT(I/O) Configuration

Input/Output-Internal Pull Up/Down

0 0 0 0 0 0 0 0 PINB(initial value)

10K10K10K10K10K10K10K10K

Internal Pull-down resistorExample:DDRB=0x00; //config PORTB as inputPORTB=0x01; //turn on internal pull-up resistor for Bit0DDRD=0x00; //config PORTD as inputPORTD=0xFF; //turn on internal pull-up

10K

VCC

Internal Pull-Up resistor

1

Page 10: PORT(I/O) Configuration

Input/Output-Turn off all Pull down resistor

PUD رجیستر 2بیت های SFIOاز مقاومت تمام آن شدن یک با و تنظیمات Pull-Upاست اگر حتی شوند می فعال و DDRxnغیرPORTxn که باشد شکلی باشند .Pull-Upبه فعال هایی پین

Example:

SFIOR|=0b00000100; //disable all internal pull-up resistor

Page 11: PORT(I/O) Configuration

BreadBoard

Page 12: PORT(I/O) Configuration

Input/Output-Example: 8فالشر روی که ای برنامه پورت LED 8کانال کند Aروی خاموش و روشن برگشتی، و رفت حرکت صورت به

#include<ioavr.h>#include<intrinsics.h>int i;main(){ DDRA=0XFF; while(1) { for(i=1;i<=128;i=i*2) { PORTA=i; __delay_cycles(100000); } for(i=64;i>1;i=i/2) { PORTA=i; __delay_cycles(100000); } }}

Page 13: PORT(I/O) Configuration

Input/Output-Example2Start-stop :کلید فشردن شماره push buttonبا پین روی پورت 7که گرفته، Dاز شماره LEDقرار پین روی 0واقعپورت شماره Cاز پین روی کلید زمانیکه تا کند حفظ را خود حالت و شود .3روشن شود فشرده پورت همان از

include<ioavr.h>main(){ DDRD_Bit7=0; PORTD_Bit7=1; DDRD_Bit3=0; PORTD_Bit3=1; DDRC_Bit0=1; while(1) { if(PIND_Bit7==0) { PORTC_Bit0=1; } if(PIND_Bit3==0) { PORTC_Bit0=0; } }}

stop

start

Page 14: PORT(I/O) Configuration

Input/Output-Current Limitجریان مجموع که کرد دقت از sourceیا sinkباید نباید پورت یک از ها 100شده پورت کل جریان و ک<ند تجاوز آمپر میلی

از بیش نباید .) 200نیز برای شود آمپر (PDIP Packageمیلی دیتاشیت در بیشتر جزئیات ،

Maximum current: 100mA

Maximum current: 100mA Maximum current: 100mA

How to amplify current or switch High voltage?Answer:-Transistor(PNP,NPN,FET,MOS,…)-Triac- Thyristor-…

Page 15: PORT(I/O) Configuration

Driversبه … نیاز ، و نور منب<ع پم<پ، موتور، هیت<ر، چون تجهیزات<ی اندازی راه برایرا ها آ<ن نیاز مورد جریان و ولتاژ ت<ا داری<م، توان ایجاد مدارهای ی<ا درایور . خروجی اما کنند، می صادر را ها فرمان میکروکنترلرها هرچند کنیم تامینفراهم را محرک تجهیزات جه<ت الزم توان نیس<تند، قادر میکروکنترلره<ا

حدود. میکروکنترلره<ا خروج<ی ولتاژ در ۵کنند ها آ<ن خروج<ی جریان و ول<ت . موتور میکروکنترلر ی<ک ب<ا کن<م، راح<ت را خیالتان اس<ت آمپ<ر میل<ی چن<د ح<د. آورد در حرک<<ت ب<<ه توان نم<<ی را بازی اس<<باب ی<<ک کوچ<<کمی فراه<م را محرک تجهیزات برای الزم جریان و ولتاژ درایور مدارهای

کنند. 

Page 16: PORT(I/O) Configuration

Relay

Page 17: PORT(I/O) Configuration

Contact us

www.e-system.ir

[email protected]


Recommended