LCD显示二维码

主函数

#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "lcd.h"
#include "qrencode.h"
#include "qr_encode.h"

const u8 QRcontent[]={"https://shop155026927.taobao.com/?spm=a230r.7195193.1997079397.2.58b92aa9OM6NCL"};  //火红色祥云淘宝链接



#define QRCODE_Y 	80	
void DISPLAY_RENCODE_TO_TFT(u8 *qrcode_data);
int main(void)
{ 
 	u8 i;
	
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置系统中断优先级分组2
	delay_init();      //初始化延时函数
	uart_init(115200);		//初始化串口波特率为115200
	LED_Init();					  //初始化LED
 	LCD_Init();           //初始化LCD FSMC接口
	POINT_COLOR=RED;      //画笔颜色:红色
    LCD_Clear(WHITE);    
    DISPLAY_RENCODE_TO_TFT((u8 *)QRcontent);  //上电初始二维码
  	while(1) 
	{	
        printf("请发送您需要显示的字符串,以 \\r\\n 结束\r\n");	
        if(USART_RX_STA&0x8000)               //检测到串口接受完成
		{
            
            printf("您发送的数据为:%s\r\n",USART_RX_BUF);
            LCD_Clear(WHITE);
            DISPLAY_RENCODE_TO_TFT((u8 *)USART_RX_BUF);
            for(i=0;i<=200;i++)     //清空数组
            USART_RX_BUF[i]=0;
            USART_RX_STA = 0;        //标志位置零
        }
		delay_ms(300);	
	} 
}


void DISPLAY_RENCODE_TO_TFT(u8 *qrcode_data)
{
	u8 i,j;
	u16 x,y,p;
	u8 stringBUFF[30];			//存放字符串
	EncodeData((char *)qrcode_data);//编码数据
	
	
	sprintf((char*)stringBUFF,"code size:%dx%d",m_nSymbleSize,m_nSymbleSize);
  printf((char*)stringBUFF);
  printf("\r\n\r\n");
	LCD_ShowString(10,25,200,100,16,stringBUFF);
  
  
	if(m_nSymbleSize*2>240)//最小点是2x2个像素点,像素点最大不能超过240点
	{
		
		LCD_ShowString(10,45,200,100,16,(u8 *)"too big");	
		return;
	}
	
	for(i=0;i<10;i++)
	{
		if((m_nSymbleSize*i*2)>240)	break;
	}
	p = (i-1)*2;//点大小
    
	x = (240-m_nSymbleSize*p)/2;
	y = QRCODE_Y;
    
	sprintf((char*)stringBUFF,"Each point:%dx%d",m_nSymbleSize,m_nSymbleSize);
	printf((char*)stringBUFF);
	printf("\r\n\r\n");
	LCD_ShowString(10,45,200,100,16,stringBUFF);
    
	for(i=0;i<m_nSymbleSize;i++)
	{
		for(j=0;j<m_nSymbleSize;j++)
		{
            
			if(m_byModuleData[i][j]==1)
			{
                
				LCD_Color_Fill(x+p*i,y+p*j,x+p*(i+1)-1,y+p*(j+1)-1, BLACK);
				printf("▇");
            }
			else
			{
			  printf("  ");
			}
		}
		printf("\r\n");	
	}
}




Qcode源码链接:

Q_Code源码链接 提取码:7f8l

发布了11 篇原创文章 · 获赞 5 · 访问量 456

猜你喜欢

转载自blog.csdn.net/weixin_43739167/article/details/104286357