找回密码
 立即注册

QQ登录

只需一步,快速开始

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

基于STM32F429的二维码识别源码+二维码解码库lib

[复制链接]
跳转到指定楼层
楼主
ID:266802 发表于 2019-10-9 21:09 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
STM32单片机源程序如下:
  1. /**
  2.   * @file    main.c
  3.   * @author  WB R&D Team - openmcu666
  4.   * @version V0.1
  5.   * @date    2016.08.24
  6.   * @brief   Main Program body
  7.   */

  8. #include "stm32f4xx.h"
  9. #include "Gpio.h"
  10. #include "usart.h"
  11. #include "delay.h"
  12. #include "stm32f429i_lcd.h"
  13. #include "ov7670.h"
  14. #include "ov2640.h"
  15. #include "ov5642.h"
  16. #include "mt9d111.h"
  17. #include "CamConfig.h"
  18. #include "sccb_bus.h"
  19. #include "RTC.h"
  20. #include "string.h"
  21. #include "QR_Decoder.h"

  22. //only for OV5642

  23. /*****************************************************************************
  24. **   Main Function  main()
  25. ******************************************************************************/
  26. int main(void)
  27. {
  28.         uint16_t temper;
  29.         char  qr_type_len=0;
  30.   short qr_data_len=0;
  31.   char qr_type_buf[10];
  32.   char qr_data_buf[512];
  33.   int addr=0;
  34.   int i=0,j=0;
  35.   char qr_num=0;
  36.         
  37.         
  38.         USART1_Init();
  39.         //LED_Init();
  40.   Key_Init();
  41.         BEEP_Init();
  42.         printf("\r\n");
  43.         printf("Hello Welcome.\r\n");
  44.         printf("Thank You For Choosing Our Products.\r\n");
  45.         printf("Thank You Very Much.\r\n");
  46.         printf("This Example Camera.\r\n");
  47.         printf("\r\n");
  48.         printf("DCMI Initialization...\r\n");
  49.         LCD_Init();
  50.         LCD_LayerInit();
  51.   LTDC_Cmd(ENABLE);
  52.   LCD_SetLayer(LCD_BACKGROUND_LAYER);  
  53.         LCD_SetTransparency(0xFF);
  54.         LCD_Clear(BLACK);
  55.         LCD_SetLayer(LCD_FOREGROUND_LAYER); //使用前景层
  56.   LCD_SetTransparency(0xFF);          //设置透明度
  57.   LCD_Clear_ARGB8888(0x40000000);
  58.    
  59.   LCD_SetTextColor_ARGB8888(0xFFFFFFFF);
  60.   LCD_DrawFullRect_ARGB8888(Frame_Width,Frame_Width);                              //绘制透明框
  61.   
  62.   LCD_DrawBox_ARGB8888(Frame_Width,Frame_Line_Length,Frame_Line_Size,0xD05CBDE7);  //绘制扫描框
  63.         
  64.         printf("Ok,Let's Go...\r\n");
  65.         
  66.         temper = ov7670_check();         //Camera是否为OV7670
  67.          
  68.         if (temper == 0x7673)
  69.         {
  70.                 printf("Cam ID : [0x%02x]\r\n",temper);
  71.                 if (ov7670_init())
  72.                 {
  73.                         printf("Init OV7670 reg Fail...\r\n");
  74.                   while (1)
  75.                   {
  76.                                 
  77.                   }
  78.                 }
  79.                 else
  80.                 {
  81.                         printf("Init OV7670 reg OK...\r\n");
  82.                         printf("Show Camer Data...\r\n");

  83.                 }               
  84.                
  85.         }
  86.         else                                       
  87.         {
  88.     temper=ov2640_check();
  89.          
  90.                 if(temper==0x2642)                        //OV2640
  91.                 {
  92.                         if (ov2640_init())
  93.                   {
  94.                         printf("Init OV2640 reg Fail...\r\n");
  95.                         while (1)
  96.                         {}
  97.                   }
  98.                   else
  99.                  {
  100.                         printf("Cam ID : [0x%02x]\r\n",temper);
  101.                         printf("Init OV2640 reg OK...\r\n");
  102.                         printf("Show Camer Data...\r\n");

  103.                  }
  104.         
  105.          }
  106.                 else                                        //ov5642 or mt9d111
  107.     {
  108.                         temper=ov5642_check();
  109.                         printf("Cam ID : [0x%02x]\r\n",temper);
  110.                   if (temper==0x5642)//mt9d111_init
  111.                   {
  112.                           ov5642_init();
  113.                           printf("Init ov5642 reg OK...\r\n");
  114.                           printf("Show Camer Data...\r\n");        
  115.                   }
  116.                  else
  117.                  {
  118.                           printf("Init ov5642 reg Fail...\r\n");                                
  119.                                 while (1){}
  120.                  }
  121.     }
  122.         }
  123. //        if(RTC_Config())                                                           //初始化RTC
  124. //        {
  125. //          printf("\r\nLSE start failed\r\n");
  126. //        }
  127. //        RTC_Set_WakeUp(RTC_WakeUpClock_CK_SPRE_16bits,0);                //配置WAKE UP中断,1秒钟中断一次,用于统计帧率
  128.   systick_delay_ms(100);
  129.         ov5642_auto_focus();
  130.         cam_start();
  131.         
  132.         while (1)
  133.   {
  134.     qr_num = QR_decoder();
  135.                  if(qr_num)
  136.       {
  137.          GPIO_SetBits(BEEP_GPIO_PORT,BEEP_GPIO_PIN);
  138.                                  systick_delay_ms(100);
  139.                                  GPIO_ResetBits(BEEP_GPIO_PORT,BEEP_GPIO_PIN);
  140.          //解码的数据是按照识别条码的个数封装好的二维数组,这些数据需要
  141.          //根据识别条码的个数,按组解包并通过串口发送到上位机串口终端
  142.          for(i=0;i < qr_num;i++)
  143.          {
  144.            qr_type_len = decoded_buf[i][addr++];//获取解码类型长度
  145.                
  146.             for(j=0;j < qr_type_len;j++)
  147.                  qr_type_buf[j]=decoded_buf[i][addr++];//解码类型
  148.                
  149.              qr_data_len  = decoded_buf[i][addr++]<<8; //解码数据的高8位
  150.              qr_data_len |= decoded_buf[i][addr++];    //解码数据的低8位
  151.                
  152.              for(j=0;j < qr_data_len;j++)
  153.                  qr_data_buf[j]=decoded_buf[i][addr++];//获取解码数据
  154.                
  155.              USART1_Send_Data((unsigned char *)qr_type_buf, qr_type_len);//串口发送解码类型
  156.              USART1_Send_Data((unsigned char *)":", 1);           
  157.              USART1_Send_Data((unsigned char *)qr_data_buf, qr_data_len);//串口发送解码数据
  158.              USART1_Send_Data((unsigned char *)"\r\n", 2);
  159.              addr =0;
  160.           }
  161.                
  162.        }
  163.   }
  164. }
复制代码

所有资料51hei提供下载:
429_Camera(OV5642)二维码识别.7z (1.21 MB, 下载次数: 39)


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

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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