久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2757|回復(fù): 1
打印 上一主題 下一主題
收起左側(cè)

基于STM32+OV9655_Camera的二維碼解碼源碼

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:411153 發(fā)表于 2018-10-17 15:34 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
大神寫的基于STM32的二維碼解碼的程序源碼
供大家參考

單片機(jī)源程序如下:
  1. /**
  2.   ******************************************************************************
  3.   * @file    OV9655_Camera/src/main.c  
  4.   * @author  MCD Application Team
  5.   * @version V1.0.0
  6.   * @date    18-April-2011
  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>© Portions COPYRIGHT 2011 STMicroelectronics</center></h2>
  19.   ******************************************************************************
  20.   */
  21. /**
  22.   ******************************************************************************
  23.   * <h2><center>© Portions COPYRIGHT 2012 Embest Tech. Co., Ltd.</center></h2>
  24.   * @file    main.c
  25.   * @author  CMP Team
  26.   * @version V1.0.0
  27.   * @date    28-December-2012
  28.   * @brief   Main program body.                        
  29.   *          Modified to support the STM32F4DISCOVERY, STM32F4DIS-BB, STM32F4DIS-CAM
  30.   *          and STM32F4DIS-LCD modules.
  31.   ******************************************************************************
  32.   * @attention
  33.   *
  34.   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  35.   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  36.   * TIME. AS A RESULT, Embest SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
  37.   * OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
  38.   * OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
  39.   * CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  40.   ******************************************************************************
  41.   */
  42. /* Includes ------------------------------------------------------------------*/
  43. #include "stm32f4xx.h"
  44. #include "stm32f4_discovery.h"
  45. #include "stm32f4_discovery_lcd.h"
  46. #include "stm32f4_discovery_lis302dl.h"
  47. #include "main.h"
  48. #include "bmp.h"
  49. #include "dcmi_ov9655.h"


  50. /** @addtogroup STM32F4xx_StdPeriph_Examples
  51.   * @{
  52.   */

  53. /** @addtogroup DCMI_OV9655_Camera
  54.   * @{
  55.   */

  56. /* Private typedef -----------------------------------------------------------*/
  57. /* Private define ------------------------------------------------------------*/
  58. #define DCMI_DR_ADDRESS     0x50050028
  59. #define FSMC_LCD_ADDRESS    0x60100000

  60. /* Private macro -------------------------------------------------------------*/
  61. /* Private variables ---------------------------------------------------------*/
  62. uint8_t KeyPressFlg = 0;
  63. __IO uint32_t TimingDelay;
  64. __IO uint32_t SysTickLimit;
  65. __IO uint64_t CycleCounter;
  66. __IO int newFrame;
  67. RCC_ClocksTypeDef RCC_Clocks;
  68. EXTI_InitTypeDef   EXTI_InitStructure;
  69. uint8_t capture_Flag = ENABLE;

  70. #define CAMERA_WIDTH    640
  71. #define CAMERA_HEIGHT   480
  72. #define HORIZONTAL_SCALE_FACTOR 2
  73. #define VERTICAL_SCALE_FACTOR   2
  74. uint8_t pbuffer1[CAMERA_WIDTH * 8 * 2];
  75. uint8_t pbuffer2[CAMERA_WIDTH * 8 * 2];
  76. static int blockRowsWritten;

  77. // TODO: put these in a proper place
  78. extern void cppInit(int width, int height);
  79. extern void cppResetBinarizer(void);
  80. extern void cppProcessBlockRow(uint8_t *blockRow);
  81. extern uint8_t *cppGetResults(void);
  82. extern int read_image(void);

  83. /* Private function prototypes -----------------------------------------------*/
  84. uint8_t DCMI_OV9655Config(void);
  85. void DCMI_Config(void);
  86. void I2C1_Config(void);
  87. void EXTILine0_Config(void);
  88. void LIS302DL_Reset(void);
  89. void DisplayBinarizedFrame(void);

  90. /* Private functions ---------------------------------------------------------*/
  91. /**
  92.   * @brief  Main program.
  93.   * @param  None
  94.   * @retval None
  95.   */
  96. int main(void)
  97. {
  98.   /*!< At this stage the microcontroller clock setting is already configured,
  99.        this is done through SystemInit() function which is called from startup
  100.        file (startup_stm32f4xx.s) before to branch to application main.
  101.        To reconfigure the default setting of SystemInit() function, refer to
  102.        system_stm32f4xx.c file
  103.      */
  104.   /* SysTick end of count event each 10ms */
  105.   RCC_GetClocksFreq(&RCC_Clocks);
  106.   SysTickLimit = RCC_Clocks.HCLK_Frequency / 1000;
  107.   SysTick_Config(SysTickLimit);

  108.   cppInit(CAMERA_WIDTH, CAMERA_HEIGHT);

  109.   LIS302DL_Reset();

  110.   /* SET USER Key */
  111.   /* Configure EXTI Line0 (connected to PA0 pin) in interrupt mode */
  112.   EXTILine0_Config();

  113.   /* Initialize the LCD */
  114.   STM32f4_Discovery_LCD_Init();
  115.   LCD_Clear(LCD_COLOR_WHITE);
  116.   LCD_SetTextColor(LCD_COLOR_BLUE);

  117.   DCMI_Control_IO_Init();

  118.   LCD_DisplayStringLine(LINE(2), "   Camera Init..");
  119.                   
  120.   /* OV9655 Camera Module configuration */
  121.   if (DCMI_OV9655Config() == 0x00)
  122.   {
  123.     LCD_DisplayStringLine(LINE(2), "                ");
  124.     LCD_SetDisplayWindow(0, 0, 320, 240);
  125.     LCD_WriteRAM_Prepare();

  126.     /* Start Image capture and Display on the LCD *****************************/
  127.     /* Enable DMA transfer */
  128.     DMA_Cmd(DMA2_Stream1, ENABLE);

  129.     /* Enable DCMI interface */
  130.     DCMI_Cmd(ENABLE);

  131.     /* Start Image capture */
  132.     DCMI_CaptureCmd(ENABLE);   

  133.     /*init the picture count*/
  134.     init_picture_count();

  135.     KeyPressFlg = 0;
  136.     while (1)
  137.     {
  138.       /* Insert 100ms delay */
  139.       //Delay(100);

  140.       if (newFrame) {
  141.         /* Processing of the frame will probably require more than the Vblank
  142.          * interval, in which case the binarized frame will be partially
  143.          * overwritten by the next one. That doesn't really matter as long
  144.          * as there is not much motion. */
  145.         DisplayBinarizedFrame();
  146.         read_image();
  147.         newFrame = 0;
  148.       }
  149.       if (KeyPressFlg) {
  150.         KeyPressFlg = 0;
  151.         /* press user KEY take a photo */
  152.         if (capture_Flag == ENABLE) {
  153.           DCMI_CaptureCmd(DISABLE);
  154.           capture_Flag = DISABLE;
  155.           //Capture_Image_TO_Bmp();
  156.           Delay(100);
  157.           LCD_SetDisplayWindow(0, 0, 320, 240);
  158.           LCD_WriteRAM_Prepare();
  159.           DCMI_CaptureCmd(ENABLE);
  160.           capture_Flag = ENABLE;
  161.         }                       
  162.       }
  163.     }
  164.   } else {
  165.     LCD_SetTextColor(LCD_COLOR_RED);

  166.     LCD_DisplayStringLine(LINE(2), "Camera Init.. fails");   
  167.     LCD_DisplayStringLine(LINE(4), "Check the Camera HW ");   
  168.     LCD_DisplayStringLine(LINE(5), "  and try again ");

  169.     /* Go to infinite loop */
  170.     while (1);      
  171.   }
  172. }

  173. extern void fastDisplayBinarizedRow(uint16_t *out, uint8_t *in, uint32_t count);

  174. #define SCALE_DOWN_FACTOR       2

  175. void DisplayBinarizedFrame(void) {
  176.   uint8_t *results = cppGetResults();
  177.   /* It's not worth trying to optimise this loop. Profiling has revealed that
  178.    * the majority of time is spent waiting for the LCD. */

  179.   // Uncomment this block to rescale image
  180.   for (int y = 0; y < CAMERA_HEIGHT; y += SCALE_DOWN_FACTOR) {
  181.     for (int x = 0; x < CAMERA_WIDTH; x += 8) {
  182.       uint8_t el = results[(y * CAMERA_WIDTH + x) >> 3];
  183.       for (int j = 0; j < 8; j += SCALE_DOWN_FACTOR) {
  184.         *(uint16_t *)FSMC_LCD_ADDRESS = el & 1 ? 0: 0xffff;
  185.         el >>= SCALE_DOWN_FACTOR;
  186.       }
  187.     }
  188.   }
  189.   // Uncomment this block to zoom in on middle
  190.   /*for (int y = 120; y < 360; y++) {
  191.     for (int x = 160; x < 480; x += 8) {
  192.       uint8_t el = results[(y * CAMERA_WIDTH + x) >> 3];
  193.       for (int j = 0; j < 8; j++) {
  194.         *(uint16_t *)FSMC_LCD_ADDRESS = el & 1 ? 0: 0xffff;
  195.         el >>= 1;
  196.       }
  197.     }
  198.   }*/
  199. }

  200. /**
  201.   * @brief  Configures all needed resources (I2C, DCMI and DMA) to interface with
  202.   *         the OV9655 camera module
  203.   * @param  None
  204.   * @retval 0x00 Camera module configured correctly
  205.   *         0xFF Camera module configuration failed
  206.   */
  207. uint8_t DCMI_OV9655Config(void)
  208. {
  209.   /* I2C1 will be used for OV9655 camera configuration */
  210.   I2C1_Config();

  211.   /* Reset and check the presence of the OV9655 camera module */
  212.   if (DCMI_SingleRandomWrite(OV9655_DEVICE_WRITE_ADDRESS,0x12, 0x80))
  213.   {
  214.      return (0xFF);
  215.   }

  216.   ///* OV9655 Camera size setup */   
  217.   DCMI_OV9655_VGASizeSetup();

  218.   ///* Set the RGB565 mode */
  219.   //DCMI_SingleRandomWrite(OV9655_DEVICE_WRITE_ADDRESS, OV9655_COM7, 0x63);
  220.   //DCMI_SingleRandomWrite(OV9655_DEVICE_WRITE_ADDRESS, OV9655_COM15, 0x10);
  221.   ///* Set the Raw RGB mode */
  222.   //DCMI_SingleRandomWrite(OV9655_DEVICE_WRITE_ADDRESS, OV9655_COM7, 0x60);
  223.   //DCMI_SingleRandomWrite(OV9655_DEVICE_WRITE_ADDRESS, OV9655_COM15, 0xc0);
  224.   /* Set the YUV mode */
  225.   DCMI_SingleRandomWrite(OV9655_DEVICE_WRITE_ADDRESS, OV9655_COM7, 0x62);
  226.   DCMI_SingleRandomWrite(OV9655_DEVICE_WRITE_ADDRESS, OV9655_TSLB, 0xc0);
  227.   DCMI_SingleRandomWrite(OV9655_DEVICE_WRITE_ADDRESS, OV9655_COM15, 0xc0);

  228.   ///* Enable colour bar test mode */
  229.   //DCMI_SingleRandomWrite(OV9655_DEVICE_WRITE_ADDRESS, OV9655_COM3, 0x80);
  230.   //DCMI_SingleRandomWrite(OV9655_DEVICE_WRITE_ADDRESS, OV9655_COM20, 0x10);

  231.   /* Enable night mode */
  232.   // Actually, night mode seems to be a bad idea; it makes motion blur
  233.   // much worse while reducing noise only a little bit.
  234.   //DCMI_SingleRandomWrite(OV9655_DEVICE_WRITE_ADDRESS, OV9655_COM11, 0xe4);

  235.   /* Invert the HRef signal*/
  236.   DCMI_SingleRandomWrite(OV9655_DEVICE_WRITE_ADDRESS, OV9655_COM10, 0x08);

  237.   /* Configure the DCMI to interface with the OV9655 camera module */
  238.   DCMI_Config();
  239.   
  240.   return (0x00);
  241. }

  242. volatile static uint64_t last;
  243. //static int ccc;

  244. uint64_t getCycleCounter(void) {
  245.   return CycleCounter + (uint64_t)(SysTickLimit - 1 - SysTick->VAL);
  246. }

  247. extern void extractLuminance(uint8_t *out, uint8_t *in, uint32_t count);

  248. void DMA2_Stream1_IRQHandler(void)
  249. {
  250.   if (DMA_GetITStatus(DMA2_Stream1, DMA_IT_TCIF1) != RESET) {
  251.     uint8_t *p;
  252.     uint8_t luminances[CAMERA_WIDTH * 8];
  253.     if (DMA_GetCurrentMemoryTarget(DMA2_Stream1) == DMA_Memory_0) {
  254.       p = pbuffer2;
  255.     } else {
  256.       p = pbuffer1;
  257.     }
  258.     /*for (int y = 0; y < 8; y += VERTICAL_SCALE_FACTOR) {
  259.       //if (y & 1) continue;
  260.       for (int x = 0; x < CAMERA_WIDTH; x += HORIZONTAL_SCALE_FACTOR) {
  261.         // extract Y component and convert to RGB565 greyscale
  262.         uint32_t yuv = *(uint8_t *)&(p[x * 2]);
  263.         uint16_t t1 = yuv >> 2;
  264.         uint16_t t2 = yuv >> 3;
  265.         uint16_t rgb = (t2 << 11) | (t1 << 5) | (t2);
  266.         //uint16_t rgb = yuv > 0x80 ? 0xffff: 0;
  267.         *(uint16_t *)FSMC_LCD_ADDRESS = rgb;
  268.   //      luminances[i] = p[i * 2];
  269.       }
  270.       p += (CAMERA_WIDTH * 2 * VERTICAL_SCALE_FACTOR);
  271.     }*/
  272.     /*if ((blockRowsWritten >= 20) && (blockRowsWritten < 50))
  273.     {
  274.       for (int y = 0; y < 8; y++) {
  275.         //if (y & 1) continue;
  276.         for (int x = 160; x < 480; x ++) {
  277.           // extract Y component and convert to RGB565 greyscale
  278.           uint32_t yuv = *(uint8_t *)&(p[x * 2]);
  279.           uint16_t t1 = yuv >> 2;
  280.           uint16_t t2 = yuv >> 3;
  281.           uint16_t rgb = (t2 << 11) | (t1 << 5) | (t2);
  282.           *(uint16_t *)FSMC_LCD_ADDRESS = rgb;
  283.         }
  284.         p += (CAMERA_WIDTH * 2);
  285.       }
  286.     }*/
  287.     extractLuminance(luminances, p, sizeof(luminances));
  288.     //uint64_t current = getCycleCounter();
  289.     //uint64_t diff = current - last;
  290.     //last = current;
  291.     //char s[32];
  292.     //sprintf(s, "%u       ", (unsigned int)diff);
  293.     //LCD_DisplayStringLine(LINE(blockRowsWritten), s);
  294.     //blockRowsWritten = (blockRowsWritten + 1) % 6;
  295.     //sprintf(s, "%d %d ", (int)ccc / 30, (int)ccc++);
  296.    
  297.     cppProcessBlockRow(luminances);
  298.     blockRowsWritten++;
  299.     if (blockRowsWritten >= (CAMERA_HEIGHT >> 3)) {
  300.       newFrame = 1;
  301.       cppResetBinarizer();
  302.       blockRowsWritten = 0;
  303.     }
  304.     //LCD_DisplayStringLine(LINE(7), s);
  305.    
  306.     DMA_ClearITPendingBit(DMA2_Stream1, DMA_IT_TCIF1);
  307.   }
  308. }

  309. /**
  310.   * @brief  Configures the I2C1 used for OV9655 camera module configuration.
  311.   * @param  None
  312.   * @retval None
  313.   */
  314. void I2C1_Config(void)
  315. {
  316.   GPIO_InitTypeDef GPIO_InitStructure;
  317.   I2C_InitTypeDef  I2C_InitStruct;

  318. /* I2C1 clock enable */
  319.   RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
  320.   /* GPIOB clock enable */
  321.   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);

  322.   /* Connect I2C1 pins to AF4 ************************************************/
  323.   GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_I2C1);
  324.   GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_I2C1);  
  325.   
  326.   /* Configure I2C1 GPIOs *****************************************************/  
  327.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
  328.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  329.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  330.   GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  331.   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;   
  332.   GPIO_Init(GPIOB, &GPIO_InitStructure);

  333.   /* Configure I2C1 ***********************************************************/  
  334.   /* I2C DeInit */   
  335.   I2C_DeInit(I2C1);
  336.    
  337.   /* Enable the I2C peripheral */
  338.   I2C_Cmd(I2C1, ENABLE);

  339.   /* Set the I2C structure parameters */
  340.   I2C_InitStruct.I2C_Mode = I2C_Mode_I2C;
  341.   I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2;
  342.   I2C_InitStruct.I2C_OwnAddress1 = 0xFE;
  343.   I2C_InitStruct.I2C_Ack = I2C_Ack_Enable;
  344.   I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
  345.   I2C_InitStruct.I2C_ClockSpeed = 30000;
  346.   
  347.   /* Initialize the I2C peripheral w/ selected parameters */
  348.   I2C_Init(I2C1, &I2C_InitStruct);
  349. }

  350. /**
  351.   * @brief  Configures the DCMI to interface with the OV9655 camera module.
  352.   * @param  None
  353.   * @retval None
  354.   */
  355. void DCMI_Config(void)
  356. {
  357.   DCMI_InitTypeDef DCMI_InitStructure;
  358.   GPIO_InitTypeDef GPIO_InitStructure;
  359.   DMA_InitTypeDef  DMA_InitStructure;
  360.   DCMI_CROPInitTypeDef DCMI_CropInitStructure;
  361.   
  362.   /* Enable DCMI GPIOs clocks */
  363.   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOE |
  364.                          RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOA, ENABLE);

  365.   /* Enable DCMI clock */
  366.   RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_DCMI, ENABLE);

  367.   /* Connect DCMI pins to AF13 ************************************************/
  368.   /* PCLK */
  369.   GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_DCMI);
  370.   /* D0-D7 */
  371.   GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_DCMI);
  372.   GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_DCMI);
  373.   GPIO_PinAFConfig(GPIOE, GPIO_PinSource0, GPIO_AF_DCMI);
  374.   GPIO_PinAFConfig(GPIOE, GPIO_PinSource1, GPIO_AF_DCMI);
  375.   GPIO_PinAFConfig(GPIOE, GPIO_PinSource4, GPIO_AF_DCMI);
  376.   GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_DCMI);
  377.   GPIO_PinAFConfig(GPIOE, GPIO_PinSource5, GPIO_AF_DCMI);
  378.   GPIO_PinAFConfig(GPIOE, GPIO_PinSource6, GPIO_AF_DCMI);
  379.   /* VSYNC */
  380.   GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_DCMI);
  381.   /* HSYNC */
  382.   GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_DCMI);
  383.   
  384.   /* DCMI GPIO configuration **************************************************/
  385.   /* D0 D1(PC6/7) */
  386.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
  387.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  388.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  389.   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  390.   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;  
  391.   GPIO_Init(GPIOC, &GPIO_InitStructure);

  392.   /* D2..D4(PE0/1/4) D6/D7(PE5/6) */
  393.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1
  394.                                       | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6;
  395.   GPIO_Init(GPIOE, &GPIO_InitStructure);

  396.   /* D5(PB6), VSYNC(PB7) */
  397.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
  398.   GPIO_Init(GPIOB, &GPIO_InitStructure);

  399.   /* PCLK(PA6) HSYNC(PA4)*/
  400.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_6;
  401.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  402.   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  403.   GPIO_Init(GPIOA, &GPIO_InitStructure);
  404.   
  405.   /* DCMI configuration *******************************************************/
  406.   DCMI_InitStructure.DCMI_CaptureMode = DCMI_CaptureMode_Continuous;
  407.   DCMI_InitStructure.DCMI_SynchroMode = DCMI_SynchroMode_Hardware;
  408.   DCMI_InitStructure.DCMI_PCKPolarity = DCMI_PCKPolarity_Falling;
  409.   DCMI_InitStructure.DCMI_VSPolarity = DCMI_VSPolarity_High;
  410.   DCMI_InitStructure.DCMI_HSPolarity = DCMI_HSPolarity_High;
  411.   DCMI_InitStructure.DCMI_CaptureRate = DCMI_CaptureRate_All_Frame;
  412.   DCMI_InitStructure.DCMI_ExtendedDataMode = DCMI_ExtendedDataMode_8b;

  413.   // All horizontal crop values are multiplied by 2 because there are 2
  414.   // pixel clocks per pixel.
  415.   DCMI_CropInitStructure.DCMI_VerticalStartLine = 0;
  416.   DCMI_CropInitStructure.DCMI_HorizontalOffsetCount = 0;
  417. #ifdef CROP_LAST_BLOCK_ROW
  418.   DCMI_CropInitStructure.DCMI_VerticalLineCount = CAMERA_HEIGHT - 8;
  419. #else
  420.   DCMI_CropInitStructure.DCMI_VerticalLineCount = CAMERA_HEIGHT;
  421. #endif
  422.   DCMI_CropInitStructure.DCMI_CaptureCount = CAMERA_WIDTH * 2;
  423.   // According to the STM32F4 reference manual, the counts in the registers
  424.   // are 1 less than the actual count.
  425.   DCMI_CropInitStructure.DCMI_CaptureCount--;
  426.   DCMI_CropInitStructure.DCMI_VerticalLineCount--;
  427.   DCMI_Init(&DCMI_InitStructure);
  428.   DCMI_CROPConfig(&DCMI_CropInitStructure);
  429.   DCMI_CROPCmd(ENABLE);

  430.   /* DMA2 interrupt configuration */
  431.   NVIC_InitTypeDef NVIC_InitStructure;
  432.   NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream1_IRQn;
  433.   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  434.   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  435.   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  436.   NVIC_Init(&NVIC_InitStructure);

  437.   /* Configures the DMA2 to transfer Data from DCMI to the LCD ****************/
  438.   /* Enable DMA2 clock */
  439.   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);  
  440.   
  441.   /* DMA2 Stream1 Configuration */  
  442.   DMA_DeInit(DMA2_Stream1);

  443.   DMA_InitStructure.DMA_Channel = DMA_Channel_1;  
  444.   DMA_InitStructure.DMA_PeripheralBaseAddr = DCMI_DR_ADDRESS;       
  445.   DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)pbuffer1;
  446.   DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
  447.   DMA_InitStructure.DMA_BufferSize = sizeof(pbuffer1) / sizeof(uint32_t);
  448.   DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  449.   DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
  450.   DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
  451.   DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
  452.   DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
  453.   DMA_InitStructure.DMA_Priority = DMA_Priority_High;
  454.   DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;         
  455.   DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
  456.   DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
  457.   DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;

  458.   DMA_Init(DMA2_Stream1, &DMA_InitStructure);
  459.   DMA_DoubleBufferModeConfig(DMA2_Stream1, (uint32_t)pbuffer2, DMA_Memory_0);
  460.   DMA_DoubleBufferModeCmd(DMA2_Stream1, ENABLE);
  461.   DMA_ITConfig(DMA2_Stream1, DMA_IT_TC, ENABLE);
  462. }

  463. /**

  464.   * @brief  
  465.   * @param  None
  466.   * @retval None
  467.   */
  468. void LIS302DL_Reset(void)
  469. {
  470.   uint8_t ctrl = 0;
  471.   
  472.   LIS302DL_InitTypeDef  LIS302DL_InitStruct;
  473.   LIS302DL_InterruptConfigTypeDef LIS302DL_InterruptStruct;  
  474.   
  475.   /* Set configuration of LIS302DL*/
  476.   LIS302DL_InitStruct.Power_Mode = LIS302DL_LOWPOWERMODE_ACTIVE;
  477.   LIS302DL_InitStruct.Output_DataRate = LIS302DL_DATARATE_100;
  478.   LIS302DL_InitStruct.Axes_Enable = LIS302DL_X_ENABLE | LIS302DL_Y_ENABLE | LIS302DL_Z_ENABLE;
  479.   LIS302DL_InitStruct.Full_Scale = LIS302DL_FULLSCALE_2_3;
  480.   LIS302DL_InitStruct.Self_Test = LIS302DL_SELFTEST_NORMAL;
  481.   LIS302DL_Init(&LIS302DL_InitStruct);
  482.    
  483.   /* Set configuration of Internal High Pass Filter of LIS302DL*/
  484.   LIS302DL_InterruptStruct.Latch_Request = LIS302DL_INTERRUPTREQUEST_LATCHED;
  485.   LIS302DL_InterruptStruct.SingleClick_Axes = LIS302DL_CLICKINTERRUPT_Z_ENABLE;
  486.   LIS302DL_InterruptStruct.DoubleClick_Axes = LIS302DL_DOUBLECLICKINTERRUPT_Z_ENABLE;
  487.   LIS302DL_InterruptConfig(&LIS302DL_InterruptStruct);

  488.   /* Required delay for the MEMS Accelerometre: Turn-on time = 3/Output data Rate
  489.                                                              = 3/100 = 30ms */
  490.   Delay(30);
  491.   
  492.   /* Configure Click Window */
  493.   ctrl = 0xC0;
  494.   LIS302DL_Write(&ctrl, LIS302DL_CLICK_CTRL_REG3_ADDR, 1);
  495. }

  496. /**
  497.   * @brief  MEMS accelerometre management of the timeout situation.
  498.   * @param  None.
  499.   * @retval None.
  500.   */
  501. uint32_t LIS302DL_TIMEOUT_UserCallback(void)
  502. {
  503.   /* MEMS Accelerometer Timeout error occured */
  504.   while (1) ;
  505. }

  506. /**
  507.   * @brief  Configures EXTI Line0 (connected to PA0 pin) in interrupt mode
  508.   * @param  None
  509.   * @retval None
  510.   */
  511. void EXTILine0_Config(void)
  512. {
  513.   
  514.   GPIO_InitTypeDef   GPIO_InitStructure;
  515.   NVIC_InitTypeDef   NVIC_InitStructure;

  516.   /* Enable GPIOA clock */
  517.   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  518.   /* Enable SYSCFG clock */
  519.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
  520.   
  521.   /* Configure PA0 pin as input floating */
  522.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  523.   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  524.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  525.   GPIO_Init(GPIOA, &GPIO_InitStructure);

  526.   /* Connect EXTI Line0 to PA0 pin */
  527.   SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);

  528.   /* Configure EXTI Line0 */
  529.   EXTI_InitStructure.EXTI_Line = EXTI_Line0;
  530.   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  531.   EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;  
  532.   EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  533.   EXTI_Init(&EXTI_InitStructure);

  534.   /* Enable and set EXTI Line0 Interrupt to the lowest priority */
  535.   NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
  536.   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;
  537.   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;
  538.   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  539.   NVIC_Init(&NVIC_InitStructure);
  540. }

  541. /**
  542.   * @brief  Inserts a delay time.
  543.   * @param  nTime: specifies the delay time length, in milliseconds
  544.   * @retval None
  545.   */
  546. void Delay(uint32_t nTime)
  547. {
  548.   TimingDelay = nTime;

  549.   while (TimingDelay != 0);

  550. }

  551. /**

  552.   * @brief  Decrements the TimingDelay variable.
  553.   * @param  None
  554.   * @retval None
  555.   */
  556. void TimingDelay_Decrement(void)
  557. {
  558.   CycleCounter += SysTickLimit;
  559.   if (TimingDelay != 0x00)
  560.   {
  561.     TimingDelay--;
  562.   }
  563. }

  564. #ifdef  USE_FULL_ASSERT
  565. /**
  566.   * @brief  Reports the name of the source file and the source line number
  567.   *   where the assert_param error has occurred.
  568.   * @param  file: pointer to the source file name
  569.   * @param  line: assert_param error line source number
  570.   * @retval None
  571.   */
  572. void assert_failed(uint8_t* file, uint32_t line)
  573. {
  574.   /* User can add his own implementation to report the file name and line number,
  575.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  576.   /* Infinite loop */
  577.   while (1)
  578.   {
  579.   }
  580. }
  581. #endif

  582. /**
  583.   * @}
  584.   */



  585. /*********** Portions COPYRIGHT 2012 Embest Tech. Co., Ltd.*****END OF FILE****/

復(fù)制代碼

所有資料51hei提供下載:
STM32 二維碼解碼.zip (1.5 MB, 下載次數(shù): 28)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

沙發(fā)
ID:353912 發(fā)表于 2019-8-19 11:56 | 只看該作者
謝謝,學(xué)習(xí)下
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 成人午夜免费视频 | 国产一区欧美 | 男女午夜激情视频 | 天天射天天干 | 看片wwwwwwwwwww | 亚洲一区二区精品视频在线观看 | 国产精品成人一区二区三区 | 综合精品久久久 | 91干b| 亚洲精品久久久久久久久久久久久 | 国产高清视频在线观看 | 九色在线视频 | 伊人网综合在线 | 欧美精品成人一区二区三区四区 | 日韩精品在线免费观看 | 精品久久中文 | 国产香蕉视频在线播放 | 黄色a视频 | 日本电影网站 | 国产黄色在线观看 | 黄色片在线免费看 | 91精品国产一区二区在线观看 | 久久这里只有精品首页 | 二区亚洲| 国产精品美女久久久免费 | 亚洲视频国产视频 | 麻豆亚洲| 狠狠的干狠狠的操 | 美女久久久久久久 | 成年人的视频免费观看 | 国产亚洲成av人片在线观看桃 | 色综合久久天天综合网 | 成人h视频在线 | 精品国产乱码久久久久久久久 | 一区二区三区四区国产 | 国产精品成人国产乱一区 | 91色综合 | 成年人在线观看 | 搞av.com| 国产精品毛片 | 中文字幕国产一区 |