示例#1
0
/*******************************************************************************
* 串口发送温度上下限
********************************************************************************/
void setUartSend(uint8 NodeID)
{
    int i;
    switch(NodeID)
    {
        case 1 :
        {
            for(i = 1;i < RxSize ; ++i)
            {
                if(i != 3)
                {
                    UART_1_WriteTxData(RxBuffer[i]);
                    //LCD_Char_1_PutChar(RxBuffer[i]);
                }                
            }
            break;
        }
        case 2 :
        {
            for(i = 1;i < RxSize ; ++i)
            {
                if(i != 3)
                {
                    UART_2_WriteTxData(RxBuffer[i]);
                    //LCD_Char_1_PutChar(RxBuffer[i]);
                }                
            }
            break;
        }
        case 11 :
        {
            for(i = 0;i < RxSize ; ++i)
            {
                if(i != 3 && i!= 2)
                {
                    UART_1_WriteTxData(RxBuffer[i]);
                    //LCD_Char_1_PutChar(RxBuffer[i]);
                }                
            }
            break;
        }
        case 12 :
        {
            for(i = 0;i < RxSize ; ++i)
            {
                if(i != 3 && i!= 2)
                {
                    UART_2_WriteTxData(RxBuffer[i]);
                    //LCD_Char_1_PutChar(RxBuffer[i]);
                }                
            }
            break;
        }
        default :
        {
            break;
        }
    }
}
示例#2
0
int main()
{    
    uint8 ch;           /* Data sent on the serial port */
    uint8 count = 0u;    /* Initializing the count value */
    uint8 pos = 0u;

    CyGlobalIntEnable; 

    isr_1_Start();      /* Initializing the ISR */
    UART_1_Start();     /* Enabling the UART */
    LCD_Char_1_Start(); /* Enabling the LCD */

        
    for(ch = START_CHAR_VALUE; ch <= END_CHAR_VALUE; ch++)
    {
        UART_1_WriteTxData(ch); /* Sending the data */

        count++;        
        if(count % LCD_NUM_COLUMNS == 0u) /* If the count value reaches the count 16 start from first location */
        {
            pos = 0u;  /* resets the count value */
            LCD_Char_1_WriteControl(LCD_Char_1_CLEAR_DISPLAY); /* Display will be cleared when reached count value 16 */
        }    

        LCD_Char_1_Position(0u, pos++);   /* LCD position to the count++ */
        LCD_Char_1_PutChar(ch);         /* print the value in the LCD */
                
        LCD_Char_1_Position(1u, 0u);
        LCD_Char_1_PrintInt8(count);    /* prints the count in the LCD */
        CyDelay(200u);
    }

    for(;;) {}
}
void main(){
	/* initialize UART */
    UART_1_Start();
	
	/* disable interrupts */
	UART_1_DisableRxInt();
	UART_1_DisableTxInt();
	
	UART_1_ClearTxBuffer();
	UART_1_ClearRxBuffer();
	
	LCD_Char_1_Start();
	LCD_Char_1_Position(0,0);
	
	/* initialize or source array */
	int j;
	for(j = 0; j < DATA_SIZE; ++j){
		sourceData[j] = j;
	}
	
	/* loop to transmit all 4096 bytes of our source array */
	int i;
	for(i = 0; i < DATA_SIZE; ++i){
		UART_1_WriteTxData(sourceData[i]);
		
		/* we check the receiver FIFO to see when we get the data */
		while(UART_1_ReadRxStatus() != UART_1_RX_STS_FIFO_NOTEMPTY){}
		
		/* if FIFO is not empty, save the data */
		receiveData[i] = UART_1_ReadRxData();
	}
 
 	int k;
	int errors = 0;
	/* loop through received data to verify it */
	for(k = 0; k < DATA_SIZE; ++k)
		if(sourceData[k] != receiveData[k]) ++errors;
	
	/* print errors */
	LCD_Char_1_PrintString("errors: ");
	LCD_Char_1_PrintNumber(errors);
	for(;;){
	
    }
}