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

📄 telnet.c

📁 embedded ethernet code for pic18F
💻 C
字号:
#include <p18cxxx.h>
#include <usart.h>
#include <delays.h>
#include "sockets.h"

//******************************************************************
//*	Application Code
//*   Your application code goes here.
//*   Following a * this module writes the hex value that follows
//*   the * to the 74HCT573 latch..
//*   Use Telnet to connect.
//*   Example:  *55 writes 01010101 to the 74HCT573 latch
//******************************************************************



unsigned const rom char telnet_banner8089[]="\r\nEDTP ethernet 8089>";
unsigned const rom char telnet_latch_banner[]="\r\nLatched byte to output\r\nEDTP ethernet 8089>";

const rom char alphabet[]="0123456789abcdef";

void printByte(unsigned char output)
{
	while(BusyUSART());
	putcUSART(alphabet[output>>4]);
	while(BusyUSART());
	putcUSART(alphabet[output&15]);
	while(BusyUSART());
}


unsigned int inputBytes2=0;
unsigned char flag2=0;

#define NONE 0
#define ECHO 1
#define NEWLINE 2
#define LATCH 3

void put8089(int bytesIn,FLAGS *flags,unsigned char *dataPacket)
{
   static unsigned char latched=0; 
   static unsigned char cntr2=0;
   static unsigned char hexflag2=0;
   static unsigned char byteout2;
   unsigned char i,j,dataHex;

   cntr2++;
   
   //if(FLAGbits.debug)
   //{
	   //if(hexflag==1) putrsUSART("Hexflag on ");
	   //else putrsUSART("Hexflag off ");
	   //putrsUSART("cntr = ");
	   //printInteger(cntr);
	   //putrsUSART("\r\n");
 //}
 
 
 
 if(dataPacket[0] != 0x0A)
 {
	 flag2=ECHO;
	 inputBytes2=bytesIn;
  }
   
   if(dataPacket[0] == '*')
   {
	 putrsUSART("Latch mode\r\n");
	 hexflag2=1;
     cntr2=0;
   }
   else if(hexflag2==1)
   {
	 putrsUSART("Hex on\r\n");
	 if(dataPacket[0] >= '0' && dataPacket[0] <= '9') dataHex=dataPacket[0] - 0x30;
	 else if(dataPacket[0] >= 'A' && dataPacket[0] <= 'F') dataHex=dataPacket[0] - 0x37;
	 else if(dataPacket[0] >= 'a' && dataPacket[0] <= 'f') dataHex=dataPacket[0] - 0x67;
     else 
     {
	     hexflag2=0;
	     cntr2=0;
	 }
     if(cntr2 == 1)
     {
	   putrsUSART("Top nibble\r\n");
	   byteout2 = (dataHex &0xf) << 4;
     }
	 if(cntr2 == 2)
     {
	   putrsUSART("Bottom nibble\r\n");  
       byteout2 |= dataHex & 0x0F;
       TRISD=0xff;
       PORTD=byteout2;
       PORTCbits.RC1=1;
       Delay10TCYx(1);
       PORTCbits.RC1=0;
       hexflag2=0;
       putrsUSART("Byte latched out was ");printByte(byteout2);putrsUSART("\r\n");
       flag2=LATCH;
     }
   }
   
   
	   
   
   if(dataPacket[0] == 0x0A)
   {
      flag2=NONE;
      hexflag2=0;
   }
   
   if ((dataPacket[0] == 0x0D||isFirstPacket(flags)))
   {
         flag2=NEWLINE;
   }
   
    
 }


unsigned int get8089(FLAGS *flags,unsigned char *dataPacket)
 {
	 unsigned int bytesOut,i,j;
	 
	 switch(flag2)
	 {
		 case ECHO:
		 	bytesOut=inputBytes2;
		 	break;
		 case NEWLINE:
		 	bytesOut = sizeof(telnet_banner8089);
	     	for(i=0;i<bytesOut;++i) dataPacket[i] = telnet_banner8089[i];
	     	break;
	     case LATCH:
	     	j=sizeof(telnet_latch_banner);
       		for(i=0;i<j;i++) dataPacket[1+i]=telnet_latch_banner[i];
       		bytesOut=1+j;
       		break;
	     default:
	     	bytesOut=0;
	     	break;
	  }
	  flag2=NONE;
	  return bytesOut;
}

⌨️ 快捷键说明

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