#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 */;
}
}
(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"
#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 */;
}
}
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.
#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 */;
}
}
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
#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 */;
}
}
#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 */;
}
}
#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 */;
}
}
#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 */;
}
}
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
#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 */;
}
}
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
#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 */;
}
}