⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 s7600a.c

📁 S7600 TCP_IP网络协议接口芯片资料
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <stdio.h>                          #include <string.h>		    //Standard header library file#include <stdlib.h>			// ORI strtol function#include <process.h>#include <conio.h>#include <ctype.h>                                 #include <time.h>		    //Limit side effection#include <C:\test\custom.h>     							//Header file set up the systemtypedef unsigned char BYTE;typedef unsigned char U8;typedef unsigned int U16;typedef unsigned long U32;void HwSocketInit(char * name, char * password); //PPP connectionvoid HwSocketClose(void);           //PPP disconnectint  HwTcpOpen(void);               //Require TCP connection to the 									//server as a clientint  HwTcpClose(void);                      				    //Force TCP from CLOSE_WAIT status to CLOSE status int  HwTcpState(int);               //Obtain TCP Stateint  HwTcpRcv(void);                //Display Socket Datavoid DialUp(unsigned long BAUD , char * isp_num); //Dial to the service provider int  AtModem(char*, int);           //AT command release procedurevoid abort(void);                   //close PPP connectionint  nstep(void);                           				    //Get the instruction for the procedure followed void EscSeq(char*);                 //escape sequence procedurevoid x_write( BYTE, BYTE );         //1 byte data write driver for S-7600A SDK Board for ISA BUSBYTE x_read( BYTE );                        //1 byte data read driver for S-7600A SDK Board for ISA BUSvoid timer(int);                            //Timervoid print_usage(void){  printf("Usage: S7600A <baud> <ISP> <name> <password>\n");  printf("  <baud> = 300/1200/2400/4800/9600/19200/38400/57600/115200\n");  printf("  <ISP NO.> = ISP phone number\n");  printf("  <name> = PAP username\n");  printf("  <password> = PAP password\n");}/********************************************************//*                          Main                        *//********************************************************///Start programvoid main(int argc, char * argv[]) {    int keyPressed = 0;    BYTE stat;    unsigned long BAUDRATE;     printf("\nS-7600A AT Command Program Ver.1.1 with SDK Board ISA 1.0\n");    printf("(C) All copyrights reserved by Seiko Instruments Inc. 2000.\n");#if MSVC8    printf("Compile by Microsoft C/C++ Optimizing Compiler Version 8.00c.\n");#endif#if VC4    printf("Compile by Microsoft Visual C++ 5.0 Console Application.\n");#endif#if BC4    printf("Compile by Borland C++ Version 4.02 DOS standard.\n");#endif    printf("\n");  // check for proper number of arguements  if ( argc != 5 )  {	print_usage();	exit(0);  }  // parse BAUDRATE  BAUDRATE = strtol(argv[1], 0, 10);  switch (BAUDRATE)  {  case 115200:  case 57600:  case 38400:  case 19200:  case 9600:  case 4800:  case 2400:  case 1200:  case 300:    break;  default:    printf("invalid baud rate\n");    print_usage();    exit(1);  }  // print welcome banner  printf("baud %d, ISP %s, username %s, password %s\n", BAUDRATE, argv[2], argv[3],           argv[4]);    printf("\nReset S-7600A.....");    x_write( 0x01, 0x01 );               //Software Reset.    printf("Done.\n\n");    DialUp(BAUDRATE , argv[2]);               //Dial to the service provider    HwSocketInit(argv[3] , argv[4]);          //PPP connection    while(1){        printf("\nPress a Key !!    T : TCP Request   E : Exit  ");        keyPressed = toupper(getch());        printf("\n\n");        if (keyPressed == 'T')       //Request DAYTIME service        {            x_write(0x08, 0x01);     //ASCTL = Hardware control							         //Enable modem            timer(1);                //Wait for the modem ready            stat = x_read(0x08);            stat = stat & 0x70;      //Confirm the modem is ready            if(stat != 0){           //Modem ready is not confirmed                printf("Modem Hardware Error.\n");                while(1){                    if(nstep() == FALSE){       	       //Get instruction for the procedure followed                        break;                    }                }            }            if(HwTcpOpen() == FALSE){                   //Require TCP connect DAYTIME server                continue;            }            printf("\n");            if(HwTcpRcv() == FALSE){                    //Get service from DAYTIME server 						  //and display                continue;       //DAYTIME server sends FIN after the 						  //service is finished.            }            printf("\n\n");            HwTcpClose();                   //Change TCP from CLOSE_WAIT status to CLOSE status//DAYTIME server sends FIN when service is finished            x_write( 0x08, 0x03 );          //After RTS disenabled, instruct maintains connection and //waiting status to the modem        }        else if (keyPressed == 'E')         //end        {            printf("Disconnect Sequence.\n");            abort();                        //Close PPP connection        }    }}/********************************************************//*                          abort                       *//********************************************************///Close PPP connectionvoid abort(void){    HwSocketClose();                        //Disconnect PPP    EscSeq("+++");                        							      //Send escape code to modem and make it online command mode    AtModem("ATH", TRUE);               //Disconnect dial line    x_write( 0x08, 0x06 );                  //disenable modem    exit(1);                                //end}/********************************************************//*                  DialUp                              *//********************************************************/      //Dial to the service providervoid DialUp(unsigned long BAUD , char * isp_num){    BYTE baudlo;    BYTE baudhigh;    BYTE clocklo;    BYTE clockhigh;    char atdt_isp[22] = "ATDT "; //ORI ATDT = 5 , isp = 11 long ditance     baudlo   = (BYTE)( (CF/BAUD)-1 );                //Set up baud rate and clock frequency of S-7600A SDK board for    // ISA BUS    baudhigh = (BYTE)( ( (CF/BAUD)-1 ) >> 8 );      //Calculate register value     clocklo   = (BYTE) ( (CF/1000)-1 );    clockhigh = (BYTE) ( ( (CF/1000)-1 ) >> 8 );    x_write( 0x0C, baudlo );          //BAUD_Rate_Div low    x_write( 0x0D, baudhigh );        //BAUD_Rate_Div high    x_write( 0x1C, clocklo );         //Clock_Div_Low    x_write( 0x1D, clockhigh );       //Clock_Div_High    printf("Dial Up.... If Connected , Press Space bar!!\n");    AtModem("AT", TRUE);            //Confirm the modem is OK          strcat(atdt_isp , isp_num); // concatenating ATDT with phone number    AtModem(atdt_isp, FALSE);   //Dial to the service provider}/********************************************************//*                  AtModem                             *//********************************************************///Procedure of AT command releaseint AtModem(char* atc, int tryen){//atc  : Pointer to the command character line//tryen : set up the times of trial&error to obtain echo and result//Modem must be off line command mode before you call this function//To obtail S_DAV(0X08_BIT7) of S-7600A, you have to confirm//number of times of CYATA_COUNT//To obtail echo and result to the AT command, times of the //trial&error set up as MAX_TRY    int i,len, cyata0, cyata1;    BYTE stat;    char buf[BUF_SIZE + 1];    BYTE echo;    x_write(0x08, 0);             //SCTL = MPU control    timer(1);                                   //Waiting for safety reasons, because Status would be changed    stat = x_read(0x08) & 0x20;   //Confirm modem DSR    if(stat != 0){                //Can not confirm DSR of the modem        printf("Modem Hardware Error.\n");        while(1){            if(nstep() == FALSE){                       //Instruction procedure as followed                break;            }        }    }    cyata0 = 0;    cyata1 = 0;    while(1){                     //Serial Port Data Register(0x0b)        stat = x_read(0x08) & 0x80;                 //If you have invalid data, then discard        if(stat != 0){            cyata0 = 0;            cyata1++;            if(cyata1 >= CYATA_COUNT){              //To obtail S_DAV(0X08_BIT7) of S-7600A, you have to confirm    //number of times of CYATA_COUNT                cyata1 = 0;                                     //Serial Port Data Register(0x0b)                echo = x_read(0x0b);            //1 char read                             putch(echo);                continue;            }        }        else{            cyata1 = 0;            cyata0++;            if(cyata0 >= MAX_TRY){                  //Confirm 0 of S_DAV(0X08_BIT7) of S-7600A time of MAX_TRY                break;                              //Times of trial&error to obtain invalid data reaches times of      //MAX_TRY            }                                   								    //Break by judging there is no invalid data        }    }    strcpy(buf, atc);                           strcat(buf, "\r");				      //Add terminator CR:0X0d:\r to command character line    len = strlen(buf);    for(i = 0; i < len; i++){      //Serial Port Data Register(0x0b)        x_write(0x0b, (BYTE)(buf[i]));      //Write 1 char by 1 char        cyata1 = 0;        while(1){            stat = x_read(0x08) & 0x80;            if(stat != 0){                cyata1++;                                                   // Modem returnes echo of write data                if(cyata1 >= CYATA_COUNT){                                                  // Confirm 1 of S_DAV(0X08_BIT7) of S-7600A time of CYATA_COUNT                     echo = x_read(0x0b);                        //Serial Port Data Register(0x0b)                    putch(echo);                                // Read 1 char and display                    break;                }            }            else{                cyata1 = 0;            }        }        cyata0 = 0;                                 while(1){                                       stat = x_read(0x08) & 0x80;                                                     // S-7600A S_DAV(0X08_BIT7) goes 0 when write of command ended            if(stat == 0){                cyata0++;                if(cyata0 >= CYATA_COUNT){                                                  // Confirm 0 of S_DAV(0X08_BIT7) of S-7600A time of CYATA_COUNT                     break;                }            }            else{                cyata0 = 0;            }        }    }    cyata0 = 0;    cyata1 = 0;    while(1){                                                                               // Modem sends back result when write of command done        stat = x_read(0x08) & 0x80;        if(stat != 0){            cyata1++;            if(cyata1 >= CYATA_COUNT){                                                      // Confirm 1 of S_DAV(0X08_BIT7) of S-7600A time of CYATA_COUNT                 echo = x_read(0x0b);                        //Serial Port Data Register(0x0b)                putch(echo);                                // Read 1 char and display                continue;            }        }        else if(tryen == TRUE){                     // In case tryen == TRUE            cyata0++;            cyata1 = 0;                                                                             // Confirm 0 of S_DAV(0X08_BIT7) of S-7600A time of MAX_TRY            if(cyata0 >= MAX_TRY){                                                                   //Trial&error reaches the times of MAX_TRY                break;                                                                               //Return by judging sequence has been ended             }        }        if(nstep() == FALSE){                                                                //If something is input             return(FALSE);                                                                  //Get instruction for procedure folloowed         }    }    return(1);}/********************************************************//*                  EscSeq                              *//********************************************************///Procedure for escape sequensevoid EscSeq(char* atc){//atc   : Pointer for escape code character line//Modem goes online when the function is called//To obtain S_DAV(0X08_BIT7) of S-7600A, you have to confirm//number of times of CYATA_COUNT    int i,len, cyata0, cyata1;    BYTE stat;    char buf[BUF_SIZE + 1];    BYTE echo;    x_write(0x08, 0);             //SCTL = MPU control    cyata0 = 0;    cyata1 = 0;    while(1){                     //Serial Port Data Register(0x0b)        stat = x_read(0x08) & 0x80;                                                         // Sweep out all the data when invalid data left         if(stat != 0){            cyata0 = 0;            cyata1++;            if(cyata1 >= CYATA_COUNT){                                                          

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -