/************************************************************* 函数功能:该函数用来设置时钟芯片的日期 *************************************************************/ void SetDate(void) { write_ds(0x09,timer.w_year); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); write_ds(0x08,timer.w_month); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); write_ds(0x07,timer.w_date); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); }
/************************************************************* 函数功能:该函数用来设置时钟芯片的时间 *************************************************************/ void SetTime(void) { write_ds(0x04,timer.hour); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); write_ds(0x02,timer.min); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); write_ds(0x0, timer.sec); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); }
void GetTime(void) { // hour = read_ds(0x04); timer.hour = read_ds(0x04); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); // minute = read_ds(0x02); timer.min = read_ds(0x02); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); // second = read_ds(0x0); timer.sec = read_ds(0x0); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); __nop(); if(timer.sec>59) { timer.sec=0; write_ds(0x0, timer.sec); } }
void keyscan() { static int flag=0,flag_ymd=0; if(s1==0) //功能键s1 { delay(10); if(s1==0) { while(!s1); flag++; di(); if(flag==1) { flag_ds=1; write_com(0x80+0x40+10); write_com(0x0f); diii(); } if(flag==2) { write_com(0x80+0x40+7); } if(flag==3) { write_com(0x80+0x40+4); } if(flag==4)//week { write_com(0x80+12); flag_ymd=1; } if(flag==5) //day { write_com(0x80+9); flag_ymd=2; } if(flag==6) //moth { write_com(0x80+6); flag_ymd=3; } if(flag==7) //year { write_com(0x80+3); flag_ymd=4; } if(flag==8) { diii(); flag=0; flag_ds=0; flag_ymd=0; write_com(0x0c); write_ds(0,miao); write_ds(2,fen); write_ds(4,shi); write_ds(6,week); write_ds(7,day); write_ds(8,moth); write_ds(9,year); } } } if(flag!=0) { if(s2==0) //加数键s2 加数键s2 加数键s2 加数键s2 { delay(5); if(s2==0) { while(!s2); di(); if(flag_ymd==0) { /*****************************/ if(flag==1) { miao++; if(miao==60) { miao=0; } write_time(10,miao,2); write_com(0x80+0x40+10); } if(flag==2) { fen++; if(fen==60) { fen=0; } write_time(7,fen,2); write_com(0x80+0x40+7); } if(flag==3) { shi++; if(shi==24) { shi=0; } write_time(4,shi,2); write_com(0x80+0x40+4); } /**************************/ } if(flag_ymd==1) { week++; if(week==8) { week=1; } write_week(week); write_com(0x80+12); } if(flag_ymd==2) { day++; if(day==32) { day=1; } write_time(9,day,1); write_com(0x80+9); } if(flag_ymd==3) { moth++; if(moth==13) { moth=1; } write_time(6,moth,1); write_com(0x80+6); } if(flag_ymd==4) { year++; if(year==30) { year=1; } write_time(3,year,1); write_com(0x80+3); } } } //加数 if(s3==0) //减数键s3 减数键s3 减数键s3 减数键s3 { delay(5); if(s3==0) { while(!s3); di(); if(flag_ymd==0) { /*************************************/ if(flag==1) { miao--; if(miao==60||miao<0) { miao=0; } write_time(10,miao,2); write_com(0x80+0x40+10); } if(flag==2) { fen--; if(fen==60||fen<0) { fen=0; } write_time(7,fen,2); write_com(0x80+0x40+7); } if(flag==3) { shi--; if(shi==24||shi<0) { shi=0; } write_time(4,shi,2); write_com(0x80+0x40+4); } /*******************************************/ } if(flag_ymd==1) { week--; if(week==0) { week=7; } write_week(week); write_com(0x80+12); } if(flag_ymd==2) { day--; if(day==0) { day=31; } write_time(9,day,1); write_com(0x80+9); } if(flag_ymd==3) { moth--; if(moth==0) { moth=12; } write_time(6,moth,1); write_com(0x80+6); } if(flag_ymd==4) { year--; if(year==0) { year=30; } write_time(3,year,1); write_com(0x80+3); } } } //减数 } }
static int parse_complete(token_t *tok) { unsigned int t0; _cffi_opcode_t t1; int modifiers_length, modifiers_sign; qualifiers: switch (tok->kind) { case TOK_CONST: /* ignored for now */ next_token(tok); goto qualifiers; case TOK_VOLATILE: /* ignored for now */ next_token(tok); goto qualifiers; default: ; } modifiers_length = 0; modifiers_sign = 0; modifiers: switch (tok->kind) { case TOK_SHORT: if (modifiers_length != 0) return parse_error(tok, "'short' after another 'short' or 'long'"); modifiers_length--; next_token(tok); goto modifiers; case TOK_LONG: if (modifiers_length < 0) return parse_error(tok, "'long' after 'short'"); if (modifiers_length >= 2) return parse_error(tok, "'long long long' is too long"); modifiers_length++; next_token(tok); goto modifiers; case TOK_SIGNED: if (modifiers_sign) return parse_error(tok, "multiple 'signed' or 'unsigned'"); modifiers_sign++; next_token(tok); goto modifiers; case TOK_UNSIGNED: if (modifiers_sign) return parse_error(tok, "multiple 'signed' or 'unsigned'"); modifiers_sign--; next_token(tok); goto modifiers; default: break; } if (modifiers_length || modifiers_sign) { switch (tok->kind) { case TOK_VOID: case TOK__BOOL: case TOK_FLOAT: case TOK_STRUCT: case TOK_UNION: case TOK_ENUM: return parse_error(tok, "invalid combination of types"); case TOK_DOUBLE: if (modifiers_sign != 0 || modifiers_length != 1) return parse_error(tok, "invalid combination of types"); next_token(tok); t0 = _CFFI_PRIM_LONGDOUBLE; break; case TOK_CHAR: if (modifiers_length != 0) return parse_error(tok, "invalid combination of types"); modifiers_length = -2; /* fall-through */ case TOK_INT: next_token(tok); /* fall-through */ default: if (modifiers_sign >= 0) switch (modifiers_length) { case -2: t0 = _CFFI_PRIM_SCHAR; break; case -1: t0 = _CFFI_PRIM_SHORT; break; case 1: t0 = _CFFI_PRIM_LONG; break; case 2: t0 = _CFFI_PRIM_LONGLONG; break; default: t0 = _CFFI_PRIM_INT; break; } else switch (modifiers_length) { case -2: t0 = _CFFI_PRIM_UCHAR; break; case -1: t0 = _CFFI_PRIM_USHORT; break; case 1: t0 = _CFFI_PRIM_ULONG; break; case 2: t0 = _CFFI_PRIM_ULONGLONG; break; default: t0 = _CFFI_PRIM_UINT; break; } } t1 = _CFFI_OP(_CFFI_OP_PRIMITIVE, t0); } else { switch (tok->kind) { case TOK_INT: t1 = _CFFI_OP(_CFFI_OP_PRIMITIVE, _CFFI_PRIM_INT); break; case TOK_CHAR: t1 = _CFFI_OP(_CFFI_OP_PRIMITIVE, _CFFI_PRIM_CHAR); break; case TOK_VOID: t1 = _CFFI_OP(_CFFI_OP_PRIMITIVE, _CFFI_PRIM_VOID); break; case TOK__BOOL: t1 = _CFFI_OP(_CFFI_OP_PRIMITIVE, _CFFI_PRIM_BOOL); break; case TOK_FLOAT: t1 = _CFFI_OP(_CFFI_OP_PRIMITIVE, _CFFI_PRIM_FLOAT); break; case TOK_DOUBLE: t1 = _CFFI_OP(_CFFI_OP_PRIMITIVE, _CFFI_PRIM_DOUBLE); break; case TOK_IDENTIFIER: { const char *replacement; int n = search_in_typenames(tok->info->ctx, tok->p, tok->size); if (n >= 0) { t1 = _CFFI_OP(_CFFI_OP_TYPENAME, n); break; } n = search_standard_typename(tok->p, tok->size); if (n >= 0) { t1 = _CFFI_OP(_CFFI_OP_PRIMITIVE, n); break; } replacement = get_common_type(tok->p, tok->size); if (replacement != NULL) { n = parse_common_type_replacement(tok, replacement); if (n < 0) return parse_error(tok, "internal error, please report!"); t1 = _CFFI_OP(_CFFI_OP_NOOP, n); break; } return parse_error(tok, "undefined type name"); } case TOK_STRUCT: case TOK_UNION: { int n, kind = tok->kind; next_token(tok); if (tok->kind != TOK_IDENTIFIER) return parse_error(tok, "struct or union name expected"); n = search_in_struct_unions(tok->info->ctx, tok->p, tok->size); if (n < 0) { if (kind == TOK_STRUCT && tok->size == 8 && !memcmp(tok->p, "_IO_FILE", 8)) n = _CFFI__IO_FILE_STRUCT; else return parse_error(tok, "undefined struct/union name"); } else if (((tok->info->ctx->struct_unions[n].flags & _CFFI_F_UNION) != 0) ^ (kind == TOK_UNION)) return parse_error(tok, "wrong kind of tag: struct vs union"); t1 = _CFFI_OP(_CFFI_OP_STRUCT_UNION, n); break; } case TOK_ENUM: { int n; next_token(tok); if (tok->kind != TOK_IDENTIFIER) return parse_error(tok, "enum name expected"); n = search_in_enums(tok->info->ctx, tok->p, tok->size); if (n < 0) return parse_error(tok, "undefined enum name"); t1 = _CFFI_OP(_CFFI_OP_ENUM, n); break; } default: return parse_error(tok, "identifier expected"); } next_token(tok); } return parse_sequel(tok, write_ds(tok, t1)); }
static int parse_sequel(token_t *tok, int outer) { /* Emit opcodes for the "sequel", which is the optional part of a type declaration that follows the type name, i.e. everything with '*', '[ ]', '( )'. Returns the entry point index pointing the innermost opcode (the one that corresponds to the complete type). The 'outer' argument is the index of the opcode outside this "sequel". */ int check_for_grouping, abi=0; _cffi_opcode_t result, *p_current; header: switch (tok->kind) { case TOK_STAR: outer = write_ds(tok, _CFFI_OP(_CFFI_OP_POINTER, outer)); next_token(tok); goto header; case TOK_CONST: /* ignored for now */ next_token(tok); goto header; case TOK_VOLATILE: /* ignored for now */ next_token(tok); goto header; case TOK_CDECL: case TOK_STDCALL: /* must be in a function; checked below */ abi = tok->kind; next_token(tok); goto header; default: break; } check_for_grouping = 1; if (tok->kind == TOK_IDENTIFIER) { next_token(tok); /* skip a potential variable name */ check_for_grouping = 0; } result = 0; p_current = &result; while (tok->kind == TOK_OPEN_PAREN) { next_token(tok); if (tok->kind == TOK_CDECL || tok->kind == TOK_STDCALL) { abi = tok->kind; next_token(tok); } if ((check_for_grouping--) == 1 && (tok->kind == TOK_STAR || tok->kind == TOK_CONST || tok->kind == TOK_VOLATILE || tok->kind == TOK_OPEN_BRACKET)) { /* just parentheses for grouping. Use a OP_NOOP to simplify */ int x; assert(p_current == &result); x = tok->output_index; p_current = tok->output + x; write_ds(tok, _CFFI_OP(_CFFI_OP_NOOP, 0)); x = parse_sequel(tok, x); result = _CFFI_OP(_CFFI_GETOP(0), x); } else { /* function type */ int arg_total, base_index, arg_next, flags=0; if (abi == TOK_STDCALL) { flags = 2; /* note that an ellipsis below will overwrite this flags, which is the goal: variadic functions are always cdecl */ } abi = 0; if (tok->kind == TOK_VOID && get_following_char(tok) == ')') { next_token(tok); } /* (over-)estimate 'arg_total'. May return 1 when it is really 0 */ arg_total = number_of_commas(tok) + 1; *p_current = _CFFI_OP(_CFFI_GETOP(*p_current), tok->output_index); p_current = tok->output + tok->output_index; base_index = write_ds(tok, _CFFI_OP(_CFFI_OP_FUNCTION, 0)); if (base_index < 0) return -1; /* reserve (arg_total + 1) slots for the arguments and the final FUNCTION_END */ for (arg_next = 0; arg_next <= arg_total; arg_next++) if (write_ds(tok, _CFFI_OP(0, 0)) < 0) return -1; arg_next = base_index + 1; if (tok->kind != TOK_CLOSE_PAREN) { while (1) { int arg; _cffi_opcode_t oarg; if (tok->kind == TOK_DOTDOTDOT) { flags = 1; /* ellipsis */ next_token(tok); break; } arg = parse_complete(tok); switch (_CFFI_GETOP(tok->output[arg])) { case _CFFI_OP_ARRAY: case _CFFI_OP_OPEN_ARRAY: arg = _CFFI_GETARG(tok->output[arg]); /* fall-through */ case _CFFI_OP_FUNCTION: oarg = _CFFI_OP(_CFFI_OP_POINTER, arg); break; default: oarg = _CFFI_OP(_CFFI_OP_NOOP, arg); break; } assert(arg_next - base_index <= arg_total); tok->output[arg_next++] = oarg; if (tok->kind != TOK_COMMA) break; next_token(tok); } } tok->output[arg_next] = _CFFI_OP(_CFFI_OP_FUNCTION_END, flags); } if (tok->kind != TOK_CLOSE_PAREN) return parse_error(tok, "expected ')'"); next_token(tok); } if (abi != 0) return parse_error(tok, "expected '('"); while (tok->kind == TOK_OPEN_BRACKET) { *p_current = _CFFI_OP(_CFFI_GETOP(*p_current), tok->output_index); p_current = tok->output + tok->output_index; next_token(tok); if (tok->kind != TOK_CLOSE_BRACKET) { size_t length; int gindex; char *endptr; switch (tok->kind) { case TOK_INTEGER: errno = 0; if (sizeof(length) > sizeof(unsigned long)) { #ifdef MS_WIN32 # ifdef _WIN64 length = _strtoui64(tok->p, &endptr, 0); # else abort(); /* unreachable */ # endif #else length = strtoull(tok->p, &endptr, 0); #endif } else length = strtoul(tok->p, &endptr, 0); if (endptr != tok->p + tok->size) return parse_error(tok, "invalid number"); if (errno == ERANGE || length > MAX_SSIZE_T) return parse_error(tok, "number too large"); break; case TOK_IDENTIFIER: gindex = search_in_globals(tok->info->ctx, tok->p, tok->size); if (gindex >= 0) { const struct _cffi_global_s *g; g = &tok->info->ctx->globals[gindex]; if (_CFFI_GETOP(g->type_op) == _CFFI_OP_CONSTANT_INT || _CFFI_GETOP(g->type_op) == _CFFI_OP_ENUM) { int neg; struct _cffi_getconst_s gc; gc.ctx = tok->info->ctx; gc.gindex = gindex; neg = ((int(*)(struct _cffi_getconst_s*))g->address) (&gc); if (neg == 0 && gc.value > MAX_SSIZE_T) return parse_error(tok, "integer constant too large"); if (neg == 0 || gc.value == 0) { length = (size_t)gc.value; break; } if (neg != 1) return parse_error(tok, "disagreement about" " this constant's value"); } } /* fall-through to the default case */ default: return parse_error(tok, "expected a positive integer constant"); } next_token(tok); write_ds(tok, _CFFI_OP(_CFFI_OP_ARRAY, 0)); write_ds(tok, (_cffi_opcode_t)length); } else write_ds(tok, _CFFI_OP(_CFFI_OP_OPEN_ARRAY, 0)); if (tok->kind != TOK_CLOSE_BRACKET) return parse_error(tok, "expected ']'"); next_token(tok); } *p_current = _CFFI_OP(_CFFI_GETOP(*p_current), outer); return _CFFI_GETARG(result); }