📄 serial._c
字号:
#include "iom64v.h"
#include "serial.h"
void Init_Usart(void)
{
UBRR0L=25;
UBRR1L=25;
UBRR0H=0;
UBRR1H=0;
UCSR0A=0x20;
UCSR1A=0x20;
UCSR0B=0x18;
UCSR1B=0x18;
UCSR0C=0x06;
UCSR1C=0x06;
}
void USART0_Transmit( uchar data1 )// printer driver by usart0
{
while ( !( UCSR0A & trcom ) );
UCSR0A=UCSR0A &(~trcom);
UDR0 = data1;
}
uchar USART0_Receive( void )
{
while ( !(UCSR0A & recom) );
UCSR0A=UCSR0A & (~recom) ;
return UDR0;
}
void USART1_Transmit( uchar data )// communaction to other by usart1
{
while ( ( UCSR1A & 0x20 )==0 );
UDR1 = data;
}
uchar USART1_Receive( void )
{
if((UCSR1A & recom)!=0)
{
UCSR1A=UCSR1A &(~recom);
return UDR1;
}
else
return 0x55;
}
void PrintByte(uchar PrintByte)
{
uchar i;
i=0;
USART1_Transmit(PrintByte);
i=USART1_Receive();
while(i==0x13)
{
i=USART1_Receive();
}
}
void TestPrin(void)
{
uchar t[10]={0x1b,0x38,0x04,0xc8,0xd9,0xb4,0xef,0x0d};
uchar i;
for(i=0;i<8;i++)
PrintByte(t[i]);
}
void printer(uchar *PrinBuff,uchar Type )
{
switch(Type)
{
case 1:
{
PrintByte(0x1b);
PrintByte(0x63);
PrintByte(0x01);
PrintByte(0x1b);
PrintByte(0x38);
PrintByte(0x03);
PrintByte(0x1b);
PrintByte(0x2d);
PrintByte(0x01);
PrintByte(Number[(PrinBuff[11])]);
PrintByte(Number[(PrinBuff[12])]);
PrintByte(Number[(PrinBuff[13])]);
PrintByte(Number[(PrinBuff[14])]);
PrintByte(0xc4);
PrintByte(0xea);
PrintByte(Number[(PrinBuff[15])]);
PrintByte(Number[(PrinBuff[16])]);
PrintByte(0xd4);
PrintByte(0xc2);
PrintByte(Number[(PrinBuff[17])]);
PrintByte(Number[(PrinBuff[18])]);
PrintByte(0xc8);
PrintByte(0xd5);
PrintByte(Number[(PrinBuff[19])]);
PrintByte(Number[(PrinBuff[20])]);
PrintByte(0xca);
PrintByte(0xb1);
PrintByte(Number[(PrinBuff[21])]);
PrintByte(Number[(PrinBuff[22])]);
PrintByte(0xb7);
PrintByte(0xd6);
PrintByte(0x1b);
PrintByte(0x2d);
PrintByte(0x00);
PrintByte(0x0a);
PrintByte(0x56);
PrintByte(0x3a);
PrintByte(Number[(PrinBuff[8])]);
PrintByte(Number[(PrinBuff[9])]);
PrintByte(Number[(PrinBuff[10])]);
PrintByte(0x4f);
PrintByte(0x47);
PrintByte(0x2f);
PrintByte(0x6d);
PrintByte(0x69);
PrintByte(0x6e);
PrintByte(0x0a);
PrintByte(0x54);
PrintByte(0x3a);
PrintByte(Number[(PrinBuff[5])]);
PrintByte(Number[(PrinBuff[6])]);
PrintByte(0x2e);
PrintByte(Number[(PrinBuff[7])]);
PrintByte(0x4f);
PrintByte(0x4b);
PrintByte(0x0a);
PrintByte(0x4d);
PrintByte(0x3a);
PrintByte(Number[(PrinBuff[2])]);
PrintByte(Number[(PrinBuff[3])]);
PrintByte(0x2e);
PrintByte(Number[(PrinBuff[4])]);
PrintByte(0x25);
PrintByte(0x0d);
PrintByte(0xb0);
PrintByte(0xe0);
PrintByte(0xb4);
PrintByte(0xce);
PrintByte(0x3a);
PrintByte(Number[(PrinBuff[0])]);
PrintByte(Number[(PrinBuff[1])]);
PrintByte(0x0a);
break;
}
case 2:
{
PrintByte(0x1b);
PrintByte(0x38);
PrintByte(0x03);
PrintByte(0x30);
PrintByte(0x60);
PrintByte(0x34);
PrintByte(0x4E);
PrintByte(0x3a);
PrintByte(Number[(PrinBuff[0])]);
PrintByte(Number[(PrinBuff[1])]);
PrintByte(0x0a);
PrintByte(0x51);
PrintByte(0x3a);
PrintByte(Number[(PrinBuff[2])]);
PrintByte(Number[(PrinBuff[3])]);
PrintByte(Number[(PrinBuff[4])]);
PrintByte(Number[(PrinBuff[5])]);
PrintByte(Number[(PrinBuff[6])]);
PrintByte(Number[(PrinBuff[7])]);
PrintByte(0x54);
PrintByte(0x51);
PrintByte(0x54);
PrintByte(0x3a);
PrintByte(Number[(PrinBuff[8])]);
PrintByte(Number[(PrinBuff[9])]);
PrintByte(Number[(PrinBuff[10])]);
PrintByte(Number[(PrinBuff[11])]);
PrintByte(Number[(PrinBuff[12])]);
PrintByte(Number[(PrinBuff[13])]);
PrintByte(0x54);
PrintByte(0x1b);
PrintByte(0x2d);
PrintByte(0x01);
PrintByte(Number[(PrinBuff[14])]);
PrintByte(Number[(PrinBuff[15])]);
PrintByte(Number[(PrinBuff[16])]);
PrintByte(Number[(PrinBuff[17])]);
PrintByte(0x44);
PrintByte(0x6a);
PrintByte(Number[(PrinBuff[18])]);
PrintByte(Number[(PrinBuff[19])]);
PrintByte(0x54);
PrintByte(0x42);
PrintByte(Number[(PrinBuff[20])]);
PrintByte(Number[(PrinBuff[21])]);
PrintByte(0x48);
PrintByte(0x55);
PrintByte(Number[(PrinBuff[22])]);
PrintByte(Number[(PrinBuff[23])]);
PrintByte(0x4a);
PrintByte(0x31);
PrintByte(Number[(PrinBuff[24])]);
PrintByte(Number[(PrinBuff[25])]);
PrintByte(0x37);
PrintByte(0x56);
PrintByte(0x1b);
PrintByte(0x2d);
PrintByte(0x00);
PrintByte(0x0a);
break;
}
default:
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -