-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
121 lines (95 loc) · 2.69 KB
/
main.c
File metadata and controls
121 lines (95 loc) · 2.69 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <stdint.h>
#include <MDR32F9Qx_port.h>
#include <MDR32F9Qx_rst_clk.h>
#include "MDR32F9Qx_config.h" // Keil::Device:Startup
#define PIN_DB0 PORT_Pin_0
#define PIN_DB1 PORT_Pin_1
#define PIN_DB2 PORT_Pin_1
#define PIN_DB3 PORT_Pin_3
#define PORT_DB0 MDR_PORTC
#define PORT_DB1 MDR_PORTC
#define PORT_DB2 MDR_PORTF
#define PORT_DB3 MDR_PORTF
#define PIN_WR1 PORT_Pin_2
#define PIN_WR2 PORT_Pin_3
#define PIN_A0 PORT_Pin_6
#define PORT_WR1 MDR_PORTF
#define PORT_WR2 MDR_PORTA
#define PORT_A0 MDR_PORTA
#define LOCK_ADDRESS 0x0F
#define UNLOCK_VALUE 0x01
#define DELAY {__asm__("NOP");__asm__("NOP");__asm__("NOP");__asm__("NOP");}
void InitIO()
{
RST_CLK_PCLKcmd(RST_CLK_PCLK_PORTC, ENABLE);
RST_CLK_PCLKcmd(RST_CLK_PCLK_PORTF, ENABLE);
RST_CLK_PCLKcmd(RST_CLK_PCLK_PORTA, ENABLE);
PORT_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.PORT_MODE = PORT_MODE_DIGITAL;
GPIO_InitStruct.PORT_SPEED = PORT_SPEED_FAST;
GPIO_InitStruct.PORT_OE = PORT_OE_OUT;
GPIO_InitStruct.PORT_FUNC = PORT_FUNC_PORT;
GPIO_InitStruct.PORT_PULL_UP = PORT_PULL_UP_OFF;
GPIO_InitStruct.PORT_Pin = PIN_DB0;
PORT_Init(PORT_DB0, &GPIO_InitStruct);
GPIO_InitStruct.PORT_Pin = PIN_DB1;
PORT_Init(PORT_DB1, &GPIO_InitStruct);
GPIO_InitStruct.PORT_Pin = PIN_DB2;
PORT_Init(PORT_DB2, &GPIO_InitStruct);
GPIO_InitStruct.PORT_Pin = PIN_DB3;
PORT_Init(PORT_DB3, &GPIO_InitStruct);
GPIO_InitStruct.PORT_Pin = PIN_WR1;
PORT_Init(PORT_WR1, &GPIO_InitStruct);
GPIO_InitStruct.PORT_Pin = PIN_WR2;
PORT_Init(PORT_WR2, &GPIO_InitStruct);
GPIO_InitStruct.PORT_Pin = PIN_A0;
PORT_Init(PORT_A0, &GPIO_InitStruct);
}
void SetData(uint8_t data)
{
PORT_WriteBit(PORT_DB0, PIN_DB0, (data & 0x01));
PORT_WriteBit(PORT_DB1, PIN_DB1, (data & 0x02) >> 1);
PORT_WriteBit(PORT_DB2, PIN_DB2, (data & 0x04) >> 2);
PORT_WriteBit(PORT_DB3, PIN_DB3, (data & 0x08) >> 3);
}
void WriteData(uint8_t adress, uint8_t data)
{
PORT_WriteBit(PORT_WR2, PIN_WR2, 1);
SetData(adress);
DELAY
PORT_WriteBit(PORT_A0, PIN_A0, 0);
DELAY
PORT_WriteBit(PORT_WR1, PIN_WR1, 1);
DELAY
PORT_WriteBit(PORT_WR1, PIN_WR1, 0);
DELAY
PORT_WriteBit(PORT_A0, PIN_A0, 1);
DELAY
SetData(data);
DELAY
PORT_WriteBit(PORT_WR1, PIN_WR1, 1);
DELAY
PORT_WriteBit(PORT_WR1, PIN_WR1, 0);
DELAY
SetData(data);
DELAY
PORT_WriteBit(PORT_WR1, PIN_WR1, 1);
DELAY
PORT_WriteBit(PORT_WR1, PIN_WR1, 0);
DELAY
PORT_WriteBit(PORT_WR2, PIN_WR2, 0);
}
void UnlockBus()
{
WriteData(LOCK_ADDRESS, UNLOCK_VALUE);
}
int main()
{
InitIO();
UnlockBus();
WriteData(0x00, 0x01);
WriteData(0x00, 0x00);
while (1)
{
}
}