Академический Документы
Профессиональный Документы
Культура Документы
******************************************************************************
* @file
ADC/Potentiometer/main.c
* @author
ARMVN Application Team
* @version
V1.0.0
* @date
14/03/2010
* @brief
Main program body.
******************************************************************************
* @copy
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>© COPYRIGHT 2009 ARMVietNam</center></h2>
*/
/*
********************************************************************************
*****************************************************
*
INCLUDED FILES
*
********************************************************************************
*****************************************************
*/
#include <stdio.h>
#include "main.h"
/** @addtogroup STM32F10x_GEM3M_Examples
* @{
*/
/** @addtogroup ADC_Potentiometer
* @{
*/
/*
********************************************************************************
*****************************************************
*
PRIVATE DEFINE
*
********************************************************************************
*****************************************************
*/
/* constant for adc resolution is 12 bit = 4096 */
#define ADC_12BIT_FACTOR
4095
/* constant for adc threshold value 3.3V */
#define ADC_VREF
330
/*
********************************************************************************
*****************************************************
*
DATA TYPE DEFINE
*
********************************************************************************
*****************************************************
*/
#ifndef f32
#define f32
float
#endif
/*
********************************************************************************
*****************************************************
*
PRIVATE VARIABLES
*
********************************************************************************
*****************************************************
*/
GPIO_InitTypeDef GPIO_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
USART_InitTypeDef USART_InitStructure;
/*
********************************************************************************
*****************************************************
*
LOCAL FUNCTIONS
*
********************************************************************************
*****************************************************
*/
/**
* @brief
Configures the different system clocks.
* @param
None
* @retval
None
*/
void RCC_Configuration(void)
{
/* Setup the microcontroller system. Initialize the Embedded Flash Inter
face,
initialize the PLL and update the SystemFrequency variable. */
//SystemInit();
// no need because SystemInit() is already calle
d in start up code
/* Enable GPIOA clocks */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
}
/**
* @brief
Inserts a delay time with resolution is 10 milisecond..
* @param
nCount: specifies the delay time length.
* @retval
None
*/
void Delay(__IO uint32_t num)
{
__IO uint32_t index = 0;
/* default system clock is 72MHz */
for(index = (720000 * num); index != 0; index--)
{
}
}
/**
* @brief Retargets the C library printf function to the USART.
* @param None
* @retval None
*/
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */
USART_SendData(USART1, (uint8_t) ch);
/* Loop until the end of transmission */
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
{}
return ch;
}
/*
********************************************************************************
*****************************************************
*
GLOBAL FUNCTIONS
*
********************************************************************************
*****************************************************
*/
/**
* @brief
Main program.
* @param
None
* @retval
None
*/
int main(void)
{
u16 adc_raw_val = 0;
u16 potentionmeter_val = 0;
float x;
/* Configure the system clocks */
RCC_Configuration();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/*
*
configure UART pins
*/
/* Enable UART clock, if using USART2 or USART3 ... we must use RCC_APB1
PeriphClockCmd(RCC_APB1Periph_USARTx, ENABLE) */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
/* Configure PA9 for USART Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure PA10 for USART Rx as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* USARTx configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
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_HardwareFlowContro
l_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
/* USART configuration */
USART_Init(USART1, &USART_InitStructure);
/* Enable USART */
USART_Cmd(USART1, ENABLE);
/*
*
*/
//GPIOC->ODR&=~(1<<5);
}
else if( x > 3.9)
{
//GPIOC->ODR=(1<<5);
//GPIO_WriteBit(GPIOC, GPIO_Pin_5, (BitAction )0);
//GPIO_ResetBits(GPIOC, GPIO_Pin_5);
GPIO_SetBits(GPIOC, GPIO_Pin_5);
//Delay(1);
}
}
}
#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 2010 ARMVietNam *****END OF FILE****/