|
#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
2019-7-8 20:04 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
274.01 KB, 下載次數(shù): 67, 下載積分: 黑幣 -5
|