Skip to content

Instantly share code, notes, and snippets.

@Mervetafrali
Created March 24, 2017 09:04
Show Gist options
  • Save Mervetafrali/33bafa86fdc2909cfdf5478da074fb62 to your computer and use it in GitHub Desktop.
Save Mervetafrali/33bafa86fdc2909cfdf5478da074fb62 to your computer and use it in GitHub Desktop.

Sistem Programlama → 5.Sunum

1

Tiva & Stellaris Port Bağlantıları

1
2
3

Tiva & Stellaris Port

4
5

PortD Kullanılarak Led Yakma

6
7
#include <stdint.h>
#include "inc/tm4c123gh6pm.h"        // #include "inc/lm4f120h5qr.h"
void init_port_D() {
    volatile unsigned long delay;
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOD;
    delay = SYSCTL_RCGC2_R;
    GPIO_PORTD_DIR_R |= 0x0F;
    GPIO_PORTD_AFSEL_R &= ~0x0F;
    GPIO_PORTD_DEN_R |= 0x0F;
}
int main() {
    volatile unsigned long delay;
    init_port_D();
    while (1) {
      GPIO_PORTD_DATA_R |= 0b0010;
      GPIO_PORTD_DATA_R &= ~0b0001;
      for (delay = 0 ; delay < 400000 ; delay++)    /* bos dongu */;
      GPIO_PORTD_DATA_R |= 0b0001;
      GPIO_PORTD_DATA_R &= ~0b0010;
      for (delay = 0 ; delay < 400000 ; delay++)    /* bos dongu */;
    }
}

Gerekli Kütüphanelerin Eklenmesi

(int8_t, int16_t, int32_t, uint8_t, uint16_t, uint32_t) tipindeki tamsayı değerlerinin kullanılmasını sağlar
#include <stdint.h>


tiva kütüphanesi
#include "inc/tm4c123gh6pm.h"



stellaris kütüphanesi
#include "inc/lm4f120h5qr.h"

PortD Kullanılarak Led Yakma

#include <stdint.h>
#include "inc/tm4c123gh6pm.h"        // #include "inc/lm4f120h5qr.h"
void init_port_D() {
    volatile unsigned long delay;
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOD;
    delay = SYSCTL_RCGC2_R;
    GPIO_PORTD_DIR_R |= 0x0F;
    GPIO_PORTD_AFSEL_R &= ~0x0F;
    GPIO_PORTD_DEN_R |= 0x0F;
}
int main() {
    volatile unsigned long delay;
    init_port_D();
    while (1) {
      GPIO_PORTD_DATA_R |= 0b0010;
      GPIO_PORTD_DATA_R &= ~0b0001;
      for (delay = 0 ; delay < 400000 ; delay++)    /* bos dongu */;
      GPIO_PORTD_DATA_R |= 0b0001;
      GPIO_PORTD_DATA_R &= ~0b0010;
      for (delay = 0 ; delay < 400000 ; delay++)    /* bos dongu */;
    }
}

“volatile” (uçucu) değişken

Değişkenin değerini donanım değiştirsin;
int delay = 0;
while(delay == 0);

Derleyici donanım sevyesine inmeden değişkeni kaldırır:

Derleyicinin değişkene müdahil olmasını engellemek için;

volatile int delay = 0;
while(delay == 0);
“volatile” değişkene derleyici Müdahil olmaz
Farklı işlem (process) veya donanımsal etkiler sonucunda değeri değişen bir değişken (variable) kullanıyorsak, bu değişkeni volatile olarak tanımlamamız gerekir. Aksi halde derleyici (compiler) bu değişkeni optimize ederek görevini yerine getiremez bir hale sokabilir.

PortD Kullanılarak Led Yakma

#include <stdint.h>
#include "inc/tm4c123gh6pm.h"        // #include "inc/lm4f120h5qr.h"
void init_port_D() {
    volatile unsigned long delay;
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOD;
    delay = SYSCTL_RCGC2_R;
    GPIO_PORTD_DIR_R |= 0x0F;
    GPIO_PORTD_AFSEL_R &= ~0x0F;
    GPIO_PORTD_DEN_R |= 0x0F;
}
int main() {
    volatile unsigned long delay;
    init_port_D();
    while (1) {
      GPIO_PORTD_DATA_R |= 0b0010;
      GPIO_PORTD_DATA_R &= ~0b0001;
      for (delay = 0 ; delay < 400000 ; delay++)    /* bos dongu */;
      GPIO_PORTD_DATA_R |= 0b0001;
      GPIO_PORTD_DATA_R &= ~0b0010;
      for (delay = 0 ; delay < 400000 ; delay++)    /* bos dongu */;
    }
}

System Control Run Mod Clock Gate Control Register

8
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOA;     // Port A clock aktifleştirir
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOB;     // Port B clock aktifleştirir
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOC;     // Port C clock aktifleştirir
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOD;     // Port D clock aktifleştirir
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOE;     // Port E clock aktifleştirir
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOF;     // Port F clock aktifleştirir

/ Port D sayacını aktifleştirir
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOD;

SYSCTL_RCGC2_R x x x x x x x x
SYSCTL_RCGC2_GPIOD 0 0 0 0 1 0 0 0
OR--------------------------------------------
SYSCTL_RCGC2_R x x x x 1 x x x

SYSCTL_RCGC2_R |= 0x01;     // Port A sayacını aktifleştirir
SYSCTL_RCGC2_R |= 0x02;    // Port B sayacını aktifleştirir
SYSCTL_RCGC2_R |= 0x04;    // Port C sayacını aktifleştirir
SYSCTL_RCGC2_R |= 0x08;    // Port D sayacını aktifleştirir
SYSCTL_RCGC2_R |= 0x10;    // Port E sayacını aktifleştirir
SYSCTL_RCGC2_R |= 0x20;     // Port F sayacını aktifleştirir

0b00000001 = 0x01
0b00000010 = 0x02
0b00000100 = 0x04
0b00001000 = 0x08
0b00010000 = 0x10
0b00100000 = 0x20

PortD Kullanılarak Led Yakma

#include <stdint.h>
#include "inc/tm4c123gh6pm.h"        // #include "inc/lm4f120h5qr.h"
void init_port_D() {
    volatile unsigned long delay;
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOD;
    delay = SYSCTL_RCGC2_R;
    GPIO_PORTD_DIR_R |= 0x0F;
    GPIO_PORTD_AFSEL_R &= ~0x0F;
    GPIO_PORTD_DEN_R |= 0x0F;
}
int main() {
    volatile unsigned long delay;
    init_port_D();
    while (1) {
      GPIO_PORTD_DATA_R |= 0b0010;
      GPIO_PORTD_DATA_R &= ~0b0001;
      for (delay = 0 ; delay < 400000 ; delay++)    /* bos dongu */;
      GPIO_PORTD_DATA_R |= 0b0001;
      GPIO_PORTD_DATA_R &= ~0b0010;
      for (delay = 0 ; delay < 400000 ; delay++)    /* bos dongu */;
    }
}

Direction Register

GPIO_PORTD_DIR_R |= 0x0F; // PD 3,2,1,0 pinlerini cikis yap

GPIO_PORTD_DIR_R x x x x x x x x
0 0 0 0 1 1 1 1
OR---------------------------------------------
GPIO_PORTD_DIR_R x x x x 1 1 1 1

10
11
12

PortD Kullanılarak Led Yakma

#include <stdint.h>
#include "inc/tm4c123gh6pm.h"        // #include "inc/lm4f120h5qr.h"
void init_port_D() {
    volatile unsigned long delay;
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOD;
    delay = SYSCTL_RCGC2_R;
    GPIO_PORTD_DIR_R |= 0x0F;
    GPIO_PORTD_AFSEL_R &= ~0x0F;
    GPIO_PORTD_DEN_R |= 0x0F;
}
int main() {
    volatile unsigned long delay;
    init_port_D();
    while (1) {
      GPIO_PORTD_DATA_R |= 0b0010;
      GPIO_PORTD_DATA_R &= ~0b0001;
      for (delay = 0 ; delay < 400000 ; delay++)    /* bos dongu */;
      GPIO_PORTD_DATA_R |= 0b0001;
      GPIO_PORTD_DATA_R &= ~0b0010;
      for (delay = 0 ; delay < 400000 ; delay++)    /* bos dongu */;
    }
}

Alternative Function Register

GPIO_PORTD_AFSEL_R &= ~0x0F;

GPIO_PORTD_AFSEL_R x x x x x x x x
~(0 0 0 0 1 1 1 1)
1 1 1 1 0 0 0 0
AND--------------------------------------------------- GPIO_PORTD_AFSEL_R x x x x 0 0 0 0

13

PortD Kullanılarak Led Yakma

#include <stdint.h>
#include "inc/tm4c123gh6pm.h"        // #include "inc/lm4f120h5qr.h"
void init_port_D() {
    volatile unsigned long delay;
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOD;
    delay = SYSCTL_RCGC2_R;
    GPIO_PORTD_DIR_R |= 0x0F;
    GPIO_PORTD_AFSEL_R &= ~0x0F;
    GPIO_PORTD_DEN_R |= 0x0F;
}
int main() {
    volatile unsigned long delay;
    init_port_D();
    while (1) {
      GPIO_PORTD_DATA_R |= 0b0010;
      GPIO_PORTD_DATA_R &= ~0b0001;
      for (delay = 0 ; delay < 400000 ; delay++)    /* bos dongu */;
      GPIO_PORTD_DATA_R |= 0b0001;
      GPIO_PORTD_DATA_R &= ~0b0010;
      for (delay = 0 ; delay < 400000 ; delay++)    /* bos dongu */;
    }
}

Digital Enable Register

GPIO_PORTD_DEN_R |= 0x0F; // PD 3,2,1,0 pinlerini aktiflestir

GPIO_PORTD_DEN_R x x x x x x x x
0 0 0 0 1 1 1 1
OR------------------------------------------------
GPIO_PORTD_DEN_R x x x x 1 1 1 1

14

PortD Kullanılarak Led Yakma

#include <stdint.h>
#include "inc/tm4c123gh6pm.h"        // #include "inc/lm4f120h5qr.h"
void init_port_D() {
    volatile unsigned long delay;
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOD;
    delay = SYSCTL_RCGC2_R;
    GPIO_PORTD_DIR_R |= 0x0F;
    GPIO_PORTD_AFSEL_R &= ~0x0F;
    GPIO_PORTD_DEN_R |= 0x0F;
}
int main() {
    volatile unsigned long delay;
    init_port_D();
    while (1) {
      GPIO_PORTD_DATA_R |= 0b0010;
      GPIO_PORTD_DATA_R &= ~0b0001;
      for (delay = 0 ; delay < 400000 ; delay++)    /* bos dongu */;
      GPIO_PORTD_DATA_R |= 0b0001;
      GPIO_PORTD_DATA_R &= ~0b0010;
      for (delay = 0 ; delay < 400000 ; delay++)    /* bos dongu */;
    }
}

Digital Enable Register

GPIO_PORTD_DATA_R |= 0b0010; // PD1’i 1 yap GPIO_PORTD_DATA_R &= ~0b0001; // PD0’i 0 yap

GPIO_PORTD_DATA_R x x x x
0 0 1 0
OR--------------------------------------
GPIO_PORTD_DATA_R x x 1 x

GPIO_PORTD_DATA_R x x 1 x
1 1 1 0
AND-------------------------------------
GPIO_PORTD_DATA_R x x 1 0

GPIO_PORTD_DATA_R |= 0b0010; // PD1’i 1 yap
GPIO_PORTD_DATA_R &= ~0b0001; // PD0’i 0 yap

14

PortD Kullanılarak Led Yakma

#include <stdint.h>
#include "inc/tm4c123gh6pm.h"        // #include "inc/lm4f120h5qr.h"
void init_port_D() {
    volatile unsigned long delay;
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOD;
    delay = SYSCTL_RCGC2_R;
    GPIO_PORTD_DIR_R |= 0x0F;
    GPIO_PORTD_AFSEL_R &= ~0x0F;
    GPIO_PORTD_DEN_R |= 0x0F;
}
int main() {
    volatile unsigned long delay;
    init_port_D();
    while (1) {
      GPIO_PORTD_DATA_R |= 0b0010;
      GPIO_PORTD_DATA_R &= ~0b0001;
      for (delay = 0 ; delay < 400000 ; delay++)    /* bos dongu */;
      GPIO_PORTD_DATA_R |= 0b0001;
      GPIO_PORTD_DATA_R &= ~0b0010;
      for (delay = 0 ; delay < 400000 ; delay++)    /* bos dongu */;
    }
}

Digital Enable Register

GPIO_PORTD_DATA_R |= 0b0001; // PD1’i 1 yap
GPIO_PORTD_DATA_R &= ~0b0010; // PD0’i 0 yap

GPIO_PORTD_DATA_R x x x x
0 0 0 1
OR--------------------------------------
GPIO_PORTD_DATA_R x x x 1

PIO_PORTD_DATA_R x x x 1
1 1 0 1
AND-------------------------------------
GPIO_PORTD_DATA_R x x 0 1

Digital Enable Register

GPIO_PORTD_DATA_R |= 0b0010; // PD1’i 1 yap
GPIO_PORTD_DATA_R &= ~0b0001; // PD0’i 0 yap

15

PortD Kullanılarak Led Yakma

#include <stdint.h>
#include "inc/tm4c123gh6pm.h"        // #include "inc/lm4f120h5qr.h"
void init_port_D() {
    volatile unsigned long delay;
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOD;
    delay = SYSCTL_RCGC2_R;
    GPIO_PORTD_DIR_R |= 0x0F;
    GPIO_PORTD_AFSEL_R &= ~0x0F;
    GPIO_PORTD_DEN_R |= 0x0F;
}
int main() {
    volatile unsigned long delay;
    init_port_D();
    while (1) {
      GPIO_PORTD_DATA_R |= 0b0010;
      GPIO_PORTD_DATA_R &= ~0b0001;
      for (delay = 0 ; delay < 400000 ; delay++)    /* bos dongu */;
      GPIO_PORTD_DATA_R |= 0b0001;
      GPIO_PORTD_DATA_R &= ~0b0010;
      for (delay = 0 ; delay < 400000 ; delay++)    /* bos dongu */;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment