//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();

  }
}
Пример #2
0
void UART_OutUDec(unsigned long n,int i){
  if(n >= 10){
    UART_OutUDec(n/10,i);
    n = n%10;
  }
	switch(i)
	{
		case 1:
						UART1_OutChar(n+'0'); /* n is between 0 and 9 */
						break;
		case 2:
						UART2_OutChar(n+'0');
						break;
		case 3:
						UART3_OutChar(n+'0');
						break;
		case 4:
						UART4_OutChar(n+'0');
						break;
		case 5:
						UART5_OutChar(n+'0');
						break;
		case 7:
						UART7_OutChar(n+'0');
						break;
	}
}
Пример #3
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 */
}
// do not edit this main
// your job is to implement the UART_OutUDec UART_OutDistance functions 
int main(void){ unsigned long n;
  TExaS_Init();             // initialize grader, set system clock to 80 MHz
  UART_Init();              // initialize UART
  EnableInterrupts();       // needed for TExaS
  UART_OutString("Running Lab 11");
  while(1){
    UART_OutString("\n\rInput:");
    n = UART_InUDec();
    UART_OutString(" UART_OutUDec = ");
    UART_OutUDec(n);     // your function
    UART_OutString(",  UART_OutDistance ~ ");
    UART_OutDistance(n); // your function
  }
}
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);
}
int main(void){

PLL_Init();
SysTick_Init();
	
UART4_Init();
	Edge_Detect_Init();

	Timer_Capture_Init();
	UART_OutUDec(1,4);
while(1)
{
	 SysTick_Wait10ms(100);

	if(((1<<TIMER0_RIS_R)&(0x1)))
	{
		TIMER0_ICR_R|=(1<<1);
		UART_OutUDec(TIMER0_TAR_R,4);
		New_Line(4);
		
	}
	
}
}
Пример #7
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 )
Пример #8
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);
	
	}
}
Пример #9
0
//-----------------------UART_OutUDecNL-----------------------
// Runs UART_OutUDec() and adds a new line.
// Input: 32-bit number to be transferred
// Output: none
// Variable format 1-10 digits with no space before or after
void UART_OutUDecNL(uint32_t n){
	UART_OutUDec(n);
	UART_OutCRLF();
}