1 | /* Includes ------------------------------------------------------------------*/
|
2 | #include "stm32f10x_conf.h"
|
3 | #include <stdio.h>
|
4 | #include <time.h>
|
5 |
|
6 | /** @addtogroup Template_Project
|
7 | * @{
|
8 | */
|
9 |
|
10 | /* Private typedef -----------------------------------------------------------*/
|
11 | /* Private define ------------------------------------------------------------*/
|
12 | /* Private macro -------------------------------------------------------------*/
|
13 | /* Private variables ---------------------------------------------------------*/
|
14 | volatile unsigned short TimerVar;
|
15 |
|
16 | /* Private function prototypes -----------------------------------------------*/
|
17 | void NVIC_Configuration(void);
|
18 | void RCC_Configuration(void);
|
19 | void IO_Configuration(void);
|
20 |
|
21 | int ReadValue;
|
22 |
|
23 | /* Private functions ---------------------------------------------------------*/
|
24 |
|
25 | /**
|
26 | * @brief Main program.
|
27 | * @param None
|
28 | * @retval None
|
29 | */
|
30 | int main(void)
|
31 | {
|
32 | int x,anzahl;
|
33 | anzahl = 40;
|
34 |
|
35 | RCC_Configuration(); // es muss richtige Definition in stm32f10x.h einkommentiert sein (STM32F10X_MD)
|
36 | IO_Configuration ();
|
37 | //NVIC_Configuration();
|
38 |
|
39 | SysTick_Config(75000); // ruft in cyklischen Abständen eine ISR auf (1ms)
|
40 |
|
41 | // LED 3 und 4 leuchten immer
|
42 |
|
43 |
|
44 | /* Infinite loop
|
45 | while (1)
|
46 | {
|
47 |
|
48 | GPIO_ResetBits(GPIOD, GPIO_Pin_13);
|
49 | int start;
|
50 | start = GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13);
|
51 | if (start == 1)
|
52 | {
|
53 | GPIO_SetBits(GPIOD, GPIO_Pin_13);
|
54 |
|
55 |
|
56 | }
|
57 |
|
58 | do {
|
59 | GPIO_SetBits(GPIOD, GPIO_Pin_3);
|
60 | }while(anzahl < 40);*/
|
61 |
|
62 | //for (x=1;x=anzahl;x++)
|
63 | //for (x=1;x=anzahl;x++);
|
64 | /*GPIO_ResetBits(GPIOD, GPIO_Pin_3);
|
65 | GPIO_SetBits(GPIOD, GPIO_Pin_4);
|
66 | GPIO_SetBits(GPIOD, GPIO_Pin_3);
|
67 | GPIO_SetBits(GPIOD, GPIO_Pin_13);*/
|
68 | //warte(100);
|
69 | //GPIO_SetBits(GPIOD, GPIO_Pin_7);
|
70 | //GPIO_SetBits(GPIOD, GPIO_Pin_13);
|
71 |
|
72 |
|
73 | // Wenn Taster B3 nicht betätigt leuchtet LED4,
|
74 | // Reset von LED3 damit immer nur eine der beiden LEDs leuchtet
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | // while(1)
|
80 |
|
81 | //{
|
82 |
|
83 | // Variable für bessere Übersicht festlegen
|
84 | ReadValue = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_9);
|
85 |
|
86 | if (ReadValue == 1)
|
87 |
|
88 | GPIO_SetBits(GPIOD, GPIO_Pin_7);//, GPIO_ResetBits(GPIOD, GPIO_Pin_7);// , GPIO_ResetBits(GPIOD, GPIO_Pin_7) , GPIO_ResetBits(GPIOD, GPIO_Pin_13);
|
89 | else
|
90 | GPIO_ResetBits(GPIOD, GPIO_Pin_7);
|
91 | //wait(100);
|
92 | /* if (ReadValue == 1)
|
93 | GPIO_ResetBits(GPIOD, GPIO_Pin_7);// , GPIO_SetBits(GPIOD, GPIO_Pin_3) , GPIO_ResetBits(GPIOD, GPIO_Pin_7) , GPIO_ResetBits(GPIOD, GPIO_Pin_13);
|
94 |
|
95 | if (ReadValue == 1)
|
96 | GPIO_ResetBits(GPIOD, GPIO_Pin_4) , GPIO_ResetBits(GPIOD, GPIO_Pin_3) , GPIO_SetBits(GPIOD, GPIO_Pin_7) , GPIO_ResetBits(GPIOD, GPIO_Pin_13);
|
97 | else GPIO_SetBits(GPIOD, GPIO_Pin_3) , GPIO_ResetBits(GPIOD, GPIO_Pin_4);
|
98 |
|
99 | if (ReadValue == 1)
|
100 |
|
101 | GPIO_SetBits(GPIOD, GPIO_Pin_7) , GPIO_ResetBits(GPIOD, GPIO_Pin_13);
|
102 |
|
103 | else GPIO_SetBits(GPIOD, GPIO_Pin_13) , GPIO_ResetBits(GPIOD, GPIO_Pin_7);
|
104 |
|
105 | */
|
106 | //}
|
107 | }
|
108 |
|
109 |
|
110 |
|
111 | void NVIC_Configuration(void)
|
112 | {
|
113 | NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
|
114 | }
|
115 |
|
116 | void RCC_Configuration(void)
|
117 | {
|
118 | // The maximum frequency of the AHB and the APB2 domains is 72 MHz
|
119 | // The maximum allowed frequency of the APB1 domain is 36 MHz
|
120 |
|
121 | ErrorStatus HSEStartUpStatus;
|
122 |
|
123 | RCC_DeInit(); // RCC system reset(for debug purpose)
|
124 |
|
125 |
|
126 | RCC_HSEConfig(RCC_HSE_ON); // Enable HSE
|
127 | HSEStartUpStatus = RCC_WaitForHSEStartUp(); // Wait till HSE is ready
|
128 |
|
129 | if(HSEStartUpStatus == SUCCESS)
|
130 | {
|
131 | FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); // Enable Prefetch Buffer
|
132 | FLASH_SetLatency(FLASH_Latency_2); // Flash 2 wait state
|
133 | RCC_HCLKConfig(RCC_SYSCLK_Div1); // HCLK = SYSCLK
|
134 | RCC_PCLK2Config(RCC_HCLK_Div1); // PCLK2 = HCLK // ABP2 max 72 MHz !!! WICHTIG
|
135 | RCC_PCLK1Config(RCC_HCLK_Div2); // PCLK1 = HCLK/2 // ABP1 max 36 MHz !!! WICHTIG
|
136 | RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_3); // PLLCLK = 25MHz * 3 = 75 MHz !!! WICHTIG
|
137 | RCC_PLLCmd(ENABLE); // Enable PLL
|
138 |
|
139 | while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); // Wait till PLL is ready
|
140 |
|
141 | RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); // Select PLL as system clock source
|
142 |
|
143 | while(RCC_GetSYSCLKSource() != 0x08); // Wait till PLL is used as system clock source
|
144 | }
|
145 |
|
146 |
|
147 | }
|
148 |
|
149 |
|
150 | void IO_Configuration(void)
|
151 | {
|
152 | /* Configure all the GPIOA in Input Floating mode */
|
153 | GPIO_InitTypeDef GPIO_InitStructure;
|
154 |
|
155 |
|
156 |
|
157 | //RCC->APB2ENR |= RCC_APB2ENR_IOPBEN| RCC_APB2ENR_AFIOEN; // clock für PortB
|
158 | //RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOB , ENABLE);
|
159 |
|
160 |
|
161 |
|
162 | // LED Ports definieren
|
163 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD , ENABLE);
|
164 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_7 | GPIO_Pin_13;
|
165 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
166 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
167 |
|
168 | GPIO_Init(GPIOD, &GPIO_InitStructure);
|
169 |
|
170 |
|
171 | //Tasterinitialisierung
|
172 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB , ENABLE);
|
173 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
|
174 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
175 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
|
176 | GPIO_Init(GPIOB, &GPIO_InitStructure);
|
177 | GPIO_Init(GPIOC, &GPIO_InitStructure);
|
178 |
|
179 |
|
180 |
|
181 | /*
|
182 | GPIOB->CRL &= ~(GPIO_CRL_MODE4 | GPIO_CRL_CNF4);
|
183 | GPIOB->CRL &= ~(GPIO_CRL_MODE5 | GPIO_CRL_CNF5);
|
184 | GPIOB->CRL &= ~(GPIO_CRL_MODE6 | GPIO_CRL_CNF6);
|
185 | GPIOB->CRL &= ~(GPIO_CRL_MODE7 | GPIO_CRL_CNF7);
|
186 |
|
187 |
|
188 | GPIOB->CRL |= GPIO_CRL_MODE4
|
189 | | GPIO_CRL_MODE5
|
190 | | GPIO_CRL_MODE6
|
191 | | GPIO_CRL_MODE7;
|
192 |
|
193 | AFIO->MAPR &= ~AFIO_MAPR_SWJ_CFG;
|
194 | AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_1;
|
195 | */
|
196 |
|
197 | }
|
198 |
|
199 |
|
200 |
|
201 | #ifdef USE_FULL_ASSERT
|
202 |
|
203 |
|
204 | void assert_failed(uint8_t* file, uint32_t line)
|
205 | {
|
206 | /* User can add his own implementation to report the file name and line number,
|
207 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
208 |
|
209 | /* Infinite loop */
|
210 | while (1)
|
211 | {
|
212 | }
|
213 | }
|
214 | #endif
|
215 |
|
216 | /**
|
217 | * @}
|
218 | */
|