|
#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接 蓝牙模块
bluetooth_swi(1);//打开蓝牙模块
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)//按下按键,继续往下执行
{
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();//打印机更新数据
printer_updata_pic();
if (uart_buffer.rx_len != rx_flg)//防止重复执行这里
{
if (uart_buffer.rx_len > 0) //收到数据
{
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(); //打印机更新数据
TIM3->EGR = 1<<0; /* 软件更新 */
TIM3->SR = 0; /* 清0状态标识 */
TIM3->CR1 |= 0x01;
}
rx_flg = uart_buffer.rx_len;
}
if ((TIM3->CR1 & 1) == 0)//如果当前没有打印
{
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(); //打印机更新数据
TIM3->EGR = 1<<0; /* 软件更新 */
TIM3->SR = 0; /* 清0状态标识 */
TIM3->CR1 |= 0x01;
}
}
}//end while(1)
}
|
|