📄 s_utility.c
字号:
*(P_U16)0xFFFFF910 |=0xF2FF;
} else if (com==1) {
*(P_U16)0xFFFFF900 |=0xF2FF;
}
break;
default:
break;
}
switch (charLen) {
case SEVEN_BIT_CHAR :
if (com==2) {
*(P_U16)0xFFFFF910 &=0xFEFF;
} else if (com==1) {
*(P_U16)0xFFFFF900 &=0xFEFF;
}
break;
case EIGHT_BIT_CHAR :
if (com==2) {
*(P_U16)0xFFFFF910 |=0x0100;
} else if (com==1) {
*(P_U16)0xFFFFF900 |=0x0100;
}
break;
default:
break;
}
return PPSM_OK;
}
void EL_Open(void){
ClearPenIRQFlagValue();
if ( ELWorkFlag==PDAEL_ON) {
ElWorkCount=0;
} else if ( ELWorkFlag==PDAEL_OFF) {
ELWorkFlag=PDAEL_ON;
EL_ON();
ElWorkCount=0;
}
}
void Elcheck(void){
U8 tmpVal;
if (ElWorkCount>PDAEL_COUNT && ELWorkFlag==PDAEL_ON) {
ELWorkFlag=PDAEL_OFF;
EL_OFF();
ElWorkCount=0;
}
if ( ELWorkFlag==PDAEL_ON) {
ElWorkCount++;
}
tmpVal=ReadPenIRQFlagValue();
if (tmpVal==0) {
VoltageProcess3();
}
}
U8 CheckCutButton(void){
U8 count;
*(P_U8)M328_PDSEL |= 0x10;
*(P_U8)M328_PDDIR &= 0xEF;
count=*(P_U8)M328_PDDATA;
count &=0x10;
count >>= 4;
return count;
}
void CutDownCheck(void){
U32 i;
TEXT cutingtxt[]={'正','在','保','存','数','据',',','等','待','关','机','..','.',0};
if ( CheckCutButton()==0) {
CkeckCutButtonFlag++;
} else {
CkeckCutButtonFlag=0;
}
if (CkeckCutButtonFlag>3) {
ClearScreen(WHITE);
if (PutString270((P_TEXT)cutingtxt,20,80,16,16) !=PPSM_OK) rv=PPSM_ERROR;
for (i=0;i<0x2FFFF;i++);
/************************
**关机前存内存数据
************************/
POWER_OFF();//关闭电源
asm(" JSR START");
}
}
void DecToBCD(P_U16 pt,U8 number)
{
U8 i,temp1,temp2;
for (i=0;i<number;i++) {
temp1 =*pt%10;
temp2 =*pt%100;
temp2 /=10;
*pt =temp2;
*pt <<=4;
*pt |=temp1;
pt++;
}
}
void GetSetData(P_U8 data,U8 flag )
{
U16 time_read[7];
S16 xSrc, ySrc, xDest, yDest;
P_U16 inData ;
U32 okIconId,canIconId,minuteId,secondId,size,id;
U8 ret_value,i,temp;
TEXT pleaseinputdate[]={'请','输','入','日','期',0};
TEXT pleaseinputid[]={'请','输','入','ID',0};
TEXT selectinputstyle[]={'是','否','直','接','利','用','PD','A ','的','日','期','?',0};
TEXT selectyes[]={'YE','S ',0};
TEXT selectno[]={'NO',0};
switch (flag) {
case 1:
{
ClearScreen(WHITE);
Typing(GB_NORMAL_FONT, REPLACE_STYLE, BLACK, 15, 90, (P_U8)selectinputstyle);
if (TextButton(&okIconId,GB_NORMAL_FONT,(P_TEXT)selectyes,40, 284, 60, 35, 1)
!=PPSM_OK) rv=PPSM_ERROR;
if (TextButton(&canIconId,GB_NORMAL_FONT,(P_TEXT)selectno,140, 284, 60, 35, 1)
!=PPSM_OK) rv=PPSM_ERROR;
ActiveAreaEnable((P_U32)&minuteId ,ICON_AREA ,CONTINUOUS_MODE ,284,40,319,100);
ActiveAreaEnable((P_U32)&secondId ,ICON_AREA ,CONTINUOUS_MODE ,284,140,319,200);
while (1) {
IrptGetData((P_U32)&id, (P_U32*)&inData, (P_U32)&size);
{
if (ActiveAreaRead(id,&xSrc,&ySrc,&xDest,&yDest)
!= PPSM_OK) rv = PPSM_ERROR;
if (InvRec(xSrc+1,ySrc+1,(xDest-(xSrc+1)),(yDest-(ySrc+1)))
!= PPSM_OK) rv = PPSM_ERROR;
if (*inData == PPSM_ICON_PEN_UP) {
if ((id==okIconId)||(id==secondId)) {
ret_value=AnyGetTime(time_read);
DecToBCD(time_read,6);
if (ret_value==1) {
for (i=0;i<6;i++) {
temp=time_read[i];
*data=temp;
data++;
}
}
return;
break;
} else if ((id==canIconId)||(id==minuteId)) {
return;
break;
}
}
}
}
break;
}
case 0:
{
Typing(GB_NORMAL_FONT, REPLACE_STYLE, BLACK, 40, 15, (P_U8)pleaseinputid);
break;
}
default:
break;
}
}
/**
void TimeDateTxtToBCD( U8 year[4],U8 month[2],U8 day[2],U8 hour[2],U8 minute[2],U8 second[2],U8 set_time[6],P_U16 year_time)
{
U8 i,temp[10];
for (i=0;i<4;i++) {
temp[i] =year[i]-0x30;
*year_time <<= 4;
*year_time |=temp[i];
}
for (i=0;i<2;i++) {
temp[i] =month[i]-0x30;
set_time[1] <<= 4;
set_time[1] |=temp[i];
}
for (i=0;i<2;i++) {
temp[i] =day[i]-0x30;
set_time[2] <<= 4;
set_time[2] |=temp[i];
}
for (i=0;i<2;i++) {
temp[i] =hour[i]-0x30;
set_time[3] <<= 4;
set_time[3] |=temp[i];
}
for (i=0;i<2;i++) {
temp[i] =minute[i]-0x30;
set_time[4] <<= 4;
set_time[4] |=temp[i];
}
for (i=0;i<2;i++) {
temp[i] =second[i]-0x30;
set_time[5] <<= 4;
set_time[5] |=temp[i];
}
}
**/
/**
* 将当时间字符串转换成BCD
*
**/
void TimeDateTxtToBCDNew( U8 year[4],U8 month[2],U8 day[2],U8 hour[2],U8 minute[2],U8 second[2],P_U8 SetDes,P_U16 year_time)
{
U8 i,temp[10];
for (i=0;i<4;i++) {
temp[i] =year[i]-0x30;
*year_time <<= 4;
*year_time |=temp[i];
}
for (i=0;i<2;i++) {
temp[i] =month[i]-0x30;
*SetDes <<= 4;
*SetDes |=temp[i];
}
SetDes++;
for (i=0;i<2;i++) {
temp[i] =day[i]-0x30;
*SetDes <<= 4;
*SetDes |=temp[i];
}
SetDes++;
for (i=0;i<2;i++) {
temp[i] =hour[i]-0x30;
*SetDes <<= 4;
*SetDes |=temp[i];
}
SetDes++;
for (i=0;i<2;i++) {
temp[i] =minute[i]-0x30;
*SetDes <<= 4;
*SetDes |=temp[i];
}
*SetDes++;
for (i=0;i<2;i++) {
temp[i] =second[i]-0x30;
*SetDes <<= 4;
*SetDes |=temp[i];
}
*SetDes++;
}
void JudgeTimeSet(U16 read_time[7],U8 set_time[6],P_U16 set_year)
{
TEXT timesetsuccess[]={'时','间','设','置','成','功','!',0};
TEXT timesetfail[]={'时','间','设','置','失','败','!',0};
//void BCD_to_dec(P_U16 BCD_data)
//set_time[5]-second,set_time[4]-minute,set_time[3]-hour,set_time[2]-day,set_time[1]-month,set_year_time-year;
//read_time[0]-----year
//read_time[1]-----month
//read_time[2]-----day
//read_time[3]-----hour
//read_time[4]-----minute
//read_time[5]-----second
//read_time[6]-----week
U16 i,temp;
//2005/11/15 修改时间设置相关函数
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//去掉原比较部分
/**
temp = *set_year;
BCD_to_dec(&temp);
if (temp!=read_time[0])
goto error_set;
for (i=1;i<5;i++) {
temp = set_time[i];
BCD_to_dec(&temp);
if (temp!=read_time[i])
goto error_set;
}
if (i==5)
goto right_set;
**/
//更新比较部分
temp = *set_year;
U16BCD2Dec(&temp);
if (temp!=read_time[0])
goto error_set;
for (i=0;i<4;i++) {
temp=set_time[i];
U16BCD2Dec(&temp);
if (temp!=read_time[i+1]) {
goto error_set;
}
}
goto right_set;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
error_set:
ClearScreen(WHITE);
CursorSetStatus(PPSM_CURSOR_OFF);
Typing(GB_NORMAL_FONT, REPLACE_STYLE, BLACK, 50, 130, (P_U8)timesetfail);
DelaySomeTime();
return;
right_set:
ClearScreen(WHITE);
CursorSetStatus(PPSM_CURSOR_OFF);
Typing(GB_NORMAL_FONT, REPLACE_STYLE, BLACK, 50, 130, (P_U8)timesetsuccess);
DelaySomeTime();
return;
}
void Uart1SendDataPacket (unsigned char *ptr,unsigned int len ){
U16 Uart1ReceiveVal;
U8 UartDataVal,loop;
U16 UartTxstatus;
U16 i;
U32 n;
U16 j;
U16 temploop;
loop=1;
temploop=0;
while (loop) {
Uart1ReceiveVal=*(P_U16)0xFFFFF904;
UartTxstatus=*(P_U16)0xFFFFF906;
if ( Uart1ReceiveVal & 0x2000 ) { // RDR is full?
RecieveDataFrom_Uart1Register();
} else if ( UartTxstatus & 0x2000) {
if (len >1024 ) return;
n=0;
while (len) {
UartTxstatus=*(P_U16)0xFFFFF906;
Uart1ReceiveVal=*(P_U16)0xFFFFF904;
if ( Uart1ReceiveVal & 0x2000 ) { // RDR is full?
RecieveDataFrom_Uart1Register();
for (j=20000;j>0;j--);
} else if ( UartTxstatus & 0x2000 ) { // TDR is empty?
*(P_U8)0xFFFFF907 = *ptr++;
len--;
} else {
n++;
if (n==0xFFFFF) return;
}
}
loop--;
return;
}
for (i=0x100;i>0;i--);
temploop++;
if ( temploop>1024 ) return;
}
}
U32 StrcpyU8andretlength(P_U8 dest,P_U8 src)
{
U32 i;
for (i=0;i<0xFFFFFFFF;i++) {
if (*src==0)
break;
*dest++ = *src++;
}
return(i);
}
void DecToText(P_U8 temp ){
switch (*temp) {
case 0:
*temp='0';
break;
case 1:
*temp='1';
break;
case 2:
*temp='2';
break;
case 3:
*temp='3';
break;
case 4:
*temp='4';
break;
case 5:
*temp='5';
break;
case 6:
*temp='6';
break;
case 7:
*temp='7';
break;
case 8:
*temp='8';
break;
case 9:
*temp='9';
break;
default:
break;
}
}
void DelaySomeTime(void)
{
U32 loop;
for (loop=0;loop<0x1FFFF;loop++);
for (loop=0;loop<0x1FFFF;loop++);
for (loop=0;loop<0x1FFFF;loop++);
for (loop=0;loop<0x1FFFF;loop++);
for (loop=0;loop<0x1FFFF;loop++);
for (loop=0;loop<0x1FFFF;loop++);
for (loop=0;loop<0x1FFFF;loop++);
for (loop=0;loop<0x1FFFF;loop++);
for (loop=0;loop<0x1FFFF;loop++);
for (loop=0;loop<0x1FFFF;loop++);
for (loop=0;loop<0x1FFFF;loop++);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -