Presentation is loading. Please wait.

Presentation is loading. Please wait.

(6. Sunu) (AVR Assembly Örnekleri)

Similar presentations


Presentation on theme: "(6. Sunu) (AVR Assembly Örnekleri)"— Presentation transcript:

1 (6. Sunu) (AVR Assembly Örnekleri)
BM-305 Mikrodenetleyiciler Güz 2016 (6. Sunu) (AVR Assembly Örnekleri) (Yrd. Doç. Dr. Deniz Dal)

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

3 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

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

5 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;

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

7 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,0x ;LoaD Immeadiate value to R16 OUT DDRB,R ;Set PORTB.5 as output LDI R16,0x ;LoaD Immeadiate value to R16 OUT PORTB,R ;Turn led off OUT DDRD,R ;Set PORTB.2 as input loop: IN R16,PIND ;Read PORTD pin values and store them in R16 ANDI R16,0x ;AND Immediate BRNE elseLabel ;BRanch Not Equal ifLabel: RJMP ifEndLabel ;Relative JuMP elseLabel: OUT PORTB,R ;Turn led on ifEndLabel: RJMP loop ;Relative JuMP Bu program nereye yüklenecek?

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

9 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

10 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;// while((TIFR1&(1<<TOV1))==0);//Polling TIFR1|=(1<<TOV1);//Clear the overflow flag?? PORTB^=(1<<5);//Toogle Pin 13 } return 0;

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

12 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= ; ;Led connected to Digital Pin 13 (PORTB.5) ; .INCLUDE "m328pdef.inc";Header for ATMEGA328P setup: LDI R16,0x ;LoaD Immeadiate value to R16 OUT DDRB,R ;Set PORTB.5 as output LDI R16,0x ;LoaD Immeadiate value to R16 OUT PORTB,R ;Turn led off ;No action is required for Normal Mode LDI R16,0x ;Turn CS12 and CS10 on STS TCCR1B,R ;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,R ;STore direct to data Space STS TCNT1L,R ;STore direct to data Space pollingLabel: IN R16,TIFR ;Read the flags ANDI R16,0x ;Check if the TOV1 flag is 0 BREQ pollingLabel ;BRanch EQual ORI R16,0x ;OR Immediate OUT TIFR1,R ;Clear TOV1 flag by setting IN R16,PORTB ;Read PORTB pins LDI R17, 0x ;LoaD Immeadiate value to R17 EOR R16,R ;Exclusive OR OUT PORTB,R ;Toggle Pin 13 RJMP loop ;Relative JuMP Bu AVR Assembly programı toplamda kaç byte lık veri içeriyor? Bu program nereye yüklenecek?

13 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)

14 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;// while((TIFR1&(1<<TOV1))==0);//Polling TIFR1|=(1<<TOV1);//Clear the overflow flag

15 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= ; ;Led connected to Digital Pin 13 (PORTB.5) ; .INCLUDE "m328pdef.inc";Header for ATMEGA328P setup: ;Initialize Stack Pointer LDI R16,LOW(RAMEND) OUT SPL,R ;Stack Pointer Low LDI R16,HIGH(RAMEND) OUT SPH,R ;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,0x ;Turn CS12 and CS10 on STS TCCR1B,R ;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,R ;STore direct to data Space STS TCNT1L,R ;STore direct to data Space pollingLabel: IN R16,TIFR ;Read the flags ANDI R16,0x ;Check if the TOV1 flag is 0 BREQ pollingLabel ;BRanch EQual ORI R16,0x ;OR Immediate OUT TIFR1,R ;Clear TOV1 flag by setting DEC R18 BRNE delay1sec POP R18 RET

16 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= ; ;Led connected to Digital Pin 13 (PORTB.5) ; .INCLUDE "m328pdef.inc";Header for ATMEGA328P setup: ;Initialize Stack Pointer LDI R16,low(RAMEND) OUT SPL,R ;Stack Pointer Low LDI R16,high(RAMEND) OUT SPH,R ;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,0x ;Turn CS12 and CS10 on STS TCCR1B,R ;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,R ;STore direct to data Space STS TCNT1L,R ;STore direct to data Space pollingLabel: IN R16,TIFR ;Read the flags ANDI R16,0x ;Check if the TOV1 flag is 0 BREQ pollingLabel ;BRanch EQual ORI R16,0x ;OR Immediate OUT TIFR1,R ;Clear TOV1 flag by setting DEC R18 BRNE delay1sec POP R18 RET

17 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= ; ;Led connected to Digital Pin 13 (PORTB.5) ; .INCLUDE "m328pdef.inc";Header for ATMEGA328P setup: ;Initialize Stack Pointer LDI R16,low(RAMEND) OUT SPL,R ;Stack Pointer Low LDI R16,high(RAMEND) OUT SPH,R ;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,0x ;Turn CS12 and CS10 on STS TCCR1B,R ;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,R ;STore direct to data Space STS TCNT1L,R ;STore direct to data Space pollingLabel: IN R16,TIFR ;Read the flags ANDI R16,0x ;Check if the TOV1 flag is 0 BREQ pollingLabel ;BRanch EQual ORI R16,0x ;OR Immediate OUT TIFR1,R ;Clear TOV1 flag by setting DEC R18 BRNE delay1sec POP R18 RET


Download ppt "(6. Sunu) (AVR Assembly Örnekleri)"

Similar presentations


Ads by Google