示例#1
0
文件: main.c 项目: wuweijia1994/PSOC
/*******************************************************************************
* Function Name: UpdateDisplay
********************************************************************************
*
* Summary:
* Print voltage raw count result to the LCD. Clears some characters if
* necessary.
*
* Parameters:
* voltageRawCount: The voltage raw counts being received from the ADC
*
* Return:
* void
*
*******************************************************************************/
void UpdateDisplay (uint16 voltageRawCount, int row)
{
	/* Move the cursor to Row 0 Column 0 */
	LCD_Char_1_Position(ROW_0,COLUMN_0); 
	/* Print Label for the pot voltage raw count */
	LCD_Char_1_PrintString("TEMP NOW:");
	
	LCD_Char_1_Position(ROW_0,COLUMN_13); 
	LCD_Char_1_PrintString("C");
	
	LCD_Char_1_Position(ROW_1,COLUMN_0);
	LCD_Char_1_PrintString("TEMP SET:    C");

	/* Move the cursor to Row 0, Column 10 */
	LCD_Char_1_Position(row,COLUMN_10);
	/* Print the result */
	LCD_Char_1_PrintNumber(voltageRawCount); 
	
	if (voltageRawCount < 10)
	{
		/* Move the cursor to Row 0, Column 11 */
		LCD_Char_1_Position(row,COLUMN_11);
		LCD_Char_1_PrintString(CLEAR_TENS_HUNDREDS); /* Clear last characters */
	}
	else if (voltageRawCount < 100)
	{
		/* Move the cursor to Row 0, Column 12 */
		LCD_Char_1_Position(row,COLUMN_12);
		LCD_Char_1_PrintString(CLEAR_HUNDREDS); /* Clear last characters */
	}
	else
	{
		/* Continue on */
	}
}
void main(){

    UART_1_Start();
	
	/* choose when we receive interrupts from tx and rx */
	UART_1_SetTxInterruptMode(UART_1_TX_STS_COMPLETE);
	UART_1_SetRxInterruptMode(UART_1_RX_STS_FIFO_NOTEMPTY);
	
	CyGlobalIntEnable;
    
	UART_1_ClearTxBuffer();
	UART_1_ClearRxBuffer();
	
	LCD_Char_1_Start();
	LCD_Char_1_Position(0,0);
	
	/* initialize our source data to index */
	int j;
	for(j = 0; j < DATA_SIZE; ++j){
		sourceData[j] = j;
	}
	
	/* enable our interrupt routines */
	isr_1_StartEx(tx_int);
	isr_2_StartEx(rx_int);	
		
	/* idle loop until we finish our transmission */	
 	while(!rx_done){}

 	int k;
	int errors = 0;
	/* data validation */
	for(k = 0; k < DATA_SIZE; ++k)
		if(sourceData[k] != receiveData[k]) ++errors;
	
	/* print errors to lcd */
	LCD_Char_1_PrintString("errors: ");
	LCD_Char_1_PrintNumber(errors);
	
	LCD_Char_1_Position(1,0);
	LCD_Char_1_PrintString("tx:");

	LCD_Char_1_PrintNumber(tx_cnt);
	LCD_Char_1_PrintString(" rx:");

	LCD_Char_1_PrintNumber(rx_cnt);

	for(;;){
	
    }
}
示例#3
0
/*******************************************************************************
* 显示数据到显示屏
********************************************************************************/
void updateDisplay (uint16 tempture)
{
    //LCD_Char_1_ClearDisplay();//清除显示    
    LCD_Char_1_PrintString("Tempture:");/* 打印提示信息 */
    
	LCD_Char_1_Position(0,9); /* 把光标移动到1行,10列 */
	LCD_Char_1_PrintNumber(tempture/10); /* 打印小数点前面的数据 */
    LCD_Char_1_PutChar('.');
    LCD_Char_1_PrintNumber(tempture%10); /* 打印小数点后面的数据 */
    
    LCD_Char_1_PrintString(" ");
    //LCD_Char_1_PutChar(LCD_Char_1_CUSTOM_7);
    LCD_Char_1_PrintString("C");
    
}
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(;;){
	
    }
}
示例#5
0
/*******************************************************************************
* Function Name: main
********************************************************************************
*
* Summary:
*  Main function performs following functions:
*   1: Initializes the LCD
*   2: Get the temperature of the Die
*   3: Print the Die Temperature value in LCD
*   4: Print the Status value in the LCD
*
* Parameters:
*  None.
*
* Return:
*  None.
*
*******************************************************************************/
int main()
{
    cystatus Status;
    int16 temperature;

    /* Initializing the LCD */
    LCD_Char_1_Start();

    while(1)
    {
        /* Providing some delay */
        CyDelay(50);

        /* Reading the Die Temperature value */
        Status = DieTemp_1_GetTemp(&temperature);
       

        /* Displaying the Die Temperature value on the LCD */
        LCD_Char_1_Position(0u, 0u);
        LCD_Char_1_PrintString("Temp = ");

        if (temperature >= 0)
        {
            LCD_Char_1_PrintString("+");
        }
        else
        {
            /* If the temperature value is negative, display "-" sign and make value positive */
            LCD_Char_1_PrintString("-");
            temperature = (uint16)(~temperature + 1u);
        }
        
        LCD_Char_1_PrintNumber((uint16) (temperature));
        LCD_Char_1_PrintString(" ");
        
        LCD_Char_1_PutChar(LCD_Char_1_CUSTOM_7);
        LCD_Char_1_PrintString("C");

        /* Displaying the status value on the LCD */
        LCD_Char_1_Position(1u, 0u);
        LCD_Char_1_PrintString("Status = ");
        LCD_Char_1_PrintInt8((uint8) Status);
    }
}
示例#6
0
文件: main.c 项目: wuweijia1994/PSOC
void main()
{
	CYGlobalIntEnable; /* Enable global interrupts */
	
	ADC_DelSig_1_Start();/* Configure and power up ADC */
	LCD_Char_1_Start(); /* Initialize and clear the LCD */
	
	/* Move the cursor to Row 0 Column 0 */
	LCD_Char_1_Position(ROW_0,COLUMN_0); 
	/* Print Label for the pot voltage raw count */
	LCD_Char_1_PrintString("TEMP NOW:    C");
	
	LCD_Char_1_Position(ROW_1,COLUMN_0);
	LCD_Char_1_PrintString("TEMP SET:    C");
	
	ADC_DelSig_1_StartConvert(); /* Force ADC to initiate a conversion */
	
	/* Start capsense and initialize baselines and enable scan */
	CapSense_Start();
	CapSense_InitializeAllBaselines();
	CapSense_ScanEnabledWidgets();

    /* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */
	//Start the pwm;
	PWM_1_Start();
    for(;;)
    {
		/* If scanning is completed update the baseline count and check if sensor is active */
		while(CapSense_IsBusy());
		
		/* Update baseline for all the sensors */
		CapSense_UpdateEnabledBaselines();
		CapSense_ScanEnabledWidgets();
		
		/* Test if button widget is active */
		stateB_1 = CapSense_CheckIsWidgetActive(CapSense_BUTTON0__BTN);
		stateB_2 = CapSense_CheckIsWidgetActive(CapSense_BUTTON1__BTN);
	
        /* Wait for end of conversion */
		ADC_DelSig_1_IsEndConversion(ADC_DelSig_1_WAIT_FOR_RESULT);
		/* Get converted result */
		voltageRawCount = ADC_DelSig_1_GetResult16();
		//Change voltageRawCount to Temperature;
		temp = voltageRawCount / 3.870 * 0.1017 + 0.5;
		cold = (9999 - (temp > temp_set ? temp - temp_set : 0) * 50);
		if(cold < 1000)
			cold = 1000;
		if(cold > 9999)
			cold = 9999;
		//Change the pwm;
		PWM_1_WriteCompare(cold);
		/* Set range limit */
		if (temp > 0x7FFF)
		{
			temp = 0;
		}
		else
		{
		/* Continue on */
		}
		if(show < 10)
		{
			show++;
		}
		else
		{
			show = 0;
			UpdateDisplay(temp, 0); /* Print result on LCD */
			UpdateButtonState(stateB_1, stateB_2);
		}
    }
}
示例#7
0
void errorDisplay()
{
    LCD_Char_1_ClearDisplay();    
    LCD_Char_1_PrintString("DATA ERROR");/* 打印错误提示信息 */
}
示例#8
0
int main()
{
    init();
    while(1)
    {   
        //LCD_Char_1_PrintNumber(RxSize);
        if(RxSize>4)//来自PC的数据,应该进行解析
        {       
            int i = 0;
            //LCD_Char_1_PrintNumber(RxSize);
            if(RxBuffer[RxSize-1] == 'e' && RxBuffer[0] == 's')
            {
                uint8 config = 0;
                switch(RxBuffer[3])//获取针对节点的信息
                {
                    case 'a' :
                    {
                        config += 3;
                        break;
                    }
                    case '0' :
                    {
                        config += 0;
                        break;
                    }
                    case '1' :
                    {
                        config += 1;
                        break;
                    }
                    case '2' :
                    {
                        config += 2;
                        break;
                    }
                    default :
                    {
                        config = 20;
                        break;
                    }
                }
                switch(RxBuffer[1])
                {                    
                    case 'c' : //设置节点
                    {  
                        if(RxBuffer[2] == 'o')//打开
                        {
                            ;                           
                        }
                        else if(RxBuffer[2] == 'c')//关闭
                        {
                            config += 10; 
                        }
                        
                        configNode(config);
                        break;
                    }
                    case 's' :
                    {
                        if(RxBuffer[2] == 'h')//打开
                        {
                            ;                           
                        }
                        else if(RxBuffer[2] == 'l')//关闭
                        {
                            config += 10; 
                        }                        
                        setNode(config);
                        break;
                    }
                    case 'p' :
                    {
                        setPeriod(config);
                        break;
                    }
                    default :
                    {
                        break;
                    }
                }
                for(i = 0; i < RxSize; ++i)//处理完 清指令队列
                {
                    RxBuffer[RxSize] = '\0';
                }
                RxSize = 0;
                
            }
            else if(RxBuffer[RxSize-1] == 'e' && RxBuffer[0] != 's')//指令出错
            {                
                LCD_Char_1_PrintString("e0");
                for(i = 0; i < RxSize; ++i)//错误指令 清指令队列
                {
                    RxBuffer[RxSize] = '\0';
                }
                RxSize = 0;
            }
            else if(RxSize > 10)
            {
                LCD_Char_1_PrintString("c0");
                for(i = 0; i < RxSize; ++i)//错误指令 清指令队列
                {
                    RxBuffer[i] = '\0';
                }
                RxSize = 0;
            }
            
        }
        
        if(Rx_1_Size > 2)//来自结点1的数据,应该转发给电脑
        {
            uint8 i = 0;                 
            if(Rx_1_Buffer[Rx_1_Size-1] == 'e' && Rx_1_Buffer[0] == 's')
            {
                LCD_Char_1_PrintString(Rx_1_Buffer);
                if(Rx_1_Buffer[1] == 't') //转发温度,加上节点号
                {
                    char tem[9]; 
                    tem[0] = 's';
                    tem[1] = 't';
                    tem[2] = '1';//节点号
                    tem[3] = Rx_1_Buffer[2];
                    tem[4] = Rx_1_Buffer[3];
                    tem[5] = Rx_1_Buffer[4];
                    tem[6] = 'e';
                    tem[7] = '\0';
                    UART_PutString(tem);
                }
                else if(Rx_1_Buffer[1] == 'h') //转发温度过高
                {
                    LCD_Char_1_PutChar('l');
                    UART_PutString("sh1he");
                }
                else if(Rx_1_Buffer[1] == 'l') //转发温度过低
                {
                    UART_PutString("sh1le");
                }
                for(i = 0; i < Rx_1_Size; ++i)//处理完 清指令队列
                {
                    Rx_1_Buffer[i] = '\0';
                }
                Rx_1_Size = 0;
            }
            
            else if(Rx_1_Buffer[Rx_1_Size-1] == 'e' && Rx_1_Buffer[0] != 's')//指令出错
            {                
                LCD_Char_1_PrintString("e");
                for(i = 0; i < Rx_1_Size; ++i)//错误指令 清指令队列
                {
                    Rx_1_Buffer[i] = '\0';
                }
                Rx_1_Size = 0;
            }
            else if(Rx_1_Size > 10)
            {
                LCD_Char_1_PrintString("c");
                for(i = 0; i < Rx_1_Size; ++i)//错误指令 清指令队列
                {
                    Rx_1_Buffer[i] = '\0';
                }
                Rx_1_Size = 0;
            }
        }
        
        if(Rx_2_Size > 4)//来自结点2的数据,应该转发给电脑
        {
            uint8 i = 0;                 
            if(Rx_2_Buffer[Rx_2_Size-1] == 'e' && Rx_2_Buffer[0] == 's')
            {
                if(Rx_2_Buffer[1] == 't') //转发温度,加上节点号
                {
                    char tem[9]; 
                    tem[0] = 's';
                    tem[1] = 't';
                    tem[2] = '2';//节点号
                    tem[3] = Rx_2_Buffer[2];
                    tem[4] = Rx_2_Buffer[3];
                    tem[5] = Rx_2_Buffer[4];
                    tem[6] = 'e';
                    tem[7] = '\0';
                    UART_PutString(tem);
                }
                else if(Rx_2_Buffer[1] == 'h') //转发温度过高
                {
                    UART_PutString("sh2he");
                }
                else if(Rx_2_Buffer[1] == 'l') //转发温度过低
                {
                    UART_PutString("sh2le");
                }
                for(i = 0; i < Rx_2_Size; ++i)//处理完 清指令队列
                {
                    Rx_2_Buffer[i] = '\0';
                }
                Rx_2_Size = 0;
            }
            
            else if(Rx_2_Buffer[Rx_2_Size-1] == 'e' && Rx_2_Buffer[0] != 's')//指令出错
            {                
                LCD_Char_1_PrintString("e");
                for(i = 0; i < Rx_2_Size; ++i)//错误指令 清指令队列
                {
                    Rx_2_Buffer[i] = '\0';
                }
                Rx_2_Size = 0;
            }
            else if(Rx_2_Size > 10)
            {
                LCD_Char_1_PrintString("c");
                for(i = 0; i < Rx_2_Size; ++i)//错误指令 清指令队列
                {
                    Rx_2_Buffer[i] = '\0';
                }
                Rx_2_Size = 0;
            }
        }
        
    }
}