📄 printer.c
字号:
//#include "font.h"
#include "type.h"
#include "LPC23xx.h"
#include "irq.h"
#include "printer.h"
#include "prn_font.h"
#include "stdio.h"
#include "uart.h"
#include "rtc.h"
#include "adc.h"
#include "KeyBoard.h"
#define STROBE_VAL 0x04000C33
#define MOT_OFF (0xF << 14)
/***************************************************/
//PRINTER Functions
/**************************************************/
//void prn_pow_init(void);
//extern __inline void prn_pow(unsigned char);
//void dotlines(void);
//void st_prt(void);
//void dotlines_dw(void);
//void prt_msg(unsigned char * ,unsigned char );
//void prt_msgb(unsigned char * );
//void sm_prt(unsigned char);
//extern __inline void prt_bcd2(unsigned char );
//extern __inline void prt_bcd1(unsigned char );
////void prt_time(void);
////void prt_date(void);
//void prt_int(unsigned int Pint, unsigned char Plimit);
//void prt_date_time(unsigned int prt_bcd2_data);
/*******************************************/
//printer Variables
/*******************************************/
unsigned int prt_dh_flag;
unsigned int prt_dw_flag;
unsigned int prt_stop_flag;
volatile unsigned int prt_strobe_complete;
unsigned char line_count;
unsigned char smprn_i;
volatile unsigned char prt_step_cnt;
volatile unsigned char prt_time_cnt;
//unsigned char flag;
unsigned char test_msg[32];
unsigned char Pint_rem[40];
unsigned char const * prt_line_ptr[] =
{
font_12x16_1,font_12x16_2,font_12x16_3,font_12x16_4,font_12x16_5,font_12x16_6,font_12x16_7,font_12x16_8,
font_12x16_9,font_12x16_10,font_12x16_11,font_12x16_12,font_12x16_13,font_12x16_14,font_12x16_15,
font_12x16_16
};
unsigned char const * prt_linedw_ptr[] =
{
font_12x16dw_1,font_12x16dw_2,font_12x16dw_3,font_12x16dw_4,font_12x16dw_5,font_12x16dw_6,font_12x16dw_7,
font_12x16dw_8,font_12x16dw_9,font_12x16dw_10,font_12x16dw_11,font_12x16dw_12,font_12x16dw_13,
font_12x16dw_14,font_12x16dw_15,font_12x16dw_16
};
void prn_pow_init(void)
{
T0CTCR = 0x00;
T0MCR = 0x03;
T0MR0 = 0x8ca0;//0x7080;
T0EMR = 0x30;
if ( install_irq( TIMER0_INT, (void *)timer0, LOWEST_PRIORITY ) == FALSE )
{
//serial_send('#');
//return (FALSE);
} //T0IR = 0x01;
//T0TCR = 0x01;
SSP1CPSR = 0x0C; //0x1C 1MHz, 0x0C 2MHz
SSP1CR0 = 0x00c7;
SSP1CR1 = 0X02;
smprn_i = 0;
init_ADC(1);
}
void prn_pow(unsigned char onoff)
{
//DWORD iz = 0;
if(onoff==1)
{
//T0MR0 = 0x8ca0;//0x7080;
//T0TCR = 0x01;
//init_ADC();
prt_strobe_complete = 0;
prt_stop_flag = 1;
prt_time_cnt = 0;
prt_step_cnt = 0;
//iz=read_ADC();
// if(i>=0x3e0)
// { //printf("paper\n");
// FIO0CLR = (1 << 28); // PRINTER POWER ON
// T0TCR = 0x01;}
// else
// //printf("no paper\n");
// buzzer();
// while(1)
// {
// buzzer();
// delay_Ms(20);
// buzzer();
// delay_Ms(100);
// buzzer();
// delay_Ms(500);
// buzzer();
// delay_Ms(1000);
// iz=read_ADC(1);
// if(iz>=0x3e0) break;
// }
FIO0CLR = (1 << 28); // PRINTER POWER ON
T0TCR = 0x01;
}
else
{
T0TCR = 0x02; // RESET TIMER
FIO0SET = STROBE_VAL; //STROBES = 0
FIO1SET = MOT_OFF; //DISABLE MOTOR
FIO0SET = (1 << 28); //PRINTER POWER OFF
}
}
void prt_msg(unsigned char * prt_msg_data,unsigned char max_char)
{
unsigned char count,prt_msg_ch;
for(count=0;count<max_char;count++)
{
prt_msg_ch= *(prt_msg_data + count);
if(prt_msg_ch == 0x0a)
{
if(prt_dw_flag)
{
while(smprn_i<16)
{
test_msg[smprn_i]=0x00;
smprn_i++;
}
st_prt();
smprn_i=0;
}
else
{
while(smprn_i<32)
{
test_msg[smprn_i]=0x00;
smprn_i++;
}
st_prt();
smprn_i=0;
}
}
else
{
test_msg[smprn_i] = prt_msg_ch - 0x20;
smprn_i++;
if(prt_dw_flag)
{
if(smprn_i>=16)
{
st_prt();
smprn_i=0;
}
}
else
{
if(smprn_i>=32)
{
st_prt();
smprn_i=0;
}
}
}
}
}
void st_prt(void)
{
line_count = 0;
prn_pow(1);
//while(1);
while(prt_time_cnt != 1);
while(prt_time_cnt==1);
while(prt_time_cnt!=1);
while(prt_time_cnt==1);
while(prt_time_cnt!=1);
while(prt_time_cnt==1);
while(prt_time_cnt!=1);
// while(prt_time_cnt==1);
prt_strobe_complete = 1;
while(1)
{
//serial_send('$');
if(prt_dw_flag)
{
dotlines_dw();
if(prt_dh_flag == 1)
dotlines_dw();
}
else
{
dotlines();
if(prt_dh_flag == 1)
dotlines();
}
line_count++;
if(line_count >15)
break;
//prt_pwr = ~ prt_pwr;
}
while(prt_strobe_complete);
while(prt_time_cnt!=1);
prn_pow(0);
smprn_i =0;
}
void dotlines(void)
{
unsigned char dl_dot_count,dl_temp_cnt, dl_blk_cnt;
unsigned char dl_temp1, dl_temp2, dl_temp3, dl_temp4;
unsigned char const * dl_ptr;
unsigned int dl_temp_add;
dl_dot_count = 0;
//dl_temp_cnt = smprn_i;
dl_ptr = prt_line_ptr[line_count];
dl_temp_cnt = 0;
//printf("%d", (int)(smprn_i));
for(dl_temp_cnt = 0; dl_temp_cnt < smprn_i;)
{
//serial_send('#');
dl_temp_add = 2*test_msg[dl_temp_cnt];
dl_temp1 = *(dl_ptr + dl_temp_add);
dl_temp_add++;
dl_temp2 = *(dl_ptr + dl_temp_add);
dl_temp_cnt++;
dl_temp_add = 2*test_msg[dl_temp_cnt];
dl_temp3 = *(dl_ptr + dl_temp_add);
dl_temp_add++;
dl_temp4 = *(dl_ptr + dl_temp_add);
dl_temp_cnt++;
dl_temp1 = (dl_temp2 >> 4) |( dl_temp1 << 4);
dl_temp2 = (dl_temp2 << 4) | dl_temp3;
SSP1DR = dl_temp1;
while( SSP1SR & 0x10 );
SSP1DR = dl_temp2;
while( SSP1SR & 0x10 );
SSP1DR = dl_temp4;
while( SSP1SR & 0x10 );
dl_dot_count += prt_dot_cnt[dl_temp1];
dl_dot_count += prt_dot_cnt[dl_temp2];
dl_dot_count += prt_dot_cnt[dl_temp4];
if((dl_dot_count > 64) && (dl_temp_cnt < smprn_i))
{
dl_blk_cnt = 3 * (dl_temp_cnt >> 1);
for(;dl_blk_cnt<48; dl_blk_cnt++)
{
SSP1DR = 0x00;
while( SSP1SR & 0x10 );
}
while(prt_strobe_complete);
while((prt_time_cnt != 1)&& (prt_time_cnt != 3));
prt_stop_flag = 0;
prt_strobe_complete = 1;
FIO0CLR = (1 << 6); // LAT = 0;
__nop();
__nop();
FIO0SET = (1 << 6); //LAT = 1;
FIO0CLR = STROBE_VAL;
//lat = 0;
//lat = 1;
//dbus = 0xff;
//stren = 1;
//stren = 0;
dl_blk_cnt = 3 * (dl_temp_cnt >> 1);
while(dl_blk_cnt)
{
SSP1DR = 0x00;
while(SSP1SR & 0x10);
dl_blk_cnt--;
}
dl_dot_count = 0;
}
}
while(prt_strobe_complete);
while((prt_time_cnt != 1)&& (prt_time_cnt != 3));
prt_stop_flag = 1;
prt_strobe_complete = 1;
FIO0CLR = (1 << 6); // LAT = 0;
__nop();
__nop();
FIO0SET = (1 << 6); //LAT = 1;
FIO0CLR = STROBE_VAL;
}
void dotlines_dw(void)
{
unsigned char dl_dot_count,dl_temp_cnt, dl_blk_cnt;
unsigned char dl_temp1, dl_temp2, dl_temp3;
unsigned char const * dl_ptr;
unsigned int dl_temp_add;
dl_dot_count = 0;
//dl_temp_cnt = smprn_i;
dl_ptr = prt_linedw_ptr[line_count];
//SPITDR = 0x00; //send read command
//SPICON0 = SPICON0 | 0x40; //enable SPI TX
//while(!(SPISTAT & 0x02)); //wait till SPITDR is empty
dl_temp_cnt = 0;
//printf("%d", (int)(smprn_i));
for(dl_temp_cnt = 0; dl_temp_cnt < smprn_i;)
{
dl_temp_add = 3*test_msg[dl_temp_cnt];
dl_temp1 = *(dl_ptr + dl_temp_add);
dl_temp_add++;
dl_temp2 = *(dl_ptr + dl_temp_add);
dl_temp_add++;
dl_temp3 = *(dl_ptr + dl_temp_add);
SSP1DR = dl_temp1;
while( (SSP1SR & 0x10) );
SSP1DR = dl_temp2;
while( (SSP1SR & 0x10) );
SSP1DR = dl_temp3;
while( (SSP1SR & 0x10) );
dl_temp_cnt++;
//send_hex(dl_temp1);
//send_hex(dl_temp2);
//send_hex(dl_temp3);
dl_dot_count += prt_dot_cnt[dl_temp1];
dl_dot_count += prt_dot_cnt[dl_temp2];
dl_dot_count += prt_dot_cnt[dl_temp3];
if((dl_dot_count > 64) && (dl_temp_cnt < smprn_i))
{
dl_blk_cnt = 3 * dl_temp_cnt;
for(;dl_blk_cnt<48; dl_blk_cnt++)
{
SSP1DR = 0x00;
while( (SSP1SR & 0x10) );
}
while(prt_strobe_complete);
while((prt_time_cnt != 1)&& (prt_time_cnt != 3));
prt_stop_flag = 0;
prt_strobe_complete = 1;
FIO0CLR = (1 << 6); // LAT = 0;
__nop();
__nop();
FIO0SET = (1 << 6); //LAT = 1;
FIO0CLR = STROBE_VAL;
//lat = 0;
//lat = 1;
//dbus = 0xff;
//stren = 1;
//stren = 0;
dl_blk_cnt = 3 * dl_temp_cnt;
while(dl_blk_cnt)
{
SSP1DR = 0x00;
while( (SSP1SR & 0x10) );
dl_blk_cnt--;
}
dl_dot_count = 0;
}
}
while(prt_strobe_complete);
while((prt_time_cnt != 1)&& (prt_time_cnt != 3));
prt_stop_flag = 1;
prt_strobe_complete = 1;
FIO0CLR = (1 << 6); // LAT = 0;
__nop();
__nop();
FIO0SET = (1 << 6); //LAT = 1;
FIO0CLR = STROBE_VAL;
//lat = 0;
//lat = 1;
//dbus = 0xff;
//stren = 1;
//stren = 0;
}
void timer0(void) __irq
{
//unsigned char xdata port_temp;
unsigned int const mot_step[]= {0x0c, 0x04, 0x00, 0x8};
T0IR = 1; /* clear interrupt flag */
prt_strobe_complete = 1;
if(prt_stop_flag)
{
prt_step_cnt++;
if(prt_step_cnt >4)
prt_step_cnt = 1;
FIO1MASK = ~(0x0f << 14);//0x3fff;
FIO1PIN = (mot_step[prt_step_cnt - 1] << 14);
//port_temp = P4;
//port_temp = port_temp & 0x0f;
//port_temp = port_temp | mot_step[prt_step_cnt - 1];
//P4 = port_temp;
FIO1MASK = 0;//0x3fff;
}
//while(!(U0LSR & 0X20));
//U0THR = '*';
prt_time_cnt++;
if(prt_time_cnt > 4)
prt_time_cnt = 1;
if((prt_time_cnt == 1)|| (prt_time_cnt == 3))
{
prt_strobe_complete = 0;
FIO0SET = STROBE_VAL;//dbus = 0x00;
//stren = 1;
//stren = 0;
}
VICVectAddr = 0; /* Acknowledge Interrupt */
//TR0 = 1;
}
//********************************************************************
// Added Ones
//********************************************************************
void sm_prt(unsigned char prn_msgch)
{
if(prn_msgch == 0x0a)
{
if(prt_dw_flag)
{
while(smprn_i<16) //36
{
test_msg[smprn_i]=0x00;
smprn_i++;
}
}
else
{
while(smprn_i<32) //36
{
test_msg[smprn_i]=0x00;
smprn_i++;
}
}
st_prt();
smprn_i=0;
}
else
{
test_msg[smprn_i] = prn_msgch-0x20;
smprn_i++;
if(prt_dw_flag)
{
if(smprn_i>=16) //36
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -