main.c
1.85 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
#include <stdint.h>
#include <stdbool.h>
#define PA_PER (*((volatile uint32_t*)0xFFFFF200))
#define PA_PDR (*((volatile uint32_t*)0xFFFFF204))
#define PA_OER (*((volatile uint32_t*)0xFFFFF210))
#define PA_SODR (*((volatile uint32_t*)0xFFFFF230))
#define PA_CODR (*((volatile uint32_t*)0xFFFFF234))
#define PA_PDSR (*((volatile uint32_t*)0xFFFFF23C))
#define PB_PER (*((volatile uint32_t*)0xFFFFF400))
#define PB_PDR (*((volatile uint32_t*)0xFFFFF404))
#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 PER_ID_PBIOC_TO_PIOE 4
#define DS1 (1 << 8) //PB8
#define DS2 (1 << 29) //PC29
#define BT2 (1 << 4) //PC4
#define BT1 (1 << 5) //PC5
void delay(void)
{
volatile uint64_t i;
for(i = 0; i < 100000000; i++);
}
int main(void)
{
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;
while(true)
{
// delay();
if(PC_PDSR & BT1)
PB_SODR = DS1;
else
PB_CODR = DS1;
if(PC_PDSR & BT2)
PC_SODR = DS2;
else
PC_CODR = DS2;
}
}