Exemplo 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;
}
Exemplo n.º 2
0
// Print a character to UART.
int fputc(int ch, FILE *f){
  if((ch == 10) || (ch == 13) || (ch == 27)){
    UART_OutChar(13);
    UART_OutChar(10);
    return 1;
  }
  UART_OutChar(ch);
  return 1;
}
Exemplo n.º 3
0
void Xbee_Init(unsigned char ChannelNum){
	unsigned char nextStep = 0;
	SysTick_Init();

//	printf("Initializing...%c",NEWLINE);
	while(nextStep == 0){
		UART_OutChar('x');
		SysTick_Wait10ms(110);//wait 1.1ms
		UART_OutChar('+');
		UART_OutChar('+');
		UART_OutChar('+');
		SysTick_Wait10ms(110);//wait 1.1ms
		nextStep = lookforCR();
	}
//	printf("okay1%c",NEWLINE);
	nextStep = 0;
	while(nextStep == 0){
		UART_OutString(ATCMD1);
		SysTick_Wait10ms(2);
		nextStep = lookforCR();
	}
//	printf("okay2%c",NEWLINE);
	nextStep = 0;
	while(nextStep == 0){
		UART_OutString(ATCMD2);
		SysTick_Wait10ms(2);
		nextStep = lookforCR();
	}
//	printf("okay3%c",NEWLINE);
	nextStep = 0;
	while(nextStep == 0){
		UART_OutString(ATCMD3);
		SysTick_Wait10ms(2);
		nextStep = lookforCR();
	}
//	printf("okay4%c",NEWLINE);
	nextStep = 0;
	while(nextStep == 0){
		UART_OutString(ATCMD4);
		SysTick_Wait10ms(2);
		nextStep = lookforCR();
	}
	//printf("okay5%c",NEWLINE);
	nextStep = 0;
	while(nextStep == 0){
		UART_OutString(ATCMD5);
		SysTick_Wait10ms(2);
		nextStep = lookforCR();
	}
//	printf("okay6%c",NEWLINE);
}
Exemplo n.º 4
0
SYSTICK HANDLER
	

void SysTick_Handler()
{
	  GPIO_PORTG_DATA_R ^= 0x4;
		sample = ADC_In();
		GPIO_PORTG_DATA_R ^= 0x4;
		sample = Convert(sample);
		thousands = sample%1000;
		hundreds = (sample%100)-(thousands*10);
		tens = (sample%10) - ( (hundreds*10) + (thousands*100) );
		ones = ( sample - (tens*10 + hundreds*100 + thousands*1000 ) );
	
	
		UART_OutChar(0x2);									// STx
		UART_OutChar((thousands)+0x30);		// first number ASCII
	  UART_OutChar(0x2E);									// dot ASCII
		UART_OutChar( (hundreds) + 0x30);		// second number ASCII
	  UART_OutChar( tens +0x30);					// third
		UART_OutChar(ones +0x30);					// last number ASCII
		UART_OutChar(0x0D);								// CR, whatever that is
		UART_OutChar(0x3);			 					// ETx
	
		samplecount++;
	
		GPIO_PORTG_DATA_R ^= 0x4;
		
}
void UART_OutUDec(long long n,int i)
{
	if(n<0)
	{
		n=-n;
		UART_OutChar('-',i);
	}
  if(n>=10)
	{
    UART_OutUDec(n/10,i);
    n%=10;
  }
	UART_OutChar(n+'0',i);
}
Exemplo n.º 6
0
//------------UART_OutString------------
// Output String (NULL termination)
// Input: pointer to a NULL-terminated string to be transferred
// Output: none
void UART_OutString(unsigned char buffer[]){
// as part of Lab 11 implement this function
   int i;
	 for(i = 0; buffer[i] != '\0'; ++i) {
			UART_OutChar(buffer[i]);    
		}
}
Exemplo n.º 7
0
Arquivo: Lab5.c Projeto: oujoshua/445M
void TestFile(void){   int i; char data; 
  printf("\n\rEE345M/EE380L, Lab 5 eFile test\n\r");
  // simple test of eFile
  //if(eFile_Init())              diskError("eFile_Init",0); 
  if(eFile_Format())            diskError("eFile_Format",0); 
  eFile_Directory(&printf);
  if(eFile_Create("file1"))     diskError("eFile_Create",0);
  if(eFile_WOpen("file1"))      diskError("eFile_WOpen",0);
  for(i=0;i<1000;i++){
    if(eFile_Write('a'+i%26))   diskError("eFile_Write",i);
    if(i%52==51){
      if(eFile_Write('\n'))     diskError("eFile_Write",i);  
      if(eFile_Write('\r'))     diskError("eFile_Write",i);
    }
  }
  if(eFile_WClose())            diskError("eFile_Close",0);
  eFile_Directory(&printf);
  if(eFile_ROpen("file1"))      diskError("eFile_ROpen",0);
  for(i=0;i<1000;i++){
    if(eFile_ReadNext(&data))   diskError("eFile_ReadNext",i);
    UART_OutChar(data);
  }
  if(eFile_Delete("file1"))     diskError("eFile_Delete",0);
  eFile_Directory(&printf);
  printf("Successful test of creating a file\n\r");
 // OS_Kill();
}
//------------UART_OutString------------
// Output String (NULL termination)
// Input: pointer to a NULL-terminated string to be transferred
// Output: none
void UART_OutString(unsigned char buffer[]){
// as part of Lab 11 implement this function
 while(*buffer){
    UART_OutChar(*buffer);
    buffer++;
  }
}
Exemplo n.º 9
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);
 }
Exemplo n.º 10
0
//--------------------------UART_OutUHex----------------------------
// Output a 32-bit number in unsigned hexadecimal format
// Input: 32-bit number to be transferred
// Output: none
// Variable format 1 to 8 digits with no space before or after
void UART_OutUHex(uint32_t number){
// This function uses recursion to convert the number of
//   unspecified length as an ASCII string
  if(number >= 0x10){
    UART_OutUHex(number/0x10);
    UART_OutUHex(number%0x10);
  }
  else{
    if(number < 0xA){
      UART_OutChar(number+'0');
     }
    else{
      UART_OutChar((number-0x0A)+'A');
    }
  }
}
Exemplo n.º 11
0
// copy from hardware RX FIFO to software RX FIFO
// stop when hardware RX FIFO is empty or software RX FIFO is full
void static copyHardwareToSoftware(void){
  char letter;
  while(((UART0_FR_R&UART_FR_RXFE) == 0) && (RxFifo_Size() < (FIFOSIZE - 1))){
    letter = UART0_DR_R;
    RxFifo_Put(letter);
		UART_OutChar(letter); 
  }
}
Exemplo n.º 12
0
int uart_write(int dev_fd, const char *buf, unsigned count){ unsigned int num=count;
  while(num){
    UART_OutChar(*buf);
    buf++;
    num--;
  }
  return count;
}
//------------UART_OutString------------
// Output String (NULL termination)
// Input: pointer to a NULL-terminated string to be transferred
// Output: none
void UART_OutString(unsigned char buffer[]){
// written by Billy.Ljm
	int i = 0;
	while(buffer[i]){
		UART_OutChar(buffer[i]);
		i++;
	}
}
Exemplo n.º 14
0
// Internal use only
void Sound_Transmit(uint8_t sound, uint8_t loop) {
	UART_OutChar(0x02);
	UART_OutChar(sound);
	UART_OutChar(loop);
	UART_OutChar(0x00);
	UART_OutChar(0x00);
	UART_OutChar(0x00);
	UART_OutChar(0x00);
	UART_OutChar(0x03);
}
Exemplo n.º 15
0
//-----------------------UART_OutUDec-----------------------
// Output a 32-bit number in unsigned decimal format
// Input: 32-bit number to be transferred
// Output: none
// Variable format 1-10 digits with no space before or after
void UART_OutUDec(uint32_t n){
// This function uses recursion to convert decimal number
//   of unspecified length as an ASCII string
  if(n >= 10){
    UART_OutUDec(n/10);
    n = n%10;
  }
  UART_OutChar(n+'0'); /* n is between 0 and 9 */
}
Exemplo n.º 16
0
//------------UART_OutString------------
// Output String (NULL termination)
// Input: pointer to a NULL-terminated string to be transferred
// Output: none
void UART_OutString(unsigned char buffer[]){
// as part of Lab 11 implement this function
  int i=0;
  while(buffer[i]!='\0'){
    UART_OutChar(buffer[i]);
    i++;
  }

}
Exemplo n.º 17
0
Arquivo: Xbee.c Projeto: liulvc/EE445L
void XBee_TxStatus(void){
	UART_OutChar(0x7E);
	UART_OutChar(0x00);
	UART_OutChar(0x03);
	UART_OutChar(0x89);
	UART_OutChar(RxFrameId);
	if(successfulDecryption == 1){
		UART_OutChar(0x01);
		UART_OutChar(0x84);
	}
	else{
		UART_OutChar(0x00);
		UART_OutChar(0xB5);
	}
}
Exemplo n.º 18
0
int fputc (int ch, FILE *f) {
 if(streamToFile()){
	if(eFile_Write(ch)){ // close file on error
		eFile_EndRedirectToFile(); // cannot write to file
		return 1; // failure
	}
	return 0; // success writing
 }
 // regular UART output
 UART_OutChar(ch);
 return 0;
}
Exemplo n.º 19
0
 void XBeeSendTxFrame(char * frame, int len){
	 
	 int i;
	 char a;
//	 UART_OutArray(frame, len);
//	 UART_OutString(frame);
	 for (i=0;i<len;i++){
		a = frame[i];
		UART_OutChar(frame[i]);
	 }
	 
 }
Exemplo n.º 20
0
//debug code
int main(void){
  char ch;
  char string[20];  // global to assist in debugging
  uint32_t n;

  PLL_Init(Bus50MHz);       // 50  MHz
  UART_Init();              // initialize UART
  
  OutCRLF();
  for(ch='A'; ch<='Z'; ch=ch+1){// print the uppercase alphabet
    UART_OutChar(ch);
  }
  OutCRLF();
  UART_OutChar(' ');
  for(ch='a'; ch<='z'; ch=ch+1){// print the lowercase alphabet
    UART_OutChar(ch);
  }
  OutCRLF();
  UART_OutChar('-');
  UART_OutChar('-');
  UART_OutChar('>');
  while(1){
    UART_OutString("InString: ");
    UART_InString(string,19);
    UART_OutString(" OutString="); UART_OutString(string); OutCRLF();

    UART_OutString("InUDec: ");  n=UART_InUDec();
    UART_OutString(" OutUDec="); UART_OutUDec(n); OutCRLF();

    UART_OutString("InUHex: ");  n=UART_InUHex();
    UART_OutString(" OutUHex="); UART_OutUHex(n); OutCRLF();

  }
}
Exemplo n.º 21
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);
 }
  }
Exemplo n.º 22
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;
}
Exemplo n.º 23
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;
}
Exemplo n.º 24
0
int main(void){
	
	unsigned int i;
	unsigned char string[10] = {'A','B','C','D','E','F','G','H','I','J'};
	PLL_Init();
	Nokia5110_Init();
	UART_Init();
	
	while(1)
	{
	for(i=0;i<10;i++)
	{aa
	UART_OutChar(string[i]);
	}
	}
}
Exemplo n.º 25
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 );
}
Exemplo n.º 26
0
int main(void) {
    // Initialize all hardware
    PLL_Init();
    eStopInit();
    encoderInit(actlPos);
    motorInit();
    lightsInit();
    lightsUpdate(COLOR_RED);
    UART_Init();
    Timer1_Init();
    softRun();
    
    // Send welcome message to UART terminal
    UART_OutChar('W');UART_OutChar('e');UART_OutChar('l');UART_OutChar('c');
    UART_OutChar('o');UART_OutChar('m');UART_OutChar('e');
    UART_OutChar(CR);UART_OutChar(LF);
 
    // Spin forever
    while(1) {
        parse(UART_InUDec()); // read commands from UART
            
        // All other functions performed by Timer 1 interrupt handler
    }
}
Exemplo n.º 27
0
void SysTick_Handler(void){ // every 25 ms
	
	uint8_t ADC_Temp[8];
	uint8_t i;
//Toggle Heartbeat Twice
	PF3 ^= 0xFF;          
  PF3 ^= 0xFF;
//Sample the ADC
	ADCMail = ADC_In();
//Set Flag
	ADCStatus = fresh;
	PF3 ^= 0xFF;
//Send Measurement to UART_OutChar
	ADCMail = Convert(ADCMail);
	ADC_Temp[0] = 0x02;
	ADC_Temp[1] = (ADCMail/1000);
	ADCMail -= 1000*ADC_Temp[1];
	ADC_Temp[1] += 0x30;
	ADC_Temp[2] = 0x2E;
	ADC_Temp[3] = ADCMail/100;
	ADCMail -= 100*ADC_Temp[3];
	ADC_Temp[3] += 0x30;
	ADC_Temp[4] = ADCMail/10;
	ADCMail -= 10*ADC_Temp[4];
	ADC_Temp[4] += 0x30;
	ADC_Temp[5] = ADCMail;
	ADC_Temp[5] += 0x30;
	ADC_Temp[6] = 0x0D;
	ADC_Temp[7] = 0x03;
	for(i=0; i<8; i++){
		UART_OutChar(ADC_Temp[i]);
	}
//Increment Counter
	TxCounter++;
//Toggle LED
	PF3	 ^= 0xFF;


}
Exemplo n.º 28
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;
}
Exemplo n.º 29
0
// this is used for printf to output to the usb uart
int fputc(int ch, FILE *f){
  UART_OutChar(ch);
  return 1;
}
Exemplo n.º 30
0
//------------UART_OutString------------
// Output String (NULL termination)
// Input: pointer to a NULL-terminated string to be transferred
// Output: none
void UART_OutString(char *pt){
  while(*pt){
    UART_OutChar(*pt);
    pt++;
  }
}