標(biāo)題: 基于STM32藍(lán)牙打印機源程序 [打印本頁]

作者: 真得浪    時間: 2019-7-8 16:34
標(biāo)題: 基于STM32藍(lán)牙打印機源程序
#include "motor.h"
#include "delay.h"
#include "timer.h"
#include "printer.h"
#include "led.h"
#include "usart.h"
#include "uart_font.h"
#include "flash.h"
#include "dma.h"
#include <string.h>
u8 const test_str[]="\r\n\

void updata_font()//更新字庫
{
        u8 i;
        u8 group = 0;
        u32 write_addr = 0;
        
        LED1 = 0;
        uart1_printf("flash init ok!\n");
        
//         spi_flah_erase_chip();
        for (i=0; i<148; i++)
        {
                spi_flash_erase_sector(i);
        }
         
         uart1_printf("flash erase ok!\n");
         
         while (1)
         {
                 if (font_buffer[group].uart_rev_len)
                 {
                         spi_flash_write_nocheck((u8*)font_buffer[group].data_buf, write_addr,
                                                                                 font_buffer[group].uart_rev_len);
                        
//                         uart1_printf("pg_addr:%-6d ok\n",write_addr);
                        
                         write_addr += font_buffer[group].uart_rev_len;
                        
                         font_buffer[group].uart_rev_len = 0;
                        
                         group = !group;
                 }
               
                if (key_scan() == 1)
                {
                        break;
                }
         }
}

int main()
{
        u32 cnt = 0;
        u16 rx_flg = 0;
        
        init_delay(72);
        
        init_motor_gpio();
        init_printer_gpio();
        
        usart2_init(36, 9600);        //串口2接 藍(lán)牙模塊
         bluetooth_swi(1);//打開藍(lán)牙模塊
        
        DMAx_Config(DMA1_Channel7, (u32)&USART2->DR, (u32)(uart_buffer.tx_buf));
        
        init_usart1(72, 921600);//串口1 燒錄字庫
        DMAx_Config(DMA1_Channel4, (u32)&USART1->DR, (u32)uart1_tx_buf);
        
        init_key();
        init_led();
        init_timer3_int(1100-1,72-1);//800us溢出一次
        spi_flash_init();
        
        if (spi_flash_read_id() != W25Q64)
        {
                uart_printf("flash error!\n");
               
                while (1)
                {
                        ;
                }
        }               
        
        if (key_scan() == 1)
        {
                updata_font();
        }
        else
        {
                while (1)
                {
                        if (key_scan() == 1)//按下按鍵,繼續(xù)往下執(zhí)行
                        {
                                break;
                        }
                }
        }
        BUZZ = 1;
        delay_ms(200);
        BUZZ = 0;
         uart_printf("The printer is ready.\n");
        uart_buffer.rx_len = rx_flg;
        while (1)
        {
                printer_updata();//打印機更新數(shù)據(jù)        
                printer_updata_pic();
               
                if (uart_buffer.rx_len != rx_flg)//防止重復(fù)執(zhí)行這里
                {
                        if (uart_buffer.rx_len > 0)        //收到數(shù)據(jù)  
                        {
                                uart_printf("OK:printing ...\r\n");
                                bluetooth_data_formatting((u8*)uart_buffer.rx_buf);
                                uart1_printf("%s", uart_buffer.rx_buf);
                                printer_status = PRINT_TEXT;
                                print_updata_text_flg = 1;
                                printer_updata();                //打印機更新數(shù)據(jù)        
                                
                                TIM3->EGR = 1<<0;                /* 軟件更新 */
                                TIM3->SR = 0;                        /* 清0狀態(tài)標(biāo)識 */

                                TIM3->CR1 |= 0x01;
                        }
                        rx_flg = uart_buffer.rx_len;
                }

                if ((TIM3->CR1 & 1) == 0)//如果當(dāng)前沒有打印
                {
                        if (++cnt == 600000)
                        {
                                cnt = 0;
                        }
                        
                        LED1 = cnt<60000 ? 0 : 1;
                        
                        if (key_scan() == 1)
                        {
                                strcpy((char*)uart_buffer.rx_buf, (char*)test_str);

                                bluetooth_data_formatting((u8*)uart_buffer.rx_buf);
                                uart_printf("OK:printing ...\r\n");
                                
                                printer_status = PRINT_TEXT;
                                print_updata_text_flg = 1;
                                printer_updata();                //打印機更新數(shù)據(jù)        
                                
                                TIM3->EGR = 1<<0;                /* 軟件更新 */
                                TIM3->SR = 0;                        /* 清0狀態(tài)標(biāo)識 */

                                TIM3->CR1 |= 0x01;
                        }
                }
        }//end while(1)
}



藍(lán)牙打印機總程序.7z

274.01 KB, 下載次數(shù): 67, 下載積分: 黑幣 -5


作者: admin    時間: 2019-7-8 20:05
本帖需要重新編輯補全電路原理圖,源碼,詳細(xì)說明與圖片即可獲得100+黑幣(帖子下方有編輯按鈕)




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1