cmdproc.rar

  • yyywwweee
    了解作者
  • C/C++
    开发工具
  • 4KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 7
    下载次数
  • 2005-08-12 08:10
    上传日期
这是一个模拟单片机与12887时钟芯片的通信控制程序 可以对其设定时间年月 可以向芯片内部ram写和读数据
cmdproc.rar
  • 12887
  • ds12887.c
    4.1KB
  • DS12887.h
    393B
  • CmdProc.c
    12.3KB
  • www.pudn.com.txt
    218B
内容介绍
static char code menu[] = __DATE2__ " "__TIME__ "\n" "调试程序\n" "+*************** Command proc 2005.07.22 VER1.00 **************+\n" "+ command -+ syntax -----+ function ---------------------------+\n" "| Read | R adds | read adds mem |\n" "| Write | W adds:data | write adds mem with data |\n" "| Display | D | display current measurement values |\n" "| Set Time | T hh:mm:ss | set time |\n" "| Swt Date | I mm:ss.ttt | set interval time |\n" "| Test | Z xxxx:xx | Test |\n" "| Fill Mem | C ? | ?=(0,1) |\n" "+----------+-------------+-------------------------------------+\n"; #include <reg52.h> #include <stdio.h> /* standard I/O .h-file */ #include <absacc.h rel='nofollow' onclick='return false;'> #include <ctype.h> /* character functions */ #define CNTLQ 0x11 #define CNTLS 0x13 #define DEL 0x7F #define BACKSPACE 0x08 #define CR 0x0D #define LF 0x0A char code ERROR [] = "\n*** ERROR: %s\n"; /* ERROR message string in code */ extern void set_time(unsigned char * buffer); extern void set_date(unsigned char * buffer); extern void disp_time(void); extern void disp_date(void); sbit Bell = P1^0; sbit LcdPwrSw = P1^1; sbit RS485Rec = P1^2; void getline (unsigned char idata *line, unsigned char n) { unsigned char cnt = 0; unsigned char c; // RS485Rec = 0; do { if ((c = _getkey ()) == CR) c = LF; /* read character */ if (c == BACKSPACE || c == DEL) /* process backspace */ { if (cnt != 0) { cnt--; /* decrement count */ line--; /* and line pointer */ // RS485Rec = 1; putchar (0x08); /* echo backspace */ putchar (' '); putchar (0x08); while(!TI); // RS485Rec = 0; } } else if (c != CNTLQ && c != CNTLS) /* ignore Control S/Q */ { // RS485Rec = 1; putchar ((char) (*line = c)); /* echo and store character */ while(!TI); // RS485Rec = 0; line++; /* increment line pointer */ cnt++; /* and count */ } }while (cnt < n - 1 && c != LF); /* check limit and line feed */ *line = 0; /* mark end of string */ // RS485Rec = 1; } void InitSerialPort(void) { SCON = 0x50; // SCON: mode 1, 8-bit UART, enable rcvr TMOD |= 0x20; // TMOD: timer 1, mode 2, 8-bit reload // TH1 = 253; // TH1: reload value for 9600 baud @ 11.0592MHz TH1 = 250; // TH1: reload value for 9600 baud @ 22.1184MHz TR1 = 1; // TR1: timer 1 run TI = 1; // TI: set TI to send first char of UART } void Test(unsigned char * buffer) { unsigned char args; /* number of arguments */ unsigned int iAdds; args = sscanf (buffer, "%4x", &iAdds); if (args == EOF) { printf (ERROR, "INVALID ADDS FORMAT"); } else /* if inputs valid then */ { printf ("Will Loop Adds=0x%04x\n",iAdds); while(1) { args=XBYTE[iAdds]; } } } void DispMem(unsigned char * buffer) { unsigned char args,uData; /* number of arguments */ unsigned int iAdds; unsigned char i,Temp; args = sscanf (buffer, "%4x", &iAdds); if (args == EOF) { printf (ERROR, "INVALID ADDS FORMAT"); } else /* if inputs valid then */ { // printf ("%04d:%02bd\n",iAdds,uData); EA = 0; /* disable interrupts while */ Temp=(unsigned char)(iAdds&0x000f); iAdds=iAdds&0xfff0; printf ("%04hx:",iAdds); for(i=0;i<Temp;i++) { printf (" "); } for(i=Temp;i<16;i++) { uData = XBYTE[iAdds+i]; printf ("%02bx ",uData); } EA = 1; /* enable interrupts again */ printf("\n"); } } void WriteMem(unsigned char * buffer) { unsigned char args,uData; /* number of arguments */ unsigned int iAdds; args = sscanf (buffer, "%4x:%2bx",&iAdds,&uData); if (args < 2 || args == EOF) { printf (ERROR, "INVALID ADDS:DATA FORMAT"); } else /* if inputs valid then */ { EA = 0; /* disable interrupts while */ XBYTE[iAdds] = uData; EA = 1; /* enable interrupts again */ printf ("Write Mem OK!\n"); } } #define MemBaseAdds 0x4000 void ListRecord(unsigned char * buffer) { // unsigned char args,uHour,uMin; /* number of arguments */ unsigned char args,uMonth,uDay; /* number of arguments */ unsigned int iAdds; args = sscanf (buffer, "%2bu.%2bu",&uMonth,&uDay); if (args < 2 || args == EOF ) { printf (ERROR, "INVALID MONTH.DAY FORMAT"); } if( (uMonth > 12) || (uDay > 31) ) { printf("Month <=12 and Day <=31\n"); } else /* if inputs valid then */ { printf ("List Record--\n"); printf("Time CH0 CH1 CH2 CH3 CH4 CH5 CH6 CH7\n"); printf("%02bu.%02bu ",uMonth,uDay); /* args = uMonth; uMonth >>= 4; uMonth *= 10; uMonth += args&0x0f; args = uDay; uDay >>= 4; uDay *= 10; uDay += args&0x0f; */ iAdds = MemBaseAdds + (unsigned int)(uMonth*31*20) + (unsigned int)(uDay*20); printf("(A=%04x Mon=%02bu Day=%02bu %02bx %02bx) ",iAdds,uMonth,uDay,XBYTE[iAdds],XBYTE[iAdds+1]); iAdds +=2; for(args=0;args<8;args++) { printf("%02bx%02bx ",XBYTE[iAdds+1+args*2],XBYTE[iAdds+args*2]); } } } void FillMem(unsigned int iAdds,unsigned int iLength,unsigned char uData) { unsigned int i; for(i=0;i<iLength;i++) { XBYTE[iAdds+i] = uData; } } void Mem_Clear(unsigned char * buffer) { unsigned char args; /* number of arguments */ unsigned char uData; args = sscanf (buffer, "%bu",&uData); if(args == EOF) { printf (ERROR, "INVALID ADDS:DATA FORMAT"); } else { switch (uData) { case 0: FillMem(MemBaseAdds,0x2000,0x00); printf("FillMem(0x4000,0x2000,0x00)\n"); break; case 1: FillMem(MemBaseAdds,0x2000,0x55); printf("FillMem(0x4000,0x2000,0x55)\n"); break; default: printf (ERROR, "INVALID FORMAT"); break; } } } void Mem_Fill(unsigned char * buffer) { unsigned char args,uData; /* number of arguments */ unsigned int i,iAdds,iLen; args = sscanf (buffer, "%4x %4x %2bx",&iAdds,&iLen,&uData); if (args < 3 || args == EOF) { printf (ERROR, "INVALID ADDS LEN DATA FORMAT"); } else /* if inputs valid then */ { EA = 0; /* disable interrupts while */ for(i=0;i<iLen;i++) { XBYTE[iAdds+i] = uData; } EA = 1; /* enable int
评论
    相关推荐