你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

我来录人上STM8的驱动TFT屏

[复制链接]
holts1 提问时间:2015-1-9 13:10 /

  1. /**
  2.   ********************************************************************
  3.   * @file    main.c
  4.   * @author  Holts.he
  5.   * @version V2.1.0
  6.   * @date    2014-04-07
  7.   * @brief   Main program body
  8.   ********************************************************************
  9.   * @attention
  10.   *
  11.   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  12.   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  13.   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  14.   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  15.   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  16.   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  17.   *
  18.   * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  19.   ********************************************************************
  20.   */

  21. /* Includes ------------------------------------------------------------------*/
  22. #include "stm8s.h"
  23. #include "ptask.h"
  24. //#include "lcd_hx8309.h"
  25. //#include "gui_disp.h"
  26. #include "cms015.h"
  27. //#include "st7585.h"


  28. /* Private typedef -----------------------------------------------------------*/

  29. /* Private define ------------------------------------------------------------*/
  30. #define TIM4_TICK_1MS        124

  31. #define LED_Port   GPIOA     //LED控制口
  32. #define LED_PINS  (GPIO_PIN_1 | GPIO_PIN_2)


  33. /* Private macro -------------------------------------------------------------*/
  34. /* Private variables ---------------------------------------------------------*/


  35. /* Private function prototypes -----------------------------------------------*/
  36. void PWM1_Init(void);
  37. void TIM4_Config(void);

  38. unsigned char task1(void);
  39. unsigned char task2(void);

  40. /* Private functions ---------------------------------------------------------*/
  41. /* Global variables ----------------------------------------------------------*/
  42. volatile unsigned char timers[MAXTASKS];
  43. volatile unsigned char Trg;
  44. volatile unsigned char Cont;
  45. volatile unsigned char LCDDly = 0;

  46. unsigned char DutyCycle;

  47. /* Public functions ----------------------------------------------------------*/

  48. // SPI初始化
  49. //void SPI_Init(void)
  50. //{
  51.   //  SPI_DeInit();
  52.     //CLK_PeripheralClockConfig(CLK_PERIPHERAL_SPI, ENABLE);
  53.     //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);
  54.     //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);
  55.     //SPI_Cmd(ENABLE);
  56. //}

  57. /**
  58.   * @brief  Main program.
  59.   * @param  None
  60.   * @retval None
  61.   */
  62. void main(void)
  63. {
  64.   /* Configures clocks  Fmaster = 16MHz */
  65.   CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);  

  66.   TIM4_Config();
  67.    
  68.   //SPI_Init();

  69.   /* enable interrupts */
  70.   enableInterrupts();
  71.    
  72.   GPIO_Init(LED_Port, (GPIO_Pin_TypeDef)LED_PINS, GPIO_MODE_OUT_PP_HIGH_FAST);

  73.   /* Init LCD */
  74.   //LCD_hx8309_Initialization();无反应
  75.   //LCD_init(); // 无反应
  76.   //PowerOnLcdinit();

  77.   /* Init the Font */
  78.   //GUI_Font_Init();
  79.    
  80.   //LCD_SetCursorPos(LCD_LINE1, 0);
  81.   //LCD_Print("SPI-LCD example");        
  82.   //LCDTEST();
  83.   //Test_GUI_Font();
  84.    
  85.   //hx8309_Write_Dat(0x5555);
  86.   //hx8309_Write_Dat(0xAAAA);
  87.   LcdTest();
  88.    
  89.   while(1)
  90.   {
  91.     //if ( LCDDly == 0 ) LCDDly = 200;
  92.     //GPIO_WriteReverse(LED_Port, LED_PINS);

  93.     //while (LCDDly != 0);
  94.     RunTask(task1,Task1_ID);
  95.   RunTask(task2,Task2_ID);
  96.         
  97.     }

  98. }


  99. /**
  100.   * @brief  Print ST logo on the LCD
  101.   * @param  None
  102.   * @retval None
  103.   */
  104. /*unsigned char DlyMs1(unsigned char nCount);
  105. {
  106.   ;
  107. }
  108. */

  109. /**
  110.   *****************************************************************
  111.   * @brief Initialize all the PWM Parameters
  112.   * @par Parameters: None
  113.   * @retval void None
  114.   * @par Required preconditions: None
  115.   *****************************************************************
  116.   */
  117. void PWM1_Init(void)
  118. {
  119.    /* PWM1 Mode configuration Channel2
  120.     * Duty Cycle = [TIM1_CCR2/(TIM1_ARR+1)]*100=50% */
  121.    
  122.    TIM1_DeInit();
  123.         
  124.    /* Time Base configuration */
  125.    /*
  126.    TIM1_Prescaler = 320   分频16000/320 = 50 KHz
  127.    TIM1_Period = 99     频率50K /(99+1) = 500Hz
  128.    TIM1_CounterMode = TIM1_COUNTERMODE_UP
  129.    TIM1_RepetitionCounter = 0
  130.     */
  131.    //TIM1_TimeBaseInit(640, TIM1_COUNTERMODE_UP, 99, 0);   //250Hz
  132.    //TIM1_TimeBaseInit(320, TIM1_COUNTERMODE_UP, 99, 0);   //500Hz
  133.    TIM1_TimeBaseInit(160, TIM1_COUNTERMODE_UP, 99, 0);   //1KHz
  134.    //TIM1_TimeBaseInit(106, TIM1_COUNTERMODE_UP, 99, 0);  //1.5KHz
  135.    //TIM1_TimeBaseInit(80, TIM1_COUNTERMODE_UP, 99, 0);   //2KHz
  136.    //TIM1_TimeBaseInit(64, TIM1_COUNTERMODE_UP, 99, 0);   //2.5KHz
  137.    //TIM1_TimeBaseInit(52, TIM1_COUNTERMODE_UP, 99, 0);   //3KHz
  138.    //TIM1_TimeBaseInit(45, TIM1_COUNTERMODE_UP, 99, 0);   //3.5KHz
  139.    //TIM1_TimeBaseInit(40, TIM1_COUNTERMODE_UP, 99, 0);   //4KHz
  140.    //TIM1_TimeBaseInit(36, TIM1_COUNTERMODE_UP, 99, 0);   //4.5KHz
  141.    //TIM1_TimeBaseInit(32, TIM1_COUNTERMODE_UP, 99, 0);   //5KHz
  142.    //TIM1_TimeBaseInit(16, TIM1_COUNTERMODE_UP, 99, 0);   //10KHz
  143.    //TIM1_TimeBaseInit(8, TIM1_COUNTERMODE_UP, 99, 0);   //20KHz

  144.    /* Channel 2 Configuration in PWM mode */
  145.    /*
  146.        TIM1_OCMode = TIM1_OCMODE_PWM2
  147.        TIM1_OutputState = TIM1_OUTPUTSTATE_ENABLE
  148.        TIM1_OutputNState = TIM1_OUTPUTNSTATE_ENABLE
  149.        TIM1_Pulse = DutyCycle
  150.        TIM1_OCPolarity = TIM1_OCPOLARITY_LOW
  151.        TIM1_OCNPolarity = TIM1_OCNPOLARITY_HIGH
  152.        TIM1_OCIdleState = TIM1_OCIDLESTATE_SET
  153.        TIM1_OCNIdleState = TIM1_OCIDLESTATE_RESET
  154.     */
  155.    TIM1_OC3Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE, DutyCycle,  TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_RESET);
  156.                              
  157.    TIM1_OC4Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, DutyCycle, TIM1_OCPOLARITY_LOW, TIM1_OCIDLESTATE_SET);
  158.                                     
  159.    /* TIM1 counter enable */
  160.    TIM1_Cmd(ENABLE);
  161.          
  162.    /* TIM1 Main Output Enable */
  163.    TIM1_CtrlPWMOutputs(ENABLE);
  164. }

  165. /**
  166.   *****************************************************************
  167.   * @brief  Configure TIM4 to generate an update interrupt each 1ms
  168.   * @param  None
  169.   * @retval None
  170.   *****************************************************************
  171.   */
  172. void TIM4_Config(void)
  173. {
  174.   /* TIM4 configuration:
  175.    - TIM4CLK is set to 16 MHz, the TIM4 Prescaler is equal to 128 so the TIM1 counter
  176.    clock used is 16 MHz / 128 = 125 000 Hz
  177.   - With 125 000 Hz we can generate time base:
  178.       max time base is 2.048 ms if TIM4_PERIOD = 255 --> (255 + 1) / 125000 = 2.048 ms
  179.       min time base is 0.016 ms if TIM4_PERIOD = 1   --> (  1 + 1) / 125000 = 0.016 ms
  180.   - In this example we need to generate a time base equal to 1 ms
  181.    so TIM4_PERIOD = (0.001 * 125000 - 1) = 124 */

  182.   /* Time base configuration */
  183.   TIM4_TimeBaseInit(TIM4_PRESCALER_128, TIM4_TICK_1MS);
  184.   /* Clear TIM4 update flag */
  185.   TIM4_ClearFlag(TIM4_FLAG_UPDATE);
  186.   /* Enable update interrupt */
  187.   TIM4_ITConfig(TIM4_IT_UPDATE, ENABLE);

  188.   /* Enable TIM4 */
  189.   TIM4_Cmd(ENABLE);
  190. }

  191. /*******************************
  192.           task1
  193. *******************************/
  194. unsigned char task1(void)
  195. {
  196.   _SS
  197.     while(1)
  198.     {
  199.         WaitX(100);
  200.       GPIO_WriteHigh(LED_Port, GPIO_PIN_1);
  201.         WaitX(200);
  202.       GPIO_WriteLow(LED_Port, GPIO_PIN_1);
  203.     }
  204.     _EE
  205. }

  206. /*******************************
  207.           task2
  208. *******************************/
  209. unsigned char  task2(void)
  210. {
  211.     _SS
  212.     while(1)
  213.     {
  214.       GPIO_WriteHigh(LED_Port, GPIO_PIN_2);
  215.     WaitX(50);
  216.       GPIO_WriteLow(LED_Port, GPIO_PIN_2);
  217.     WaitX(50);
  218.     }
  219.     _EE
  220. }


  221. #ifdef USE_FULL_ASSERT

  222. /**
  223.   * @brief  Reports the name of the source file and the source line number
  224.   *   where the assert_param error has occurred.
  225.   * @param file: pointer to the source file name
  226.   * @param line: assert_param error line source number
  227.   * @retval None
  228.   */
  229. void assert_failed(uint8_t* file, uint32_t line)
  230. {
  231.   /* User can add his own implementation to report the file name and line number,
  232.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  233.   /* Infinite loop */
  234.   while (1)
  235.   {
  236.   }
  237. }
  238. #endif

  239. /**
  240.   * @}
  241.   */

  242. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/

复制代码


收藏 评论0 发布时间:2015-1-9 13:10

举报

0个回答
关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32Cube扩展软件包
意法半导体边缘AI套件
ST - 理想汽车豪华SUV案例
ST意法半导体智能家居案例
STM32 ARM Cortex 32位微控制器
关注我们
st-img 微信公众号
st-img 手机版