⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adc_uart_lcd.c

📁 cypress的uart和lcd模块的应用.希望可以对大家有个抛砖引玉的作用.
💻 C
字号:
//----------------------------------------------------------------------------
// C_ADC_UART_LCD Project
//-----------------------------------------------------------------------------


#include <m8c.h>                         // part specific constants and macros
#include "PSoCAPI.h"                     // PSoC API definitions for all User Modules
	
#define RESOLUTION 12                    // ADC resolution
#define SCALE_BG  (( 1 << RESOLUTION)/55) // BarGraph scale factor

int  iResult;                            // ADC result variable

void main()
{
    BYTE bgPos;                          // BarGraph position

    UART_1_Start(UART_PARITY_NONE);      // Enable UART
    UART_1_CPutString("Example ADC_UART_LCD"); // Example string
    UART_1_PutCRLF();
     
    PGA_1_Start(PGA_1_MEDPOWER);         // Turn on PGA power
    ADCINC12_1_Start(ADCINC12_1_MEDPOWER); // Turn on ADC power
    ADCINC12_1_GetSamples(0);            // Sample forever
    
    LCD_1_Start();                       // Init the LCD
    LCD_1_InitBG(LCD_1_SOLID_BG);
    LCD_1_Position(0,0);
    LCD_1_PrCString("PSoC LCD");
    
    M8C_EnableGInt;                      // Enable Global interrupts
    
    while (1)// Main loop 
    {   
       if (ADCINC12_1_fIsDataAvailable() != 0) // If ADC sample is ready...
       {
          iResult = ADCINC12_1_iGetData() + 2048; // Get result, convert to unsigned and clear flag
          ADCINC12_1_ClearFlag();
          
          UART_1_PutSHexInt(iResult);    // Print result to UART
          UART_1_PutCRLF();              // Tack on a CR and LF
         
          LCD_1_Position(1,0);           // display result on LCD in hex and as a bar graph
          LCD_1_PrHexInt(iResult);
          bgPos = (BYTE)(iResult/SCALE_BG);
          LCD_1_DrawBG(1, 5, 11, bgPos);
       }
    }
}





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -