Пример #1
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(;;) {}
}
Пример #2
0
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 UpdateButtonState(uint8 slot_1, uint8 slot_2)
{
	LCD_Char_1_Position(ROW_0,COLUMN_0);
	
	/* Check the state of the buttons and update the LCD and the temperature setting */
	if (slot_1 && slot_2)
	{
		//do nothing;
	}
	else if (slot_1 || slot_2)
	{
		if (slot_1)
		{
			if(temp_set < 28)
			{
				temp_set++;
			}
		}
		if (slot_2)
		{
			if(temp_set > 18)
			{
				temp_set--;
			}
		}
	}
	else
	{
		//do nothing;
	}
	UpdateDisplay(temp_set, 1);
}
Пример #4
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);
    }
}
Пример #5
0
/*******************************************************************************
* 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 */
	}
}
Пример #6
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");
    
}
Пример #7
0
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(;;){
	
    }
}
Пример #8
0
/*******************************************************************************
* Function Name: LCD_Char_1_DrawHorizontalBG
********************************************************************************
*
* Summary:
*  Draws the horizontal bargraph.
*
* Parameters:
*  row:            The row in which the bar graph starts.
*  column:         The column in which the bar graph starts.
*  maxCharacters:  The max length of the graph in whole characters.
*  value:          The current length or height of the graph in pixels.
*
* Return:
*  void.
*
*******************************************************************************/
void LCD_Char_1_DrawHorizontalBG(uint8 row, uint8 column, uint8 maxCharacters, uint8 value) \
                                                        
{
    /* 8-bit Counter */
    uint8 count8 = 0u;
    uint8 fullChars;
    uint8 remainingPixels;

    /* Number of full characters to draw */
    fullChars = value / LCD_Char_1_CHARACTER_WIDTH;
   
    /* Number of remaining pixels to draw */
    remainingPixels = value % LCD_Char_1_CHARACTER_WIDTH; 
    
    /* Ensure that the maximum character limit is followed. */
    if(fullChars >= maxCharacters)
    {
        fullChars = maxCharacters;
    }
    
    /* Put Cursor at start position */
    LCD_Char_1_Position(row, column);

    /* Write full characters */
    for(count8 = 0u; count8 < fullChars; count8++)
    {
        LCD_Char_1_WriteData(LCD_Char_1_CUSTOM_5);
    }

    if(fullChars < maxCharacters)
    {
        /* Write remaining pixels */
        LCD_Char_1_WriteData(remainingPixels);

        if(fullChars < (maxCharacters - 1u))
        {
            /* Fill with whitespace to end of bar graph */
            for(count8 = 0u; count8 < (maxCharacters - fullChars - 1u); count8++)
            {
                LCD_Char_1_WriteData(LCD_Char_1_CUSTOM_0);
            }
        }
    }
}
Пример #9
0
/*******************************************************************************
*  Function Name: LCD_Char_1_DrawVerticalBG
********************************************************************************
*
* Summary:
*  Draws the vertical bargraph.
*
* Parameters:
*  row:            The row in which the bar graph starts.
*  column:         The column in which the bar graph starts.
*  maxCharacters:  The max height of the graph in whole characters.
*  value:          The current length or height of the graph in pixels.
*
* Return:
*  void.
*
*******************************************************************************/
void LCD_Char_1_DrawVerticalBG(uint8 row, uint8 column, uint8 maxCharacters, uint8 value) \
                                                        
{
    /* 8-bit Counter */
    uint8 count8 = 0u;
    /* Current Row Tracker */
    int8 currentRow;
    uint8 fullChars;
    uint8 remainingPixels;

    /* Row number error.  Don't write remaining pixels.*/
    currentRow = row;

    /* Number of full characters to draw */
    fullChars = value / LCD_Char_1_CHARACTER_HEIGHT;
    
    /* Number of remaining pixels to draw */
    remainingPixels = value % LCD_Char_1_CHARACTER_HEIGHT;

    /* Put Cursor at start position */
    LCD_Char_1_Position(row, column);

    /* Make sure the bar graph fits inside the space allotted */
    if(fullChars >= maxCharacters)
    {
        fullChars = maxCharacters;
    }

    /*  Write full characters */
    while(count8 < fullChars)
    {
        LCD_Char_1_WriteData(LCD_Char_1_CUSTOM_7);
        
        count8++;
       
        /* Each pass through, move one row higher */
        if((row - count8) >= 0u)
        {
            LCD_Char_1_Position(row - count8, column);
        }
        else
        {
            break;
        }    
    }

    if(((row - count8) >= 0u) && (fullChars < maxCharacters))
    {
        /* Write remaining pixels */
        if(remainingPixels == 0u)
        {
            LCD_Char_1_WriteData(' ');
        }
        else
        {
            LCD_Char_1_WriteData(remainingPixels - 1u);
        }

        currentRow = row - count8 - 1u;

        if(currentRow >= 0u)
        {
            /* Move up one row and fill with whitespace till top of bar graph */
            for(count8 = 0u; count8 < (maxCharacters - fullChars - 1u); count8++)
            {
                LCD_Char_1_Position(currentRow, column);
                LCD_Char_1_WriteData(' ');
                currentRow --;
            }
        }
    }
}
Пример #10
0
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);
		}
    }
}