找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

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

基于STM32藍(lán)牙打印機(jī)源程序

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:387744 發(fā)表于 2019-7-8 16:34 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
#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()//更新字庫(kù)
{
        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 燒錄字庫(kù)
        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();//打印機(jī)更新數(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();                //打印機(jī)更新數(shù)據(jù)        
                                
                                TIM3->EGR = 1<<0;                /* 軟件更新 */
                                TIM3->SR = 0;                        /* 清0狀態(tài)標(biāo)識(shí) */

                                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();                //打印機(jī)更新數(shù)據(jù)        
                                
                                TIM3->EGR = 1<<0;                /* 軟件更新 */
                                TIM3->SR = 0;                        /* 清0狀態(tài)標(biāo)識(shí) */

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



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

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

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

使用道具 舉報(bào)

沙發(fā)
ID:1 發(fā)表于 2019-7-8 20:05 | 只看該作者
本帖需要重新編輯補(bǔ)全電路原理圖,源碼,詳細(xì)說(shuō)明與圖片即可獲得100+黑幣(帖子下方有編輯按鈕)
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

快速回復(fù) 返回頂部 返回列表