برای هر پورت سه آدرس در حافظهSRAM یا سه ثبات ورودی خروجی I/O 8 بیتی تعریف میشود که عبارتند از: 1- یک ثبات برای نوشتن و خواندن داده به نام PORTX (Port.

Slides:



Advertisements
Similar presentations
Awe sim.
Advertisements

فصل چهارم مدارهای ترکیبی.
 | bit OR & bit AND ~ bit NOT ^ bit EXLUSIVE OR (XOR) > bit RIGHT SHIFT.
معاونت درمان امور مامایی اردیبهشت 90. برای ثبت اطلاعات در برنامه نرم افزاری نظام مراقبت مرگ پریناتال ابتدا لازم است برنامه نرم افزار info-path وپرنیان.
COMP3221: Microprocessors and Embedded Systems--Lecture 8 1 COMP3221: Microprocessors and Embedded Systems Lecture 8: Program Control Instructions
Programming the ATmega16
Decision Tree.
مثال های کاربردی (1) محاسبه سطوح دايره ای شکل –آبياری بارانی –سم پاشها تعريف مسئله: تهيه برنامه ای که بر اساس يک شعاع مفروض ورودی سطح دايره متناظر را محاسبه.
Butterfly I/O Ports CS-212 Dick Steflik. I/O for our labs To get data into and out of our Butterfly its a little trickier than using printf and scanf.
AVR Programming CS-212 Dick Steflik. ATmega328P I/O for our labs To get data into and out of our Arduino its a little trickier than using printf and.
فایل پردازی در C File based Programming in C. انواع فایل متنی –سرعت بالا –حجم کمتر –امکان دسترسی تصادفی –حفظ امنیت داده ها دودویی (باینری) –امکان باز.
AVR Microcontrollers Firsrt Session.
ARM Session , Spring Copyright © 2012 Mohammad Moallemi.
Embedded Systems Programming 1 ETEE 3285 Topic HW3: Coding, Compiling, Simulating.
Timer/counter Chapter 12
I/O Ports CS-280 Dr. Mark L. Hornick 1. CS-280 Dr. Mark L. Hornick 2 Ports are channels from the CPU to external hardware and software Atmega32 has: 4.
1 Network Address Translation (NAT). 2 Private Network شبکه خصوصی شبکه ای است که بطور مستقیم به اینترنت متصل نیست در یک شبکه خصوصی آدرس های IP به دلخواه.
1 Lab 1: Introduction. 2 Configure ATMEL AVR Starter Kit 500 (STK500), a prototyping/development board for Lab1. ATmega16 ( V) is the chip used.
1 بنام خدا زبان برنامه نویسی C (21814( Lecture 14 Structures.
به نام خدا برنامه سازی سمت سرور (php)
نوشتن كد برنامه در AVR STUDIO. شروع برنامه قسمت داده :.DSEG.ORG 0X60.DEF TEMP,R16.EQU LENGTH,10.SET KEY_PORT,PORTC.STRING:.BYTE 5.
Timers and Interrupts Anurag Dwivedi. Let Us Revise.
Input / Output (Peripheral) Interfacing
1 بنام خدا زبان برنامه نویسی C (21814( Lecture 9 Selected Topics.
فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Program is created in the editor and stored on disk. Preprocessor.
Discussion 2 STATE MACHINES AND AVR ASSEMBLY CMPE 311 / FALL 2015 DR. MOHSENIN & MR. SMITH GTAS: RUTHVIK KUKKAPALLI, AMEY KULKARNI UTAS: JASON KLIMEK,
11. Temperature & Time 제어 충북인력개발원 전자과 공학박사 강원찬.
فصل 4 پرتهای ورودی و خروجی. برای هر پورت سه ثبات 8 بیتی در منطقه رجیسترهای I/O وجود دارد که بعنوان مثال برای پورت A این ثبات ها عبارتند از:
Stepper Motor Configuration
Alphanumeric LCD Configuration
PORT(I/O) Configuration
Seven Segment Configuration Lecturer: Reza Arjmandi Autumn 2015 Lecture 5: Introduction 7Segment Configuration.
Arduino Mega Arduino Mega 2560 Arduino Mega 2560.
BRANCHES SUBROUTINES AND MEMORY USAGE AVR Assembler M. Neil - Microprocessor Course 1.
Interrupt Control Unit Lecturer: Reza Arjmandi Autumn 2015 Lecture 10, 11: Introduction Interrupt Concept, interrupt control unit and External Interrupt.
Lecturer: Reza Arjmandi Autumn 2015
CS-280 Dr. Mark L. Hornick 1 Sequential Execution Normally, CPU sequentially executes instructions in a program Subroutine calls are synchronous to the.
تایمر در میکروکنترلرهای AVR. تایمرها در میکروکنترلرهای AVR تایمر در حقیقت یک شمارنده است که پالس ورودی را می شمارد. در صورتی که پالس ورودی کنتور از پالس.
Introduction to AVR Name : 1) Abhishek Yadav ) Prakash Giri ) Kheni Niral ) Bhadresh Langadiya Branch.
Vishwakarma government engineering college Prepare by. Hardik Jolapara( ) LCD Interfacing with ATmega16.
Interfacing of Input/Output devices with AVR Microcontroller Enrolment No. : Name of the student: SOMAIYA ISHA.
1 Lab 4: D/A Converter Lab 4: D/A Converter This is a simple resistive network for a D/A converter Port 1, Port 0 are digital inputs ==> 00 (minimum),
آشنايي با سيستم اعداد.
Assembly Language with GCC
Introduction to Smart Systems
Embedded Systems Programming Examples and Comparison
(6. Sunu) (AVR Assembly Örnekleri)
COMP2121: Microprocessors and Interfacing
[c.
The Arduino Microcontroller: Atmel AVR Atmega 328
Session 3,4.
ATmega103 Timer0 and Interrupts
Session 6.
تمرین هفتم بسم الله الرحمن الرحیم درس یادگیری ماشین محمدعلی کیوان راد
بنام خدا زبان برنامه نویسی C (21814( Lecture 12 Selected Topics
Mobile Robot Kinematics
I/O Ports in AVR Sepehr Naimi
تکنیک دیماتل DEMATEL: decision making trial and evaluation laboratory.
Session 5.
Tim Sumner, Imperial College, Rm: 1009, x47552
Tim Sumner, Imperial College, Rm: 1009, x47552
I/O Ports in AVR Sepehr Naimi
جستجوی منابع الکترونیک
فصل ششم مدارهای ترتیبی.
برنامه ریزی خطی پیشرفته (21715( Advanced Linear Programming Lecture 7
مباني كامپيوتر و برنامه سازي Basics of Computer and Programming
مباني كامپيوتر و برنامه سازي Basics of Computer and Programming
طریقه ارسال اطلاعات به فیدا و دریافت شناسه فروشنده
(Dr. Öğr. Üyesi Deniz Dal)
COMP3221: Microprocessors and Embedded Systems
Presentation transcript:

برای هر پورت سه آدرس در حافظهSRAM یا سه ثبات ورودی خروجی I/O 8 بیتی تعریف میشود که عبارتند از: 1- یک ثبات برای نوشتن و خواندن داده به نام PORTX (Port Data Reg.) X مشخص کننده نام پورت بوده و میتواند یکی از حروف D, C, B, A باشد. 2- یک ثبات برای تعیین جهت پورت به نام DDRX(Port Data Direction Reg.) اگر در بیت های این ثبات مقدار 1 نوشته شود بیت پورت مورد نظر خروجی و در صورتی که 0 نوشته شود بیت پورت مذکور ورودی خواهد بود. 3- یک ثبات برای خواندن اطلاعات از پورت ورودی، به نام PINX(Port Input Pins Reg.) که فقط میتوان از آن خواند. 4- هر بیت از پورت ها درثبات هایDDRX PINX, PORTX, با PORTxn, DDRxn و PINxn نشان داده میشود. که x نام پورت و n شماره بیت پورت میباشد. به عنوان مثال: PORTB0, DDRC2, PORTD5 5- زمانی که یک پایه پورت بصورت ورودی تعریف شود اگر در بیت نظیر PORTxn مقدار 1نوشته شود در این صورت مقاومت Pull-up در ورودی قرار داده میشود، در غیر اینصورت پایه ورودی در حالت Tri-state است

مثال: برنامه ای به زبان اسمبلی AVR ATmega32 بنویسید که مرتبا از پورت D بخواند و بر پورت B بنویسد. حل:

;port0.asm ;*********************************************** ;A Section ; ;* Number :atmega32 ;* File Name :port0.asm ;* Title :Setup and Use The ports ;*********************************************** ;B Section ;.include "m32def.inc“.org0x000;* Reset-Address rjmpReset;1-jump reset ;***********************************************

; *** Begin of Program Execution *** ;C Section ; ;*******Main program entry point on Reset******* Reset: ;***Initializing *** ;***Initializing PORTB as output*** ser r16;2-r16=0FFh out DDRB,r16 ;3-PORTB output ;***Initialize PORTD as input *** clr r16;4-PORTD as out DDRD,r16 ;5- input ser r17 ;6-Pull-up out PORTD,r17 ;7-PORTD ;*********************************************** ;D Section ; ;***Read PORTD & write on PORTB(constantly) *** loopforever: in r8,PIND;8- Read from PORTD out PORTB,r8;9- write on PORTB rjmp loopforever ;10- jump loopforever

مثال: برنامه ای به زبان اسمبلی AVR ATmega16 بنویسید که مرتبا از بیت های 0و 1 پورت B بخواند و آنها را AND کرده نتیجه را در بیت 2 پورت B بنویسد. حل:

; bit_port_Atmega16.asm ;***************************************************** ;A section ; ;AVR number :atmega16 ;File name:bit_port_Atmega16.asm ;Description:This is a sample of assembly ; :structure only using registers ; : & input output ports ;* recomendation:1-use R26-R31 for pointers ; ;2-R16-up for load immediate ;**************************************************** ;B Section ;.include "m16def.inc" ;This header file is needed ; ;for all avr atmega16 ; ;assembly language ;Interrupt vectors table.org0x000;Reset address rjmpReset;(1) Jump to reset ;****************************************************

;C Section ; ;*******Main program entry point on reset Reset: ; ;Initializing the PortB ;PB0,PB1 as Inputs & PB2 as Output LDIR16,0b ;(2) OUTDDRB,R16 ;(3) ;Pull Up PB0,PB1 LDIR16,0b ;(4) OUTPORTB,R16 ;(5) ;initialize R18 LDIR18,0X03 ;(6)R18=3 ;*************************************************** ;D Section ; loopforever: CBIPORTB,2;(7) Clear bit PB2 ;(turn off led) AGAIN: INR17,PinB;(8)Read port B ANDR17,R18;(9)AND registers CPIR17,3;(10) Compare BREQSET_PB2 ;(11)Branch if Equal RJMPloopforever ;(12)Jump loopforever SET_PB2: SBIPORTB,2;(13)Set Bit PB2 RJMPAGAIN;(14)go again

مثال: برنامه ای به زبان اسمبلی AVR ATmega8 و با استفاده از سابروتین بنویسید که پورت D را با یک تاخیر متناوبا 0و1 کند. حل:

; led.asm ;***************************************************** ;A section ;AVR number:atmega8 ;File name:led.asm ;Descrption::This is a sample assembly ;:program with subroutine ;***************************************************** ;B section.include "m8def.inc";Header file for Atmega8 ;Interrupt vector table.org 0x000;Reset_address rjmpReset ;(1) ;***************************************************** ;C section ; begin of main program reset: ;*****************initializing stack pointer********** ldi r16,low(RAMEND);(2) out SPL,r16;(3) ldi r16,high(RAMEND);(4) out SPH,r16;(5) ;********initializing the ports ;PortD as output ldi r16, 0xFF ;(6) out DDRD, r16 ;(7)DDRD=0xFF ;*****************loopforever************************

;D section loopforever: ser R16 ;(8)r16=0xFF in R17,PORTD ;(9)read PORTD to R17 eor R17,R16 ;(10)XOR R17 with R16 out PORTD,R17 ;(11)write R17 to PORTD rcall Delay ;(12)call subroutine Delay rjmp loopforever ;(13)jump to loopforever ;************Write subroutine************************* ;E section ;subroutine to make a delay Delay: ldi r24,0 ;(14)r24=0 ldi r25,0 ;(15)r25=0 wait: inc r24 ;(16)increment r24 cpi r24,0xFF ;(17)compare r24 with 0xFF brne wait ;(18)branch not equal to wait inc r25 ;(19)increment r25 cpi r25,0x4F ;(20)compare r25 to 0x0F brne wait ;(21)branch not equal to wait ret ;(22)return from subroutine

نوشتن برنامه های میکروکنترلرهای AVR به زبان c در محیط نرم افزار CodeVisionAVR مزیت زبان C: مناسب برای برنامه های بزرگ و پیچیده معایب زبان C: بر خلاف زبان اسمبلی فضای زیادی از حافظه را اشغال کرده و سرعت پایینی دارد. مثال: برنامه ای به زبان C برای AVR ATmega8 بنویسید که از پورت D بخواند و بر پورت B بنویسد. حل:

/***************************************************** This program was produced by the CodeWizardAVR V1.24.2c Standard Automatic Program Generator © Copyright Pavel Haiduc, HP InfoTech s.r.l. Project : Version : Date : 2006/11/06 Author : srazi Company : Comments: Chip type : ATmega8 Program type : Application Clock frequency : MHz Memory model : Small External SRAM size : 0 Data Stack size : 256 *****************************************************/ #include //(0) // Declare your global variables here

void main(void) { // Declare your local variables here // Input/Output Ports initialization // Port B initialization,Port B as output // Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out // Func2=Out Func1=Out Func0=Out // State7=0 State6=0 State5=0 State4=0 State3=0 //State2=0 State1=0 State0=0 PORTB=0x00; //(1) DDRB=0xFF; //(2) // Port D initialization, Port D as input with pull_up // Func7=In Func6=In Func5=In Func4=In Func3=In //Func2=In Func1=In Func0=In // State7=P State6=P State5=P State4=P State3=P //State2=P State1=P State0=P PORTD=0xFF; //(3) DDRD=0x00; //(4) while (1) { // Place your code here //Read port D and write on port B PORTB=PIND; //(5) }; }

مثال: برنامه ای به زبان C با میکروکنترلر AVR ATmega8 و در محیط CodeVisionAVR بنویسید که پورت D را با یک تاخیر 1 ثانیه مکمل کند. حل:

/***************************************************** This program was produced by the CodeWizardAVR V1.24.2c Standard Automatic Program Generator © Copyright Pavel Haiduc, HP InfoTech s.r.l. Project : Version : Date : 2006/11/09 Author : srazi Company : Comments: Chip type : ATmega8 Program type : Application Clock frequency : MHz Memory model : Small External SRAM size : 0 Data Stack size : 256 *******************************************************/

#include //(1) //include function dealay for using delay in program #include //(2) // Declare your global variables here void main(void) { // Declare your local variables here // Input/Output Ports initialization // Port D initialization, Port D as output // Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out //Func2=Out Func1=Out Func0=Out // State7=0 State6=0 State5=0 State4=0 State3=0 //State2=0 State1=0 State0=0 PORTD=0x00;//(3) DDRD=0xFF; //(4) //main program loop while (1) { // Place your code here PORTD=~PORTD; //(5)invert Port D delay_ms(1000); //(6)make 1000 //ms delay }; }

اتصال LCD به میکروکنترلرهای AVR

اطلاعات را میتوان به صورت 8 بیتی یا 4 بیتی برای LCD ارسال نمود.

طریقه استفاده از LCD و اتصال آن به میکروکنترلرهای AVR در محیط نرم افزاری CodeVisionAVR

برنامه ای به زبان C برای میکروکنترلرهای ATmega32 بنویسد که بر روی LCD پیغام microcontroller course را بنویسد.

/***************************************************** This program was produced by the CodeWizardAVR V1.24.2c Standard Automatic Program Generator © Copyright Pavel Haiduc, HP InfoTech s.r.l. Project : Version : Date : 2006/11/22 Author : srazi Company : Comments: Chip type : ATmega8L Program type : Application Clock frequency : MHz Memory model : Small External SRAM size : 0 Data Stack size : 256 *****************************************************/ #include //(1) // Alphanumeric LCD Module functions #asm //(2).equ __lcd_port=0x18 ;PORTB //(3) #endasm //(4) #include //(5) // Declare your global variables here

void main(void) //(6) { // Declare your local variables here // Input/Output Ports initialization // Port B initialization,Port B as input // Func7=In Func6=In Func5=In Func4=In Func3=In //Func2=In Func1=In Func0=In // State7=T State6=T State5=T State4=T State3=T //State2=T State1=T State0=T PORTB=0x00; //(7) DDRB=0x00; //(8) // LCD module initialization lcd_init(16); //(9)LCD is 16 characters lcd_clear(); //(10)clear LCD lcd_gotoxy(0,0); //(11)go to column 0 line 0 lcd_putsf("microcontroller"); //(12)write microcontroller lcd_gotoxy(5,1); //(13)go to column 5 line 1 lcd_putsf("course"); //(14)write course while (1) { // Place your code here }; }

مثال: برنامه ای بنویسید که با موتور پله ای 1.8 درجه برای هر پالس مقدار 90 درجه بچرخد.

/************************************************ A Section Chip type : ATmega8 Program type : Application Clock frequency : MHz *****************************************************/ //B Section #include //(1) #include //(2) unsigned int WORK; //(3) counter char DELAY; //(4) unsigned int MAX; //(5) number of iteration char STEP; //(6) // Declare your global variables here void main(void) //(7) { // Declare your local variables here // Input/Output Ports initialization // Port B initialization // Func7=In Func6=In Func5=In Func4=In //Func3=Out Func2=Out Func1=Out Func0=Out // State7=T State6=T State5=T State4=T // State3=0 State2=0 State1=0 State0=0 PORTB=0x00; //(8) DDRB=0x0F; //(9)

//Initial values DELAY=20; //(10) STEP=0xCC; //(11) WORK=0; //(12) MAX=50; //(13) //C Sction********************************************** while (WORK<MAX) //(14) { PORTB=STEP; //(15) delay_ms(DELAY); //(16) STEP=STEP>>1; //(17) WORK++; //(18) if (STEP==1) //(19) { PORTB=0x09; //(20) delay_ms(DELAY); //(21) STEP=0xCC; //(22) WORK++; //(23) } //(24) }; //(25) } //(26)

مثال : برنامه ای بنویسید که اعداد 0 تا 9999 را بر روی چهار لامپ هفت قسمتی 1 تا 4 نشان دهد.

/***************************************************** Chip type : ATmega16 Program type : Application Clock frequency : MHz *****************************************************/ #include //(1) Header file #include //(2) long int temp1, temp2, temp3, temp4, temp5, temp6, i; //(3) Define int j;//(4) Parameters flash unsigned char number[10]={0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90};//(5) Define codes in flash void main (void)//(6) Main program { while(1)//(7) Do it again { DDRA = 0xff;//(8) Define port A & B as output PORTA = 0xff;//(9) DDRB = 0xff;//(10) PORTB = 0xff; //(11)

for(i=1;i<=9999;i++)//(12)First FOR, count i from 1 to 9999 { //Calculate yekan, dahgan, sadgan, hezargan of i temp1=i/10;//(13) temp2=i-10*temp1;//(14) temp3=temp1/10;//(15) temp4=temp1-10*temp3;//(16) temp5=temp3/10;//(17) temp6=temp3-10*temp5;//(18) //Display yekan, dahgan, sadgan, heazrgan on lamp 1 to 4,60 times for(j=1;j<60;j++)//(19) { PORTB=0xfe;//(20) PORTA=number[temp2]; //(21) delay_ms(1); //(22) PORTB=0xfd;//(23) PORTA=number[temp4]; //(24) delay_ms(1); //(25) PORTB=0xfb;//(26) PORTA=number[temp6]; //(27) delay_ms(1); //(28) PORTB=0xf7;//(29) PORTA=number[temp5]; //(30) delay_ms(1); //(31) } //(32) } //(33) }//(34)Do it again for next number of i }//(35)