main.c
2.06 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <stdint.h>
#include <stdbool.h>
#define PB_PER (*((volatile uint32_t*)0xFFFFF400))
#define PB_OER (*((volatile uint32_t*)0xFFFFF410))
#define PB_SODR (*((volatile uint32_t*)0xFFFFF430))
#define PB_CODR (*((volatile uint32_t*)0xFFFFF434))
#define PB_PDSR (*((volatile uint32_t*)0xFFFFF43C))
#define PC_PER (*((volatile uint32_t*)0xFFFFF600))
#define PC_ODR (*((volatile uint32_t*)0xFFFFF614))
#define PC_OER (*((volatile uint32_t*)0xFFFFF610))
#define PC_SODR (*((volatile uint32_t*)0xFFFFF630))
#define PC_CODR (*((volatile uint32_t*)0xFFFFF634))
#define PC_PDSR (*((volatile uint32_t*)0xFFFFF63C))
#define PC_PUER (*((volatile uint32_t*)0xFFFFF664))
#define PMC_PCER (*((volatile uint32_t*)0xFFFFFC10))
#define CLK_PIO_CDE 4
#define DS1 (1 << 8) //PB8
#define DS2 (1 << 29) //PC29
#define BT2 (1 << 4) //PC4
#define BT1 (1 << 5) //PC5
void delay_ms (int delay)
{
volatile uint64_t DelayStep;
for(DelayStep = 0; DelayStep < 100000*delay; DelayStep++);
}
void ConfigureLEDs (void)
{
PB_PER = DS1;
PC_PER = DS2;
PB_OER = DS1;
PC_OER = DS2;
PB_SODR = DS1;
PC_SODR = DS2;
}
void ConfigureButtons (void)
{
PMC_PCER = 1 << CLK_PIO_CDE;
PC_PER = BT1 | BT2;
PC_ODR = BT1 | BT2;
PC_PUER = BT1 | BT2;
}
int main(void)
{
int Decimator=0;
ConfigureLEDs();
ConfigureButtons();
#if 0
PMC_PCER = 1 << PER_ID_PBIOC_TO_PIOE;
PB_PER = DS1; //PIO enable register
// PB_PDR = 0xffffffff; //PIO disable register
PB_OER = DS1; //PIO controller output enable register
PC_PER = DS2 | BT1 | BT2; //PIO enable register
PC_OER = DS2; //PIO controller output enable register
PC_ODR = BT1 | BT2;
PC_PUER = BT1 | BT2;
#endif
while(true)
{
for (Decimator=0; Decimator<100; Decimator++)
{
if((PC_PDSR & BT1) == 0)
PB_SODR = DS1;
if((PC_PDSR & BT2) == 0)
PB_CODR = DS1;
delay_ms(10);
}
PC_CODR = DS2;
for (Decimator=0; Decimator<100; Decimator++)
{
if((PC_PDSR & BT1) == 0)
PB_SODR = DS1;
if((PC_PDSR & BT2) == 0)
PB_CODR = DS1;
delay_ms(10);
}
PC_SODR = DS2;
}
}