这是主程序,附件是全部的源码。
/**
******************************************************************************
* @file main.c
* @author MCD Application Team
* @version V1.0.0
* @date 23-March-2012
* @brief Main program body
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include <stdio.h> //printf º¯ÊýÓÃ
//#pragma import(__use_no_semihosting)
struct __FILE
{
int handle;
};
FILE __stdout;
int _sys_exit(int x)
{
x = x;
return 0;
}
/** @addtogroup STM32F0-Discovery_Demo
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
static __IO uint32_t TimingDelay;
uint8_t BlinkSpeed = 0;
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/**
* @brief Main program.
* @param None
* @retval None
*/
void mul99(void)
{
int i,j;
for(i=1;i<=9;i++){
for(j=1;j<=i;j++)
printf("%d*%d=%d\t",i,j,i*j);
printf("\n\r");}
for (i=30;i>0;i--)
{
printf("%2d\r",i);Delay(200);
STM_EVAL_LEDToggle(LED3);
STM_EVAL_LEDToggle(LED4);
}
for(i = 32; i < 127; i++) {
printf(" [%c %3d %2x] ", i, i, i);
if ((i%5)==0) printf("\n\r");
}
printf("\n\r");
for (i=30;i>0;i--)
{
printf("%2d\r",i);Delay(200);
STM_EVAL_LEDToggle(LED3);
STM_EVAL_LEDToggle(LED4);
}
}
int main(void)
{
int a;
RCC_ClocksTypeDef RCC_Clocks;
/* Configure LED3 and LED4 on STM32F0-Discovery */
STM_EVAL_LEDInit(LED3);
STM_EVAL_LEDInit(LED4);
/* Initialize User_Button on STM32F0-Discovery */
STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO);
/*20121224 by wangkj www.1yq.com*/
UART1_Configuration();
/*-------------------------------*/
/* SysTick end of count event each 1ms */
RCC_GetClocksFreq(&RCC_Clocks);
SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);
/* Initiate Blink Speed variable */
BlinkSpeed = 1;
a=0x21;
/*
wangkj 20121224
*/
/* __DATE__, __TIME__, __FILE__, __LINE__ are predefined symbols */
STM_EVAL_LEDToggle(LED3);
STM_EVAL_LEDToggle(LED4);
for(a=0;a<100;a++) //clear screen
{
printf("\r\n" );
}
printf("µÚÒ»Ò×Ƕ http://www.1YQ.com\r\n" );
printf("Îļþ±àÒëµÄʱ¼äÈÕÆÚ\r\n" );
printf("File : %s\r\n", __FILE__);
printf("Date : %s\r\n", __DATE__);
printf("Time : %s\r\n", __TIME__);
printf("Line : %d\\r\n", __LINE__);
mul99();
Delay(2000);
STM_EVAL_LEDToggle(LED3);
STM_EVAL_LEDToggle(LED4);
printf("³ÌÐòÎļþÃû%s,º¯ÊýÃû%s,Ö´ÐÐÐÐÊý%d\r\n",__FILE__,__func__,__LINE__);
Delay(2000);
printf("ÇëÊäÈë32-127Ö®¼äµÄÊý×Ö£¬È»ºó»Ø³µ:\r\n");
scanf("%d",&a) ;
printf("ÎÞ·ûºÅÊ®½øÖÆÐÎʽ:%u\r\n",a);
printf("Ê®Áù½øÖÆÐÎʽ:%x\r\n",a);
printf("×Ö·ûÐÎʽ:%c\r\n",a);
printf("³ÌÐòÎļþÃû%s,Ö´ÐÐÐÐÊý%d\r\n",__FILE__,__LINE__);
STM_EVAL_LEDToggle(LED3);
printf("³ÌÐòÎļþÃû%s,º¯ÊýÃû%s,Ö´ÐÐÐÐÊý%d\r\n",__FILE__,__func__,__LINE__); STM_EVAL_LEDToggle(LED4);
Delay(3000);
a=0;
while(1)
{
/* Check if the user button is pressed */
if(STM_EVAL_PBGetState(BUTTON_USER)== SET)
{
/* BlinkSpeed: 1 -> 2 -> 0, then re-cycle */
/* Turn on LD4 Blue LED during 1s each time User button is pressed */
STM_EVAL_LEDOn(LED4);
printf("%d||³ÌÐòÎļþÃû%s,Ö´ÐÐÐÐÊý%d\r\n",a++,__FILE__,__LINE__);
/* wait for 1s */
Delay(1000);
/* Turn off LD4 Blue LED after 1s each time User button is pressed */
STM_EVAL_LEDOff(LED4);
/* Increment the blink speed counter */
BlinkSpeed++;
/* Default value for blink speed counter */
if(BlinkSpeed == 3)
{
BlinkSpeed = 0;
}
}
/* Test on blink speed */
if(BlinkSpeed == 2)
{
/* LED3 toggles each 100 ms */
STM_EVAL_LEDToggle(LED3);
printf("%d||³ÌÐòÎļþÃû%s,Ö´ÐÐÐÐÊý%d\r\n",a++,__FILE__,__LINE__);
/* maintain LED3 status for 100ms */
Delay(100);
}
else if(BlinkSpeed == 1)
{
/* LED3 toggles each 200 ms */
STM_EVAL_LEDToggle(LED3);
printf("%d||³ÌÐòÎļþÃû%s,Ö´ÐÐÐÐÊý%d\r\n",a++,__FILE__,__LINE__);
/* maintain LED3 status for 200ms */
Delay(200);
}
else
{
/* LED3 Off */
STM_EVAL_LEDOff(LED3);
printf("%d||³ÌÐòÎļþÃû%s,Ö´ÐÐÐÐÊý%d\r\n",a++,__FILE__,__LINE__);
}
}
}
/**
* @brief Inserts a delay time.
* @param nTime: specifies the delay time length, in 1 ms.
* @retval None
*/
void Delay(__IO uint32_t nTime)
{
TimingDelay = nTime;
while(TimingDelay != 0);
}
/**
* @brief Decrements the TimingDelay variable.
* @param None
* @retval None
*/
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{}
}
#endif
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
/*******************************************************************************
* Function Name : UART1_Configuration
* Description : Configures the different UART1 ports.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void UART1_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
// Configure USART1_Tx as alternate function push-pull
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// Configure USART1_Rx as input floating
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1);
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No ;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
/* Enable the USART1 */
USART_Cmd(USART1, ENABLE);
}
/*******************************************************************************
* Function Name : Uart1_PutChar
* Description : printf a char to the uart.
* Input : ch ÐèÒª·¢Ë͵Ä×Ö·û
* Output : None
* Return : None
*******************************************************************************/
uint8_t Uart1_PutChar(uint8_t ch)
{
/* Write a character to the USART */
USART_SendData(USART1, (uint8_t) ch);
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)
{
}
return ch;
}
/*******************************************************************************
* Function Name : int fputc(int ch, FILE *f)
* Description : Retargets the C library printf function to the USART.printfÖض¨Ïò
* Input : None
* Output : None
* Return : None
*******************************************************************************/
int fputc(int ch, FILE *f)
{
/* Write a character to the USART */
USART_SendData(USART1, (uint8_t) ch);
/* Loop until the end of transmission */
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)
{
}
return ch;
}
/**
* @brief Inserts a delay time.
* @param nTime: specifies the delay time length, in 1 ms.
* @retval None
*/
/****************************************************************************
* Ãû ³Æ£ºint fgetc(FILE *f)
* ¹¦ ÄÜ£ºÖض¨Òåfgetcº¯Êý£¬printfº¯Êý´ÓÖÕ¶ËÊäÈëÊý¾Ý
* Èë¿Ú²ÎÊý£ºÎÞ
* ³ö¿Ú²ÎÊý£ºÎÞ
* ˵ Ã÷£ºÎÞ
****************************************************************************/
int fgetc(FILE *f)
{
while (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);
return (int)USART_ReceiveData(USART1);
}
void delay(void)
{
int i,j;
for(i=0;i<2000;i++)
for(j=0;j<2000;j++);
}
|