Ejemplo n.º 1
0
/**************************************************************
 *  Name                 :	UART0_GetString
 *  Description          :	Receive a string through UART0 and
 *  						store it in array rub_UART_String. 
 *  						Print the string read character by
 *  						character (echo).
 *  						
 *  Parameters           :  None
 *  						
 *  Return               :	
 *                          T_UBYTE *rub_UART_String : Locality of array where the string was stored
 *                          
 *  Critical/explanation :  No
 **************************************************************/
PUBLIC_FCT PTR_UBYTE UART0_GetString(void)
{
	T_UBYTE lub_Data = 0;						//Temporarily variable to every character
	T_BOOLEAN lbi_StringComplete = FALSE;		//Flag to indicate finished reading
	T_UBYTE lub_index = 0;

	while(!lbi_StringComplete)
	{
		lub_Data = UART0_GetChar();					//Read character
		if((lub_Data != '\r') && (lub_Data != 0))
		{
			rub_UART_String[lub_index] = lub_Data;	//Store read character
			lub_index++;							//Point to next location
			UART0_SendChar(lub_Data);				//Echo data
		}	
		else
		{
			rub_UART_String[lub_index] = 0;			//Finish the string
			UART0_SendChar(CR);						//Print escape sequence
			UART0_SendChar(LF);						//Print escape sequence
			lbi_StringComplete = TRUE;				//Finish the reading
		}
	}
    return (PTR_UBYTE)rub_UART_String;				//Return the pointer where string is stored
}
Ejemplo n.º 2
0
int main(void)
{  unsigned char input[16]="0123456789abcdef";
   unsigned char output[16];
   unsigned char K[32];
   int C_UART0=0;
   unsigned int keysize=128	;
   aes_context ctx;



	SystemInit();
	UART0_Init();
	UART2_Init();
	memset(K, 1, 32 );
	//aes_setkey_enc(&ctx, K , 128 );

    while (1)
	{ input[C_UART0++]=UART0_GetChar ();
	  if (C_UART0==16)
	{
	 //aes_crypt_ecb(&ctx,1,input,output );
	 UART0_SendString (input);	
	 UART0_SendString (output);	 
	 C_UART0=0;}
	 }


}
Ejemplo n.º 3
0
int main()
{
	char data;
	
	leds_init();
	//开始默认关闭LED灯
	leds_OFF_all();

	// 串口初始化, 在start.S中已经调用过
	UART0_Port_Init();
	UART0_Set_BaudRate();
	UART0_Set_Format();

	
	// '\n' 换行
	// '\r' 回车
	UART0_SendString("\n\rHello World!\n\r");
	//UART0_SendString("Hello World!\n");

	while(1)
	{
		data = UART0_GetChar();
		UART0_PutChar(data);
	}
    return 0;
}
Ejemplo n.º 4
0
int main()
{
	char data;
	
	// 串口初始化, 在start.S中已经调用过
	UART0_Port_Init();
	UART0_Set_BaudRate();
	UART0_Set_Format();

	
	// 测试看门狗的定时功能
 	//watchdog_init(66, 0, 62500, 1, 0);	//仅中断, 不复位
 	//watchdog_init(66, 0, 62500, 1, 1);	//中断&复位, 配置复位后, 中断函数就鸡肋了, 不会被调用;

	// '\n' 换行
	// '\r' 回车
	UART0_SendString("\n\rHello World!\n\r");
	//UART0_SendString("Hello World!\n");

	while(1)
	{
		data = UART0_GetChar();
		UART0_PutChar(data);
	}
    return 0;
}
Ejemplo n.º 5
0
/**
 * @brief         fgetc
 * @param[in]     void
 * @param[in,out] void
 * @return        char
 */
int fgetc(FILE *f) {
	
	char c;
	/* get key */
	c =  UART0_GetChar();
	/* print echo */
	UART0_PutChar(c);
  return (int)c;
}
Ejemplo n.º 6
0
int main(void)
{
	char usFdiv;
	SystemInit();
	UART0_Init();								 //初始化串口
	Rest();										 //复位
	UART0_GetChar(17);							 //接收复位信息
		  
	UART0_SendByte(4,SendBuf_0); 				 //发送提速命令
	UART0_GetChar(4);

	LPC_UART0->LCR  = 0x83;                      /* 允许设置波特率               */
    usFdiv = (11059200*2 / 16) / 230400;         /* 设置波特率                   */
    LPC_UART0->DLM  = usFdiv / 256;
    LPC_UART0->DLL  = usFdiv % 256; 
	
    LPC_UART0->LCR  = 0x1F;                      /* 锁定波特率                   */
    LPC_UART0->FCR  = 0x87; 					  //清空接收发送寄存器

	UART0_SendByte(5,SendBuf_1);				  //发送获取随机数命令
	UART0_GetChar(11);							  //获取随机数
	while(1);
}
Ejemplo n.º 7
0
int main( void )
{
    int         i;
    int         led = 0;
    uint16_t    prevSwitches = 0;

    InitHardware();
    InitADC();
    InitMotors();

    eeprom_read_block( &gMemParam, &gEEParam, sizeof( gMemParam ));

    if ( gMemParam.thresh_hi == 0xFF )
    {
        gMemParam.thresh_hi = 0x80;
    }
    if ( gMemParam.thresh_lo == 0xFF )
    {
        gMemParam.thresh_lo = 0x10;
    }

#if CFG_LOG_USE_STDIO
    fdevopen( UART0_PutCharStdio, UART0_GetCharStdio );

    LogInit( stdout );
#endif

    // The first handle opened for read goes to stdin, and the first handle
    // opened for write goes to stdout. So u0 is stdin, stdout, and stderr

    Log( "*****\n" );
    Log( "***** Line Maze program\n" );
    Log( "*****\n" );

    LCD_Init( 2, 16 );
    LCD_Printf( " SRS Sample Bot " );
    LCD_MoveTo( 0, 1 );
    LCD_Printf( "Second line" );

    Log( "\n" );

    MENU_Init( gTopMenu );

    LED_OFF( GREEN );

    while( 1 )
    {
        uint16_t    switches;
        uint8_t     pinc;
        uint8_t     pind;
        int8_t      error;

        LED_TOGGLE( GREEN );

        led++;
        if ( led >= 6 )
        {
            led = 0;
        }

        error = GetLineError();

        if ( MENU_IsActive() )
        {
            MENU_Event( MENU_EVENT_TIMER );
        }
        else
        {
            if ( MENU_IsModified() )
            {
                eeprom_write_block( &gMemParam, &gEEParam, sizeof( gMemParam ));
                MENU_ClearModified();

                LCD_Clear();
                LCD_Printf( "EEPROM Updated\n" );
                Log( "EEPROM Updated\n" );
                ms_spin( 1000 );
            }

            //switches = EXP_TransferWord( ~( 1 << ( led + 2 )), EXP_OUT_LED_MASK );
            switches = EXP_TransferWord( 0, 0 );
            Log( "SW:%04x ", switches );

            if ( switches != prevSwitches )
            {
                LCD_Clear();
                prevSwitches = switches;
            }
            for ( i = 0; i < 8; i++ )
            {
                Log( "%02x ", gLineADC[ i ]);
            }

            //Log( "C: %02x\n", PINC );

            switch (( switches & 0xF0 ) >> 4 )
            {
            case 0:
            {
                LCD_MoveTo( 0, 0 );
                LCD_Printf( " SRS Sample Bot " );
                LCD_MoveTo( 0, 1 );
                LCD_Printf( "Second line" );
                break;
            }

            case 1:
            {
                LCD_MoveTo( 0, 0 );
                LCD_Printf( "Joy: %c%c%c%c%c",
                            (( switches & 0x4000 ) == 0 ) ? 'L' : ' ',
                            (( switches & 0x2000 ) == 0 ) ? 'R' : ' ',
                            (( switches & 0x0800 ) == 0 ) ? 'U' : ' ',
                            (( switches & 0x0400 ) == 0 ) ? 'D' : ' ',
                            (( switches & 0x1000 ) == 0 ) ? 'X' : ' ' );
                LCD_MoveTo( 0, 1 );
                LCD_Printf( "S1:%d S2:%d S3:%d",
                            ( switches & 0x0200 ) == 0,
                            ( switches & 0x0100 ) == 0,
                            ( PIND & ( 1 << 6 ))  == 0 );
                break;
            }

            case 2:
            {
                LCD_MoveTo( 0, 0 );
                LCD_Printf( "L %02x %02x %02x %02x %02x",
                            gLineADC[ 0 ],
                            gLineADC[ 1 ],
                            gLineADC[ 2 ],
                            gLineADC[ 3 ],
                            gLineADC[ 4 ] );

                LCD_MoveTo( 0, 1 );
                LCD_Printf( "E %02x %02x %3d B %02x", gADC[ 0 ], gADC[ 7 ], error, gADC[ 6 ] );
                break;
            }

            default:
            {
                LCD_MoveTo( 0, 0 );
                LCD_Printf( "Setting: %d", ( switches & 0xF0 ) >> 4 );
                break;
            }
            }

            pinc = PINC;
            pind = PIND;

            Log( " QL:%d%d QR:%d%d EC-L:%d EC-R:%d Err:%2d L:%5b H:%5b\n",
                 ( ENCODER_L_A_PIN & ENCODER_L_A_MASK ) != 0,
                 ( ENCODER_L_B_PIN & ENCODER_L_B_MASK ) != 0,
                 ( ENCODER_R_A_PIN & ENCODER_R_A_MASK ) != 0,
                 ( ENCODER_R_B_PIN & ENCODER_R_B_MASK ) != 0,
                 gEncoderCountL,
                 gEncoderCountR,
                 error, gLowMask, gHighMask );
        }

        // Tick rate is 100/sec so waiting for 50 waits for 1/2 sec

        for ( i = 0; i < 50; i++ )
        {
            WaitForTimer0Rollover();
            CheckSwitches();

#if 1
            if ( UART0_IsCharAvailable() )
            {
                char    ch = UART0_GetChar();

                if ( ch == ' ' )
                {
                    DebugKey();
                }
                else
                {
                    Log( "Read: '%c'\n", ch );
                }
            }
#endif
        }
    }

    return 0;
}
Ejemplo n.º 8
0
int main( void )
{
    uint8_t delay;
    uint8_t counter;
    uint8_t doStatus = 1;

    InitTimer();
    InitUART();

    SetDirectionOut( LED );

    SetDirectionOut( MOSI );
    SetDirectionIn(  MISO );
    SetDirectionOut( SCK );
    SetDirectionOut( SS );
    SetDirectionIn(  INT );
    SetDirectionOut( TRIGGER );

    TRIGGER_PORT &= ~TRIGGER_MASK;

    SPI_MasterInit();

    Log( "*****\n" );
    Log( "***** WLN CLI program\n" );
    Log( "*****\n" );

    sei();

    counter = 0;
    while ( 1 )
    {
        LED_PORT ^= LED_MASK;

        if ( doStatus )
        {
            if ( counter == 0 )
            {
                uint8_t status = WLN_ReadStatus();
                WLN_PrintStatus( status );
            }
            counter = ( counter + 1 ) & 0x03;
        }

        // Tick rate is 100/sec so waiting for 50 waits for 1/2 sec

        for ( delay = 0; delay < 50; delay++ ) 
        {
            tick_t prevCount = gTickCount;
            while ( gTickCount == prevCount )
            {
                LogBufDump();
            }

            if ( UART0_IsCharAvailable() )
            {
                char    ch = UART0_GetChar();

                switch ( ch )
                {
                    case '!':
                    {
                        doStatus = !doStatus;
                        Log( "Turning status %s\n", doStatus ? "on" : "off" );
                        break;
                    }

                    case '*':
                    {
                        Log( "Reset\n" );

                        SetDirectionOut( RESET );
                        RESET_PORT &= ~RESET_MASK;
                        break;
                    }

                    case ' ':
                    {
                        WLN_ReadData();
                        break;
                    }

                    default:
                    {
                        Log( "Read: '%c'\n", ch );
                        WLN_WriteByte( ch );
                        break;
                    }
                }

            }
        }
    }

} // main
Ejemplo n.º 9
0
int main(void)
{
    int         i;
    int         led = 0;
    uint16_t    prevSwitches = 0;

    InitHardware();

    LogInit( printfFunc );

    // The first handle opened for read goes to stdin, and the first handle
    // opened for write goes to stdout. So u0 is stdin, stdout, and stderr

    Log( "*****\n" );
    Log( "***** Flash-LED program - 2\n" );
    Log( "*****\n" );

    Log( "SPCR = 0x%02x\n", SPCR );

    LCD_Init();
    LCD_Printf( " SRS Sample Bot " );
    LCD_MoveTo( 0, 1 );
    LCD_Printf( "Second line" );

    Log( "\n" );

    LED_OFF( GREEN );

    while( 1 )
    {
        uint16_t    switches;
        uint8_t     pinc;
        uint8_t     pind;

        LED_TOGGLE( GREEN );

        led++;
        if ( led >= 6 )
        {
            led = 0;
        }

        //switches = EXP_TransferWord( ~( 1 << ( led + 2 )), EXP_OUT_LED_MASK );
        switches = EXP_TransferWord( ~0, EXP_OUT_LED_MASK );
        Log( "SW:%04x ", switches ); 

        if ( switches != prevSwitches )
        {
            LCD_Clear();
            prevSwitches = switches;
        }
        // Read the ADC

        for ( i = 0; i < 8; i++ ) 
        {
            gADC[ i ] = a2d_8( i );

            Log( "%02x ", gADC[ i ]);
        }
        //Log( "C: %02x\n", PINC );


        switch (( switches & 0xF0 ) >> 4 )
        {
            case 0:
            {
                LCD_MoveTo( 0, 0 );
                LCD_Printf( " SRS Sample Bot " );
                LCD_MoveTo( 0, 1 );
                LCD_Printf( "Second line" );
                break;
            }

            case 1:
            {
                LCD_MoveTo( 0, 0 );
                LCD_Printf( "Joy: %c%c%c%c%c", 
                            (( switches & 0x4000 ) == 0 ) ? 'L' : ' ',
                            (( switches & 0x2000 ) == 0 ) ? 'R' : ' ',
                            (( switches & 0x0800 ) == 0 ) ? 'U' : ' ',
                            (( switches & 0x0400 ) == 0 ) ? 'D' : ' ',
                            (( switches & 0x1000 ) == 0 ) ? 'X' : ' ' );
                LCD_MoveTo( 0, 1 );
                LCD_Printf( "S1:%d S2:%d S3:%d",
                            ( switches & 0x0200 ) == 0,
                            ( switches & 0x0100 ) == 0,
                            ( PIND & ( 1 << 6 ))  == 0 );
                break;
            }

            case 2:
            {
                LCD_MoveTo( 0, 0 );
                LCD_Printf( "L %02x %02x %02x %02x %02x", gADC[ 4 ], gADC[ 1 ], gADC[ 2 ], gADC[ 3 ], gADC[ 5 ] );
                LCD_MoveTo( 0, 1 );
                LCD_Printf( "E %02x %02x     B %02x", gADC[ 0 ], gADC[ 7 ], gADC[ 6 ] );
                break;
            }

            default:
            {
                LCD_MoveTo( 0, 0 );
                LCD_Printf( "Setting: %d", ( switches & 0xF0 ) >> 4 );
                break;
            }
        }

        pinc = PINC;
        pind = PIND;

        Log( " QL:%d%d QR:%d%d EC-L:%d EC-R:%d\n", 
             ( ENCODER_L_A_PIN & ENCODER_L_A_MASK ) != 0,
             ( ENCODER_L_B_PIN & ENCODER_L_B_MASK ) != 0,
             ( ENCODER_R_A_PIN & ENCODER_R_A_MASK ) != 0,
             ( ENCODER_R_B_PIN & ENCODER_R_B_MASK ) != 0,
             gEncoderCountL,
             gEncoderCountR );


        // Tick rate is 100/sec so waiting for 50 waits for 1/2 sec

        for ( i = 0; i < 50; i++ ) 
        {
            WaitForTimer0Rollover();

#if 1
            if ( UART0_IsCharAvailable() )
            {
                char    ch = UART0_GetChar();

                if ( ch == ' ' )
                {
                    DebugKey();
                }
                else
                {
                    Log( "Read: '%c'\n", ch );
                }
            }
#endif
        }
    }

    return 0;
}