-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
61 lines (51 loc) · 1.44 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
******************************************************************************
* @file main.c
* @author Burak Keten
* @version V1.0.0
* @date 18-August-2018
* @compiler SDCC
* @brief Led blinking
******************************************************************************
**/
#include "stm8l.h"
void Clock_Init(void);
void GPIO_Init(void);
void _delay(void);
void main(void)
{
Clock_Init();
GPIO_Init();
PE_ODR |= (1 << 7); //yesil led yakiliyor
PC_ODR &= ~(1 << 7); //mavi led söndürülüyor
for(;;)
{
PE_ODR ^= (1 << 7); //yesil led blinking
PC_ODR ^= (1 << 7); //mavi led blinking
_delay(); //bekleme
}
}
void Clock_Init(void)
{
CLK_ICKCR = 0x01; //High-speed internal RC oscillator ON
while(!(CLK_ICKCR & 0x02)); //HSI clock hazir olana kadar bekle
CLK_SWR = 0x01; //HSI selected as systemclock source
while(CLK_SCSR!=0x01); //HSI Systemclock icin stabilizasyonu saglanana kadar bekle
CLK_CKDIVR = 0x00; //System clock source/1
}
void GPIO_Init(void)
{
// Yesil Led (PE7)
PE_DDR |= (1 << 7); //Output olarak ayarlaniyor
PE_CR1 |= (1 << 7); //Push-pull
PE_ODR &= (0 << 7); //Cikis degeri
// Mavi Led (PC7)
PC_DDR |= (1 << 7); //Output olarak ayarlaniyor
PC_CR1 |= (1 << 7); //Push-pull
PC_ODR &= (0 << 7); //Cikis degeri
}
void _delay(void)
{
unsigned long int j=150000;
while(j--);
}