找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 15962|回复: 24
打印 上一主题 下一主题
收起左侧

STM32学习-使用dsp库的FFT函数测相位

  [复制链接]
跳转到指定楼层
楼主
ID:81272 发表于 2015-5-27 18:04 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
完整程序源代码工程文件下载地址: 使用dsp库的FFT函数测相位.rar (426.12 KB, 下载次数: 356)
stm32 dsp库下载:http://www.51hei.com/bbs/dpj-35381-1.html

  1. /**
  2.   ******************************************************************************
  3.   * @file FFT_Demo/src/main.c
  4.   * @author  MCD Application Team
  5.   * @version  V2.0.0
  6.   * @date  04/27/2009
  7.   * @brief  Main program body
  8.   ******************************************************************************
  9.   * @copy
  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>© COPYRIGHT 2009 STMicroelectronics</center></h2>
  19.   */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "stm32f10x.h"
  22. #include <math.h>
  23. #include "stm3210b_lcd.h"
  24. #include "stm32_dsp.h"
  25. #include "table_fft.h"   
  26. //------------------------------------------------------------------------------

  27. #define FreqSample      (50*NPT)        // 50Hz*64=3200
  28. #define ScalingFactor   20000                // 幅值系数,最大为32767
  29. #define PERCENT_DC                0.06                // 直流分量对应的百分比,对应直流分量lBUFMAG[0]=1200
  30. #define PI              3.1415926           
  31. #define PI2             6.28318530717959   // 2*3.14
  32. #define NPT             256                       /* 采样点数,必须为64,256,1024之一*/

  33. #if (NPT==64)
  34.             #define cr4_fft_stm32 cr4_fft_64_stm32
  35. #elif (NPT==256)
  36.             #define cr4_fft_stm32 cr4_fft_256_stm32
  37. #else
  38.             #define cr4_fft_stm32 cr4_fft_1024_stm32
  39.         error!!!!
  40.         // 使用的ram超过了22K,超过了EK-STM32F仿真板上的STM32F103VBT6的ram
  41. #endif
  42. //------------------------------------------------------------------------------
  43. extern volatile uint32_t TimingDelay ;
  44. long lBUFIN[NPT];           /* Complex input vector */
  45. long lBUFOUT[NPT];          /* Complex output vector */
  46. long lBUFMAG[NPT + NPT/2];  /* Magnitude vector */
  47. float lBUFPHASE[NPT + NPT/2];/* phase vector,单位为度 */

  48. /* Private function prototypes -----------------------------------------------*/
  49. void MyDualSweep(uint32_t freqinc1,uint32_t freqinc2);
  50. void MygSin(long nfill, long Fs, long Freq1, long Freq2, long Ampli);
  51. void powerMag(long nfill, char* strPara);
  52. void power_Phase_Radians(long nfill);
  53. void DSPDemoInit(void);
  54. //------------------------------------------------------------------------------
  55. //------------------------------------------------------------------------------
  56. //------------------------------------------------------------------------------
  57. int main(void)
  58. {
  59.   DSPDemoInit();

  60.   while (1)
  61.   {
  62.             MyDualSweep(FreqSample/NPT,6*FreqSample/NPT);     // 测试fft
  63.   }
  64. }
  65. //-----------------------------------------------------------------------------

  66. /**
  67.   * @brief  Produces a combination of two sinewaves as input signal
  68.   * @param freq1: frequency increment for 1st sweep,频率步进值1
  69.   *   Freq2: frequency increment for 2nd sweep,频率步进值2
  70.   * @retval : None
  71.   */
  72. void MyDualSweep(uint32_t freqinc1,uint32_t freqinc2)
  73. {
  74.     uint32_t freq;
  75.      
  76.     freq = freqinc1;
  77.     MygSin(NPT, FreqSample, freq, 0, ScalingFactor);                           
  78.            cr4_fft_stm32(lBUFOUT, lBUFIN, NPT);
  79.            powerMag(NPT,"");       // lBUFIN[0]=1192 ,lBUFIN[1]=20008
  80.     power_Phase_Radians(NPT);   
  81.          
  82.     freq = freqinc1;
  83.     MygSin(NPT, FreqSample, freq, freqinc2, ScalingFactor);                           
  84.            cr4_fft_stm32(lBUFOUT, lBUFIN, NPT);
  85.            powerMag(NPT,"");        // lBUFIN[0]=1192 ,lBUFIN[1]=20008, lBUFIN[6]=4000   
  86.     power_Phase_Radians(NPT);
  87. }
  88. //------------------------------------------------------------------------------
  89. /**
  90.   * @brief  Produces a combination of two sinewaves as input signal
  91.   * @param ill: length of the array holding input signal
  92.   *   Fs: sampling frequency
  93.   *   Freq1: frequency of the 1st sinewave
  94.   *   Freq2: frequency of the 2nd sinewave
  95.   *   Ampli: scaling factor
  96.   * @retval : None
  97.   */
  98. void MygSin(long nfill, long Fs, long Freq1, long Freq2, long Ampli)
  99. {
  100.   uint32_t i;
  101.   float fFs, fFreq1, fFreq2, fAmpli;
  102.   float fZ,fY;

  103.   fFs = (float) Fs;
  104.   fFreq1 = (float) Freq1;
  105.   fFreq2 = (float) Freq2;
  106.   fAmpli = (float) Ampli;

  107.   for (i=0; i < nfill; i++)
  108.   {
  109.     fY =PERCENT_DC/2            // 相位范围0°----360°
  110.             + sin((196.0*PI/180.0)+PI2 * i * (fFreq1/fFs)) ;
  111.     if (fFreq2)
  112.             fY += 0.2*sin((293.0*PI/180.0)+PI2 * i * (fFreq2/fFs));
  113.    
  114.     fZ = fAmpli * fY;
  115.        
  116. // lBUFIN数组中,每个单元数据高字(高16位)中存储采样数据的实部,低字(低16位)存储采样数据的虚部(总是为0)
  117.     lBUFIN[i]= ((short)fZ) << 16 ;  /* sine_cosine  (cos=0x0) */
  118.                                                                         // 高16bit为实部,低16bit为虚部,没有的话,就用0代替
  119.   }
  120. }
  121. //------------------------------------------------------------------------------
  122. /**
  123.   * @brief  Removes the aliased part of the spectrum (not tested)
  124.   * @param ill: length of the array holding power mag
  125.   * @retval : None
  126.   */
  127. void onesided(long nfill)
  128. {
  129.   uint32_t i;
  130.   
  131.   lBUFMAG[0] = lBUFMAG[0];
  132.   lBUFMAG[nfill/2] = lBUFMAG[nfill/2];
  133.   for (i=1; i < nfill/2; i++)
  134.   {
  135.     lBUFMAG[i] = lBUFMAG[i] + lBUFMAG[nfill-i];
  136.     lBUFMAG[nfill-i] = 0x0;
  137.   }
  138. }
  139. //------------------------------------------------------------------------------
  140. /**
  141.   * @brief  Compute power magnitude of the FFT transform  进行FFT变换,并计算各次谐波幅值
  142.   * @param ill: length of the array holding power mag
  143.   *   : strPara: if set to "1SIDED", removes aliases part of spectrum (not tested)
  144.   * @retval : None
  145.   */
  146. void powerMag(long nfill, char* strPara)
  147. {
  148.   int32_t lX,lY;
  149.   uint32_t i;

  150.   for (i=0; i < nfill/2; i++)
  151.   {
  152.     lX= (lBUFOUT[i]<<16)>>16; /* 取低16bit,sine_cosine --> cos */
  153.     lY= (lBUFOUT[i] >> 16);   /* 取高16bit,sine_cosine --> sin */   
  154.     {
  155.       float X=  (float)lX*(NPT/32768.0);      
  156.       float Y = (float)lY*(NPT/32768.0);
  157.       float Mag = sqrt(X*X+ Y*Y)/nfill;
  158.       lBUFMAG[i] = (uint32_t)(Mag*65536);
  159.     }   
  160.   }
  161. }
  162. //------------------------------------------------------------------------------
  163. /*
  164. 参考 labwindows的函数 ToPolar1D
  165. Converts the set of rectangular coordinate points (arrayXReal, arrayXImg) to a
  166. set of polar coordinate points (magnitude, phase). ToPolar1D obtains the  
  167. element of the polar coordinate set using the following formulas:

  168. The phase value is in the range [-pi: pi].

  169. ToPolar1D can perform the operations in place;
  170. that is, the input and output arrays can be the same.

  171. Prototype

  172. AnalysisLibErrType ToPolar1D (double Array_X_Real[], double Array_X_Imaginary[], int Number_of_Elements, double Magnitude[], double Phase_Radians[]);

  173. */
  174. void power_Phase_Radians(long nfill)
  175. {
  176.     int32_t lX,lY;
  177.     uint32_t i;

  178.     for (i=0; i < nfill/2; i++)
  179.     {
  180.         lX= (lBUFOUT[i]<<16)>>16; /* 取低16bit,sine_cosine --> cos */
  181.         lY= (lBUFOUT[i] >> 16);   /* 取高16bit,sine_cosine --> sin */   
  182.         {
  183.             float X=  NPT*((float)lX)/32768;
  184.             float Y = NPT*((float)lY)/32768;
  185.             float phase = atan(Y/X);
  186.              if (Y>=0)
  187.              {
  188.                 if (X>=0)
  189.                   ;
  190.                 else
  191.                   phase+=PI;  
  192.              }
  193.              else
  194.              {            
  195.                 if (X>=0)
  196.                   phase+=PI2;                  
  197.                 else
  198.                   phase+=PI;                    
  199.              }                  
  200.             
  201.             lBUFPHASE[i] = phase*180.0/PI;
  202.         }   
  203.     }
  204. }
  205. //------------------------------------------------------------------------------
  206. /**
  207.   * @brief  Inserts a delay time.
  208.   * @param ount: specifies the delay time length (time base 10 ms).
  209.   * @retval : None
  210.   */
  211. void Delay(uint32_t nCount)
  212. {
  213.   /* Configure the systick */
  214.   __enable_irq();
  215.          
  216.      /* Setup SysTick Timer for 10 msec interrupts */
  217.   if (SysTick_Config(SystemFrequency /100)) /* SystemFrequency is defined in
  218.    搒ystem_stm32f10x.h?and equal to HCLK frequency */
  219.    {
  220.     /* Capture error */
  221.      while (1);
  222.     }     
  223.   /* Enable the SysTick Counter */
  224.   TimingDelay = nCount;
  225.    while (TimingDelay )  {}            
  226.    TimingDelay=0;
  227.    __disable_irq();

  228. }
  229. //------------------------------------------------------------------------------
  230. /**
  231.   * @brief  Initializes the DSP lib demo (clock, peripherals and LCD).
  232.   * @param  None
  233.   * @retval : None
  234.   */
  235. void DSPDemoInit(void)
  236. {
  237.   GPIO_InitTypeDef GPIO_InitStructure;
  238.   ErrorStatus HSEStartUpStatus = ERROR;

  239.   /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/
  240.   /* RCC system reset(for debug purpose) */
  241.   RCC_DeInit();

  242.   /* Enable HSE */
  243.   RCC_HSEConfig(RCC_HSE_ON);

  244.   /* Wait till HSE is ready */
  245.   HSEStartUpStatus = RCC_WaitForHSEStartUp();

  246.   if(HSEStartUpStatus == SUCCESS)
  247.   {
  248.     /* Enable Prefetch Buffer */
  249.     FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

  250.     /* Flash 2 wait state */
  251.     FLASH_SetLatency(FLASH_Latency_2);

  252.     /* HCLK = SYSCLK */
  253.     RCC_HCLKConfig(RCC_SYSCLK_Div1);

  254.     /* PCLK2 = HCLK */
  255.     RCC_PCLK2Config(RCC_HCLK_Div1);

  256.     /* PCLK1 = HCLK/2 */
  257.     RCC_PCLK1Config(RCC_HCLK_Div2);

  258.     /* PLLCLK = 8MHz * 9 = 72 MHz */
  259.     RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);

  260.     /* Enable PLL */
  261.     RCC_PLLCmd(ENABLE);

  262.     /* Wait till PLL is ready */
  263.     while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
  264.     {
  265.     }

  266.     /* Select PLL as system clock source */
  267.     RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

  268.     /* Wait till PLL is used as system clock source */
  269.     while(RCC_GetSYSCLKSource() != 0x08)
  270.     {
  271.     }
  272.   }

  273.   /* Enable GPIOA, GPIOB, GPIOC, GPIOD, GPIOE and AFIO clocks */
  274.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |RCC_APB2Periph_GPIOC
  275.          | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE);

  276.   /* TIM1 Periph clock enable */
  277.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
  278.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);


  279.   /* SPI2 Periph clock enable */
  280.   RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);

  281.   /* TIM2  and TIM4 clocks enable */
  282.   RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM4, ENABLE);

  283.   /*------------------- Resources Initialization -----------------------------*/
  284.   /* GPIO Configuration */
  285.   /* Configure PC.06 and PC.07 as Output push-pull */
  286.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
  287.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  288.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  289.   GPIO_Init(GPIOC, &GPIO_InitStructure);


  290.   /*------------------- Drivers Initialization -------------------------------*/
  291.   /* Initialize the LCD */
  292.   STM3210B_LCD_Init();

  293.   /* Clear the LCD */
  294.   LCD_Clear(White);

  295.   LCD_SetTextColor(White);
  296.   LCD_SetBackColor(Black);

  297. }
  298. //------------------------------------------------------------------------------
  299. #ifdef  USE_FULL_ASSERT

  300. /**
  301.   * @brief  Reports the name of the source file and the source line number
  302.   *   where the assert_param error has occurred.
  303.   * @param file: pointer to the source file name
  304.   * @param line: assert_param error line source number
  305.   * @retval : None
  306.   */
  307. void assert_failed(uint8_t* file, uint32_t line)
  308. {
  309.   /* User can add his own implementation to report the file name and line number,
  310.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  311.   /* Infinite loop */
  312.   while (1)
  313.   {
  314.   }
  315. }
  316. #endif

  317. /**
  318.   * @}
  319.   */

  320. /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
复制代码



  1. /**
  2.   ******************************************************************************
  3.   * @file FFT_Demo/src/stm3210b_lcd.c
  4.   * @author  MCD Application Team
  5.   * @version  V2.0.0
  6.   * @date  04/27/2009
  7.   * @brief  This file includes the LCD driver for AM-240320LTNQW00H
  8. *                      (LCD_HX8312), AM-240320L8TNQW00H (LCD_ILI9320),
  9. *                      AM-240320LDTNQW00H (LCD_SPFD5408B) Liquid Crystal Display
  10. *                      Module of STM3210B-EVAL board.
  11.   ******************************************************************************
  12.   * @copy
  13.   *
  14.   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  15.   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  16.   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  17.   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  18.   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  19.   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  20.   *
  21.   * <h2><center>© COPYRIGHT 2009 STMicroelectronics</center></h2>
  22.   */


  23. /* Includes ------------------------------------------------------------------*/
  24. #include "stm3210b_lcd.h"
  25. #include "fonts.h"

  26. /** @addtogroup FFT_Demo
  27.   * @{
  28.   */


  29. /* Private typedef -----------------------------------------------------------*/
  30. /* Private define ------------------------------------------------------------*/
  31. #define LCD_ILI9320     0x9320
  32. #define LCD_HX8312      0x8312
  33. #define LCD_SPFD5408    0x5408

  34. #define START_BYTE      0x70
  35. #define SET_INDEX       0x00
  36. #define READ_STATUS     0x01
  37. #define LCD_WRITE_REG   0x02
  38. #define LCD_READ_REG    0x03

  39. /* Private macro -------------------------------------------------------------*/
  40. /* Private variables ---------------------------------------------------------*/
  41.   /* Global variables to set the written text color */
  42. static __IO uint16_t TextColor = 0x0000, BackColor = 0xFFFF;
  43. static __IO uint32_t LCDType = LCD_ILI9320;

  44. /* Private function prototypes -----------------------------------------------*/
  45. static void LCD_WriteRegHX8312(uint8_t LCD_Reg, uint8_t LCD_RegValue);
  46. static void LCD_WriteRegILI9320(uint8_t LCD_Reg, uint16_t LCD_RegValue);

  47. /* Private functions ---------------------------------------------------------*/



  48. /**
  49.   * @brief  Setups the LCD.
  50.   * @param  None
  51.   * @retval : None
  52.   */
  53. void LCD_Setup(void)
  54. {
  55. /* Configure the LCD Control pins --------------------------------------------*/
  56.   LCD_CtrlLinesConfig();
  57.   
  58. /* Configure the SPI2 interface ----------------------------------------------*/
  59.   LCD_SPIConfig();

  60.   if(LCDType == LCD_ILI9320)
  61.   {
  62.     Delay(5); /* Delay 50 ms */

  63.     /* Start Initial Sequence ------------------------------------------------*/
  64.     LCD_WriteReg(R229, 0x8000); /* Set the internal vcore voltage */
  65.     LCD_WriteReg(R0,  0x0001); /* Start internal OSC. */
  66.     LCD_WriteReg(R1,  0x0100); /* set SS and SM bit */
  67.     LCD_WriteReg(R2,  0x0700); /* set 1 line inversion */
  68.     LCD_WriteReg(R3,  0x1030); /* set GRAM write direction and BGR=1. */
  69.     LCD_WriteReg(R4,  0x0000); /* Resize register */
  70.     LCD_WriteReg(R8,  0x0202); /* set the back porch and front porch */
  71.     LCD_WriteReg(R9,  0x0000); /* set non-display area refresh cycle ISC[3:0] */
  72.     LCD_WriteReg(R10, 0x0000); /* FMARK function */
  73.     LCD_WriteReg(R12, 0x0000); /* RGB interface setting */
  74.     LCD_WriteReg(R13, 0x0000); /* Frame marker Position */
  75.     LCD_WriteReg(R15, 0x0000); /* RGB interface polarity */

  76.     /* Power On sequence -----------------------------------------------------*/
  77.     LCD_WriteReg(R16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
  78.     LCD_WriteReg(R17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
  79.     LCD_WriteReg(R18, 0x0000); /* VREG1OUT voltage */
  80.     LCD_WriteReg(R19, 0x0000); /* VDV[4:0] for VCOM amplitude */
  81.     Delay(20);                 /* Dis-charge capacitor power voltage (200ms) */
  82.     LCD_WriteReg(R16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
  83.     LCD_WriteReg(R17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
  84.     Delay(5);                  /* Delay 50 ms */
  85.     LCD_WriteReg(R18, 0x0139); /* VREG1OUT voltage */
  86.     Delay(5);                  /* Delay 50 ms */
  87.     LCD_WriteReg(R19, 0x1d00); /* VDV[4:0] for VCOM amplitude */
  88.     LCD_WriteReg(R41, 0x0013); /* VCM[4:0] for VCOMH */
  89.     Delay(5);                  /* Delay 50 ms */
  90.     LCD_WriteReg(R32, 0x0000); /* GRAM horizontal Address */
  91.     LCD_WriteReg(R33, 0x0000); /* GRAM Vertical Address */

  92.     /* Adjust the Gamma Curve ------------------------------------------------*/
  93.     LCD_WriteReg(R48, 0x0006);
  94.     LCD_WriteReg(R49, 0x0101);
  95.     LCD_WriteReg(R50, 0x0003);
  96.     LCD_WriteReg(R53, 0x0106);
  97.     LCD_WriteReg(R54, 0x0b02);
  98.     LCD_WriteReg(R55, 0x0302);
  99.     LCD_WriteReg(R56, 0x0707);
  100.     LCD_WriteReg(R57, 0x0007);
  101.     LCD_WriteReg(R60, 0x0600);
  102.     LCD_WriteReg(R61, 0x020b);
  103.   
  104.     /* Set GRAM area ---------------------------------------------------------*/
  105.     LCD_WriteReg(R80, 0x0000); /* Horizontal GRAM Start Address */
  106.     LCD_WriteReg(R81, 0x00EF); /* Horizontal GRAM End Address */
  107.     LCD_WriteReg(R82, 0x0000); /* Vertical GRAM Start Address */
  108.     LCD_WriteReg(R83, 0x013F); /* Vertical GRAM End Address */

  109.     LCD_WriteReg(R96,  0x2700); /* Gate Scan Line */
  110.     LCD_WriteReg(R97,  0x0001); /* NDL,VLE, REV */
  111.     LCD_WriteReg(R106, 0x0000); /* set scrolling line */

  112.     /* Partial Display Control -----------------------------------------------*/
  113.     LCD_WriteReg(R128, 0x0000);
  114.     LCD_WriteReg(R129, 0x0000);
  115.     LCD_WriteReg(R130, 0x0000);
  116.     LCD_WriteReg(R131, 0x0000);
  117.     LCD_WriteReg(R132, 0x0000);
  118.     LCD_WriteReg(R133, 0x0000);

  119.     /* Panel Control ---------------------------------------------------------*/
  120.     LCD_WriteReg(R144, 0x0010);
  121.     LCD_WriteReg(R146, 0x0000);
  122.     LCD_WriteReg(R147, 0x0003);
  123.     LCD_WriteReg(R149, 0x0110);
  124.     LCD_WriteReg(R151, 0x0000);
  125.     LCD_WriteReg(R152, 0x0000);

  126.     /* Set GRAM write direction and BGR = 1 */
  127.     /* I/D=01 (Horizontal : increment, Vertical : decrement) */
  128.     /* AM=1 (address is updated in vertical writing direction) */
  129.     LCD_WriteReg(R3, 0x1018);

  130.     LCD_WriteReg(R7, 0x0173); /* 262K color and display ON */
  131.   }
  132.   else if(LCDType == LCD_SPFD5408)
  133.   {   
  134.     /* Start Initial Sequence --------------------------------------------------*/
  135.     LCD_WriteReg(R227, 0x3008); /* Set internal timing */
  136.     LCD_WriteReg(R231, 0x0012); /* Set internal timing */
  137.     LCD_WriteReg(R239, 0x1231); /* Set internal timing */
  138.     LCD_WriteReg(R1, 0x0100);   /* Set SS and SM bit */
  139.     LCD_WriteReg(R2, 0x0700);   /* Set 1 line inversion */
  140.     LCD_WriteReg(R3, 0x1030);   /* Set GRAM write direction and BGR=1. */
  141.     LCD_WriteReg(R4, 0x0000);   /* Resize register */

  142.     LCD_WriteReg(R8, 0x0202);   /* Set the back porch and front porch */
  143.     LCD_WriteReg(R9, 0x0000);   /* Set non-display area refresh cycle ISC[3:0] */
  144.     LCD_WriteReg(R10, 0x0000);  /* FMARK function */
  145.     LCD_WriteReg(R12, 0x0000);  /* RGB interface setting */
  146.     LCD_WriteReg(R13, 0x0000);  /* Frame marker Position */
  147.     LCD_WriteReg(R15, 0x0000);  /* RGB interface polarity */

  148.     /* Power On sequence -------------------------------------------------------*/
  149.     LCD_WriteReg(R16, 0x0000);  /* SAP, BT[3:0], AP, DSTB, SLP, STB */
  150.     LCD_WriteReg(R17, 0x0000);  /* DC1[2:0], DC0[2:0], VC[2:0] */
  151.     LCD_WriteReg(R18, 0x0000);  /* VREG1OUT voltage */
  152.     LCD_WriteReg(R19, 0x0000);  /* VDV[4:0] for VCOM amplitude */
  153.     Delay(20);                  /* Dis-charge capacitor power voltage (200ms) */  
  154.     LCD_WriteReg(R17, 0x0007);        /* DC1[2:0], DC0[2:0], VC[2:0] */
  155.     Delay(5);                   /* Delay 50 ms */
  156.     LCD_WriteReg(R16, 0x12B0);        /* SAP, BT[3:0], AP, DSTB, SLP, STB */
  157.     Delay(5);                        /* Delay 50 ms */
  158.     LCD_WriteReg(R18, 0x01BD);  /* External reference voltage= Vci */
  159.     Delay(5);                   /* Delay 50 ms */
  160.     LCD_WriteReg(R19, 0x1400);  /* VDV[4:0] for VCOM amplitude */
  161.     LCD_WriteReg(R41, 0x000E);  /* VCM[4:0] for VCOMH */
  162.     Delay(5);                   /* Delay 50 ms */
  163.     LCD_WriteReg(R32, 0x0000);  /* GRAM horizontal Address */
  164.     LCD_WriteReg(R33, 0x013F);  /* GRAM Vertical Address */

  165.     /* Adjust the Gamma Curve --------------------------------------------------*/
  166.     LCD_WriteReg(R48, 0x0007);
  167.     LCD_WriteReg(R49, 0x0302);
  168.     LCD_WriteReg(R50, 0x0105);
  169.     LCD_WriteReg(R53, 0x0206);
  170.     LCD_WriteReg(R54, 0x0808);
  171.     LCD_WriteReg(R55, 0x0206);
  172.     LCD_WriteReg(R56, 0x0504);
  173.     LCD_WriteReg(R57, 0x0007);
  174.     LCD_WriteReg(R60, 0x0105);
  175.     LCD_WriteReg(R61, 0x0808);

  176.     /* Set GRAM area -----------------------------------------------------------*/
  177.     LCD_WriteReg(R80, 0x0000);  /* Horizontal GRAM Start Address */
  178.     LCD_WriteReg(R81, 0x00EF);  /* Horizontal GRAM End Address */
  179.     LCD_WriteReg(R82, 0x0000);  /* Vertical GRAM Start Address */
  180.     LCD_WriteReg(R83, 0x013F);  /* Vertical GRAM End Address */

  181.     LCD_WriteReg(R96,  0xA700); /* Gate Scan Line */
  182.     LCD_WriteReg(R97,  0x0001); /* NDL,VLE, REV */
  183.     LCD_WriteReg(R106, 0x0000); /* Set scrolling line */

  184.     /* Partial Display Control -------------------------------------------------*/
  185.     LCD_WriteReg(R128, 0x0000);
  186.     LCD_WriteReg(R129, 0x0000);
  187.     LCD_WriteReg(R130, 0x0000);
  188.     LCD_WriteReg(R131, 0x0000);
  189.     LCD_WriteReg(R132, 0x0000);
  190.     LCD_WriteReg(R133, 0x0000);

  191.     /* Panel Control -----------------------------------------------------------*/
  192.     LCD_WriteReg(R144, 0x0010);
  193.     LCD_WriteReg(R146, 0x0000);
  194.     LCD_WriteReg(R147, 0x0003);
  195.     LCD_WriteReg(R149, 0x0110);
  196.     LCD_WriteReg(R151, 0x0000);
  197.     LCD_WriteReg(R152, 0x0000);

  198.     /* Set GRAM write direction and BGR = 1
  199.        I/D=01 (Horizontal : increment, Vertical : decrement)
  200.        AM=1 (address is updated in vertical writing direction) */
  201.     LCD_WriteReg(R3, 0x1018);

  202.     LCD_WriteReg(R7, 0x0112);   /* 262K color and display ON */
  203.   }
  204.   else if(LCDType == LCD_HX8312)
  205.   {
  206.     /* Enable the LCD Oscillator ---------------------------------------------*/
  207.     LCD_WriteReg(R1, 0x10);
  208.     LCD_WriteReg(R0, 0xA0);
  209.     LCD_WriteReg(R3, 0x01);
  210.     Delay(1); /* Delay 10 ms */
  211.     LCD_WriteReg(R3, 0x00);
  212.     LCD_WriteReg(R43, 0x04);
  213.   
  214.     LCD_WriteReg(R40, 0x18);
  215.     LCD_WriteReg(R26, 0x05);
  216.     LCD_WriteReg(R37, 0x05);
  217.     LCD_WriteReg(R25, 0x00);
  218.    
  219.     /* LCD Power On ----------------------------------------------------------*/
  220.     LCD_WriteReg(R28, 0x73);
  221.     LCD_WriteReg(R36, 0x74);
  222.     LCD_WriteReg(R30, 0x01);
  223.     LCD_WriteReg(R24, 0xC1);
  224.     Delay(1); /* Delay 10 ms */
  225.     LCD_WriteReg(R24, 0xE1);
  226.     LCD_WriteReg(R24, 0xF1);
  227.     Delay(6); /* Delay 60 ms */
  228.     LCD_WriteReg(R24, 0xF5);
  229.     Delay(6); /* Delay 60 ms */
  230.     LCD_WriteReg(R27, 0x09);
  231.     Delay(1); /* Delay 10 ms */
  232.     LCD_WriteReg(R31, 0x11);
  233.     LCD_WriteReg(R32, 0x0E);
  234.     LCD_WriteReg(R30, 0x81);
  235.     Delay(1); /* Delay 10 ms */
  236.    
  237.     /* Chip Set --------------------------------------------------------------*/
  238.     LCD_WriteReg(R157, 0x00);
  239.     LCD_WriteReg(R192, 0x00);
  240.    
  241.     LCD_WriteReg(R14, 0x00);
  242.     LCD_WriteReg(R15, 0x00);
  243.     LCD_WriteReg(R16, 0x00);
  244.     LCD_WriteReg(R17, 0x00);
  245.     LCD_WriteReg(R18, 0x00);
  246.     LCD_WriteReg(R19, 0x00);
  247.     LCD_WriteReg(R20, 0x00);
  248.     LCD_WriteReg(R21, 0x00);
  249.     LCD_WriteReg(R22, 0x00);
  250.     LCD_WriteReg(R23, 0x00);
  251.    
  252.     LCD_WriteReg(R52, 0x01);
  253.     LCD_WriteReg(R53, 0x00);

  254.     LCD_WriteReg(R75, 0x00);
  255.     LCD_WriteReg(R76, 0x00);
  256.     LCD_WriteReg(R78, 0x00);
  257.     LCD_WriteReg(R79, 0x00);
  258.     LCD_WriteReg(R80, 0x00);
  259.   
  260.     LCD_WriteReg(R60, 0x00);
  261.     LCD_WriteReg(R61, 0x00);
  262.     LCD_WriteReg(R62, 0x01);
  263.     LCD_WriteReg(R63, 0x3F);
  264.     LCD_WriteReg(R64, 0x02);
  265.     LCD_WriteReg(R65, 0x02);
  266.     LCD_WriteReg(R66, 0x00);
  267.     LCD_WriteReg(R67, 0x00);
  268.     LCD_WriteReg(R68, 0x00);
  269.     LCD_WriteReg(R69, 0x00);
  270.     LCD_WriteReg(R70, 0xEF);
  271.     LCD_WriteReg(R71, 0x00);
  272.     LCD_WriteReg(R72, 0x00);
  273.     LCD_WriteReg(R73, 0x01);
  274.     LCD_WriteReg(R74, 0x3F);
  275.   
  276.     LCD_WriteReg(R29, 0x08);  /* R29:Gate scan direction setting */
  277.   
  278.     LCD_WriteReg(R134, 0x00);
  279.     LCD_WriteReg(R135, 0x30);
  280.     LCD_WriteReg(R136, 0x02);
  281.     LCD_WriteReg(R137, 0x05);
  282.   
  283.     LCD_WriteReg(R141, 0x01);  /* R141:Register set-up mode for one line clock */
  284.     LCD_WriteReg(R139, 0x20);  /* R139:One line SYSCLK number in one-line */
  285.     LCD_WriteReg(R51, 0x01);  /* R51:N line inversion setting */
  286.     LCD_WriteReg(R55, 0x01);  /* R55:Scanning method setting */
  287.     LCD_WriteReg(R118, 0x00);
  288.    
  289.     /* Gamma Set -------------------------------------------------------------*/
  290.     LCD_WriteReg(R143, 0x10);
  291.     LCD_WriteReg(R144, 0x67);
  292.     LCD_WriteReg(R145, 0x07);
  293.     LCD_WriteReg(R146, 0x65);
  294.     LCD_WriteReg(R147, 0x07);
  295.     LCD_WriteReg(R148, 0x01);
  296.     LCD_WriteReg(R149, 0x76);
  297.     LCD_WriteReg(R150, 0x56);
  298.     LCD_WriteReg(R151, 0x00);
  299.     LCD_WriteReg(R152, 0x06);
  300.     LCD_WriteReg(R153, 0x03);
  301.     LCD_WriteReg(R154, 0x00);
  302.   
  303.     /* Display On ------------------------------------------------------------*/
  304.     LCD_WriteReg(R1, 0x50);
  305.     LCD_WriteReg(R5, 0x04);

  306.     LCD_WriteReg(R0, 0x80);
  307.     LCD_WriteReg(R59, 0x01);
  308.     Delay(4);  /* Delay 40 ms */
  309.     LCD_WriteReg(R0, 0x20);
  310.   }  
  311. }



  312. /**
  313.   * @brief  Initializes the LCD.
  314.   * @param  None
  315.   * @retval : None
  316.   */
  317. void STM3210B_LCD_Init(void)
  318. {
  319.   /* Setups the LCD */
  320.   LCD_Setup();

  321.   /* Try to read new LCD controller ID 0x9320 */
  322.   if (LCD_ReadReg(R0) == LCD_ILI9320)
  323.   {
  324.     LCDType = LCD_ILI9320;
  325.   }
  326.   else
  327.   {
  328.     LCDType = LCD_SPFD5408;

  329.     /* Setups the LCD */
  330.     LCD_Setup();

  331.     /* Try to read new LCD controller ID 0x5408 */
  332.     if (LCD_ReadReg(R0) != LCD_SPFD5408)
  333.     {
  334.       LCDType = LCD_HX8312;
  335.       /* Setups the LCD */
  336.       LCD_Setup();
  337.     }
  338.   }
  339. }



  340. /**
  341.   * @brief  Sets the Text color.
  342.   * @param Color: specifies the Text color code RGB(5-6-5).
  343.   *   and LCD_DrawPicture functions.
  344.   * @retval : None
  345.   */
  346. void LCD_SetTextColor(__IO uint16_t Color)
  347. {
  348.   TextColor = Color;
  349. }



  350. /**
  351.   * @brief  Sets the Background color.
  352.   * @param Color: specifies the Background color code RGB(5-6-5).
  353.   *   LCD_DrawChar and LCD_DrawPicture functions.
  354.   * @retval : None
  355.   */
  356. void LCD_SetBackColor(__IO uint16_t Color)
  357. {
  358.   BackColor = Color;
  359. }



  360. /**
  361.   * @brief  Clears the selected line.
  362.   * @param Line: the Line to be cleared.
  363.   *   This parameter can be one of the following values:
  364.   * @arg Linex: where x can be 0..9
  365.   * @retval : None
  366.   */
  367. void LCD_ClearLine(uint8_t Line)
  368. {
  369.   LCD_DisplayStringLine(Line, "                    ");
  370. }



  371. /**
  372.   * @brief  Clears the hole LCD.
  373.   * @param lor: the color of the background.
  374.   * @retval : None
  375.   */
  376. void LCD_Clear(uint16_t Color)
  377. {
  378.   uint32_t index = 0;
  379.   
  380.   LCD_SetCursor(0x00, 0x013F);

  381.   if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
  382.   {
  383.     LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
  384.   }

  385.   for(index = 0; index < 76800; index++)
  386.   {
  387.     LCD_WriteRAM(Color);
  388.   }

  389.   if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
  390.   {
  391.     LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_SET);
  392.   }  
  393. }



  394. /**
  395.   * @brief  Sets the cursor position.
  396.   * @param Xpos: specifies the X position.
  397.   * @param Ypos: specifies the Y position.
  398.   * @retval : None
  399.   */
  400. void LCD_SetCursor(uint8_t Xpos, uint16_t Ypos)
  401. {
  402.   if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
  403.   {
  404.     LCD_WriteReg(R32, Xpos);
  405.     LCD_WriteReg(R33, Ypos);
  406.   }
  407.   else if(LCDType == LCD_HX8312)
  408.   {
  409.     LCD_WriteReg(R66, Xpos);
  410.     LCD_WriteReg(R67, ((Ypos & 0x100)>> 8));
  411.     LCD_WriteReg(R68, (Ypos & 0xFF));
  412.   }
  413. }



  414. /**
  415.   * @brief  Draws a character on LCD.
  416.   * @param Xpos: the Line where to display the character shape.
  417.   *   This parameter can be one of the following values:
  418.   * @param Linex: where x can be 0..9
  419.   * @param Ypos: start column address.
  420.   * @param c: pointer to the character data.
  421.   * @retval : None
  422.   */
  423. void LCD_DrawChar(uint8_t Xpos, uint16_t Ypos, const uint16_t *c)
  424. {
  425.   uint32_t index = 0, i = 0;
  426.   uint8_t Xaddress = 0;
  427.    
  428.   Xaddress = Xpos;
  429.   
  430.   LCD_SetCursor(Xaddress, Ypos);
  431.   
  432.   for(index = 0; index < 24; index++)
  433.   {
  434.     if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
  435.     {
  436.       LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
  437.     }
  438.     for(i = 0; i < 16; i++)
  439.     {
  440.       if((c[index] & (1 << i)) == 0x00)
  441.       {
  442.         LCD_WriteRAM(BackColor);
  443.       }
  444.       else
  445.       {
  446.         LCD_WriteRAM(TextColor);
  447.       }
  448.     }
  449.     if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
  450.     {
  451.       LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_SET);
  452.     }  
  453.     Xaddress++;
  454.     LCD_SetCursor(Xaddress, Ypos);
  455.   }
  456. }



  457. /**
  458.   * @brief  Displays one character (16dots width, 24dots height).
  459.   * @param Line: the Line where to display the character shape .
  460.   *   This parameter can be one of the following values:
  461.   * @arg Linex: where x can be 0..9
  462.   * @param Column: start column address.
  463.   * @param Ascii: character ascii code, must be between 0x20 and 0x7E.
  464.   * @retval : None
  465.   */
  466. void LCD_DisplayChar(uint8_t Line, uint16_t Column, uint8_t Ascii)
  467. {
  468.   Ascii -= 32;
  469.   LCD_DrawChar(Line, Column, &ASCII_Table[Ascii * 24]);
  470. }



  471. /**
  472.   * @brief  Displays a maximum of 20 char on the LCD.
  473.   * @param Line: the Line where to display the character shape .
  474.   *   This parameter can be one of the following values:
  475.   * @arg Linex: where x can be 0..9
  476.   * @param *ptr: pointer to string to display on LCD.
  477.   * @retval : None
  478.   */
  479. void LCD_DisplayStringLine(uint8_t Line, uint8_t *ptr)
  480. {
  481.   uint32_t i = 0;
  482.   uint16_t refcolumn = 319;

  483.   /* Send the string character by character on lCD */
  484.   while ((*ptr != 0) & (i < 20))
  485.   {
  486.     /* Display one character on LCD */
  487.     LCD_DisplayChar(Line, refcolumn, *ptr);
  488.     /* Decrement the column position by 16 */
  489.     refcolumn -= 16;
  490.     /* Point on the next character */
  491.     ptr++;
  492.     /* Increment the character counter */
  493.     i++;
  494.   }
  495. }



  496. /**
  497.   * @brief  Sets a display window
  498.   * @param Xpos: specifies the X buttom left position.
  499.   * @param Ypos: specifies the Y buttom left position.
  500.   * @param Height: display window height.
  501.   * @param Width: display window width.
  502.   * @retval : None
  503.   */
  504. void LCD_SetDisplayWindow(uint8_t Xpos, uint16_t Ypos, uint8_t Height, uint16_t Width)
  505. {
  506.   if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
  507.   {
  508.     /* Horizontal GRAM Start Address */
  509.     if(Xpos >= Height)
  510.     {
  511.       LCD_WriteReg(R80, (Xpos - Height + 1));
  512.     }
  513.     else
  514.     {
  515.       LCD_WriteReg(R80, 0);
  516.     }
  517.     /* Horizontal GRAM End Address */
  518.     LCD_WriteReg(R81, Xpos);
  519.     /* Vertical GRAM Start Address */
  520.     if(Ypos >= Width)
  521.     {
  522.       LCD_WriteReg(R82, (Ypos - Width + 1));
  523.     }  
  524.     else
  525.     {
  526.       LCD_WriteReg(R82, 0);
  527.     }
  528.     /* Vertical GRAM End Address */
  529.     LCD_WriteReg(R83, Ypos);
  530.   }
  531.   else if(LCDType == LCD_HX8312)
  532.   {  
  533.     LCD_WriteReg(R1, 0xD0);
  534.     LCD_WriteReg(R5, 0x14);
  535.   
  536.     LCD_WriteReg(R69, (Xpos - Height + 1));
  537.     LCD_WriteReg(R70, Xpos);

  538.     LCD_WriteReg(R71, (((Ypos - Width + 1) & 0x100)>> 8));
  539.     LCD_WriteReg(R72, ((Ypos - Width + 1) & 0xFF));

  540.     LCD_WriteReg(R73, ((Ypos & 0x100)>> 8));
  541.     LCD_WriteReg(R74, (Ypos & 0xFF));
  542.   }

  543.   LCD_SetCursor(Xpos, Ypos);
  544. }



  545. /**
  546.   * @brief  Disables LCD Window mode.
  547.   * @param  None
  548.   * @retval : None
  549.   */
  550. void LCD_WindowModeDisable(void)
  551. {
  552.   if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
  553.   {
  554.     LCD_SetDisplayWindow(239, 0x13F, 240, 320);
  555.     LCD_WriteReg(R3, 0x1018);
  556.   }
  557.   else if(LCDType == LCD_HX8312)
  558.   {
  559.     LCD_WriteReg(R1, 0x50);
  560.     LCD_WriteReg(R5, 0x04);
  561.   }
  562.    
  563. }


  564. /**
  565.   * @brief  Displays a line.
  566.   * @param Xpos: specifies the X position.
  567.   * @param Ypos: specifies the Y position.
  568.   * @param Length: line length.
  569.   * @param Direction: line direction.
  570.   *   This parameter can be one of the following values: Vertical
  571.   *   or Horizontal.
  572.   * @retval : None
  573.   */
  574. void LCD_DrawLine(uint8_t Xpos, uint16_t Ypos, uint16_t Length, uint8_t Direction)
  575. {
  576.   uint32_t i = 0;
  577.   
  578.   LCD_SetCursor(Xpos, Ypos);

  579.   if(Direction == Horizontal)
  580.   {
  581.     if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
  582.     {
  583.       LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
  584.     }
  585.     for(i = 0; i < Length; i++)
  586.     {
  587.       LCD_WriteRAM(TextColor);
  588.     }
  589.     if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
  590.     {
  591.       LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_SET);
  592.     }
  593.   }
  594.   else
  595.   {
  596.    for(i = 0; i < Length; i++)
  597.     {
  598.       if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
  599.       {
  600.         LCD_WriteRAMWord(TextColor);
  601.       }
  602.       else  if(LCDType == LCD_HX8312)
  603.       {
  604.         LCD_WriteRAM(TextColor);
  605.       }
  606.       Xpos++;
  607.       LCD_SetCursor(Xpos, Ypos);
  608.     }
  609.   }
  610. }



  611. /**
  612.   * @brief  Displays a rectangle.
  613.   * @param Xpos: specifies the X position.
  614.   * @param Ypos: specifies the Y position.
  615.   * @param Height: display rectangle height.
  616.   * @param Width: display rectangle width.
  617.   * @retval : None
  618.   */
  619. void LCD_DrawRect(uint8_t Xpos, uint16_t Ypos, uint8_t Height, uint16_t Width)
  620. {
  621.   LCD_DrawLine(Xpos, Ypos, Width, Horizontal);
  622.   LCD_DrawLine((Xpos + Height), Ypos, Width, Horizontal);
  623.   
  624.   LCD_DrawLine(Xpos, Ypos, Height, Vertical);
  625.   LCD_DrawLine(Xpos, (Ypos - Width + 1), Height, Vertical);
  626. }



  627. /**
  628.   * @brief  Displays a circle.
  629.   * @param Xpos: specifies the X position.
  630.   * @param Ypos: specifies the Y position.
  631.   * @param Height: display rectangle height.
  632.   * @param Width: display rectangle width.
  633.   * @retval : None
  634.   */
  635. void LCD_DrawCircle(uint8_t Xpos, uint16_t Ypos, uint16_t Radius)
  636. {
  637.   int32_t  D;/* Decision Variable */
  638.   uint32_t  CurX;/* Current X Value */
  639.   uint32_t  CurY;/* Current Y Value */
  640.   
  641.   D = 3 - (Radius << 1);
  642.   CurX = 0;
  643.   CurY = Radius;
  644.   
  645.   while (CurX <= CurY)
  646.   {
  647.     LCD_SetCursor(Xpos + CurX, Ypos + CurY);
  648.     if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
  649.     {
  650.       LCD_WriteRAMWord(TextColor);
  651.     }
  652.     else if(LCDType == LCD_HX8312)
  653.     {
  654.       LCD_WriteRAM(TextColor);
  655.     }
  656.     LCD_SetCursor(Xpos + CurX, Ypos - CurY);
  657.     if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
  658.     {
  659.       LCD_WriteRAMWord(TextColor);
  660.     }
  661.     else if(LCDType == LCD_HX8312)
  662.     {
  663.       LCD_WriteRAM(TextColor);
  664.     }
  665.     LCD_SetCursor(Xpos - CurX, Ypos + CurY);
  666.     if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
  667.     {
  668.       LCD_WriteRAMWord(TextColor);
  669.     }
  670.     else if(LCDType == LCD_HX8312)
  671.     {
  672.       LCD_WriteRAM(TextColor);
  673.     }
  674.     LCD_SetCursor(Xpos - CurX, Ypos - CurY);
  675.     if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
  676.     {
  677.       LCD_WriteRAMWord(TextColor);
  678.     }
  679.     else if(LCDType == LCD_HX8312)
  680.     {
  681.       LCD_WriteRAM(TextColor);
  682.     }
  683.     LCD_SetCursor(Xpos + CurY, Ypos + CurX);
  684.     if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
  685.     {
  686.       LCD_WriteRAMWord(TextColor);
  687.     }
  688.     else if(LCDType == LCD_HX8312)
  689.     {
  690.       LCD_WriteRAM(TextColor);
  691.     }
  692.     LCD_SetCursor(Xpos + CurY, Ypos - CurX);
  693.     if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
  694.     {
  695.       LCD_WriteRAMWord(TextColor);
  696.     }
  697.     else if(LCDType == LCD_HX8312)
  698.     {
  699.       LCD_WriteRAM(TextColor);
  700.     }
  701.     LCD_SetCursor(Xpos - CurY, Ypos + CurX);
  702.     if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
  703.     {
  704.       LCD_WriteRAMWord(TextColor);
  705.     }
  706.     else if(LCDType == LCD_HX8312)
  707.     {
  708.       LCD_WriteRAM(TextColor);
  709.     }
  710.     LCD_SetCursor(Xpos - CurY, Ypos - CurX);
  711.     if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
  712.     {
  713.       LCD_WriteRAMWord(TextColor);
  714.     }
  715.     else if(LCDType == LCD_HX8312)
  716.     {
  717.       LCD_WriteRAM(TextColor);
  718.     }

  719.     if (D < 0)
  720.     {
  721.       D += (CurX << 2) + 6;
  722.     }
  723.     else
  724.     {
  725.       D += ((CurX - CurY) << 2) + 10;
  726.       CurY--;
  727.     }
  728.     CurX++;
  729.   }
  730. }



  731. /**
  732.   * @brief  Displays a monocolor picture.
  733.   * @param Pict: pointer to the picture array.
  734.   * @retval : None
  735.   */
  736. void LCD_DrawMonoPict(const uint32_t *Pict)
  737. {
  738.   uint32_t index = 0, i = 0;

  739.   LCD_SetCursor(0, 319);
  740.   if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
  741.   {
  742.     LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
  743.   }
  744.   for(index = 0; index < 2400; index++)
  745.   {
  746.     for(i = 0; i < 32; i++)
  747.     {
  748.       if((Pict[index] & (1 << i)) == 0x00)
  749.       {
  750.         LCD_WriteRAM(BackColor);
  751.       }
  752.       else
  753.       {
  754.         LCD_WriteRAM(TextColor);
  755.       }
  756.     }
  757.   }
  758.   if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
  759.   {
  760.     LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_SET);
  761.   }
  762. }



  763. /**
  764.   * @brief  Reset LCD control line(/CS) and Send Start-Byte
  765.   * @param Start_Byte: the Start-Byte to be sent
  766.   * @retval : None
  767.   */
  768. void LCD_nCS_StartByte(uint8_t Start_Byte)
  769. {
  770.   LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_RESET);

  771.   SPI_I2S_SendData(SPI2, Start_Byte);

  772.   while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) != RESET)
  773.   {
  774.   }
  775. }



  776. /**
  777.   * @brief  Writes index to select the LCD register.
  778.   * @param LCD_Reg: address of the selected register.
  779.   * @retval : None
  780.   */
  781. void LCD_WriteRegIndex(uint8_t LCD_Reg)
  782. {
  783.   /* Reset LCD control line(/CS) and Send Start-Byte */
  784.   LCD_nCS_StartByte(START_BYTE | SET_INDEX);

  785.   /* Write 16-bit Reg Index (High Byte is 0) */
  786.   SPI_I2S_SendData(SPI2, 0x00);

  787.   while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) != RESET)
  788.   {
  789.   }

  790.   SPI_I2S_SendData(SPI2, LCD_Reg);

  791.   while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) != RESET)
  792.   {
  793.   }

  794.   LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_SET);
  795. }



  796. /**
  797.   * @brief  Writes to the selected LCD ILI9320 register.
  798.   * @param LCD_Reg: address of the selected register.
  799.   * @arg LCD_RegValue: value to write to the selected register.
  800.   * @retval : None
  801.   */
  802. static void LCD_WriteRegILI9320(uint8_t LCD_Reg, uint16_t LCD_RegValue)
  803. {
  804.   /* Write 16-bit Index (then Write Reg) */
  805.   LCD_WriteRegIndex(LCD_Reg);

  806.   /* Write 16-bit Reg */
  807.   /* Reset LCD control line(/CS) and Send Start-Byte */
  808.   LCD_nCS_StartByte(START_BYTE | LCD_WRITE_REG);

  809.   SPI_I2S_SendData(SPI2, LCD_RegValue>>8);
  810.   while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) != RESET)
  811.   {
  812.   }
  813.   SPI_I2S_SendData(SPI2, (LCD_RegValue & 0xFF));
  814.   while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) != RESET)
  815.   {
  816.   }

  817.   LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_SET);
  818. }



  819. /**
  820.   * @brief  Reads the selected LCD Register.
  821.   * @param  None
  822.   * @retval : LCD Register Value.
  823.   */
  824. uint16_t LCD_ReadReg(uint8_t LCD_Reg)
  825. {
  826.   uint16_t tmp = 0;
  827.   uint8_t i = 0;
  828.   
  829.   /* SPI2 prescaler: 4 */
  830.   SPI2->CR1 &= 0xFFC7;
  831.   SPI2->CR1 |= 0x0008;

  832.   /* Write 16-bit Index (then Read Reg) */
  833.   LCD_WriteRegIndex(LCD_Reg);

  834.   /* Read 16-bit Reg */
  835.   /* Reset LCD control line(/CS) and Send Start-Byte */
  836.   LCD_nCS_StartByte(START_BYTE | LCD_READ_REG);
  837.   
  838.   for(i = 0; i < 5; i++)
  839.   {
  840.     SPI_I2S_SendData(SPI2, 0xFF);
  841.     while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) != RESET)
  842.     {
  843.     }
  844.     /* One byte of invalid dummy data read after the start byte */
  845.     while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET)
  846.     {   
  847.     }
  848.     SPI_I2S_ReceiveData(SPI2);
  849.   }

  850.   SPI_I2S_SendData(SPI2, 0xFF);
  851.   /* Read upper byte */
  852.   while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) != RESET)
  853.   {
  854.   }
  855.   /* Read lower byte */
  856.   while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET)
  857.   {
  858.   }
  859.   tmp = SPI_I2S_ReceiveData(SPI2);
  860.   
  861.   
  862.   SPI_I2S_SendData(SPI2, 0xFF);
  863.   while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) != RESET)
  864.   {
  865.   }
  866.   /* Read lower byte */
  867.   while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET)
  868.   {
  869.   }
  870.   tmp = ((tmp & 0xFF) << 8) | SPI_I2S_ReceiveData(SPI2);

  871.   LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_SET);

  872.   /* SPI2 prescaler: 2 */
  873.   SPI2->CR1 &= 0xFFC7;

  874.   return tmp;
  875. }



  876. /**
  877.   * @brief  Prepare to write to the LCD RAM.
  878.   * @param  None
  879.   * @retval : None
  880.   */
  881. void LCD_WriteRAM_Prepare(void)
  882. {
  883.   LCD_WriteRegIndex(R34); /* Select GRAM Reg */

  884.   /* Reset LCD control line(/CS) and Send Start-Byte */
  885.   LCD_nCS_StartByte(START_BYTE | LCD_WRITE_REG);
  886. }



  887. /**
  888.   * @brief  Writes 1 word to the LCD RAM.
  889.   * @param RGB_Code: the pixel color in RGB mode (5-6-5).
  890.   * @retval : None
  891.   */
  892. void LCD_WriteRAMWord(uint16_t RGB_Code)
  893. {
  894.   LCD_WriteRAM_Prepare();

  895.   LCD_WriteRAM(RGB_Code);

  896.   LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_SET);
  897. }



  898. /**
  899.   * @brief  Writes to the selected LCD HX8312 register.
  900.   * @param LCD_Reg: address of the selected register.
  901.   * @arg LCD_RegValue: value to write to the selected register.
  902.   * @retval : None
  903.   */
  904. static void LCD_WriteRegHX8312(uint8_t LCD_Reg, uint8_t LCD_RegValue)
  905. {
  906.   uint16_t tmp = 0;
  907.   
  908.   LCD_CtrlLinesWrite(GPIOD, CtrlPin_NWR, Bit_RESET);
  909.   LCD_CtrlLinesWrite(GPIOD, CtrlPin_RS, Bit_RESET);
  910.   LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_RESET);
  911.   
  912.   tmp = LCD_Reg << 8;
  913.   tmp |= LCD_RegValue;

  914.   SPI_I2S_SendData(SPI2, tmp);
  915.   while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) != RESET)
  916.   {
  917.   }
  918.   
  919.   LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_SET);
  920. }



  921. /**
  922.   * @brief  Writes to the selected LCD register.
  923.   * @param LCD_Reg: address of the selected register.
  924.   * @arg LCD_RegValue: value to write to the selected register.
  925.   * @retval : None
  926.   */
  927. void LCD_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue)
  928. {
  929.   if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
  930.   {
  931.     LCD_WriteRegILI9320(LCD_Reg, LCD_RegValue);
  932.   }
  933.   else if(LCDType == LCD_HX8312)
  934.   {
  935.     LCD_WriteRegHX8312(LCD_Reg, ((uint8_t)LCD_RegValue));
  936.   }
  937. }




  938. /**
  939.   * @brief  Writes to the LCD RAM.
  940.   * @param RGB_Code: the pixel color in RGB mode (5-6-5).
  941.   * @retval : None
  942.   */
  943. void LCD_WriteRAM(uint16_t RGB_Code)
  944. {
  945.   if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
  946.   {
  947.     SPI_I2S_SendData(SPI2, RGB_Code >> 8);
  948.     while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) != RESET)
  949.     {
  950.     }
  951.     SPI_I2S_SendData(SPI2, RGB_Code & 0xFF);
  952.     while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) != RESET)
  953.     {
  954.     }
  955.   }
  956.   if(LCDType == LCD_HX8312)
  957.   {
  958.     LCD_CtrlLinesWrite(GPIOD, CtrlPin_NWR, Bit_RESET);
  959.     LCD_CtrlLinesWrite(GPIOD, CtrlPin_RS, Bit_SET);
  960.     LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_RESET);

  961.     SPI_I2S_SendData(SPI2, RGB_Code);
  962.     while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) != RESET)
  963.     {
  964.     }
  965.   
  966.     LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_SET);
  967.   }
  968. }



  969. /**
  970.   * @brief  Power on the LCD.
  971.   * @param  None
  972.   * @retval : None
  973.   */
  974. void LCD_PowerOn(void)
  975. {
  976.   if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
  977.   {
  978.     /* Power On sequence ---------------------------------------------------------*/
  979.     LCD_WriteReg(R16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
  980.     LCD_WriteReg(R17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
  981.     LCD_WriteReg(R18, 0x0000); /* VREG1OUT voltage */
  982.     LCD_WriteReg(R19, 0x0000); /* VDV[4:0] for VCOM amplitude */
  983.     Delay(20);                 /* Dis-charge capacitor power voltage (200ms) */
  984.     LCD_WriteReg(R16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
  985.     LCD_WriteReg(R17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
  986.     Delay(5);                  /* Delay 50 ms */
  987.     LCD_WriteReg(R18, 0x0139); /* VREG1OUT voltage */
  988.     Delay(5);                  /* delay 50 ms */
  989.     LCD_WriteReg(R19, 0x1d00); /* VDV[4:0] for VCOM amplitude */
  990.     LCD_WriteReg(R41, 0x0013); /* VCM[4:0] for VCOMH */
  991.     Delay(5);                  /* delay 50 ms */
  992.     LCD_WriteReg(R7, 0x0173);  /* 262K color and display ON */
  993.   }
  994.   else if(LCDType == LCD_HX8312)
  995.   {  
  996.     /* Power On Set */
  997.     LCD_WriteReg(R28, 0x73);
  998.     LCD_WriteReg(R36, 0x74);
  999.     LCD_WriteReg(R30, 0x01);
  1000.     LCD_WriteReg(R24, 0xC1);
  1001.     Delay(1); /* Delay 10 ms */
  1002.     LCD_WriteReg(R24, 0xE1);
  1003.     LCD_WriteReg(R24, 0xF1);
  1004.     Delay(6); /* Delay 60 ms */
  1005.     LCD_WriteReg(R24, 0xF5);
  1006.     Delay(6); /* Delay 60 ms */
  1007.     LCD_WriteReg(R27, 0x09);
  1008.     Delay(1); /* Delay 10 ms */
  1009.     LCD_WriteReg(R31, 0x11);
  1010.     LCD_WriteReg(R32, 0x0E);
  1011.     LCD_WriteReg(R30, 0x81);
  1012.     Delay(1); /* Delay 10 ms */
  1013.   }
  1014. }



  1015. /**
  1016.   * @brief  Enables the Display.
  1017.   * @param  None
  1018.   * @retval : None
  1019.   */
  1020. void LCD_DisplayOn(void)
  1021. {
  1022.   if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
  1023.   {
  1024.     /* Display On */
  1025.     LCD_WriteReg(R7, 0x0173); /* 262K color and display ON */
  1026.   }
  1027.   else if(LCDType == LCD_HX8312)
  1028.   {  
  1029.     LCD_WriteReg(R1, 0x50);
  1030.     LCD_WriteReg(R5, 0x04);

  1031.     /* Display On */
  1032.     LCD_WriteReg(R0, 0x80);
  1033.     LCD_WriteReg(R59, 0x01);
  1034.     Delay(4);                 /* Delay 40 ms */
  1035.     LCD_WriteReg(R0, 0x20);
  1036.   }  
  1037. }



  1038. /**
  1039.   * @brief  Disables the Display.
  1040.   * @param  None
  1041.   * @retval : None
  1042.   */
  1043. void LCD_DisplayOff(void)
  1044. {
  1045.   if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
  1046.   {
  1047.     /* Display Off */
  1048.     LCD_WriteReg(R7, 0x0);
  1049.   }
  1050.   else if(LCDType == LCD_HX8312)
  1051.   {
  1052.     /* Display Off */
  1053.     LCD_WriteReg(R0, 0xA0);
  1054.     Delay(4);                 /* Delay 40 ms */
  1055.     LCD_WriteReg(R59, 0x00);
  1056.   }
  1057. }



  1058. /**
  1059.   * @brief  Configures LCD control lines in Output Push-Pull mode.
  1060.   * @param  None
  1061.   * @retval : None
  1062.   */
  1063. void LCD_CtrlLinesConfig(void)
  1064. {
  1065.   GPIO_InitTypeDef GPIO_InitStructure;

  1066.   /* Configure NCS (PB.02) in Output Push-Pull mode */
  1067.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  1068.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  1069.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  1070.   GPIO_Init(GPIOB, &GPIO_InitStructure);
  1071.   
  1072.   /* Configure NWR(RNW), RS (PD.15, PD.07) in Output Push-Pull mode */
  1073.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_15;
  1074.   GPIO_Init(GPIOD, &GPIO_InitStructure);
  1075.   
  1076.   LCD_CtrlLinesWrite(GPIOD, CtrlPin_NWR, Bit_SET);
  1077.   LCD_CtrlLinesWrite(GPIOD, CtrlPin_RS, Bit_SET);
  1078. }



  1079. /**
  1080.   * @brief  Sets or reset LCD control lines.
  1081.   * @param GPIOx: where x can be B or D to select the GPIO peripheral.
  1082.   * @param CtrlPins: the Control line. This parameter can be:
  1083.   * @param CtrlPin_NCS: Chip Select pin (PB.02)
  1084.   * @param CtrlPin_NWR: Read/Write Selection pin (PD.15)
  1085.   * @param CtrlPin_RS: Register/RAM Selection pin (PD.07)
  1086.   * @param BitVal: specifies the value to be written to the selected bit.
  1087.   *   This parameter can be:
  1088.   * @param Bit_RESET: to clear the port pin
  1089.   * @param Bit_SET: to set the port pin
  1090.   * @retval : None
  1091.   */
  1092. void LCD_CtrlLinesWrite(GPIO_TypeDef* GPIOx, uint16_t CtrlPins, BitAction BitVal)
  1093. {
  1094.   /* Set or Reset the control line */
  1095.   GPIO_WriteBit(GPIOx, CtrlPins, BitVal);
  1096. }



  1097. /**
  1098.   * @brief  Configures the SPI2 interface.
  1099.   * @param  None
  1100.   * @retval : None
  1101.   */
  1102. void LCD_SPIConfig(void)
  1103. {
  1104.   SPI_InitTypeDef    SPI_InitStructure;
  1105.   GPIO_InitTypeDef   GPIO_InitStructure;

  1106.   /* Enable GPIOB clock */
  1107.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);

  1108.   /* Enable SPI2 clock  */
  1109.   RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);

  1110.   /* Configure SPI2 pins: NSS, SCK, MISO and MOSI */
  1111.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
  1112.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  1113.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  1114.   GPIO_Init(GPIOB, &GPIO_InitStructure);

  1115.   SPI_I2S_DeInit(SPI2);
  1116.   
  1117.   /* SPI2 Config */
  1118.   SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
  1119.   SPI_InitStructure.SPI_Mode = SPI_Mode_Master;

  1120.   if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
  1121.   {
  1122.     SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
  1123.     SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
  1124.     SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
  1125.   }
  1126.   else if(LCDType == LCD_HX8312)
  1127.   {
  1128.     SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;
  1129.     SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
  1130.     SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
  1131.   }

  1132.   SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
  1133.   SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
  1134.   SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
  1135.   SPI_Init(SPI2, &SPI_InitStructure);

  1136.   /* SPI2 enable */
  1137.   SPI_Cmd(SPI2, ENABLE);
  1138. }

  1139. /**
  1140.   * @}
  1141.   */

  1142. /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
复制代码



评分

参与人数 1黑币 +5 收起 理由
quanssmm + 5 绝世好帖!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏5 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:82014 发表于 2015-6-4 13:54 | 只看该作者

东西不错啊。。。
回复

使用道具 举报

板凳
ID:82017 发表于 2015-6-4 14:42 | 只看该作者
嗯 不错
回复

使用道具 举报

地板
ID:118731 发表于 2016-5-5 23:34 | 只看该作者
怎么没有把你的测试成果贴出来呢....我刚试了一下你的程序(只参考了相位运算的部分),也得出了结果不知道正确不正确..
回复

使用道具 举报

5#
ID:118731 发表于 2016-5-5 23:34 | 只看该作者
不过还是谢谢楼主提供了算法~~~
回复

使用道具 举报

6#
ID:120269 发表于 2016-5-12 13:00 | 只看该作者
学习了 谢谢楼主
回复

使用道具 举报

7#
ID:139609 发表于 2016-9-17 11:56 | 只看该作者
感谢分享真正学习中
回复

使用道具 举报

8#
ID:139991 发表于 2016-9-21 09:23 | 只看该作者
FFT功能很强大,可以算基准频率,很好的分享。
回复

使用道具 举报

9#
ID:140630 发表于 2016-9-27 14:24 | 只看该作者
学习了,非常有用的教程,谢谢
回复

使用道具 举报

10#
ID:140647 发表于 2016-9-27 16:18 | 只看该作者
好好看看,要是有测试结果就好了
回复

使用道具 举报

11#
ID:93651 发表于 2016-11-9 19:11 | 只看该作者
还以为是F4的
回复

使用道具 举报

12#
ID:147443 发表于 2016-11-11 17:29 | 只看该作者
谢谢分享.....
回复

使用道具 举报

13#
ID:108095 发表于 2016-11-19 23:59 | 只看该作者
自己写了一个!!正用着呢!!
回复

使用道具 举报

14#
ID:152973 发表于 2016-12-7 18:54 | 只看该作者
非常感谢! 楼主好人一生平安
回复

使用道具 举报

15#
ID:152973 发表于 2016-12-7 18:55 | 只看该作者
感觉这东西好高深呀. 还得用力学.
回复

使用道具 举报

16#
ID:152973 发表于 2016-12-7 18:58 | 只看该作者
确实是好东西,一定要下载
回复

使用道具 举报

17#
ID:153066 发表于 2016-12-8 00:02 | 只看该作者

非常感谢!
回复

使用道具 举报

18#
ID:55881 发表于 2017-1-25 09:08 | 只看该作者
没积分下载不了
回复

使用道具 举报

19#
ID:213641 发表于 2017-7-29 22:18 | 只看该作者
工程文件在哪里??找不到呢
回复

使用道具 举报

20#
ID:299936 发表于 2018-3-31 15:47 | 只看该作者
不知道能不能下载呢,多谢楼主
回复

使用道具 举报

21#
ID:442911 发表于 2019-3-15 22:07 | 只看该作者

确实是好东西
回复

使用道具 举报

22#
ID:268693 发表于 2019-6-26 22:05 | 只看该作者
我也顶一下!
回复

使用道具 举报

23#
ID:347811 发表于 2019-11-22 16:16 | 只看该作者
谢谢分享。。参考下相位的计算
回复

使用道具 举报

24#
ID:268151 发表于 2019-11-29 19:36 | 只看该作者

学习了 谢谢楼主
回复

使用道具 举报

25#
ID:456205 发表于 2019-12-13 08:55 | 只看该作者
谢谢分享

学习了 谢谢楼主
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表