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

📄 main.c

📁 1.CYPRESS ic分位置 2.cy3655_encore_tm__ii_development_kit_15.rar
💻 C
字号:
//----------------------------------------------------------------------------
// WL Encore II Example Project
//
// Description: This is a simple project that is targeted at the CY7C603xx
// part.  The functionality is quite simple.  A two channel A/D converter is 
// setup using the ADC10 User Module.  The ADC alternates between channels 
// whose source is the Potentiometers on the board. The resultant output of
// the ADC is used to set the duty of the PWM outputs.  The PWM outputs are
// connected to two of the LEDs on the board.  The application also scans 
// the two push buttons and reflects their state on the two other LEDs.
//
// Hardware: This project can be run on the CYxxxx Wireless Encore II Evaluation
// board with the connections shown below.  
//
// Wireless Encore II Eval Connections:
//       port1_pin2 -> LED1
//       port1_pin3 -> LED2
//       port1_pin4 -> LED3
//       port1_pin5 -> LED4
//       port0_pin1 -> VR1
//       port0_pin3 -> VR2
//       port0_pin4 -> SW1
//       port0_pin5 -> SW2
//
//-----------------------------------------------------------------------------

#include <m8c.h>        // part specific constants and macros
#include "PSoCAPI.h"    // PSoC API definitions for all User Modules

#define MyDefaultPeriod (137)
#define MyGetSpread(input) ((input) < 0) ? (MyDefaultPeriod) : ((input >> 3) + 9) /* 9 ... 137 */

void main()
{
	int bTemp;

    M8C_EnableGInt;
    PWMClock_Start() ;
    PWM1_Start();
    PWM2_Start();
    
    ADC10_Start(ADC10_FULLRANGE);
   	ADC10_iCal(283, ADC10_CAL_VBG);
   	ADC10_StartADC();
   
    while(1)
    {
    	//Get Data from the First Channel P0_1
    	ADC10_StopADC();
    	AMX_IN = 0x00;
    	ADC10_StartADC();
    	
    	while(!ADC10_fIsDataAvailable());
    	bTemp = MyGetSpread(ADC10_iGetDataClearFlag());
		PWM1_WritePeriod(bTemp);
		PWM1_WritePulseWidth(bTemp >> 1);

    	//Get Data from the Second Channel P0_3
    	ADC10_StopADC();
    	AMX_IN = 0x01;
    	ADC10_StartADC();

    	while(!ADC10_fIsDataAvailable());
    	bTemp = MyGetSpread(ADC10_iGetDataClearFlag());
		PWM2_WritePeriod(bTemp);
		PWM2_WritePulseWidth(bTemp >> 1);
    	
    	//Scan the buttons and place their value on the LED
    	bTemp = ~(PRT0DR);
    	bTemp = bTemp & 0x30;
    	PRT1DR = bTemp;
    }
}

⌨️ 快捷键说明

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