(Dr. Öğr. Üyesi Deniz Dal)

Slides:



Advertisements
Similar presentations
Khaled A. Al-Utaibi Interfacing an LED The Light Emitting Diode (LED) Applications DC Characteristics & Operation Interfacing to.
Advertisements

Anurag Dwivedi & Rudra Pratap Suman.  Open Source electronic prototyping platform based on flexible easy to use hardware and software.
Lab 3 General MIDI Explorer with Record/Playback
Digital & Analog Inputs. Review Fundamental parts of an Arduino program are … Setting output types using pinMode. Declaring variables Can write a digital.
Intro to Programming and Microcontrollers. Activity Group into pairs and sit back-to-back. Pick one person who is going to draw. The other person will.
COMP3221: Microprocessors and Embedded Systems--Lecture 8 1 COMP3221: Microprocessors and Embedded Systems Lecture 8: Program Control Instructions
8-Bit Timer/Counter 0 Counter/Timer 0 and 2 (TCNT0, TCNT2) are nearly identical. Differences: -TCNT0 can run off an external 32Khz clock (Tosc) or the.
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.
Finish your programs from last week STOPLIGHT CIRCUIT! You may need … – int – void setup() – void loop() – pinMode – digitalWrite – delay.
16-Bit Timer/Counter 1 and 3 Counter/Timer 1,3 (TCNT1, TCNT3) are identical in function. Three separate comparison registers exist. Thus, three separate.
chipKit Sense Switch & Control LED
Timer/counter Chapter 12
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
Khaled A. Al-Utaibi  The Push Button  Interfacing Push Buttons to Arduino  Programming Digital Inputs  Working with “Bouncy”
Good LED Circuit 5V0 GND. What Voltage Does Meter See? Answer: 5 V.
LECTURE 2 – INPUTS THIS LECTURE WILL INTRODUCE HOW TO INPUT SIGNALS INTO AN ARDUINO.
Discussion 2 STATE MACHINES AND AVR ASSEMBLY CMPE 311 / FALL 2015 DR. MOHSENIN & MR. SMITH GTAS: RUTHVIK KUKKAPALLI, AMEY KULKARNI UTAS: JASON KLIMEK,
Warmup – 16FEB2012 This one is for practice. I have paper if you need it. Suppose there are eight, single-pole, single-throw (SPST) switches connected.
Interrupt On a very basic level, an interrupt is a signal that interrupts the current processor activity. It may be triggered by an external event (change.
Arduino libraries Datatekniker Udvidet hardware/software.
BRANCHES SUBROUTINES AND MEMORY USAGE AVR Assembler M. Neil - Microprocessor Course 1.
INTERNET OF EVERYTHING SDU 2016 Week 4. Simple Digital and Analog Inputs  The Arduino’s ability to sense digital and analog inputs allows it to respond.
CS-280 Dr. Mark L. Hornick 1 Sequential Execution Normally, CPU sequentially executes instructions in a program Subroutine calls are synchronous to the.
The AVR microcontroller
Microcontroller basics Embedded systems for mortals.
Microcontroller basics Embedded systems for mortals.
Programming in Arduino Materials:Arduino Board Casperelectronics Pre Pres. Notes Photos from workshop?
Arduino + Bluetooth TYWu. Connection Arduino + Bluetooth Module.
:Blink Blink: Er. Sahil Khanna
Arduino “Getting Started” Instructor : Dr Matthew Miss Khin Yi Kyaw
Interfacing of Input/Output devices with AVR Microcontroller Enrolment No. : Name of the student: SOMAIYA ISHA.
physical computing .2 – Day 3
16-Bit Timer/Counter 1 and 3
Timers and Scheduled Interrupts
Having fun with code, using Arduino in a middle school CS classroom
Outline Introduction to Arduino UNO Programming environment setup GPIO
Assist. Prof. Rassim Suliyev - SDU 2017
Microcontroller basics
Introduction to Smart Systems
Embedded Systems Programming Examples and Comparison
Microcontroller basics
Wireless Cue Light Project
Overview of Architecture Assembly Programming Concepts
Get Your Project Started with Arduino
(6. Sunu) (AVR Assembly Örnekleri)
European Robotic LABoratory
3.0 ARDUINO WORKSHOP PRESENTATION FOR STUDENTS IN 4º DEGREE OF COMPULSORY SECONDARY EDUCATION 3.0.
Arduino.
Въведение в Arduino.
Arduino Basics Connect Arduino to USB port
BM-305 Mikrodenetleyiciler Güz 2017 (3. Sunu)
8-Bit Timer/Counter 0 Counter/Timer 0 and 2 (TCNT0, TCNT2) are nearly identical. Differences: -TCNT0 can run off an external 32Khz clock (Tosc) or the.
Timer/Counter Modified from Dr. Lam Phung’s Slides.
ATmega103 Timer0 and Interrupts
IoT Programming the Particle Photon.
Servos and Stepper Motors
I/O Ports in AVR Sepehr Naimi
CS-4540 Robotics - Lab 05 Switch inputs to the Arduino Uno
Tim Sumner, Imperial College, Rm: 1009, x47552
Tim Sumner, Imperial College, Rm: 1009, x47552
I/O Ports in AVR Sepehr Naimi
ADC and DAC Programming in AVR
Advanced Assembly Chapter 6
Wave Generation and Input Capturing
Interrupt Chapter 10.
(Dr. Öğr. Üyesi Deniz Dal)
COMP3221: Microprocessors and Embedded Systems
Arduino Uno circuit basics
Setting up a basic program with Arduino
SAURABH GINGADE.
Presentation transcript:

(Dr. Öğr. Üyesi Deniz Dal) BM-305 Mikrodenetleyiciler Güz 2018 (6. Sunu) (AVR Assembly Örnekleri) (Dr. Öğr. Üyesi Deniz Dal)

Geçici Anahtar ile LED Kontrolü (Dijital Giriş ve Çıkış)

Geçici Anahtar ile LED Kontrolü (Dijital Giriş ve Çıkış) (Arduino) /* Turns on and off a light emitting diode(LED) connected to digital pin 13, when pressing a pushbutton attached to pin 2. */ const int buttonPin = 2;//the number of the pushbutton pin const int ledPin = 13;//the number of the LED pin int buttonState = 0;//variable for reading the pushbutton status void setup() { pinMode(ledPin, OUTPUT);//initialize the LED pin as an output pinMode(buttonPin, INPUT);//initialize the pushbutton pin as an input } void loop() { //read the state of the pushbutton value buttonState = digitalRead(buttonPin); //check if the pushbutton is pressed //if it is, the buttonState is HIGH if (buttonState == HIGH) digitalWrite(ledPin, HIGH);//turn LED on else digitalWrite(ledPin, LOW);//turn LED off

Geçici Anahtar ile LED Kontrolü (Dijital Giriş ve Çıkış) (Arduino)

Geçici Anahtar ile LED Kontrolü (Dijital Giriş ve Çıkış) (AVR C) /* Led connected to Digital Pin 13 (PORTB.5) Pushbutton switch connected to Digital Pin 2 (PORTD.2) */ #include <avr/io.h> int main() { //-----------------Setup-----------------// DDRB |= (1 << 5); //Set PORTB.5 as output PORTB &= ~(1 << 5);//Turn led off DDRD &= ~(1 << 2); //Set PORTD.2 as input //-----------------Loop-----------------// while(1) if((PIND & (1 << 2)) == 0) else PORTB |= (1 << 5); //Turn led on } return 0;

Geçici Anahtar ile LED Kontrolü (Dijital Giriş ve Çıkış) (AVR C)

Geçici Anahtar ile LED Kontrolü (AVR Assembly) (Button.asm) Bu program kaç buyruk/komut içeriyor? Her bir buyruk/komut kaç byte lık veri içeriyor? Bu AVR Assembly programı toplamda kaç byte lık veri içeriyor? ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;When the button is pressed, the led is turned on ; ;Led connected to Digital Pin 13 (PORTB.5) ; ;Pushbutton switch connected to Digital Pin 2 (PORTD.2); .INCLUDE "m328pdef.inc";Header for ATMEGA328P setup: LDI R16,0x20 ;LoaD Immeadiate value to R16 OUT DDRB,R16 ;Set PORTB.5 as output LDI R16,0x00 ;LoaD Immeadiate value to R16 OUT PORTB,R16 ;Turn led off OUT DDRD,R16 ;Set PORTB.2 as input loop: IN R16,PIND ;Read PORTD pin values and store them in R16 ANDI R16,0x04 ;AND Immediate BRNE elseLabel ;BRanch Not Equal ifLabel: RJMP ifEndLabel ;Relative JuMP elseLabel: OUT PORTB,R16 ;Turn led on ifEndLabel: RJMP loop ;Relative JuMP Bu program nereye yüklenecek?

Geçici Anahtar ile LED Kontrolü (AVR Assembly) (Button.asm)

Merhaba Dünya (Digital Write with Delay) (Arduino) //Turns on an LED on for one second, then off for one second, repeatedly //setup function runs once when you press reset or power the board void setup() { //initialize digital pin LED_BUILTIN as an output pinMode(LED_BUILTIN, OUTPUT); } //loop function runs over and over again forever void loop() { digitalWrite(LED_BUILTIN, HIGH);//turn the LED on (HIGH is the voltage level) delay(1000); //wait for a second digitalWrite(LED_BUILTIN, LOW); //turn the LED off by making the voltage LOW

Merhaba Dünya (Digital Write with Delay) (AVR C) (Delay is Generated by Timer 1 in Normal Mode) //Turn the led on and off for 1 second using Timer 1 in Normal Mode //Clock Frequency (Fcpu)=16 MHz, Prescaler=1024 #include <avr/io.h> int main() { DDRB|=(1<<5);//Set Pin 13 as OUTPUT PORTB&=~(1<<5);//Set Pin 13 as LOW TCCR1B|=((1<<CS12)|(1<<CS10));//Set Timer 1 scaler as Fcpu/1024 while(1) TCNT1=49911;//65536-15625 while((TIFR1&(1<<TOV1))==0);//Polling TIFR1|=(1<<TOV1);//Clear the overflow flag?? PORTB^=(1<<5);//Toogle Pin 13 } return 0;

Merhaba Dünya (Digital Write with Delay) (AVR C) (Delay is Generated by Timer 1 in Normal Mode)

Merhaba Dünya (Digital Write with Delay) (AVR Assembly) (HelloWorld Merhaba Dünya (Digital Write with Delay) (AVR Assembly) (HelloWorld.asm) (Delay is Generated by Timer 1 in Normal Mode) Bu program kaç buyruk/komut içeriyor? Her bir buyruk/komut kaç byte lık veri içeriyor? ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Turn the led on and off for 1 second using Timer 1 in Normal Mode; ;Clock frequency (Fcpu)=16 MHz, Prescaler=1024 ; ;Led connected to Digital Pin 13 (PORTB.5) ; .INCLUDE "m328pdef.inc";Header for ATMEGA328P setup: LDI R16,0x20 ;LoaD Immeadiate value to R16 OUT DDRB,R16 ;Set PORTB.5 as output LDI R16,0x00 ;LoaD Immeadiate value to R16 OUT PORTB,R16 ;Turn led off ;No action is required for Normal Mode LDI R16,0x05 ;Turn CS12 and CS10 on STS TCCR1B,R16 ;STore direct to data Space ;Set Timer 1 prescaler as Fcpu/1024 loop: LDI R17,HIGH(49911);Load 0xC2 to R17 LDI R16,LOW(49911) ;Load 0xF7 to R16 STS TCNT1H,R17 ;STore direct to data Space STS TCNT1L,R16 ;STore direct to data Space pollingLabel: IN R16,TIFR1 ;Read the flags ANDI R16,0x01 ;Check if the TOV1 flag is 0 BREQ pollingLabel ;BRanch EQual ORI R16,0x01 ;OR Immediate OUT TIFR1,R16 ;Clear TOV1 flag by setting IN R16,PORTB ;Read PORTB pins LDI R17, 0x20 ;LoaD Immeadiate value to R17 EOR R16,R17 ;Exclusive OR OUT PORTB,R16 ;Toggle Pin 13 RJMP loop ;Relative JuMP Bu AVR Assembly programı toplamda kaç byte lık veri içeriyor? Bu program nereye yüklenecek?

Merhaba Dünya (Digital Write with Delay) (AVR Assembly) (HelloWorld Merhaba Dünya (Digital Write with Delay) (AVR Assembly) (HelloWorld.asm) (Delay is Generated by Timer 1 in Normal Mode)

Merhaba Dünya (Digital Write with Delay Function) (AVR C) (Delay is Generated by Timer 1 in Normal Mode) //Turn the led on and off for n seconds using Timer 1 in Normal Mode //Clock Frequency Fcpu=16 MHz, Prescaler=1024 #include <avr/io.h> void DelayNSecond(int n);//Function Prototype int main() { DDRB|=(1<<5);//Set Pin 13 as OUTPUT TCCR1B|=((1<<CS12)|(1<<CS10));//Set Timer 1 scaler as Fcpu/1024 while(1) PORTB&=~(1<<5);//Set Pin 13 as LOW DelayNSecond(5); PORTB|=(1<<5);//Set Pin 13 as HIGH } return 0; void DelayNSecond(int n)//Function Definition for(int i=1;i<=n;i++) TCNT1=49911;//65536-15625 while((TIFR1&(1<<TOV1))==0);//Polling TIFR1|=(1<<TOV1);//Clear the overflow flag

Merhaba Dünya (Digital Write with Delay Function) (AVR Assembly) (HelloWorld.asm) (Delay is Generated by Timer 1 in Normal Mode) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Turn the led on and off for n seconds using Timer 1 in Normal Mode; ;Clock frequency Fcpu=16 MHz, Prescaler=1024 ; ;Led connected to Digital Pin 13 (PORTB.5) ; .INCLUDE "m328pdef.inc";Header for ATMEGA328P setup: ;Initialize Stack Pointer LDI R16,LOW(RAMEND) OUT SPL,R16 ;Stack Pointer Low LDI R16,HIGH(RAMEND) OUT SPH,R16 ;Stack Pointer High ;Set PORTB.5 as output LDI R16,0x20 OUT DDRB,R16 ;No action is required for Normal Mode ;Set Timer 1 prescaler as Fcpu/1024 LDI R16,0x05 ;Turn CS12 and CS10 on STS TCCR1B,R16 ;STore direct to data Space ;Set N as 5 seconds LDI R18,0x05 loop: ;Turn led off LDI R16,0x00 OUT PORTB,R16 RCALL delayNseconds ;Relative CALL ;Turn led on RJMP loop ;Relative JuMP ;Delay subroutine delayNseconds: PUSH R18 delay1sec: LDI R17,HIGH(49911);Load 0xC2 to R17 LDI R16,LOW(49911) ;Load 0xF7 to R16 STS TCNT1H,R17 ;STore direct to data Space STS TCNT1L,R16 ;STore direct to data Space pollingLabel: IN R16,TIFR1 ;Read the flags ANDI R16,0x01 ;Check if the TOV1 flag is 0 BREQ pollingLabel ;BRanch EQual ORI R16,0x01 ;OR Immediate OUT TIFR1,R16 ;Clear TOV1 flag by setting DEC R18 BRNE delay1sec POP R18 RET

Merhaba Dünya (Digital Write with Delay Function) (AVR Assembly) (HelloWorld.asm) (Delay is Generated by Timer 1 in Normal Mode) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Turn the led on and off for n seconds using Timer 1 in Normal Mode; ;Clock frequency Fcpu=16 MHz, Prescaler=1024 ; ;Led connected to Digital Pin 13 (PORTB.5) ; .INCLUDE "m328pdef.inc";Header for ATMEGA328P setup: ;Initialize Stack Pointer LDI R16,low(RAMEND) OUT SPL,R16 ;Stack Pointer Low LDI R16,high(RAMEND) OUT SPH,R16 ;Stack Pointer High ;Set PORTB.5 as output LDI R16,0x20 OUT DDRB,R16 ;No action is required for Normal Mode ;Set Timer 1 prescaler as Fcpu/1024 LDI R16,0x05 ;Turn CS12 and CS10 on STS TCCR1B,R16 ;STore direct to data Space ;Set N as 5 seconds LDI R18,0x05 loop: ;Turn led off LDI R16,0x00 OUT PORTB,R16 RCALL delayNseconds ;Relative CALL ;Turn led on RJMP loop ;Relative JuMP ;Delay subroutine delayNseconds: PUSH R18 delay1sec: LDI R17,HIGH(49911);Load 0xC2 to R17 LDI R16,LOW(49911) ;Load 0xF7 to R16 STS TCNT1H,R17 ;STore direct to data Space STS TCNT1L,R16 ;STore direct to data Space pollingLabel: IN R16,TIFR1 ;Read the flags ANDI R16,0x01 ;Check if the TOV1 flag is 0 BREQ pollingLabel ;BRanch EQual ORI R16,0x01 ;OR Immediate OUT TIFR1,R16 ;Clear TOV1 flag by setting DEC R18 BRNE delay1sec POP R18 RET

Merhaba Dünya (Digital Write with Delay Function) (AVR Assembly) (HelloWorld.asm) (Delay is Generated by Timer 1 in Normal Mode) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Turn the led on and off for n seconds using Timer 1 in Normal Mode; ;Clock frequency Fcpu=16 MHz, Prescaler=1024 ; ;Led connected to Digital Pin 13 (PORTB.5) ; .INCLUDE "m328pdef.inc";Header for ATMEGA328P setup: ;Initialize Stack Pointer LDI R16,low(RAMEND) OUT SPL,R16 ;Stack Pointer Low LDI R16,high(RAMEND) OUT SPH,R16 ;Stack Pointer High ;Set PORTB.5 as output LDI R16,0x20 OUT DDRB,R16 ;No action is required for Normal Mode ;Set Timer 1 prescaler as Fcpu/1024 LDI R16,0x05 ;Turn CS12 and CS10 on STS TCCR1B,R16 ;STore direct to data Space ;Set N as 5 seconds LDI R18,0x05 loop: ;Turn led off LDI R16,0x00 OUT PORTB,R16 RCALL delayNseconds ;Relative CALL ;Turn led on RJMP loop ;Relative JuMP ;Delay subroutine delayNseconds: PUSH R18 delay1sec: LDI R17,HIGH(49911);Load 0xC2 to R17 LDI R16,LOW(49911) ;Load 0xF7 to R16 STS TCNT1H,R17 ;STore direct to data Space STS TCNT1L,R16 ;STore direct to data Space pollingLabel: IN R16,TIFR1 ;Read the flags ANDI R16,0x01 ;Check if the TOV1 flag is 0 BREQ pollingLabel ;BRanch EQual ORI R16,0x01 ;OR Immediate OUT TIFR1,R16 ;Clear TOV1 flag by setting DEC R18 BRNE delay1sec POP R18 RET