📄 rs232.c
字号:
/*********************************************/
// File Name: rs232.c
// Author: henny
// Date: 2006/3/1
/*********************************************/
#include <SST89x5xxRD2.h>
#include "Public.h"
extern WORD PLU_no;
extern DWORD Unit_Price;
extern WORD Weight;
extern WORD Quantity;
extern DWORD Total_Price;
extern TIME time;
extern DATE date;
extern WORD Sold_Quantity;
extern DWORD Sum_Price;
extern BYTE Record_buf[RECORD_LEN];
extern BYTE PLU_buf[PLU_LEN];
extern VOID Record_Load(WORD temp);
VOID RS232_Init()
{
SCON=0x42;
RCAP2H=V_TH2;
TH2=V_TH2;
RCAP2L=V_TL2;
TL2=V_TL2;
TCLK=1;
RCLK=1;
TR2=1;
while(!RXD);
REN=1;
}
VOID Put_Byte(BYTE b)
{
while(!TI);
TI=0;
SBUF=b;
}
BYTE Get_Byte()
{
BYTE b;
while(!RI);
b=SBUF;
RI=0;
return(b);
}
VOID Print_PLU_no(WORD temp)
{
INT8 data i,adr=0;
BYTE temp_buf[4];
DWORD divisor=1000;
for(i=3;i>=0;i--)
{
temp_buf[i]=temp/divisor;
temp=temp-temp_buf[i]*divisor;
divisor=divisor/10;
}
for(i=1;i>=0;i--)
{
Record_buf[PLU_no_Save_address+adr]=temp_buf[i*2+1];
Record_buf[PLU_no_Save_address+adr]=Record_buf[PLU_no_Save_address+adr]<<4;
Record_buf[PLU_no_Save_address+adr]+=temp_buf[i*2];
Put_Byte(Record_buf[PLU_no_Save_address+adr]);
adr++;
}
}
VOID Print_Unit_Price(DWORD temp)
{
INT8 data i,adr=0;
BYTE temp_buf[6];
DWORD divisor=100000;
for(i=5;i>=0;i--)
{
temp_buf[i]=temp/divisor;
temp=temp-temp_buf[i]*divisor;
divisor=divisor/10;
}
for(i=2;i>=0;i--)
{
Record_buf[Unit_Price_Save_address+adr]=temp_buf[i*2+1];
Record_buf[Unit_Price_Save_address+adr]=Record_buf[Unit_Price_Save_address+adr]<<4;
Record_buf[Unit_Price_Save_address+adr]+=temp_buf[i*2];
Put_Byte(Record_buf[Unit_Price_Save_address+adr]);
adr++;
}
}
VOID Print_Weight(DWORD temp)
{
INT8 data i,adr=0;
BYTE temp_buf[6];
DWORD divisor=100000;
for(i=5;i>=0;i--)
{
temp_buf[i]=temp/divisor;
temp=temp-temp_buf[i]*divisor;
divisor=divisor/10;
}
for(i=2;i>=0;i--)
{
Record_buf[Weight_Save_address+adr]=temp_buf[i*2+1];
Record_buf[Weight_Save_address+adr]=Record_buf[Weight_Save_address+adr]<<4;
Record_buf[Weight_Save_address+adr]+=temp_buf[i*2];
Put_Byte(Record_buf[Weight_Save_address+adr]);
adr++;
}
}
VOID Print_Quantity(DWORD temp)
{
INT8 data i,adr=0;
BYTE temp_buf[4];
DWORD divisor=1000;
for(i=3;i>=0;i--)
{
temp_buf[i]=temp/divisor;
temp=temp-temp_buf[i]*divisor;
divisor=divisor/10;
}
for(i=1;i>=0;i--)
{
Record_buf[Quantity_Save_address+adr]=temp_buf[i*2+1];
Record_buf[Quantity_Save_address+adr]=Record_buf[Quantity_Save_address+adr]<<4;
Record_buf[Quantity_Save_address+adr]+=temp_buf[i*2];
Put_Byte(Record_buf[Quantity_Save_address+adr]);
adr++;
}
Record_buf[Quantity+2]=0x00;
}
VOID Print_Total_Price(DWORD temp)
{
INT8 data i,adr=0;
BYTE temp_buf[8];
DWORD divisor=10000000;
for(i=7;i>=0;i--)
{
temp_buf[i]=temp/divisor;
temp=temp-temp_buf[i]*divisor;
divisor=divisor/10;
}
for(i=3;i>=0;i--)
{
Record_buf[Total_Price_Save_address+adr]=temp_buf[i*2+1];
Record_buf[Total_Price_Save_address+adr]=Record_buf[Total_Price_Save_address+adr]<<4;
Record_buf[Total_Price_Save_address+adr]+=temp_buf[i*2];
Put_Byte(Record_buf[Total_Price_Save_address+adr]);
adr++;
}
}
VOID Print_Date()
{
INT8 data i;
BYTE temp_buf[6];
temp_buf[0]=date.year%10;
temp_buf[1]=date.year/10;
temp_buf[2]=date.month%10;
temp_buf[3]=date.month/10;
temp_buf[4]=date.day%10;
temp_buf[5]=date.day/10;
for(i=0;i<3;i++)
{
Record_buf[0]=temp_buf[i*2+1];
Record_buf[0]=Record_buf[0]<<4;
Record_buf[0]+=temp_buf[i*2];
Put_Byte(Record_buf[0]);
}
}
VOID Print_Time()
{
INT8 data i;
BYTE temp_buf[4];
temp_buf[0]=time.hour%10;
temp_buf[1]=time.hour/10;
temp_buf[2]=time.min%10;
temp_buf[3]=time.min/10;
for(i=0;i<2;i++)
{
Record_buf[0]=temp_buf[i*2+1];
Record_buf[0]=Record_buf[0]<<4;
Record_buf[0]+=temp_buf[i*2];
Put_Byte(Record_buf[0]);
}
}
VOID Print_Sold_Quantity(WORD temp)
{
INT8 data i;
BYTE temp_buf[6];
DWORD divisor=100000;
for(i=5;i>=0;i--)
{
temp_buf[i]=temp/divisor;
temp=temp-temp_buf[i]*divisor;
divisor=divisor/10;
}
for(i=2;i>=0;i--)
{
Record_buf[0]=temp_buf[i*2+1];
Record_buf[0]=Record_buf[0]<<4;
Record_buf[0]+=temp_buf[i*2];
Put_Byte(Record_buf[0]);
}
}
VOID Print_Sum_Price(DWORD temp)
{
INT8 data i;
BYTE temp_buf[8];
DWORD divisor=10000000;
for(i=7;i>=0;i--)
{
temp_buf[i]=temp/divisor;
temp=temp-temp_buf[i]*divisor;
divisor=divisor/10;
}
for(i=3;i>=0;i--)
{
Record_buf[0]=temp_buf[i*2+1];
Record_buf[0]=Record_buf[0]<<4;
Record_buf[0]+=temp_buf[i*2];
Put_Byte(Record_buf[0]);
}
}
VOID Print_Record(BYTE print_type)
{
switch(print_type)
{
case PW:
Put_Byte(0xb1);
Print_PLU_no(PLU_no);
Put_Byte(0xb2);
Print_Unit_Price(Unit_Price);
Put_Byte(0xb3);
Print_Weight(Weight);
Put_Byte(0xb4);
Put_Byte(0x00);
Put_Byte(0x00);
Put_Byte(0xb5);
Print_Total_Price(Total_Price);
break;
case PN:
Put_Byte(0xb1);
Print_PLU_no(PLU_no);
Put_Byte(0xb2);
Print_Unit_Price(Unit_Price);
Put_Byte(0xb3);
Put_Byte(0x00);
Put_Byte(0x00);
Put_Byte(0x00);
Put_Byte(0xb4);
Print_Quantity(Quantity);
Put_Byte(0xb5);
Print_Total_Price(Total_Price);
break;
case MW:
Put_Byte(0xb1);
Print_PLU_no(0);
Put_Byte(0xb2);
Print_Unit_Price(Unit_Price);
Put_Byte(0xb3);
Print_Weight(Weight);
Put_Byte(0xb4);
Put_Byte(0x00);
Put_Byte(0x00);
Put_Byte(0xb5);
Print_Total_Price(Total_Price);
break;
case MN:
Put_Byte(0xb1);
Print_PLU_no(0);
Put_Byte(0xb2);
Print_Unit_Price(Unit_Price);
Put_Byte(0xb3);
Put_Byte(0x00);
Put_Byte(0x00);
Put_Byte(0x00);
Put_Byte(0xb4);
Print_Quantity(Quantity);
Put_Byte(0xb5);
Print_Total_Price(Total_Price);
break;
case TOTAL:
Put_Byte(0xc1);
Print_Date();
Put_Byte(0xc2);
Print_Time();
Put_Byte(0xc3);
Print_Sold_Quantity(Sold_Quantity);
Put_Byte(0xc4);
Print_Sum_Price(Sum_Price);
break;
}
}
VOID Print_Cancel_Record(WORD temp)
{
Record_Load(temp);
if(Record_buf[0]==PW||Record_buf[0]==MW)
{
Put_Byte(0xa1);
Put_Byte(Record_buf[PLU_no_Save_address]);
Put_Byte(Record_buf[PLU_no_Save_address+1]);
Put_Byte(0xa2);
Put_Byte(Record_buf[Unit_Price_Save_address]);
Put_Byte(Record_buf[Unit_Price_Save_address+1]);
Put_Byte(Record_buf[Unit_Price_Save_address+2]);
Put_Byte(0xa3);
Put_Byte(Record_buf[Weight_Save_address]);
Put_Byte(Record_buf[Weight_Save_address+1]);
Put_Byte(Record_buf[Weight_Save_address+2]);
Put_Byte(0xa4);
Put_Byte(0x00);
Put_Byte(0x00);
Put_Byte(0xa5);
Put_Byte(Record_buf[Total_Price_Save_address]);
Put_Byte(Record_buf[Total_Price_Save_address+1]);
Put_Byte(Record_buf[Total_Price_Save_address+2]);
Put_Byte(Record_buf[Total_Price_Save_address+3]);
}
else if(Record_buf[0]==PN||Record_buf[0]==MN)
{
Put_Byte(0xa1);
Put_Byte(Record_buf[PLU_no_Save_address]);
Put_Byte(Record_buf[PLU_no_Save_address+1]);
Put_Byte(0xa2);
Put_Byte(Record_buf[Unit_Price_Save_address]);
Put_Byte(Record_buf[Unit_Price_Save_address+1]);
Put_Byte(Record_buf[Unit_Price_Save_address+2]);
Put_Byte(0xa3);
Put_Byte(0x00);
Put_Byte(0x00);
Put_Byte(0x00);
Put_Byte(0xa4);
Put_Byte(Record_buf[Quantity_Save_address]);
Put_Byte(Record_buf[Quantity_Save_address+1]);
Put_Byte(0xa5);
Put_Byte(Record_buf[Total_Price_Save_address]);
Put_Byte(Record_buf[Total_Price_Save_address+1]);
Put_Byte(Record_buf[Total_Price_Save_address+2]);
Put_Byte(Record_buf[Total_Price_Save_address+3]);
}
}
BOOL Package_Header_Check()
{
INT8 data i;
while(Get_Byte()!=0xbb);
for(i=0;i<5;i++)
{
if(Get_Byte()!=0xbb)
return FALSE;
}
return TRUE;
}
VOID Receive_PLU_Data_from_PC()
{
while(Get_Byte()!=0xb1);
PLU_buf[0]=Get_Byte();
//Put_Byte(PLU_buf[0]);
PLU_buf[1]=Get_Byte();
//Put_Byte(PLU_buf[1]);
while(Get_Byte()!=0xb2);
PLU_buf[2]=Get_Byte();
//Put_Byte(PLU_buf[2]);
PLU_buf[3]=Get_Byte();
//Put_Byte(PLU_buf[3]);
PLU_buf[4]=Get_Byte();
//Put_Byte(PLU_buf[4]);
PLU_buf[5]=Get_Byte();
//Put_Byte(PLU_buf[5]);
PLU_buf[6]=Get_Byte();
//Put_Byte(PLU_buf[6]);
PLU_buf[7]=Get_Byte();
//Put_Byte(PLU_buf[7]);
PLU_buf[8]=Get_Byte();
//Put_Byte(PLU_buf[8]);
PLU_buf[9]=Get_Byte();
//Put_Byte(PLU_buf[9]);
PLU_buf[10]=Get_Byte();
//Put_Byte(PLU_buf[10]);
PLU_buf[11]=Get_Byte();
//Put_Byte(PLU_buf[11]);
PLU_buf[12]=Get_Byte();
//Put_Byte(PLU_buf[12]);
PLU_buf[13]=Get_Byte();
//Put_Byte(PLU_buf[13]);
PLU_buf[14]=Get_Byte();
//Put_Byte(PLU_buf[14]);
PLU_buf[15]=Get_Byte();
//Put_Byte(PLU_buf[15]);
PLU_buf[16]=Get_Byte();
//Put_Byte(PLU_buf[16]);
PLU_buf[17]=Get_Byte();
//Put_Byte(PLU_buf[17]);
while(Get_Byte()!=0xb3);
PLU_buf[18]=Get_Byte();
//Put_Byte(PLU_buf[18]);
PLU_buf[19]=Get_Byte();
//Put_Byte(PLU_buf[19]);
PLU_buf[20]=Get_Byte();
//Put_Byte(PLU_buf[20]);
}
BOOL Package_EOF_Check()
{
INT8 data i;
while(Get_Byte()!=0xcc);
for(i=0;i<5;i++)
{
if(Get_Byte()!=0xcc)
return FALSE;
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -