Ejemplo n.º 1
0
//---------------------UART_InUHex----------------------------------------
// Accepts ASCII input in unsigned hexadecimal (base 16) format
// Input: none
// Output: 32-bit unsigned number
// No '$' or '0x' need be entered, just the 1 to 8 hex digits
// It will convert lower case a-f to uppercase A-F
//     and converts to a 16 bit unsigned number
//     value range is 0 to FFFFFFFF
// If you enter a number above FFFFFFFF, it will return an incorrect value
// Backspace will remove last digit typed
uint32_t UART_InUHex(void){
uint32_t number=0, digit, length=0;
char character;
  character = UART_InChar();
  while(character != CR){
    digit = 0x10; // assume bad
    if((character>='0') && (character<='9')){
      digit = character-'0';
    }
    else if((character>='A') && (character<='F')){
      digit = (character-'A')+0xA;
    }
    else if((character>='a') && (character<='f')){
      digit = (character-'a')+0xA;
    }
// If the character is not 0-9 or A-F, it is ignored and not echoed
    if(digit <= 0xF){
      number = number*0x10+digit;
      length++;
      UART_OutChar(character);
    }
// Backspace outputted and return value changed if a backspace is inputted
    else if((character==BS) && length){
      number /= 0x10;
      length--;
      UART_OutChar(character);
    }
    character = UART_InChar();
  }
  return number;
}
Ejemplo n.º 2
0
void Interpreter(void){char inchar;

  char inString1[MAXSTRLEN];

 for(;;){
  UART_InString(inString1, MAXSTRLEN);
  
    process_cmd(inString1);
  if(StreamToFile){
		UART_OutChar('\n');
		UART_OutChar('\r');
		
    inchar = UART_InChar();
		UART_OutChar(inchar);
	
   while(inchar != 0x1B){ //while user doesn't press escape
    eFile_Write(inchar);
		inchar = UART_InChar();
		 UART_OutChar(inchar);
   }
    eFile_EndRedirectToFile();
  }
  UART_OutChar(CR);
    UART_OutChar(LF);
 }
  }
Ejemplo n.º 3
0
void xBee_ReadFrame(char * api, char * frame ){
	 unsigned int length = 0;
	int i;
	 while (UART_InChar() != 0x7e); //start delimeter of frame
	 length = ((UART_InChar() << 8) + UART_InChar());
		*api = UART_InChar();
	 for (i=0;i<length;i++)
		frame[i] = UART_InChar();
 }
Ejemplo n.º 4
0
 void sendATCommand( char * command, int waitTime, char CRout){
	 char frame2[50];
	 char done = 0;
	 char count = 0;
	 int j = 0;
	 int size;
	 int commandLen = strlen2(command);
	 for (j = 0; j < 50; j++)
		frame2[j] = 0;
	 
	 frame2[0] = 0;
	 frame2[1]  = 0;

	 do{
		 UART_OutString(command);
		 if (CRout)
			UART_OutChar(CR);
	Delay(500000*waitTime);
	j = 0;
  size = RxFifo_Size();
	while (size>0){
		frame2[j++] = UART_InChar();
		size = RxFifo_Size();
//		Delay(500000);
	}
	j = 0;
	while (frame2[j] != 'O') j++;
	if (frame2[j] == 'O' && frame2[j+1] == 'K' && frame2[j+2] == CR)
		done = 1;
	count++;
	} while (!done && count < 10);
 }
Ejemplo n.º 5
0
void UART1_Handler(void){
//Toggle Heart Beat 
  PF2 ^= 0xFF;
	PF2 ^= 0xFF;
	while((UART1_FR_R & 0x0010) == 0){
		FiFo_Put(UART_InChar());
	}
	RxCounter++;
	UART1_ICR_R = 0x10;   // this clears bit 4 (RXRIS) in the RIS register
	PF2 ^= 0xFF;
}
Ejemplo n.º 6
0
//------------UART_InString------------
// Accepts ASCII characters from the serial port
//    and adds them to a string until <enter> is typed
//    or until max length of the string is reached.
// It echoes each character as it is inputted.
// If a backspace is inputted, the string is modified
//    and the backspace is echoed
// terminates the string with a null character
// uses busy-waiting synchronization on RDRF
// Input: pointer to empty buffer, size of buffer
// Output: Null terminated string
// -- Modified by Agustinus Darmawan + Mingjie Qiu --
void UART_InString(char *bufPt, uint16_t max) {
int length=0;
char character;
  character = UART_InChar();
  while(character != CR){
    if(character == BS){
      if(length){
        bufPt--;
        length--;
        UART_OutChar(BS);
      }
    }
    else if(length < max){
      *bufPt = character;
      bufPt++;
      length++;
      UART_OutChar(character);
    }
    character = UART_InChar();
  }
  *bufPt = 0;
}
Ejemplo n.º 7
0
//------------UART_InUDec------------
// InUDec accepts ASCII input in unsigned decimal format
//     and converts to a 32-bit unsigned number
//     valid range is 0 to 4294967295 (2^32-1)
// Input: none
// Output: 32-bit unsigned number
// If you enter a number above 4294967295, it will return an incorrect value
// Backspace will remove last digit typed
uint32_t UART_InUDec(void){
uint32_t number=0, length=0;
char character;
  character = UART_InChar();
  while(character != CR){ // accepts until <enter> is typed
// The next line checks that the input is a digit, 0-9.
// If the character is not 0-9, it is ignored and not echoed
    if((character>='0') && (character<='9')) {
      number = 10*number+(character-'0');   // this line overflows if above 4294967295
      length++;
      UART_OutChar(character);
    }
// If the input is a backspace, then the return number is
// changed and a backspace is outputted to the screen
    else if((character==BS) && length){
      number /= 10;
      length--;
      UART_OutChar(character);
    }
    character = UART_InChar();
  }
  return number;
}
Ejemplo n.º 8
0
void UART1_Handler(void){
	PF1 ^= 0x02;      // Heartbeat
	PF1 ^= 0x02;      // Heartbeat
	char data;
	int x;
	while((UART1_FR_R&0x10)==0){		//while H/W RxFIFO is not empty
		data = UART_InChar();					//read data from RxFIFO
		x = Fifo_Put(data);						//put data in S/W FIFO
		if (x == 0){									//FIFO full
			Error++;
		}
		RxCounter++;								
	}
		UART1_ICR_R = 0x10;						//acknowledge
		PF1 ^= 0x02;      // Heartbeat
}
Ejemplo n.º 9
0
void XBeeInit(){
	char * commands [] = {"ATDL66", "ATDH0", "ATMY6D", "ATAP1", "ATCN", ""};
	int i = 0;
	int j;
	UART_Init();
	while (RxFifo_Size()>0){ //flush FIFO
		UART_InChar();
	}

		ID = 1;
  UART_OutString("x");
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
	 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);	 //SysTick_Wait10ms(110);		//wait waitTime number of ms;
	sendATCommand("+++", 110, 0);
	//UART_InString(response, 5);
	//RIT128x96x4StringDraw(response, 10, 10 , 15);
	
	for (i=0;i<5;i++){
		sendATCommand(commands[i], 20, 1);
	}
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
	 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10);
 SysTick_Wait10ms(10); }
Ejemplo n.º 10
0
unsigned char Bluetooth_ATcmd( void )
{
	unsigned char aux;
	
	if( UART_InCharAvailable() )
	{
		Bluetooth_OutChar( aux = UART_InChar() );
	}
	if( UART2_InCharAvailable() )
	{
	  UART_OutChar( Bluetooth_InChar() );
	}
	
	if( aux == '#' )
	  return( 0 );
	else
		return( 1 );
}
Ejemplo n.º 11
0
int main2(void){  char data;
  DisableInterrupts();
  PLL_Init(Bus80MHz);
 // LED_Init();  
  Output_Init();       // UART0 as a terminal
  printf("\n\r-----------\n\rSystem starting at 9600 baud...\n\r");

  ESP8266_InitUART(9600,true);
  ESP8266_EnableRXInterrupt();
  EnableInterrupts();
  ESP8266SendCommand("AT+RST\r\n");
  data = UART_InChar();

  
  while(1){
// echo data back and forth
    data = UART_InCharNonBlock();
    if(data){
      ESP8266_PrintChar(data);
    }
  }
}
Ejemplo n.º 12
0
void XBeeInit(){
	char * commands [] = {"ATDL66", "ATDH0", "ATMY6D", "ATAP1", "ATCN", ""};
	int i = 0;
	int j;
	unsigned long i44 = 0;
	unsigned long j44 = 0;
	unsigned long delay = 110;
//	SysTick_Init();
	UART_Init();

	while (RxFifo_Size()>0){ //flush FIFO
		UART_InChar();
	}

		ID = 1;
  UART_OutString("x");
	

//	volatile unsigned long dummy = 0;
	for (i44 = 0; i44 < delay; i44++)
		for (j44 = 0; j44 < 150000; j44++);
	//		dummy ++ ;
	
 //wait10ms(110);

//	Delay(5500000);
	 //SysTick_Wait10ms(110);		//wait waitTime number of ms;
	sendATCommand("+++", 110, 0);
	//UART_InString(response, 5);
	//RIT128x96x4StringDraw(response, 10, 10 , 15);
	
	for (i=0;i<5;i++){
		sendATCommand(commands[i], 20, 1);
	}
	for (i44 = 0; i44 < delay; i44++)
		for (j44 = 0; j44 < 150000; j44++);
//	Delay(55000000);
 }
Ejemplo n.º 13
0
// Get input from UART, echo
int fgetc (FILE *f){
  char ch = UART_InChar();  // receive from keyboard
  UART_OutChar(ch);            // echo
  return ch;
}
Ejemplo n.º 14
0
int uart_read(int dev_fd, char *buf, unsigned count){char ch;
  ch = UART_InChar();    // receive from keyboard
  ch = *buf;         // return by reference
  UART_OutChar(ch);  // echo
  return 1;
}
Ejemplo n.º 15
0
static void _SH_InCommand(char *bufPt, unsigned short max) {
	int length = 0;
	int space = 0;
	char character;
	char* startPt = bufPt;
	char* word = bufPt;
  character = UART_InChar();
  while(character != CR && character != LF && character != CTRL_C){
		if(character == ' ')
		{
			space = length;
			word = bufPt+1;
		}
    if(character == BS || character == DEL){
      if(length){
        bufPt--;
        length--;
				printf("\b \b");
      }
    }
		else if(character == CTRL_L)
		{
			int i;
			printf("\f%s", _SH_getVar(SH_PROMPT_NAME));
			for(i = 0; i < length; i++)
				UART_OutChar(startPt[i]);
		}
		else if(character == CTRL_U)
		{
			int i;
			for(i = 0; i < length + 1; i++)
			{
				printf ("\b \b");
			}
			printf("%s", _SH_getVar(SH_PROMPT_NAME));
			memset(startPt, 0, max);
			length = 0;
			bufPt = startPt;
			word = startPt;
			space = 0;
		}
		else if(character == '\t')
		{
			char fBuff[8];
			if(space) // tab complete file name
			{
				char *c = fBuff;
				memcpy(fBuff, word, length - space);
				fBuff[length - space] = 0;
				strcpy(fBuff, SH_AutoCompleteFile(fBuff, length - space - 1));
				while(*c)
				{
					*bufPt = *c;
					bufPt++;
					length++;
					UART_OutChar(*c++);
				}
			}
			else // tab complete command name
			{
				char *c = fBuff;
				memcpy(fBuff, startPt, length);
				fBuff[length] = 0;
				strcpy(fBuff, SH_AutoCompleteCommand(fBuff, length));
				while(*c)
				{
					*bufPt = *c;
					bufPt++;
					length++;
					UART_OutChar(*c++);
				}
			}
		}
		else if(character == 0x42 && length > 1
						&& startPt[length-1] == 0x5B
						&& startPt[length-2] == 0x1B) // down arrow
		{
			int i;
			printf("%c%c%c%c",  0x41, 0x1B, 0x5B, 0x42);
			if(!_SH_History[(index+1)&(SH_HISTORY-1)][0])
			{
				length -= 2;
				bufPt -= 2;
				character = UART_InChar();
				continue;
			}
			for(i = 0; i < length - 2; i++)
			{
				printf ("\b \b");
			}
			printf("\r");
			index = (index + 1) % SH_HISTORY;
			length = strlen(_SH_History[index]);
			strcpy(startPt, _SH_History[index]);
			bufPt = startPt;
			word = startPt;
			space = 0;
			UART_OutString(_SH_getVar(SH_PROMPT_NAME));
			for(; bufPt < startPt + length; bufPt++)
			{
				UART_OutChar(*bufPt);
				if(*bufPt == ' ')
				{
					space = 1;
					word = bufPt+1;
				}
			}
		}
		else if(character == 0x41 && length > 1
						&& startPt[length-1] == 0x5B
						&& startPt[length-2] == 0x1B) // up arrow
		{
			int i;
			printf("%c%c%c%c",  0x41, 0x1B, 0x5B, 0x42);
			if(!_SH_History[(index-1)&(SH_HISTORY-1)][0])
			{
				length -= 2;
				bufPt -= 2;
				character = UART_InChar();
				continue;
			}
			for(i = 0; i < length - 2; i++)
			{
				printf ("\b \b");
			}
			printf("\r");
			index = (index - 1) % SH_HISTORY;
			length = strlen(_SH_History[index]);
			strcpy(startPt, _SH_History[index]);
			bufPt = startPt;
			word = startPt;
			space = 0;
			UART_OutString(_SH_getVar(SH_PROMPT_NAME));
			for(; bufPt < startPt + length; bufPt++)
			{
				UART_OutChar(*bufPt);
				if(*bufPt == ' ')
				{
					space = 1;
					word = bufPt+1;
				}
			}
		}
    else if(length < max){
      *bufPt = character;
      bufPt++;
      length++;
      UART_OutChar(character);
    }
    character = UART_InChar();
  }
	if(character == CTRL_C)
		*startPt = 0;
  *bufPt = 0;
	if(*startPt)
	{
		strcpy(_SH_History[index], startPt);
		index = (index + 1)&(SH_HISTORY-1);
	}
}
Ejemplo n.º 16
0
int main( void )
{
	unsigned long * ptr;
	unsigned char aux;
	unsigned int tempo = 500;

	IO_Init();
	SysTick_Init_ms( tempo );
	UART_Init_16MHz();
	Nokia5110_Init();
	Bluetooth_Init();
	
  Nokia5110_OutString("SENAI");	

	for(;;)
	{
		if( UART_InCharAvailable() )
			Bluetooth_OutChar( UART_InChar() );
		
		if( Bluetooth_InCharAvailable() )
		  UART_OutChar ( aux = Bluetooth_InChar() );


		if( SysTickRun() )
		{
			if( *ptr )
		    *ptr = 0x00; 
			else
			  *ptr = 0xFF; 
		}

			switch( aux )
			{
				case 0:
				case 'R': 	*ptr = 0x00; ptr = (unsigned long *)&LED_RED;				break;
				case 'B': 	*ptr = 0x00; ptr = (unsigned long *)&LED_BLUE;			break;
				case 'G': 	*ptr = 0x00; ptr = (unsigned long *)&LED_GREEN;			break;
				case 'Y': 	*ptr = 0x00; ptr = (unsigned long *)&LED_YELLOW;		break;
				case 'P': 	*ptr = 0x00; ptr = (unsigned long *)&LED_PINK;			break;
				case 'S': 	*ptr = 0x00; ptr = (unsigned long *)&LED_SKYBLUE;		break;
				case 'W':   *ptr = 0x00; ptr = (unsigned long *)&LED_WHITE;			break;
				case 'D':   *ptr = 0x00; ptr = (unsigned long *)&LED_DARK;			break;
				case 'T': 	DHT11_In( (unsigned long *) &sensor );
										UART_OutString( "Temp: " );
										UART_OutUDec( (unsigned long)sensor.temperatura );
										UART_OutString( "\r\n" );
										Bluetooth_OutString( "Temp: " );
										Bluetooth_OutUDec( (unsigned long)sensor.temperatura ); 		
										Bluetooth_OutString( "\r\n" );
										SysTick_Init_ms( tempo );
										break;
				case 'U': 	DHT11_In( (unsigned long *) &sensor );
										UART_OutString( "Umidade: " );
										UART_OutUDec( (unsigned long)sensor.umidade );
										UART_OutString( "\r\n" );
										Bluetooth_OutString( "Umidade: " );
										Bluetooth_OutUDec( (unsigned long)sensor.umidade ); 
										Bluetooth_OutString( "\r\n" );
										SysTick_Init_ms( tempo );
										break;
			}


	} //for(;;)	
} //int main( void )
Ejemplo n.º 17
0
// input from UART, return data.
int fgetc(FILE *f){
	char ch;
	ch = UART_InChar();
	UART_OutChar(ch);
  return ch;
}
Ejemplo n.º 18
0
void Interpreter(void)    // just a prototype, link to your interpreter
{
	uint32_t stringSize;
	uint32_t adcVoltage;
	uint8_t deviceChosen;
	uint8_t taskAddedBefore = 0;
	uint8_t commandChosen = -1;
	char message[MESSAGELENGTH] = "";
	OutCRLF();
	UART_OutString("Input Command: ");
	while(1){
		OutCRLF();
		//UART_OutString("Commands: 0 - ADC, 1 - LCD, 2 - Time");
		OutCRLF();
		commandChosen = UART_InChar();
		switch(commandChosen)
		{
			case '0':
				OutCRLF();
				UART_OutString("ADC Voltage = ");
				//ADC_Open(4);
				adcVoltage = (ADC_In() *3300) / 4095; //convert to mV
				UART_OutUDec(adcVoltage);
				OutCRLF();
				break;
			case '1':
				OutCRLF();
				UART_OutString("Enter LCD device 0 or 1: ");
				deviceChosen = UART_InUDec();
				OutCRLF();
				UART_OutString("Enter message: ");
				UART_InString(message, MESSAGELENGTH);
				OutCRLF();
				stringSize = strlen(message);
				if(stringSize > 20)
				{
					OutCRLF();
					UART_OutString("String too long...");
					OutCRLF();
				}
				LCD_test(deviceChosen, message); //prints to lcd
				OutCRLF();
				break;
			case '2':
				if(!taskAddedBefore){
					OS_AddPeriodicThread(dummy, 5, 1);
					taskAddedBefore = 1;
				}
				OutCRLF();
				UART_OutUDec(OS_ReadPeriodicTime());
				OutCRLF();
				break;
			case '3':
				UART_OutString("NumSamples: ");
				UART_OutUDec(NumSamples);
				OutCRLF();
				break;
			case '4':
				UART_OutString("Jitter: ");
				UART_OutUDec(MaxJitter);
				OutCRLF();
				break;
			case '5':
				UART_OutString("DataLost: ");
				UART_OutUDec(DataLost);
				OutCRLF();
				break;
			case '6':
				UART_OutString("FilterWork: ");
				UART_OutUDec(FilterWork);
				OutCRLF();
				break;
			case '7':
				UART_OutString("NumCreated: ");
				UART_OutUDec(NumCreated);
				OutCRLF();
				break;
			case '8':
				for(int i = 0; i<64; i++)
				{
					UART_OutUDec(x[i]);
					OutCRLF();
				}
				break;
			default:
				UART_OutString("Incorrect command!");
				break;
		}

		//adcSample = ADC_In();
		//ST7735_SetCursor(0,0);
		//ST7735_OutUDec(adcSample);
	
	}
}
Ejemplo n.º 19
0
int fgetc (FILE *f){
 return (UART_InChar());
}
Ejemplo n.º 20
0
Archivo: Xbee.c Proyecto: liulvc/EE445L
unsigned int XBee_RecieveRxFrame(void){
	unsigned char byte; 
	unsigned short tempNum = 0;
	unsigned short messageLength = 0;
	unsigned short bufferIdx = 0;
	
	if (RxFifo_Size()>0) byte = UART_InChar();
	else return 0;
	
	if(decryptionStage == 0){
		if(byte == 0x7E){
			decryptionStage += 1;
			RxCheckSum = 0;
			//printf("%c",byte);
		}
	}
	else if(decryptionStage == 1){
		tempNum = byte;
		tempNum = tempNum << 8;
		byte = UART_InChar();
		tempNum = tempNum + byte;
		RxFrameLength = tempNum;
		decryptionStage += 1;
	}
	else if(decryptionStage == 2){
		RxFrameType = byte;
		RxCheckSum += byte;
		decryptionStage += 1;
	}
	else if(decryptionStage == 3){
		RxFrameId = byte;
		RxCheckSum += byte;
		decryptionStage += 1;
	}
	else if(decryptionStage == 4){
		tempNum = byte;
		RxCheckSum += byte;
		tempNum = tempNum << 8;
		byte = UART_InChar();
		RxCheckSum += byte;
		tempNum = tempNum + byte;
		TxAdrs= tempNum;
		decryptionStage += 1;
	}
	else if(decryptionStage == 5){
		RxCheckSum += byte;
		decryptionStage += 1;
	}
	else if(decryptionStage == 6){
		messageLength = RxFrameLength - 5;
//		messageBuffer[bufferIdx] = byte;
//		bufferIdx += 1;
//		messageLength -= 1;
		RxCheckSum += byte;
		messageBuffer[bufferIdx] = byte;
		for(bufferIdx = 1; bufferIdx <messageLength; bufferIdx++){
		  messageBuffer[bufferIdx] = UART_InChar();
			RxCheckSum += messageBuffer[bufferIdx];
		}
		newMessage = 1;
		messageBuffer[bufferIdx] = 0;
	//	printf("%s",messageBuffer);
		decryptionStage += 1;
	}
	else if(decryptionStage == 7){
		decryptionStage = 0;
		frameCheckSum = byte;
		if((RxCheckSum + frameCheckSum) == 0xFF){
			successfulDecryption = 1;
		}
		else{
			successfulDecryption = 0;
		}
	}
	return decryptionStage;

}