/* XDemo67: i8080 Up/Down counter Compiler: BC++ 3.1 ,TC++ 3.0, TC++ 1.01, TC 2.0 Compile mode: large Project: user.c v7000.c vModbus.c [after XS8_3002] ..\LIB\8000E.Lib ..\LIB\8080L.Lib ..\LIB\TCPIPL.Lib ..\LIB\XS8_NNNN.Lib, with NNNN being the lib file's version. 19rl -> Read the current value of Low Pass filter 19rcm -> Read the current channel mode 19cc 0 -> clear the first channel(channel 0) of Up/Down Counter 19sv -> Switch to read the counter value This demo is used to read the Up/Down Counter value of i8080 plugged in the second slot (slot1) of 8000 controller Unit. To use I-8080, you need 2 extra files(8080.h, 8080L.Lib). The original 2 files are located in directory 8000\841x881x\master\demo\8080\Lib. The i8080 is 4/8 channels counter /frequency modules. Please refer to 8000\841x881x\master\demo\8080\8080 Hardware user's manual 8000\841x881x\master\demo\8080\8080 software user's manual (C language) Hardware: 8000E + I-8080 Refer 8000\843x883x\TCP\Doc\[Big5|Eng|Gb2312]\Vxcomm.htm 8000\843x883x\TCP\Xserver\Xserver.htm 8000\843x883x\TCP\Xserver\Function.htm 8000\841x881x\master\demo\8080\readme.txt to get more information. [27/Sep/2003] by sean */ #include #include #include "..\lib\module.h" #include "..\lib\8080.h" char cinit; unsigned char slot=1;//Default slot unsigned long cnt32U; int overflow; unsigned char i8080_LibDate[20]; void UserCount(void) { /* // user's timer trigger function // // In this function cannot use any function that will use the hardware signal "clock", // Such as: // 1. ClockHigh(),ClockLow(), ClockHighLow(), // 2. Any EEPROM functions. // 3. Any 5DigitLed functions. // 4. Any NVRAM function. // 5. Any RTC function.(GetTime(),SetTime(),GetDate(),SetDate()) // // refer to demo9 for example code */ } void UserEnd(void) { Print("Call UserEnd().\r\n"); StopUserTimerFun(); } void UserInit(void) { int iRet,iver; /* In this function, user CAN: 1. initialize user's program. 2. set time interval for calling UserCount(). 3. set initial value of I/O or variables for UserLoopFun(). 4. set initial value of I/O or variables for another functions. 5. change the default TCP PORT 10000/9999/502 to others value. [after XS8_3004.lib] Syntax: Port10000=newport_10000; for calling UserCmd (user.c) Port9999=newport_9999; for calling VcomCmd7000 (v7000.c) Port502=newport_502; for calling VcomCmdModbus (vModbus.c) [after XS8_3002.lib] PortUser=newport_User; for calling VcomCmdUser (user.c) [after XS8_3005.lib] Default port value: Port10000=10000; Port9999=9999; Port502=502; PortUser=0; If the port value is 0, Xserver will not listen that port. That means the port will be disable. Please refer to XDemo09 & XDemo11 for example code */ InitLib(); // To use [MiniOS7 for 8000 new], you need call this function // at begin of c program. // XS8_nnnn.Lib has not add this function to it's kernel. // So, you need call that in UserInit. // To know what difference between original MiniOS7 and new MiniOS7, // please refer CD:\Napdos\MiniOS7\8000new\8000-new_eng.txt // 8000-new_big5.txt // 8000-new_gb2312.txt // [26,Oct,2002] by Kevin SetBaudrate1(115200L); iRet=i8080_InitDriver(slot); //Initiate the 8080 plugged on slot 1 if(iRet) { printCom1("Initiate i8080 driver failure\r\n"); } i8080_SetChannelMode(slot,0,0x01); // A0, Up_Counting_0 i8080_SetChannelMode(slot,1,0x01); // B0, Down_Counting_0 // Set first channel to Up/Down counter mode i8080_SetLowPassFilter_Us(slot,0,1U); // valid for A0 & B0, 500K // Set first channel of Low Pass filter to 1 micro sec. i8080_ClrCnt(slot,0); // clear counter A0 i8080_ClrCnt(slot,1); // clear counter B0 iver=GetLibVersion(); printCom1("8080 Lib version:%d.%d.%02d\r\n",iver>>12&0x0f,iver>>8&0x0f,iver&0xff); //Get the Library version i8080_GetLibDate(i8080_LibDate); printCom1("8080 Lib date:%s\r\n",i8080_LibDate);//Get the Library date //It must to clear the A0 and Bo in Up/Down counter } void UserLoopFun(void) { if(cinit) { i8080_AutoScan(); //It need to call i8080_AutoScan in the Loop function Delay(1); i8080_ReadCntUpDown(slot,0,&cnt32U,&overflow); // (A0,B0) printCom1("\nChannel_A0_B0 : overflow=%x,cnt32=%lx",overflow,cnt32U); } /* // VxComm.exe will call this function every scan time // refer to demo11 for scan-time evaluation */ } int UserCmd(unsigned char *Cmd,unsigned char *Response) { /* // user's command interpreter // refer to all demo */ char cAnsy[5]; unsigned int MinWidth; int parameter2; int k; if (Cmd[0]) /* Not Null command */ { sscanf(Cmd,"%s %d",cAnsy,¶meter2); //parameter2 is the printCom1("first:%s, second:%d\r\n",cAnsy,parameter2); if(!strcmp(cAnsy,"rl")) //read Low Pass filter value { i8080_ReadLowPassFilter_Us(slot,0,&MinWidth); printCom1("0 channel of Low Pass filter:%u uS\r\n",MinWidth); sprintf(Response,"%u",MinWidth); } else if(!strcmp(cAnsy,"rcm")) //read channel mode { i8080_ReadChannelMode(slot,0,&k); printCom1("0 channel Mode:%02x\r\n",k); sprintf(Response,"%02x",k); } else if(!strcmp(cAnsy,"cc")) //clear the channel of Up/Down counter { if(parameter2<3) { i8080_ClrCnt(slot,parameter2); i8080_ClrCnt(slot,parameter2+1); strcpy(Response,"Clear counter"); } } else if(!strcmp(cAnsy,"sv")) //Switch Up/Down couter { cinit=~(cinit*0x1); if(!cinit) strcpy(Response,"Stop to read counter"); else strcpy(Response,"Start to read counter"); } else strcpy(Response,Cmd); /* echo user's command back */ return 1; /* return OK */ } return 0; /* return ERROR */ } int VcomUserBinaryCmd(TCPREADDATA *p) { /* VXCOMM.EXE 2.6.12(09/04/2001) or later will support this function. TCP PORT 10000, command 23 will call this function. user can get the following message: p->ReadUartChar : the buffer store the command data(include "23") p->Length : the command data length(include the two byte "23") p->Socket : the socket number that receive the command, that is, when the user function want to return a message to the client, just use the socket to send data. use: VcomSendSocket(p->Socket,pdata,datalength); */ VcomSendSocket(p->Socket,"User-defined command(23)",24); // return 24 bytes. return 1; /* any value will be accept */ } int VcomCmdUser(TCPREADDATA *p) { /* VCOM3005 (Feb,22,2002) or later will call this function for PortUser. When packets received by TCP PORT PortUser(user defined) of 7188E/8000E, Xserver will call this function. user can get the following message: p->ReadUartChar : the buffer store the command data. Maximum length of p->ReadUartChar is 32767 bytes. p->Length : the command data length. p->Socket : the socket number that receive the command, that is when the user function wants return message to the client, just use the socket to send data. usage: VcomSendSocket(p->Socket,pdata,datalength); */ /* here just send back the command to the client. */ VcomSendSocket(p->Socket,p->ReadUartChar,p->Length); return 1; /* any value will be accept */ } void PortUserStart(int skt) { /* XS8_3200.Lib Version 3.2.00 (20,Apr,2004) or later version supports this function. When a TCP/IP client connects to the 7188E/8000E via the user's defined port(PortUser), the Xserver calls the function once. You can use function VcomSendSocket to send a message to the client when a connection is established. For example: VcomSendSocket(skt,"Connection is established.",26); //return 26 bytes. skt: socket number assigned to the TCP/IP client. */ skt=skt; //do nothing } void Port9999Start(int skt) { /* XS8_3200.Lib Version 3.2.00 (20,Apr,2004) or later version supports this function. When a TCP/IP client connects to the 7188E/8000E TCP port 9999, the Xserver calls the function once. You can use function VcomSendSocket to send a message to the client when a connection is established. For example: VcomSendSocket(skt,"Connection is established.",26); //return 26 bytes. skt: socket number assigned to the TCP/IP client. */ skt=skt; //do nothing } void Port502Start(int skt) { /* XS8_3200.Lib Version 3.2.00 (20,Apr,2004) or later version supports this function. When a TCP/IP client connects to the 7188E/8000E TCP port 502, the Xserver calls the function once. You can use function VcomSendSocket to send a message to the client when a connection is established. For example: VcomSendSocket(skt,"Connection is established.",26); //return 26 bytes. skt: socket number assigned to the TCP/IP client. */ skt=skt; //do nothing }