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

📄 adc.c

📁 基于cc1010的设计实例
💻 C
字号:
/*****************************************************************************
 *                                                                           *
 *        **********                                                         *
 *       ************                                                        *
 *      ***        ***                                                       *
 *      ***   +++   ***                                                      *
 *      ***   + +   ***                                                      *
 *      ***   +                    CHIPCON CC1010 EXAMPLE PROGRAM            *
 *      ***   + +   ***                  THE A/D CONVERTER                   *
 *      ***   +++   ***                                                      *
 *      ***       ***                                                        *
 *       ***********                                                         *
 *        *********                                                          *
 *                                                                           *
 *****************************************************************************
 * This program demonstrates the use of A/D converter.                       *
 *                                                                           *
 * The converter is connected to the variable resistor on the CC1010EB (a    *
 * grey pot meter). The sampled value is used to control the speed of a      *
 * counter. The 4 LSBs of this counter byte control the EB LEDs. This makes  *
 * it possible to adjust the blinking rate by turning the potmeter knob.     *
 *****************************************************************************
 * Author:              ROH,TEL,JOL                                          *
 *****************************************************************************
 * Revision history:                                                         *
 * 1.0  2002/08/28      First Public Release                                 *
 *                                                                           *
 * $Log: adc.c,v $
 * Revision 1.2  2002/11/18 10:08:41  kht
 * Added startup macros
 *
 * Revision 1.1  2002/10/11 14:49:36  tos
 * Initial version in CVS.
 *
 *                                                                           *
 ****************************************************************************/

#include <chipcon/hal.h>
#include <chipcon/cc1010eb.h>


// LED masks
#define RLED_MASK   0x01
#define YLED_MASK   0x02
#define GLED_MASK   0x04
#define BLED_MASK   0x08

#define CLK_FREQ    CC1010EB_CLKFREQ


/*****************************************************************************
    MAIN PROGRAM
*****************************************************************************/
void main(void) {
    unsigned short adc;
    unsigned short i;
    unsigned short waitTime = 20000;
    unsigned char counter = 0;
    
    // Disable the watchdog timer
    WDT_ENABLE(FALSE);

    // Set optimum settings for speed and low power consumption
    MEM_NO_WAIT_STATES();
    FLASH_SET_POWER_MODE(FLASH_STANDBY_BETWEEN_READS);
    
    // Enable the LEDs
    RLED_OE(TRUE);
    YLED_OE(TRUE);
    GLED_OE(TRUE);
    BLED_OE(TRUE);

    // Setup ADC, select the CC1010EB pot meter, and turn it on
    halConfigADC(ADC_MODE_SINGLE | ADC_REFERENCE_VDD, CLK_FREQ, 0); // 0: Threshold value (not used in this program)
    ADC_SELECT_INPUT(ADC_INPUT_AD0);
    ADC_POWER(TRUE); // Power up ADC from sleep mode

    // Loop forever
    while (TRUE) {       
      
        // Display the counter word on LEDs
        RLED = !(counter & RLED_MASK);
        YLED = !(counter & YLED_MASK);
        GLED = !(counter & GLED_MASK);                
        BLED = !(counter & BLED_MASK);

        // Acquire a new sample value from the pot meter
        adc = ADC_GET_SAMPLE_10BIT();
        ADC_SAMPLE_SINGLE();
        
        // Wait before incrementing the counter and updating the LEDs
        waitTime = ((unsigned short)(adc)) * 60 + 2000; // Adjust the time scale (avoids overflow)
        for (i = 0; i < waitTime; i++);

        // Double the waiting time by pressing switch 1
        if (SW1_PRESSED) {
            for (i = 0; i < waitTime; i++);            
        }        
        
        counter++;
    } 
} // main

⌨️ 快捷键说明

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