/***************************************************EEPROM*****************************************
 				Writes and Reads a character to and from EEPROM
*****************************************************TEST*****************************************/
void eeprom_test()
{
	 unsigned char eeprom_address=0x00, write_char = 'X', read_char;
	 
	UART_Printf("Connections SCL->P0.6 SDA->P0.7");
	UART_Printf("Make connections and hit 'k' to test! ");
        while(UART_RxChar()!='k');
	 UART_TxString("\n\rEeprom Write: ");      //Print the message on UART
	 UART_TxChar(write_char);			         //Print the char to be written 
	 EEPROM_WriteByte(eeprom_address,write_char);	// Write the data at memoryLocation	0x00

	 UART_TxString("  Eeprom Read: ");            //Print the message on UART
	 read_char = EEPROM_ReadByte(eeprom_address);	// Read the data from memoryLocation 0x00
	 UART_TxChar(read_char);	
}
void UART_TxNumber(unsigned int num)
{

	   UART_TxChar((num/10000)+0x30);
	   num=num%10000;

	   UART_TxChar((num/1000)+0x30);
	   num=num%1000;

	   UART_TxChar((num/100)+0x30);
	   num=num%100;

	   UART_TxChar((num/10)+0x30);

       UART_TxChar((num%10)+0x30);
}
Example #3
0
int main(void)
{
    uint16_t adc_result;
	int i;
	char value[10];
	sbi(DDRB, 4);
	sbi(DDRC, 5);
	cbi(PORTB,4);
	sbi(PORTC,5);	
    UART_init(250000);
	InitADC();
	sei();
	
	
	
	while(1)
	{
	adc_result=ReadADC(2);           // Read Analog value from channel-2
    // Voltage = adc_result*5/1024
	// Temperature = (V  -  1035 mV)/(-5.5 (mV/oC))
	itoa(adc_result,value,10);
	for(i=0;i<=2;i++){
	UART_TxChar(value[i]);}
	UART_TxStr("\n\r\0");
	PORTB ^= (1<<PB4);	
	_delay_ms(100);
	}
	
}
Example #4
0
/*
  ShowProducts routine

  This routine shows the products found in each bay.
 */
void ShowProducts(void)
{
  Uint8 Pos;


  UART_TxStr("Inputs are:");
  for (Pos = 0; Pos <= RightTablet; Pos++) {
    UART_TxChar(' ');
    UART_TxNum(InputPresent[Pos], 1);
  }
  UART_TxStr("\r\nOutputs are:");
  for (Pos = LeftBay; Pos <= RightBay; Pos++) {
    UART_TxChar(' ');
    UART_TxNum(BayProduct[Pos], 1);
  }
  UART_TxNewLine();
}
int main() 
{

    UART_Init(9600);  // Initialize UARt at 9600 baud rate
    
    while(1)
    {
        UART_TxChar('e');
    }
    return (0);
}
Example #6
0
/* Compute the 16-bit crc of the loaded application.
 * Syntax: crc
 * Response: uint16_t
 */
static void CalcAppCRC_CMD(const char *cmdbuf, uint8_t len)
{
	union
	{
		uint16_t val;
		uint8_t  by[2];
	} crc;

	crc.val = CalculateAppCRC();

	UART_TxHexByte(crc.by[1]);
	UART_TxHexByte(crc.by[0]);
	UART_TxChar('\r');
}
Example #7
0
void UART_TxDecimalNumber(uint32_t var_decNumber_u32, uint8_t var_numOfDigitsToTransmit_u8)
{
	uint8_t i=0,a[10];

	if(var_decNumber_u32==0)
	{
		/* If the number is zero then update the array with the same for transmitting */
		for(i=0;((i<var_numOfDigitsToTransmit_u8) && (i<C_MaxDigitsToTransmit_U8)) ;i++)
		   a[i] = 0x00;
	}
	else
	{
		for(i=0;i<var_numOfDigitsToTransmit_u8;i++)
		{
			/* Continue extracting the digits from right side
			   till the Specified var_numOfDigitsToTransmit_u8 */
			if(var_decNumber_u32!=0)
			{
				/* Extract the digits from the number till it becomes zero.
			    First get the remainder and divide the number by 10 each time.
                If var_number_u32 = 123 then extracted remainder will be 3 and number will be 12.
				The process continues till it becomes zero or max digits reached*/
				a[i]=util_GetMod32(var_decNumber_u32,10);
				var_decNumber_u32=var_decNumber_u32/10;
			}
			else if( (var_numOfDigitsToTransmit_u8 == C_DefaultDigitsToTransmit_U8) ||
					(var_numOfDigitsToTransmit_u8 > C_MaxDigitsToTransmit_U8))
			{
				/* Stop the iteration if the Max number of digits are reached or
			     the user expects exact(Default) digits in the number to be transmitted */ 
				break;
			}
			else
			{
				/*In case user expects more digits to be transmitted than the actual digits in number,
  			    then update the remaining digits with zero.
                Ex: var_number_u32 is 123 and user wants five digits then 00123 has to be transmitted */
				a[i]=0;
			}
		}
	}

	while(i)
	{ 
		/* Finally get the ascii values of the digits and transmit*/
		UART_TxChar(util_Dec2Ascii(a[i-1]));
		i--;
	}
}
/* start the main program */
void main() 
{
   	 char ch;

  /* Initilize the UART before Transmitting/Receiving any data */
    UART_Init();

   while(1)
    {
	    /*Receive and Transmit a char indefinitely at 9600 baud rate */
	     ch=UART_RxChar(); // Receive a char and store it in "ch"
        
         UART_TxChar(ch);  //Transmit the received char
	  }	   

  }
void UART_RxString(uint8_t var_uartChannel_u8, char *ptr_stringPointer_u8)
{
    char ch;
    while(1)
    {
        ch=UART_RxChar(var_uartChannel_u8);    //Receive a char
        UART_TxChar(var_uartChannel_u8,ch);     //Echo back the received char

        if((ch=='\r') || (ch=='\n')) //read till enter key is pressed
        {                             //once enter key is pressed null terminate the string
            *ptr_stringPointer_u8=0;           //and break the loop
            break;                  
        }
        *ptr_stringPointer_u8=ch;              //copy the char into string and increment the pointer
        ptr_stringPointer_u8++;
    }
}
/*---------------------------------------------------------------------------------
                         void UART_RxString(char *string_ptr)
 ----------------------------------------------------------------------------------
 * I/P Arguments: *string_ptr
                   Address of the string where the received data needs to be stored
 * Return value	: none

 * description  :
                1.This function is used to receive a ASCII string through UART
                  till the carriage_return/New_line
                2.The string_ptr points to the begining of the string and each
                  time UART_RxChar() function is called to receive a char and copy
                  it into the buffer(STRING) and incrment string_ptr.
                3.Once the carriage_return/New_line is encountered the loop
                  is breaked and the String is NULL terminated.

 *****NOTE*******:
  1.The received char is ECHOED back,
    if not required then comment UART_TxChar(ch) in the code.
  2.BackSlash is not taken care.
___________________________________________________________________________________*/
void UART_RxString(char *string_ptr)
 {
     char ch;
     while(1)
       {
          ch=UART_RxChar();    //Reaceive a char
          UART_TxChar(ch);     //Echo back the received char

		 if((ch=='\r') || (ch=='\n')) //read till enter key is pressed
           {						  //once enter key is pressed
              *string_ptr=0;          //null terminate the string
                break;				  //and break the loop
             }
         *string_ptr=ch;              //copy the char into string.
         string_ptr++;				  //and increment the pointer
      }
 }
void UART_TxFloatNumber(uint8_t var_uartChannel_u8, float var_floatNumber_f32)
{
    uint32_t var_tempNumber_u32;
    /* Dirty hack to support the floating point by extracting the integer and fractional part.
      1.Type cast the number to int to get the integer part.
      2.transmit the extracted integer part followed by a decimal point(.).
      3.Later the integer part is made zero by subtracting with the extracted integer value.
      4.Finally the fractional part is multiplied by 100000 to support 6-digit precision */

    var_tempNumber_u32 = (uint32_t) var_floatNumber_f32;
    UART_TxNumber(var_uartChannel_u8,C_DECIMAL_U8,var_tempNumber_u32,C_DefaultDigitsToTransmit_U8);

    UART_TxChar(var_uartChannel_u8,'.');

    var_floatNumber_f32 = var_floatNumber_f32 - var_tempNumber_u32;
    var_tempNumber_u32 = var_floatNumber_f32 * 1000000;
    UART_TxNumber(var_uartChannel_u8,C_DECIMAL_U8,var_tempNumber_u32,C_DefaultDigitsToTransmit_U8);
}
Example #12
0
/*
  SetBassTreble routine

  This routine writes the setting values to the MP3 bass/treble settings
  and displays them.
 */
void SetBassTreble(void)
{
  Uint16 Treble;


  // Write current settings to MP3 chip

  vs_set_bass(Settings.TrebleLevel, Settings.BassLevel,
      Settings.TrebleFreq,  Settings.BassFreq);

  // Show them to the user

  UART_TxStr("Bass   ");
  if (Settings.BassLevel) {
    UART_TxChar('+');
    UART_TxNum(Settings.BassLevel, 1);
    UART_TxStr("dB at ");
    UART_TxNum(Settings.BassFreq, 1);
    UART_TxStr("0Hz");
  } else {
    UART_TxStr("off");
  }

  UART_TxStr("\r\nTreble ");
  if (Settings.TrebleLevel == 0) {
    UART_TxStr("off\r\n");
  } else {
    if (!(Settings.TrebleLevel & 0b10000000)) {
      Treble = Settings.TrebleLevel;
      UART_TxStr("+");
    } else {
      Treble = 256 - Settings.TrebleLevel;
      UART_TxStr("-");
    }
    Treble = Treble * 3 / 2;
    UART_TxNum(Treble, 1);
    if (Settings.TrebleLevel & 0b1)
      UART_TxStr(".5");
    UART_TxStr("dB at ");
    UART_TxNum(Settings.TrebleFreq, 1);
    UART_TxStr("kHz\r\n");
  }
}
/* start the main program */
void main()
{
    char ch;

    /* Initilize the UART before Transmitting/Receiving any data */
    UART_Init();

    /* Initilize the lcd before displaying any thing on the lcd */
    LCD_Init();


    while(1)
    {
        /*Receive and Transmit a char indefinitely at 9600 baud rate */
        ch=UART_RxChar(); // Receive a char and store it in "ch"

        UART_TxChar(ch);  //Transmit the received char

        LCD_DataWrite(ch); //Display the received char on LCD
    }

}
void UART_Printf(uint8_t var_uartChannel_u8, const char *argList, ...)
{
    const char *ptr;
    double var_floatNum_f32;
    va_list argp;
    sint16_t var_num_s16;
    sint32_t var_num_s32;
    uint16_t var_num_u16;
    uint32_t var_num_u32;
    char *str;
    char  ch;
    uint8_t var_numOfDigitsToTransmit_u8;

    va_start(argp, argList);

    /* Loop through the list to extract all the input arguments */
    for(ptr = argList; *ptr != '\0'; ptr++)
    {

        ch= *ptr;
        if(ch == '%')         /*Check for '%' as there will be format specifier after it */
        {
            ptr++;
            ch = *ptr;
            if((ch>=0x30) && (ch<=0x39))
            {
                var_numOfDigitsToTransmit_u8 = 0;
                while((ch>=0x30) && (ch<=0x39))
                {
                    var_numOfDigitsToTransmit_u8 = (var_numOfDigitsToTransmit_u8 * 10) + (ch-0x30);
                    ptr++;
                    ch = *ptr;
                }
            }
            else
            {
                var_numOfDigitsToTransmit_u8 = C_MaxDigitsToTransmitUsingPrintf_U8;
            }                


            switch(ch)       /* Decode the type of the argument */
            {

            case 'C':
            case 'c':     /* Argument type is of char, hence read char data from the argp */
                ch = va_arg(argp, int);
                UART_TxChar(var_uartChannel_u8,ch);
                break;



            case 'd':    /* Argument type is of signed integer, hence read 16bit data from the argp */
                var_num_s16 = va_arg(argp, int);
#if (Enable_UART_TxNumber == 1)
                if(var_num_s16<0)
                { /* If the number is -ve then display the 2's complement along with '-' sign */ 
                    var_num_s16 = -var_num_s16;
                    UART_TxChar(var_uartChannel_u8,'-');
                }
                UART_TxNumber(var_uartChannel_u8,C_DECIMAL_U8,var_num_s16,var_numOfDigitsToTransmit_u8);
#endif
                break;



            case 'D':    /* Argument type is of integer, hence read 16bit data from the argp */
                var_num_s32 = va_arg(argp, sint32_t);
#if (Enable_UART_TxNumber == 1)                
                if(var_num_s32<0)
                { /* If the number is -ve then display the 2's complement along with '-' sign */
                    var_num_s32 = -var_num_s32;
                    UART_TxChar(var_uartChannel_u8,'-');
                }
                UART_TxNumber(var_uartChannel_u8,C_DECIMAL_U8,var_num_s32,var_numOfDigitsToTransmit_u8);
#endif                
                break;    



            case 'u':    /* Argument type is of unsigned integer, hence read 16bit unsigned data */
                var_num_u16 = va_arg(argp, int);
#if (Enable_UART_TxNumber == 1)                
                UART_TxNumber(var_uartChannel_u8,C_DECIMAL_U8,var_num_u16,var_numOfDigitsToTransmit_u8);
#endif                
                break;



            case 'U':    /* Argument type is of integer, hence read 32bit unsigend data */
                var_num_u32 = va_arg(argp, uint32_t);
#if (Enable_UART_TxNumber == 1)                
                UART_TxNumber(var_uartChannel_u8,C_DECIMAL_U8,var_num_u32,var_numOfDigitsToTransmit_u8);
#endif                
                break;            


            case 'x':  /* Argument type is of hex, hence hexadecimal data from the argp */
                var_num_u16 = va_arg(argp, int);
#if (Enable_UART_TxNumber == 1)                
                UART_TxNumber(var_uartChannel_u8,C_HEX_U8, var_num_u16,var_numOfDigitsToTransmit_u8);
#endif                
                break;



            case 'X':  /* Argument type is of hex, hence hexadecimal data from the argp */
                var_num_u32 = va_arg(argp, uint32_t);
#if (Enable_UART_TxNumber == 1)                        
                UART_TxNumber(var_uartChannel_u8,C_HEX_U8, var_num_u32,var_numOfDigitsToTransmit_u8);
#endif                
                break;



            case 'b':  /* Argument type is of binary,Read int and convert to binary */
                var_num_u16 = va_arg(argp, int);
#if (Enable_UART_TxNumber == 1)                        
                if(var_numOfDigitsToTransmit_u8 == C_MaxDigitsToTransmitUsingPrintf_U8)
                {
                    var_numOfDigitsToTransmit_u8 = 16;
                }
                UART_TxNumber(var_uartChannel_u8,C_BINARY_U8, var_num_u16,var_numOfDigitsToTransmit_u8);
#endif                
                break;



            case 'B':  /* Argument type is of binary,Read int and convert to binary */
                var_num_u32 = va_arg(argp, uint32_t);
#if (Enable_UART_TxNumber == 1)                
                if(var_numOfDigitsToTransmit_u8 == C_MaxDigitsToTransmitUsingPrintf_U8)
                    var_numOfDigitsToTransmit_u8 = 16;                
                UART_TxNumber(var_uartChannel_u8,C_BINARY_U8, var_num_u32,var_numOfDigitsToTransmit_u8);    
#endif                
                break;



            case 'F':
            case 'f': /* Argument type is of float, hence read double data from the argp */
                var_floatNum_f32 = va_arg(argp, double);
#if (Enable_UART_TxFloatNumber == 1)                
                UART_TxFloatNumber(var_uartChannel_u8,var_floatNum_f32);
#endif
                break;



            case 'S':
            case 's': /* Argument type is of string, hence get the pointer to sting passed */
                str = va_arg(argp, char *);
                UART_TxString(var_uartChannel_u8,str);                
                break;



            case '%':
                UART_TxChar(var_uartChannel_u8,'%');
                break;
            }
        }
        else
        {
Example #15
0
//int main(void) __attribute__((noreturn)); // Main never returns so don't waste stack space on it.
int main(void)
{
  Uint16 TempInt;


  // Set up the I/O lines

  DDRA = PortDirA;
  DDRB = PortDirB;
  SD_PowerOn();
  DDRC = PortDirC;
  DDRD = PortDirD;

  PINA = PortPullUpA;
  PINB = PortPullUpB;
  PINC = PortPullUpC;
  PIND = PortPullUpD;

  //set the channel is the keyboard.
  //mp3 init finish ,after reset the slave board have volume;
  SetBit(SelAPort, Sel0A);
  SetBit(SelAPort, Sel1A);
  SetBit(SelBPort, Sel0B);
  SetBit(SelBPort, Sel1B);
  SetBit(SelCPort, Sel0C);
  SetBit(SelCPort, Sel1C);
  LastError = 0;            // Indicate no errors yet

  // Init the peripherals

  Timer_Init();                               // Set up timers
  UART_Init();
  InitKey();
  BCMessageInit(BCAMP3Contoller);

  wdt_enable(WDTO_8S);//wdt 8s
  // Set up key vars

  UART_Rx(CmdRxBuf, 1);
  Track         = 1;
  IdleTime      = 0;
  FlashPhase    = 0;
  Volume        = 0;
  PreMuteVolume = 0;
  Ramp          = NoRamp;
  LastKey       = 0;
  for(Bay = LeftBay; Bay <= NoBay; Bay++) {
    BayProduct[Bay] = UnknownProduct;
    BaySource[Bay]  = 0xff;
  }
  Bay           = LeftBay;
  SlaveMode     = false;
  SlaveModePara = 0;
  sei();      // Enable global interrupts

  // Print product build banner

  wdt_reset();
  UART_TxStr("\r\n======================================\r\n031-517-202 ");
  UART_TxChar('0' + SWVerMajor);
  UART_TxChar('.');
  UART_TxChar('0' + SWVerMinor);
  UART_TxChar('.');
  UART_TxChar('0' + SWVerFix);
  UART_TxChar(' ');
  UART_TxStr(__TIME__);
  UART_TxChar(' ');
  UART_TxStr(__DATE__);
  UART_TxStr("\r\n======================================\r\n");

  // For reset the slave board maybe volume very high so have noise
  // so first set volume is 0

  wdt_reset();
  BCMessageReceive(RxBuf);      // Finished with it so get ready for next msg
  ExchangeBoardMsg(BCALeftBay, BCTVolume, 0, 0, BCTAck);
  BCMessageReceive(RxBuf);      // Finished with it so get ready for next msg
  ExchangeBoardMsg(BCACenterBay, BCTVolume, 0, 0, BCTAck);
  BCMessageReceive(RxBuf);      // Finished with it so get ready for next msg
  ExchangeBoardMsg(BCARightBay, BCTVolume, 0, 0, BCTAck);
  BCMessageReceive(RxBuf);      // Finished with it so get ready for next msg

  // Test the LEDs while bays boot up

  DelayMS(100);                     // Allow some time for keypad to boot up
  UART_TxStr("Testing LEDs\r\n");
  for (TempInt = 1; TempInt <= 2; TempInt++){
    for (Key = 1; Key <= MaxKey; Key++) {
      if(!SetLamp(Key)){
        SlaveMode = true;
        break;
      }
      DelayMS(250);
      wdt_reset();//feed the watchdog
    }
    if(SlaveMode)
      break;
  }

  // Show version number

  if(!SlaveMode){
    SetLamps(0);
    DelayMS(1000);
    SetLamps(LeftLEDs | SWVerMajor);
    DelayMS(2000);
    wdt_reset();
    SetLamps(RightLEDs | SWVerMinor);
    DelayMS(2000);
    wdt_reset();
    SetLamps(LeftLEDs | RightLEDs | SWVerFix);
    DelayMS(2000);
    wdt_reset();
  }

  // Load EEPROM settings

  SetLamp(1);
  LoadEEPROMSetting();
  UART_TxStr("Settings:\r\n");
  PrintSettings();


  //wait for tablet ready wait 60 seconds
  if(SlaveMode)
  {
    UART_TxStr("Wait for tablet ready\r\n");
    for(TempInt = 0; TempInt < 6000; TempInt++)
    {
      DelayMS(10);
      CheckForBoardMsg();
      wdt_reset();
    }
  }
  // Prepare MP3 decoder for work

  wdt_reset();       // Feed the watchdog
  DelayMS(500);
  SetLamp(4);
  Timer_Clear();
  for (TempInt = 1; TempInt <= 5; TempInt++) {
    if (MP3_Init())
      break;          // If init ok exit loop
    wdt_reset();      // Feed the watchdog
    DelayMS(250);     // Wait before trying again
  }
  MP3_Volume(250);
  UART_TxStr("MP3 init time = ");
  UART_TxNum(Timer_Read(), 1);
  UART_TxStr("mS\r\n");

  // Find the last track on the card
  wdt_reset();
  SetLamp(3);
  for (Tracks = 1; Tracks <= 99; Tracks++) {
    if (!MP3_OpenFile(Tracks))
      break;
  }
  Tracks--;

  SetBassTreble();  // Set the audio curve


  // Determine what is connected

  wdt_reset();
  SetLamp(2);
  SearchDevices();

  if(!SlaveMode)
  {
    ConfigDevices();    // Configure connected devices

    SetIdleState();
    MP3_Track(1);
    if (!InputPresent[MP3In])       // If no MP3 player display error
      ShowError(ErrorNoMP3, false);
  }

  UART_TxStr("Start up complete\r\n");

  //
  // Enter the main loop
  //

  Timer_Clear();
  SlaveModeTimerClear();
  for( ; ; ) {              // Run forever
    if (SlaveMode) {        // In slave mode only handle slave mode messages
      CheckForBoardMsg();
      if(SlaveModeTimerRead() > 5000)
      {
        UART_TxNum(SlaveModeTimerRead(),5);
        UART_TxStr("\r\nMore than 5 seconds change to normal mode\r\n");
        SlaveMode = false;//return to Normal mode
        SearchDevices();
        Volume = 99; //if Volume == IdleVolume the not need send the volume so need give the diffent IdleVolume value
        Bay = RightBay;
        SetIdleState();
        SetMux(Input,LeftBay);
        SetMux(Input,CenterBay);
        SetMux(Input,RightBay);
      }
      wdt_reset();  // Update the watchdog
    } else {                //  Not in slave mode so feed the MP3 engine

      if (MP3Ready && !MP3_Process())
        MainLoop(0);        // Tell the main loop we have stopped playback

      //  Call the main loop if it is due

      if (Timer_Read() >= LoopPeriod) {     // Run the main loop at 10Hz
        Timer_Clear();
        MainLoop(1);        // Tell the main loop we are still playing a track
      }
    }
  }
  return 0;
}
void UART_TxNumber(uint8_t var_uartChannel_u8, uint8_t var_numericSystem_u8, uint32_t var_number_u32, uint8_t var_numOfDigitsToTransmit_u8)
{
    uint8_t i=0,a[10];

    if(C_BINARY_U8 == var_numericSystem_u8)
    {
        while(var_numOfDigitsToTransmit_u8!=0)
        {
            /* Start Extracting the bits from the specified bit positions.
             Get the Acsii values of the bits and transmit */
            i = util_GetBitStatus(var_number_u32,(var_numOfDigitsToTransmit_u8-1));
            UART_TxChar(var_uartChannel_u8,util_Dec2Ascii(i));
            var_numOfDigitsToTransmit_u8--;
        }    
    }     
    else if(var_number_u32==0)
    {
        /* If the number is zero then update the array with the same for transmitting */
        for(i=0;((i<var_numOfDigitsToTransmit_u8) && (i<C_MaxDigitsToTransmit_U8)) ;i++)
            UART_TxChar(var_uartChannel_u8,'0');
    }
    else
    {
        for(i=0;i<var_numOfDigitsToTransmit_u8;i++)
        {
            /* Continue extracting the digits from right side
               till the Specified var_numOfDigitsToTransmit_u8 */
            if(var_number_u32!=0)
            {
                /* Extract the digits from the number till it becomes zero.
                First get the remainder and divide the number by 10 each time.

                example for Decimal number:
                If var_number_u32 = 123 then extracted remainder will be 3 and number will be 12.
                The process continues till it becomes zero or max digits reached*/
                a[i]=util_GetMod32(var_number_u32,var_numericSystem_u8);
                var_number_u32=var_number_u32/var_numericSystem_u8;
            }
            else if( (var_numOfDigitsToTransmit_u8 == C_DefaultDigitsToTransmit_U8) ||
                    (var_numOfDigitsToTransmit_u8 > C_MaxDigitsToTransmit_U8))
            {
                /* Stop the iteration if the Max number of digits are reached or
                 the user expects exact(Default) digits in the number to be transmitted */ 
                break;
            }
            else
            {
                /*In case user expects more digits to be transmitted than the actual digits in number,
                  then update the remaining digits with zero.
                Ex: var_number_u32 is 123 and user wants five digits then 00123 has to be transmitted */
                a[i]=0;
            }
        }

        while(i)
        { 
            /* Finally get the ascii values of the digits and transmit*/
            UART_TxChar(var_uartChannel_u8,util_Hex2Ascii(a[i-1]));
            i--;
        }
    }


}
Example #17
0
void UART_TxStr(const char *str)
{
    int a=0;
    while(str[a]!='\0')
	UART_TxChar(str[a++]);
}
Example #18
0
//int main(void) __attribute__((noreturn)); // Main never returns so don't waste stack space on it.
int main(void)
{
  Uint16 TempInt;


  // Set up the I/O lines

  DDRA = PortDirA;
  DDRB = PortDirB;
  DDRC = PortDirC;
  DDRD = PortDirD;

  PINA = PortPullUpA;
  PINB = PortPullUpB;
  PINC = PortPullUpC;
  PIND = PortPullUpD;

  //set the channel is the keyboard.
  //mp3 init finish ,after reset the slave board have volume;
  SetBit(SelAPort, Sel0A);
  SetBit(SelAPort, Sel1A);
  SetBit(SelBPort, Sel0B);
  SetBit(SelBPort, Sel1B);
  SetBit(SelCPort, Sel0C);
  SetBit(SelCPort, Sel1C);

  // Init the peripherals

  Timer_Init();                               // Set up timers
  UART_Init();
  BCMessageInit(BCAMP3Contoller);

  // Set up key vars

  UART_Rx(CmdRxBuf, 1);
  Track         = 1;
  IdleTime      = 0;
  FlashPhase    = 0;
  Volume        = 0;
  PreMuteVolume = 0;
  Ramp          = NoRamp;
  LastKey       = 0;
  for(Bay = LeftBay; Bay <= NoBay; Bay++) {
    BayProduct[Bay] = UnknownProduct;
    BaySource[Bay]  = 0xff;
  }
  Bay           = LeftBay;
  SlaveMode     = false;

  sei();      // Enable global interrupts

  // Print product build banner

  UART_TxStr("\r\n================================\r\n031-517-202 ");
  UART_TxStr(__TIME__);
  UART_TxChar(' ');
  UART_TxStr(__DATE__);
  UART_TxStr("\r\n================================\r\n");

  // For reset the slave board maybe volume very high so have noise
  // so first set volume is 0

  /*BCMessageReceive(RxBuf);      // Finished with it so get ready for next msg
  ExchangeBoardMsg(BCALeftBay, BCTVolume, 0, 0, BCTAck);
  BCMessageReceive(RxBuf);      // Finished with it so get ready for next msg
  ExchangeBoardMsg(BCACenterBay, BCTVolume, 0, 0, BCTAck);
  BCMessageReceive(RxBuf);      // Finished with it so get ready for next msg
  ExchangeBoardMsg(BCARightBay, BCTVolume, 0, 0, BCTAck);
  BCMessageReceive(RxBuf);      // Finished with it so get ready for next msg

  // Test the LEDs while bays boot up

  DelayMS(500);                     // Allow some time for keypad to boot up
  UART_TxStr("Testing LEDs\r\n");
  for (TempInt = 1; TempInt <= 2; TempInt++)
    for (Key = 1; Key <= MaxKey; Key++) {
      SetLamp(Key);
      DelayMS(250);
    }

  // Keyboard test
  Count = 0xff;
  SetLamps(Count);
  for(;;){
    if (BCRXAvail) {                // See if we have a new frame
      ProcessBoardMsg();
      BCMessageReceive(RxBuf);      // Get the next message
    }
    if (GetKey() != TempInt) {
      TempInt = GetKey();
      if (TempInt) {
        Count ^= 1 << (TempInt - 1);
        SetLamps(Count);
      }
    }
  }
   */

  // Load EEPROM settings

 /* SetLamp(1);
  LoadEEPROMSetting();
  UART_TxStr("Settings:\r\n");
  PrintSettings();

  // Prepare MP3 decoder for work

  SetLamp(4);
  Timer_Clear();
  MP3_Init();
  MP3_Volume(250);
  UART_TxStr("MP3 init time = ");
  UART_TxNum(Timer_Read(), 1);
  UART_TxStr("mS\r\n");

  // Find the last track on the card

  SetLamp(3);
  for (Tracks = 1; Tracks <= 99; Tracks++) {
    if (!MP3_OpenFile(Tracks))
      break;
  }
  Tracks--;

  SetBassTreble();  // Set the audio curve
  // Determine what is connected

  SetLamp(2);
  UART_TxStr("Searching for devices\r\n");

  // Look for input devices

  InputPresent[MP3In]      = true;
  InputFormat[MP3In]       = I2S32Bit;

  InputPresent[LCDIn]      = ExchangeBoardMsg(BDCLCD, BCTInquire, 0, 0, BCTInquireAnswer);
  InputFormat[LCDIn]       = RxBuf[BCPParam2];
  BCMessageReceive(RxBuf);

  InputPresent[LeftTablet] = ExchangeBoardMsg(BCATabletLeft, BCTInquire, 0, 0, BCTInquireAnswer);
  InputFormat[LeftTablet]  = RxBuf[BCPParam2];
  BCMessageReceive(RxBuf);

  InputPresent[RightTablet]= ExchangeBoardMsg(BCATabletRight, BCTInquire, 0, 0, BCTInquireAnswer);
  InputFormat[RightTablet] = RxBuf[BCPParam2];
  BCMessageReceive(RxBuf);
*/
  // Look for output devices

  /*HeadphoneBay = NoBay;
  BayCount = 0;
  for(Bay = LeftBay; Bay <= RightBay; Bay++) {
    if (ExchangeBoardMsg(BCAOutput + Bay, BCTInquire, 0, 0, BCTInquireAnswer)) {
      BayCount++;
      UART_TxStr("Found bay ");
      UART_TxNum(Bay, 1);
      UART_TxStr(" = ");
      BayProduct[Bay] = RxBuf[BCPParam1];
      if (BayProduct[Bay] == FiveHeadphones)
        HeadphoneBay = Bay;
      UART_TxNum(BayProduct[Bay], 1);
      UART_TxNewLine();
    }
  }
  Bay = LeftBay;
  BCMessageReceive(RxBuf);      // Finished with it so get ready for next msg

  // Allow E2 overwrite of detected defaults
  if (Settings.LeftProduct != UnknownProduct) {
    UART_TxStr("E2 replaced left product ");
    UART_TxNum(BayProduct[LeftBay], 1);
    UART_TxStr(" with ");
    UART_TxNum(Settings.LeftProduct, 1);
    UART_TxNewLine();
    BayProduct[LeftBay] = Settings.LeftProduct;
  }

  if (Settings.CenterProduct != UnknownProduct) {
    UART_TxStr("E2 replaced center product ");
    UART_TxNum(BayProduct[CenterBay], 1);
    UART_TxStr(" with ");
    UART_TxNum(Settings.CenterProduct, 1);
    UART_TxNewLine();
    BayProduct[CenterBay] = Settings.CenterProduct;
  }

  if (Settings.RightProduct != UnknownProduct) {
    UART_TxStr("E2 replaced right product ");
    UART_TxNum(BayProduct[RightBay], 1);
    UART_TxStr(" with ");
    UART_TxNum(Settings.RightProduct, 1);
    UART_TxNewLine();
    BayProduct[RightBay] = Settings.RightProduct;
  }

  ShowProducts();

  // Determine operational mode

  // TODO: Check for override in E2 config

  Config = TwoBaysTwoSources;   // Default mode
  if (!InputPresent[LCDIn]) {
    Config = TwoBaysOneSource;
  } else if (BayCount < 2) {
    Config = OneBayTwoSources;
  } else {
    Config = TwoBaysTwoSources;
  }

  UART_TxStr("Mode: ");
  switch (Config) {
    case TwoBaysOneSource:  UART_TxStr("Two bays, one source\r\n"); break;
    case OneBayTwoSources:  UART_TxStr("One bay, two sources\r\n"); break;
    case TwoBaysTwoSources: UART_TxStr("Two bays, two sources\r\n"); break;
  }

  // TODO: Check for override in E2 config

  if (InputPresent[LeftTablet] && InputPresent[RightTablet])  // If two tablets
    BayNotSourceButtons = false;                              // Assume input selection buttons
  else if (BayCount < 2)                                      // Only one bay
    BayNotSourceButtons = false;                              // Assume input selection buttons
  else                                                        // We have two, or more, products and one controller
    BayNotSourceButtons = true;

  ConfigDevices();    // Configure connected devices

  SetIdleState();
  MP3_Track(1);
  UART_TxStr("Start up complete\r\n");

  //
  // Enter the main loop
  //
*/
  Timer_Clear();
  for( ; ; ) {              // Run forever
    if (SlaveMode) {        // In slave mode only handle slave mode messages
      CheckForBoardMsg();

    } else {                //  Not in slave mode so feed the MP3 engine

      //if (!MP3_Process())
       // MainLoop(0);        // Tell the main loop we have stopped playback

      //  Call the main loop if it is due

      //if (Timer_Read() >= LoopPeriod) {     // Run the main loop at 10Hz
       // Timer_Clear();
        MainLoop(0);        // Tell the main loop we are still playing a track
     // }
    }
  }
  return 0;
}
void UART_TxString(uint8_t var_uartChannel_u8, char *ptr_stringPointer_u8)
{
    while(*ptr_stringPointer_u8)
        UART_TxChar(var_uartChannel_u8, *ptr_stringPointer_u8++);// Loop through the string and transmit char by char
}
Example #20
0
void UART_TxString(char *ptr_stringPointer_u8)
{
	while(*ptr_stringPointer_u8)
		UART_TxChar(*ptr_stringPointer_u8++);// Loop through the string and transmit char by char
}
Example #21
0
/* Print the result of an executed command.  Done so that all commands have a response and so that
 * they can indicate errors.
 */
static void PrintCmdStatus(cmdstatus_t status)
{
	UART_TxChar('!');
	UART_TxHexByte((uint8_t)status);
	UART_TxChar('\r');
}
Example #22
0
/*
  main routine

  Program entry point
*/
int main(void)
{
  Uint8   TxBuf[BCMsgSize];
  Uint8   RxBuf[BCMsgSize];
  Uint8   Address;            // Address of device in bay
  Uint8   Destination;        // Address we will reply to
  Uint8   Param,Param2;
  Uint8   Volume = 0;
  Uint8   TempInt;
#ifdef CTRL_LED
  Uint8   TempInt;
  Uint8   RceiveAddress;
  Uint8   i;
  i = 0;
#endif
  MainInit();

  UART_TxStr("\r\nPower up\r\n");

  UART_Rx(RxData, 9);             // Input register setting command

  Address = BCAOutput + ReadPosition();
  BCMessageInit(Address);         // Set up the UART
  BCMessageReceive(RxBuf);        // Kick off receive

  if(ReadProductID()) // 1:pill 2:beats box 3:rave
    ChannelNumbers = 1;
  else
    ChannelNumbers = 5;//0:5 position headphone
  // Enter the main loop
  LED1_ON();
  LED2_ON();
  LED_GRAPHICAL_ON();
  SetLamps(3);
  for( ; ; ) {                              // Run forever
    Timer_Clear();
    DelayMS(LoopRate);
    TempInt++;
    SettingsControl();
    if (BCRXAvail)
    {                        // We have a new message
      //send data
#ifdef  SecondUART
#ifdef DumpComms
      UART_TxStr("Receive: ");
      for (TempInt = BCPSOH; TempInt <= BCPChecksum; TempInt++)
      {
        UART_TxUint8(RxBuf[TempInt]);
        UART_TxChar(' ');
      }
      UART_TxStr("\r\n");
#endif
#endif

      if ((RxBuf[BCPAddr] & 0b1111) == Address) // Check it is for us
      {
        Destination = RxBuf[BCPAddr] >> 4;  // Pre-setup assuming we will reply
        Destination &= 0b1111;
        Destination |= Address << 4;
        TxBuf[BCPAddr] = Destination;
        DelayMS(2);                         // Allow line turn around delay
        switch (RxBuf[BCPType])
        {
          case BCTInquire:                  // Master request of slave ID
            TxBuf[BCPType] = BCTInquireAnswer;
            TxBuf[BCPParam1] = ReadProductID();
            TxBuf[BCPParam2] = 0;
            BCMessageSend(TxBuf,true);      // Send the reply
            break;
          case BCTLamps: // Set lamps
            TxBuf[BCPType]   = BCTAck;
            TxBuf[BCPParam1] = 0;
            TxBuf[BCPParam2] = 0;
            BCMessageSend(TxBuf, true);           // Send the reply
            Param =  RxBuf[BCPParam1];
            SetLamps(Param);
            break;

          case BCTVolume:                   // Volume set
            TxBuf[BCPType] = BCTAck;
            TxBuf[BCPParam1] = 0;
            TxBuf[BCPParam2] = 0;
            BCMessageSend(TxBuf,true);      // Send the reply
            Volume = RxBuf[BCPParam1];       // Save parameter so we can receive next frame while processing this request
            Param2 = RxBuf[BCPParam2];       // Save parameter so we can receive next frame while processing this request
            Volume_Set(Volume,Param2);
            break;

          case BCTHeadphoneChGain:                   // Volume set
            TxBuf[BCPType] = BCTAck;
            TxBuf[BCPParam1] = 0;
            TxBuf[BCPParam2] = 0;
            BCMessageSend(TxBuf,true);      // Send the reply
            Param = RxBuf[BCPParam1];       // Save parameter so we can receive next frame while processing this request
            Param2 = RxBuf[BCPParam2];       // Save parameter so we can receive next frame while processing this request
            SetChannelAdjust(Param,Param2);
            break;

          case BCTHeadphoneChMax:                   // Volume set
            TxBuf[BCPType] = BCTAck;
            TxBuf[BCPParam1] = 0;
            TxBuf[BCPParam2] = 0;
            BCMessageSend(TxBuf,true);      // Send the reply
            Param = RxBuf[BCPParam1];       // Save parameter so we can receive next frame while processing this request
            Param2 = RxBuf[BCPParam2];       // Save parameter so we can receive next frame while processing this request
            SetChMaxVolume(Param, Param2);
            break;

          case BCTAudioFormat:              // Audio format set
            TxBuf[BCPType] = BCTAck;
            TxBuf[BCPParam1] = 0;
            TxBuf[BCPParam2] = 0;
            BCMessageSend(TxBuf,true);      // Send the reply
            Param = RxBuf[BCPParam1];       // Save parameter so we can receive next frame while processing this request
            WM8960_SetAudioFormat(Param);
            break;


          case BCTBrightness: // Set lamp brightness
            TxBuf[BCPType] = BCTAck;
            TxBuf[BCPParam1] = 0;
            TxBuf[BCPParam2] = 0;
            BCMessageSend(TxBuf, true);           // Send the reply
            Param = RxBuf[BCPParam1];       // Save parameter so we can receive next frame while processing this request
            Param2 = RxBuf[BCPParam2];       // Save parameter so we can receive next frame while processing this request
            if (Param == 1)
              LED1 = Param2;
            else if(Param == 2)
              LED2 = Param2;
            break;

          case BCTReset:                   // Volume set
            TxBuf[BCPType] = BCTAck;
            TxBuf[BCPParam1] = 0;
            TxBuf[BCPParam2] = 0;
            BCMessageSend(TxBuf,true);      // Send the reply
            Param = RxBuf[BCPParam1];       // Save parameter so we can receive next frame while processing this request
            BCMessageReceive(RxBuf);        // Kick off receive of next frame
            asm("jmp 0x0000");//reset
            break;

          default:  // Unknown command
            TxBuf[BCPType] = BCTNAck;
            TxBuf[BCPParam1] = BCNUnkownType;
            TxBuf[BCPParam2] = RxBuf[BCPType];
            BCMessageSend(TxBuf,true);      // Send the reply
           // BCMessageReceive(RxBuf);        // Kick off receive of next frame
            break;
        }

        //this send command tv change to 031-517-209 board
#if VideoTrackCtrl
        Uint8   VideoTrack;
        Uint8   SendVideoFlag;
        if(Volume > 47)
        {
          if(SendVideoFlag)
          {
            SendVideoFlag = false;

            if(Address == BCARightBay)
            {
              VideoTrack = 1;
            }
            else if(Address == BCALeftBay)
            {
              VideoTrack = 2;
            }

            TxBuf[BCPAddr] = Address << 4;
            TxBuf[BCPAddr] |= BDCLCD;
            TxBuf[BCPType]   = BCTPlayTrack;
            TxBuf[BCPParam1] = VideoTrack;
            TxBuf[BCPParam2] = 0;
            BCMessageSend(TxBuf, true);           // Send the reply
          }
        }
        else
        {
          SendVideoFlag = 1;
        }
#endif
      }


      //this for ctrl LED it itself
#ifdef CTRL_LED
      if(RxBuf[BCPType] == BCTVolume)
      {
        RceiveAddress = RxBuf[BCPAddr] & 0b1111;
        a_Volume[RceiveAddress-BCAOutput] = RxBuf[BCPParam1];

        if((a_Volume[RceiveAddress-BCAOutput] > 47) && (LastVolume[RceiveAddress-BCAOutput] > 47))//have volume
        {
          if((RceiveAddress) == Address)
          {
            LED1_ON();
          }
          else
          {
            LED1_OFF();
          }
        }

        i = 0;
        for(TempInt = 0; TempInt < 4; ) //all  volume off
        {
          if((a_Volume[TempInt] <= 47) && (LastVolume[TempInt] <= 47))
            i++;
          TempInt++;
        }

        if(i >= TempInt)
        {
          LED1_ON();
        }

        LastVolume[RceiveAddress-BCAOutput] = a_Volume[RceiveAddress-BCAOutput];
      }
#endif
      BCMessageReceive(RxBuf);        // Kick off receive of next frame
    }

  }
Example #23
0
/* Run one iteration of the interface state machine.  This is responsible for displaying the command
 * prompt, receiving characters, and running the resulting command by searching for and calling the
 * proper command function.  Call this in your main loop.
 */
void Cmd_ProcessInterface()
{
	switch(m_cmdstate)
	{
		case eCmd_Prompt:
			if(UART_TxAvailable() >= 4)
			{
				UART_TxData("\r#> ", 4);
				m_cmdlen = 0;
				++m_cmdstate;
			}
			break;
		case eCmd_Receive:			
		{
			uint16_t avail = UART_RxAvailable();

			while(avail--)
			{
				char c = UART_RxChar();
				wdt_reset();

				if(0x08 == c)           // backspace -- remove last character
				{
					if(m_cmdlen > 0)
						--m_cmdlen;
				}
				else if(0x1B == c)      // escape -- clear prompt
				{
					m_cmdstate = eCmd_Prompt;
					break;
				}
				else                    // add the character to the buffer
				{
					m_cmdbuf[m_cmdlen] = c;
					++m_cmdlen;

					// either got a command or buffer is full
					if(c == '\r'  ||  m_cmdlen >= CMD_BUFSIZE)
					{
						m_cmdbuf[m_cmdlen] = 0;   // terminate command
						++m_cmdstate;
						break;
					}
				}
			}

			wdt_reset();
		}
		break;
		case eCmd_Run:
			m_cmdstate = eCmd_Prompt;

			if(m_numcmds > 0)
			{
				uint8_t i;

				// look for the right command and call its function
				for(i = 0; i < m_numcmds; ++i)
				{
					size_t len = strlen(m_cmds[i].name);

					if(0 == strncmp(m_cmds[i].name, m_cmdbuf, len)  &&
					   (m_cmdbuf[len] == ' '  ||  m_cmdbuf[len] == '\r'))
					{
						m_cmds[i].cmdfunc(m_cmdbuf, m_cmdlen);
						break;
					}
				}

				// didn't find the command
				if(i == m_numcmds)
					UART_TxData_P(PSTR("Unknown command\r"), 16);
			}
			break;
		case eCmd_Help:
			if(m_helpindex < m_numcmds)
			{
				size_t txlen = (strlen(m_cmds[m_helpindex].name) + 
								strlen_P(m_cmds[m_helpindex].help) + 5);

				if(txlen > UART_TX_BUFSIZE)
					txlen = UART_TX_BUFSIZE;

				if(UART_TxAvailable() >= txlen)
				{
					UART_TxString(m_cmds[m_helpindex].name);
					UART_TxData("\t - ", 4);
					UART_TxString_P(m_cmds[m_helpindex].help);
					UART_TxChar('\r');

					++m_helpindex;
				}
			}
			else
			{
				m_cmdstate = eCmd_Prompt;
				m_helpindex = 0;
			}
			break;
		default:
			m_cmdstate = eCmd_Prompt;
			break;
	}
}
/*----------------------------------------------------------------------------------
                         void UART_TxString(char *string_ptr)
 -----------------------------------------------------------------------------------
 * I/P Arguments: String(Address of the string) to be transmitted.
 * Return value	: none

 * description :This function is used to transmit the ASCII string through UART..
            The string_ptr points to the first char of the string.
            And it is incremented each time to traverse till the end(NULL CHAR).
            Each time a char is sent to UART_TxChar() fun to transmit it through UART
___________________________________________________________________________________*/
void UART_TxString(char *string_ptr)
 {
          while(*string_ptr)
           UART_TxChar(*string_ptr++);
   }