152. Data++; 153. break; 154. 155. default: 156. Data++; 157. break; 158. } 159. 160. 161. }
162. else if(*Data=='%'){ // 163. switch (*++Data){
164. case 's': //字符串 165. s = va_arg(ap, const char *); 166. for ( ; *s; s++) {
167. USART_SendData(USARTx,*s);
168. while(USART_GetFlagStatus(USARTx, USART_FLAG_TC)
==RESET); 169. } 170. Data++; 171. break;
172. case 'd': //十进制 173. d = va_arg(ap, int); 174. itoa(d, buf, 10); 175. for (s = buf; *s; s++) {
176. USART_SendData(USARTx,*s);
177. while(USART_GetFlagStatus(USARTx, USART_FLAG_TC)
==RESET); 178. } 179. Data++; 180. break; 181. default: 182. Data++; 183. break; 184. }
185. }
186. else USART_SendData(USARTx, *Data++);
187. while(USART_GetFlagStatus(USARTx, USART_FLAG_TC)==RESET
); 188. } 189. } 190.
191. /****************************************************** 192. 整形数据转字符串函数
193. char *itoa(int value, char *string, int radix)
194. radix=10 标示是10进制 非十进制,转换结果为0; 195.
196. 例:d=-379;
197. 执行 itoa(d, buf, 10); 后 198.
199. buf=\
200. **********************************************************/ 201. char *itoa(int value, char *string, int radix) 202. {
203. int i, d; 204. int flag = 0; 205. char *ptr = string; 206.
207. /* This implementation only works for decimal numbers. */ 208. if (radix != 10) 209. {
210. *ptr = 0; 211. return string; 212. } 213.
214. if (!value) 215. {
216. *ptr++ = 0x30; 217. *ptr = 0; 218. return string;
219. } 220.
221. /* if this is a negative value insert the minus sign. */ 222. if (value < 0) 223. {
224. *ptr++ = '-'; 225.
226. /* Make the value positive. */ 227. value *= -1; 228. } 229.
230. for (i = 10000; i > 0; i /= 10) 231. {
232. d = value / i; 233.
234. if (d || flag) 235. {
236. *ptr++ = (char)(d + 0x30); 237. value -= (d * i); 238. flag = 1; 239. } 240. } 241.
242. /* Null terminate the string. */ 243. *ptr = 0; 244.
245. return string; 246.
247. } /* NCL_Itoa */ 248.
249. /**************************************************************************** 250. * 名 称:void RCC_Configuration(void)
251. * 功 能:系统时钟配置为72MHZ, 外设时钟配置 252. * 入口参数:无 253. * 出口参数:无
254. * 说 明: 255. * 调用方法:无
256. ****************************************************************************/ 257. void RCC_Configuration(void) 258. {
259. SystemInit();
260. RCC_APB2PeriphClockCmd( RCC_APB2Periph_USART1 |RCC_APB2P
eriph_GPIOA | RCC_APB2Periph_GPIOB |RCC_APB2Periph_AFIO , ENABLE); 261. } 262.
263. /**************************************************************************** 264. * 名 称:void GPIO_Configuration(void) 265. * 功 能:通用IO口配置 266. * 入口参数:无 267. * 出口参数:无 268. * 说 明: 269. * 调用方法:
270. ****************************************************************************/ 271. void GPIO_Configuration(void) 272. { 273.
274. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //LED1控制
--PB5
275. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输
出
276. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 277. GPIO_Init(GPIOB, &GPIO_InitStructure); 278.
279. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //USART1 TX 280. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽
输出
281. GPIO_Init(GPIOA, &GPIO_InitStructure); //A端口 282.
283. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //USART1 RX
284. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //复用
开漏输入
285. GPIO_Init(GPIOA, &GPIO_InitStructure); //A端口 286. } 287.
288. /**************************************************************************** 289. * 名 称:void NVIC_Configuration(void) 290. * 功 能:中断源配置 291. * 入口参数:无 292. * 出口参数:无 293. * 说 明: 294. * 调用方法:无
295. ****************************************************************************/ 296. void NVIC_Configuration(void) 297. {
298. /* 结构声明*/
299. NVIC_InitTypeDef NVIC_InitStructure; 300.
301. /* Configure the NVIC Preemption Priority Bits */ 302. /* Configure one bit for preemption priority */
303. /* 优先级组 说明了抢占优先级所用的位数,和子优先级所用的位数 在这里
是1, 7 */
304. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); 305. 306.
307. NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; //设置
串口1中断
308. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //抢占
优先级 0
309. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //子优先级
为0
310. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使
能
311. NVIC_Init(&NVIC_InitStructure); 312. }