📄 taxcommon.c
字号:
//TaxCommon.c #include <time.h> #define ARM_VERSION #include "pos.h" //typedef unsigned char BYTE; typedef unsigned int WORD; typedef unsigned long DWORD;//定义 起始年,月// #define START_YEAR 1900// #define START_MONTH 1//关于日期时间设定的全局变量 struct tm *glb_now; /* { int tm_hour; // 0 to 23 int tm_min; // 0 to 59 int tm_sec; // 0 to 59 int tm_year; // linux date start at year 1900 int tm_mon; // 0 to 11 int tm_mday; // 1 to 31 } ; */ struct DT_struct { int year; int month; int day; int hour; int min; int sec; };//设定 日期时间void InitDate_1( void ){ time_t td; time(&td); td=mktime(glb_now); stime(&td);}void SetTimeAndDate( struct DT_struct *DateTimeStruct ){ glb_now->tm_hour = DateTimeStruct->hour; glb_now->tm_min = DateTimeStruct->min; glb_now->tm_sec = DateTimeStruct->sec; glb_now->tm_year = DateTimeStruct->year - START_YEAR; // linux date start at year 1900 glb_now->tm_mon = DateTimeStruct->month - START_MONTH; // 0 to 11 glb_now->tm_mday = DateTimeStruct->day; // 1 to 31 InitDate_1(); //设置日期时间 } //转换函数 //将 data_buf (小模式)数据转换成 带小数点的字符串 StrAddDecimalMarkvoid ConvHexToStrAddDeclmalMark( char StrAddDecimalMark[],unsigned char data_buf[] ){ unsigned long tmp_count; int i; //单张发票开票金额限额 (长度:4) memset( StrAddDecimalMark,0x0,20 ); //十六近制数(小模式)到计算机识别的整型的字节移动 ByteMoveHexToCount( (unsigned char *)&tmp_count,data_buf,4 ); //发票累计金额 4 HEX LongToStr( tmp_count,StrAddDecimalMark ); i = strlen( StrAddDecimalMark ); Add_Decimal( StrAddDecimalMark,&i ); //增加小数点}void DWordToAsc(BYTE *str,DWORD num,int L) { int i,Len; char buf[20]; //printf("\n%d\n",num); memset(buf,0,20); sprintf(buf,"%d",num); Len = strlen((char *)buf); for(i=0;i<L-Len;i++) *str ++ = 0x30; for(i=0;i<Len;i++) *str ++ = buf[i]; *str = 0; }//hex_data (小模式)数据转换成 固定长度的数字字符串 void Conv_minHexToMasterStr( char Str[],unsigned char hex_data[] ){ unsigned long count; ByteMoveHexToCount((unsigned char*)&count,hex_data,4); DWordToAsc( Str, count, 10 ); }void WordToAsc(BYTE *str,WORD num,int L) { int i,Len; char buf[20]; //printf("\n%d\n",num); memset(buf,0,20); sprintf(buf,"%d",num); Len = strlen((char *)buf); for(i=0;i<L-Len;i++) *str ++ = 0x30; for(i=0;i<Len;i++) *str ++ = buf[i]; *str = 0; }//得到 系统年月日,和对应的 年月日字符串: "____ 年 __ 月 __ 日"const unsigned char DateStr_0[]={"____ 年 __ 月 __ 日"};void GetSystemDate( int *year,int *month,int *day, unsigned char DateStr[] ){ time_t td; time(&td); glb_now = gmtime(&td); //gmtime(取得目前时间和日期) *year = glb_now->tm_year + START_YEAR; //tm_year 从1900 年算起至今的年数 *month = glb_now->tm_mon+START_MONTH; //tm_mon 代表目前月份,从一月算起,范围从0-11 *day = glb_now->tm_mday; //目前月份的日数,范围01-31 memmove( DateStr,DateStr_0,sizeof(DateStr_0) ); WordToAsc( DateStr, *year, 4 ); DateStr[4]=0x20; WordToAsc( &DateStr[8], *month, 2 ); DateStr[10]=0x20; WordToAsc( &DateStr[14], *day, 2 ); DateStr[16]=0x20; DateStr[19] = 0;}//得到 日期时间 (字符串,日期时间结构)void GetTimeAndDate( char DateTimeStr[] ) //,struct DT_struct *DateTimeStruct ){ time_t td; int cnt=4; //2004/04/20 15:20:00 time(&td); glb_now=gmtime(&td); /* DateTimeStruct->year = glb_now->tm_year+START_YEAR; DateTimeStruct->month = glb_now->tm_mon+START_MONTH; DateTimeStruct->day = glb_now->tm_mday; DateTimeStruct->hour = glb_now->tm_hour; DateTimeStruct->min = glb_now->tm_min; DateTimeStruct->sec = glb_now->tm_sec; */ WordToAsc( DateTimeStr,glb_now->tm_year+START_YEAR,4 ); DateTimeStr[cnt++]='/'; WordToAsc( &DateTimeStr[cnt],glb_now->tm_mon+START_MONTH,2 ); cnt+=2; DateTimeStr[cnt++]='/'; WordToAsc( &DateTimeStr[cnt],glb_now->tm_mday,2 ); cnt+=2; DateTimeStr[cnt++]=' '; WordToAsc( &DateTimeStr[cnt],glb_now->tm_hour,2 ); cnt+=2; DateTimeStr[cnt++]=':'; WordToAsc( &DateTimeStr[cnt],glb_now->tm_min,2 ); cnt+=2; DateTimeStr[cnt++]=':'; WordToAsc( &DateTimeStr[cnt],glb_now->tm_sec,2 ); cnt+=2; DateTimeStr[cnt++]=0; //sprintf(DateTimeStr,"%4d/%2d/%2d %2d:%2d:%2d", // glb_now->tm_year+START_YEAR,glb_now->tm_mon+START_MONTH,glb_now->tm_mday, // glb_now->tm_hour,glb_now->tm_min,glb_now->tm_sec);}//得到 日期时间void ShowTimeAndDate(void){ time_t td; time(&td); glb_now=gmtime(&td); printf("Current:Year:%d,Month:%d,Day:%d,Hour:%d,Min:%d,Sec:%d\n", glb_now->tm_year+START_YEAR,glb_now->tm_mon+START_MONTH,glb_now->tm_mday, glb_now->tm_hour,glb_now->tm_min,glb_now->tm_sec);} //按键函数//等待用户按任意键void TC_PressAnyKey( void ){ int ch; #ifndef ARM_VERSION while( KB_GetStatus()==0x11 ) ; #else while( ! KB_GetStatus() ) ; #endif ch = KB_GetValue();} //等待按任意键void KB_WaitAnyKey( void ) //等待按任意键{ while(!KB_GetStatus()); KB_GetValue();} //等待用户按 某一特定键int TC_WaitUserPressAnyKey( int WaitKey ) { int ch,key_in,inf = 0; #ifndef ARM_VERSION while( KB_GetStatus()== 0x11 ) ; //等待按键 #else while( ! KB_GetStatus() ) ; //等待按键 #endif key_in = KB_GetValue(); //读出键值 if( key_in != WaitKey ) inf = -1; //用户不确认,返回 return inf; } //等待用户按键,直到按下指定的键void TC_WaitUserPressSpeKey( int WaitKey ) { int ch,inf = 0; do { #ifndef ARM_VERSION while( KB_GetStatus()== 0x11 ) ; //等待按键 #else while( ! KB_GetStatus() ) ; //等待按键 #endif ch = KB_GetValue(); } while( ch != WaitKey ); } //等待按下某一特定键void KB_WaitSpesKey( int WaitKey ){ do{ while(!KB_GetStatus()); } while( KB_GetValue()!=WaitKey );} //显示光标(x1,y1,CursorMode) //Mode == 0->一行光标,==1->5行光标void LCD_CursorDiplay(int x,int y,int Mode,char SorD) { BYTE Hch,Lch; if(Mode == 0) Hch = 0x01; //显示 小光标 else Hch = 0x02; //显示 大光标 //if(Mode == 0) Hch = '_'; //0x01; //显示 小光标 //else Hch = 'X'; //0x02; //显示 大光标 Lch = 0; LCD_DisplayOneChr(x,y*6,Hch,Lch,SorD,'W'); } const int NumArr[]={0x45f0,0x16f0,0x1ef0,0x26f0,0x25f0,0x2ef0,0x36f0,0x3df0,0x3ef0,0x46f0};int IsNumeric( WORD Ch ) { int NumFlag,i; BYTE ch; //printf("\n%x,\n",Ch); //Ch = (BYTE)(Ch & 0xff); /* for(i=0;i<10;i++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -