-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathled.c
63 lines (54 loc) · 1.6 KB
/
led.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
62
63
// Source code under CC0 1.0
#include <stdint.h>
#define CLK_DIVR (*(volatile uint8_t *)0x50c6)
#define CLK_PCKENR1 (*(volatile uint8_t *)0x50c7)
#define TIM1_CR1 (*(volatile uint8_t *)0x5250)
#define TIM1_CNTRH (*(volatile uint8_t *)0x525e)
#define TIM1_CNTRL (*(volatile uint8_t *)0x525f)
#define TIM1_PSCRH (*(volatile uint8_t *)0x5260)
#define TIM1_PSCRL (*(volatile uint8_t *)0x5261)
#define PD_ODR (*(volatile uint8_t *)0x500f)
#define PD_DDR (*(volatile uint8_t *)0x5011)
#define PD_CR1 (*(volatile uint8_t *)0x5012)
#define thousand 1000
/* see *.lst output
.ascii "sada"
.db 0x12
.db 1000
*/
int clock (void)
{
unsigned char h = TIM1_CNTRH;
unsigned char l = TIM1_CNTRL;
return ((unsigned int) (h) << 8 | l);
}
int main (void)
{
// unsigned int testInt = 1;
int testInt = 1000; // init var to 1000
unsigned int ct = 1000;
char c[] = "abcd";
char hp[] = "Harry Potter";
int cv;
CLK_DIVR = 0x00; // Set the clk frequency to 16 MHz
// Configure timer
// 1000 ticks per second
TIM1_PSCRH = 0x3e;
TIM1_PSCRL = 0x80;
// vol (uint16_t) testInt = 1000;
// Enable timer
TIM1_CR1 = 0x01;
PD_DDR = 0x01;
PD_CR1 = 0x01; // which register is this
testInt++;
// testInt +=3;
// int cv;
for ( cv = 1; cv < 3; cv++)
{ // was infinite loop
// testInt ++;
// maybe read the target variable with a numeric zero
// then select alternative to 0
PD_ODR = 0x2 | clock () % 1000 < 500; // was PD_ODR = clock () % 1000 < 500;
PD_ODR = PD_ODR | 0x2;
} // set same value on another pin
}