在线时间29 小时
UID186777
ST金币0
蝴蝶豆2
注册时间2010-5-12
中级会员
- 最后登录
- 1970-1-1
|
a0a.1 32b0c
- /**
- ********************************************************************
- * @file main.c
- * @author Holts.he
- * @version V2.1.0
- * @date 2014-04-07
- * @brief Main program body
- ********************************************************************
- * @attention
- *
- * 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 2011 STMicroelectronics</center></h2>
- ********************************************************************
- */
- /* Includes ------------------------------------------------------------------*/
- #include "stm8s.h"
- #include "ptask.h"
- //#include "lcd_hx8309.h"
- //#include "gui_disp.h"
- #include "cms015.h"
- //#include "st7585.h"
- /* Private typedef -----------------------------------------------------------*/
- /* Private define ------------------------------------------------------------*/
- #define TIM4_TICK_1MS 124
- #define LED_Port GPIOA //LED控制口
- #define LED_PINS (GPIO_PIN_1 | GPIO_PIN_2)
- /* Private macro -------------------------------------------------------------*/
- /* Private variables ---------------------------------------------------------*/
- /* Private function prototypes -----------------------------------------------*/
- void PWM1_Init(void);
- void TIM4_Config(void);
- unsigned char task1(void);
- unsigned char task2(void);
- /* Private functions ---------------------------------------------------------*/
- /* Global variables ----------------------------------------------------------*/
- volatile unsigned char timers[MAXTASKS];
- volatile unsigned char Trg;
- volatile unsigned char Cont;
- volatile unsigned char LCDDly = 0;
- unsigned char DutyCycle;
- /* Public functions ----------------------------------------------------------*/
-
- // SPI初始化
- //void SPI_Init(void)
- //{
- // SPI_DeInit();
- //CLK_PeripheralClockConfig(CLK_PERIPHERAL_SPI, ENABLE);
- //SPI_Init(SPI_FIRSTBIT_MSB, SPI_BAUDRATEPRESCALER_256, SPI_MODE_MASTER, SPI_CLOCKPOLARITY_LOW, SPI_CLOCKPHASE_1EDGE, SPI_DATADIRECTION_1LINE_TX, SPI_NSS_SOFT, 0x00);
- //SPI_Init(SPI_FIRSTBIT_MSB, SPI_BAUDRATEPRESCALER_128, SPI_MODE_MASTER, SPI_CLOCKPOLARITY_LOW, SPI_CLOCKPHASE_2EDGE, SPI_DATADIRECTION_2LINES_FULLDUPLEX, SPI_NSS_SOFT,0x00);
- //SPI_Cmd(ENABLE);
- //}
- /**
- * @brief Main program.
- * @param None
- * @retval None
- */
- void main(void)
- {
- /* Configures clocks Fmaster = 16MHz */
- CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
- TIM4_Config();
-
- //SPI_Init();
- /* enable interrupts */
- enableInterrupts();
-
- GPIO_Init(LED_Port, (GPIO_Pin_TypeDef)LED_PINS, GPIO_MODE_OUT_PP_HIGH_FAST);
- /* Init LCD */
- //LCD_hx8309_Initialization();无反应
- //LCD_init(); // 无反应
- //PowerOnLcdinit();
- /* Init the Font */
- //GUI_Font_Init();
-
- //LCD_SetCursorPos(LCD_LINE1, 0);
- //LCD_Print("SPI-LCD example");
- //LCDTEST();
- //Test_GUI_Font();
-
- //hx8309_Write_Dat(0x5555);
- //hx8309_Write_Dat(0xAAAA);
- LcdTest();
-
- while(1)
- {
- //if ( LCDDly == 0 ) LCDDly = 200;
- //GPIO_WriteReverse(LED_Port, LED_PINS);
- //while (LCDDly != 0);
- RunTask(task1,Task1_ID);
- RunTask(task2,Task2_ID);
-
- }
- }
- /**
- * @brief Print ST logo on the LCD
- * @param None
- * @retval None
- */
- /*unsigned char DlyMs1(unsigned char nCount);
- {
- ;
- }
- */
- /**
- *****************************************************************
- * @brief Initialize all the PWM Parameters
- * @par Parameters: None
- * @retval void None
- * @par Required preconditions: None
- *****************************************************************
- */
- void PWM1_Init(void)
- {
- /* PWM1 Mode configuration Channel2
- * Duty Cycle = [TIM1_CCR2/(TIM1_ARR+1)]*100=50% */
-
- TIM1_DeInit();
-
- /* Time Base configuration */
- /*
- TIM1_Prescaler = 320 分频16000/320 = 50 KHz
- TIM1_Period = 99 频率50K /(99+1) = 500Hz
- TIM1_CounterMode = TIM1_COUNTERMODE_UP
- TIM1_RepetitionCounter = 0
- */
- //TIM1_TimeBaseInit(640, TIM1_COUNTERMODE_UP, 99, 0); //250Hz
- //TIM1_TimeBaseInit(320, TIM1_COUNTERMODE_UP, 99, 0); //500Hz
- TIM1_TimeBaseInit(160, TIM1_COUNTERMODE_UP, 99, 0); //1KHz
- //TIM1_TimeBaseInit(106, TIM1_COUNTERMODE_UP, 99, 0); //1.5KHz
- //TIM1_TimeBaseInit(80, TIM1_COUNTERMODE_UP, 99, 0); //2KHz
- //TIM1_TimeBaseInit(64, TIM1_COUNTERMODE_UP, 99, 0); //2.5KHz
- //TIM1_TimeBaseInit(52, TIM1_COUNTERMODE_UP, 99, 0); //3KHz
- //TIM1_TimeBaseInit(45, TIM1_COUNTERMODE_UP, 99, 0); //3.5KHz
- //TIM1_TimeBaseInit(40, TIM1_COUNTERMODE_UP, 99, 0); //4KHz
- //TIM1_TimeBaseInit(36, TIM1_COUNTERMODE_UP, 99, 0); //4.5KHz
- //TIM1_TimeBaseInit(32, TIM1_COUNTERMODE_UP, 99, 0); //5KHz
- //TIM1_TimeBaseInit(16, TIM1_COUNTERMODE_UP, 99, 0); //10KHz
- //TIM1_TimeBaseInit(8, TIM1_COUNTERMODE_UP, 99, 0); //20KHz
- /* Channel 2 Configuration in PWM mode */
- /*
- TIM1_OCMode = TIM1_OCMODE_PWM2
- TIM1_OutputState = TIM1_OUTPUTSTATE_ENABLE
- TIM1_OutputNState = TIM1_OUTPUTNSTATE_ENABLE
- TIM1_Pulse = DutyCycle
- TIM1_OCPolarity = TIM1_OCPOLARITY_LOW
- TIM1_OCNPolarity = TIM1_OCNPOLARITY_HIGH
- TIM1_OCIdleState = TIM1_OCIDLESTATE_SET
- TIM1_OCNIdleState = TIM1_OCIDLESTATE_RESET
- */
- TIM1_OC3Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE, DutyCycle, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_RESET);
-
- TIM1_OC4Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, DutyCycle, TIM1_OCPOLARITY_LOW, TIM1_OCIDLESTATE_SET);
-
- /* TIM1 counter enable */
- TIM1_Cmd(ENABLE);
-
- /* TIM1 Main Output Enable */
- TIM1_CtrlPWMOutputs(ENABLE);
- }
- /**
- *****************************************************************
- * @brief Configure TIM4 to generate an update interrupt each 1ms
- * @param None
- * @retval None
- *****************************************************************
- */
- void TIM4_Config(void)
- {
- /* TIM4 configuration:
- - TIM4CLK is set to 16 MHz, the TIM4 Prescaler is equal to 128 so the TIM1 counter
- clock used is 16 MHz / 128 = 125 000 Hz
- - With 125 000 Hz we can generate time base:
- max time base is 2.048 ms if TIM4_PERIOD = 255 --> (255 + 1) / 125000 = 2.048 ms
- min time base is 0.016 ms if TIM4_PERIOD = 1 --> ( 1 + 1) / 125000 = 0.016 ms
- - In this example we need to generate a time base equal to 1 ms
- so TIM4_PERIOD = (0.001 * 125000 - 1) = 124 */
- /* Time base configuration */
- TIM4_TimeBaseInit(TIM4_PRESCALER_128, TIM4_TICK_1MS);
- /* Clear TIM4 update flag */
- TIM4_ClearFlag(TIM4_FLAG_UPDATE);
- /* Enable update interrupt */
- TIM4_ITConfig(TIM4_IT_UPDATE, ENABLE);
- /* Enable TIM4 */
- TIM4_Cmd(ENABLE);
- }
- /*******************************
- task1
- *******************************/
- unsigned char task1(void)
- {
- _SS
- while(1)
- {
- WaitX(100);
- GPIO_WriteHigh(LED_Port, GPIO_PIN_1);
- WaitX(200);
- GPIO_WriteLow(LED_Port, GPIO_PIN_1);
- }
- _EE
- }
- /*******************************
- task2
- *******************************/
- unsigned char task2(void)
- {
- _SS
- while(1)
- {
- GPIO_WriteHigh(LED_Port, GPIO_PIN_2);
- WaitX(50);
- GPIO_WriteLow(LED_Port, GPIO_PIN_2);
- WaitX(50);
- }
- _EE
- }
- #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 2011 STMicroelectronics *****END OF FILE****/
复制代码
|
|