📄 main.c
字号:
#include "71x_lib.h"
#include "LED.h"
int main(void)
{
int m,n;
#ifdef DEBUG
debug();
#endif
// LCD_Init();
// Configure the used analog input to HI_AIN_
GPIO_Config(GPIO1, 0x0008, GPIO_HI_AIN_TRI); //AIN.3 p1.3
// Initialize the conveter register.
ADC12_Init();
LED_Init();
// Configure the prescaler register using the configured PCLK
// with a sampling frequency=100Hz
ADC12_PrescalerConfig(100);
// Select the conversion mode=single channel
ADC12_ModeConfig(ADC12_SINGLE);
// Select the channel to be converted
ADC12_ChannelSelect(ADC12_CHANNEL3);
// Start the Converter
ADC12_ConversionStart();
m=0;
while(1)
{
int flag=0x0000;
// Wait until the availabiliy of data in the specific flags
while(ADC12_FlagStatus(ADC12_DA3) == RESET);
// Get the conversion result from the correponding Data register
n = ADC12_ConversionValue(ADC12_CHANNEL3);
ADC12->CSR &= ~ADC12_DA3;
flag=(n-m); //flag=n-m
if ((flag&0xf000)!=0x0000) flag=m-n;//flag is the abs(n-m)
if (flag>0x0004)
{
if (n>m)
{
LED_Set(LED3,GPIO1,LED_ON); //bigger
LED_Set(LED4,GPIO1,LED_OFF);
}
else
{
LED_Set(LED3,GPIO1,LED_OFF); //smaller
LED_Set(LED4,GPIO1,LED_ON);
}
}
m=n;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -