main.c

来自「STR71X系列ARM微控制器原理与实践配套光盘」· C语言 代码 · 共 55 行

C
55
字号
#include "71x_lib.h"

#include "LCD.h"

void Main(void)
{
	#ifdef DEBUG
		debug();
	#endif

	LCD_Init();

	// Configure the used analog input to HI_AIN_
	GPIO_Config(GPIO1, 0x0001, GPIO_HI_AIN_TRI);

	// Initialize the conveter register.
	ADC12_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_CHANNEL0);

	// Start the Converter
	ADC12_ConversionStart();

	LCD_Goto(0, 0);
	LCD_Puts("ADC: ");
	while(1)
	{
		int n, i;

		// Wait until the availabiliy of data in the specific flags
		while(ADC12_FlagStatus(ADC12_DA0) == RESET);

		// Get the conversion result from the correponding Data register
		n = ADC12_ConversionValue(ADC12_CHANNEL0);
		ADC12->CSR &= ~ADC12_DA0;

		// Show the result on LCD
		LCD_Goto(0, 5);
		LCD_Printf("%4d(0x%03X)", n, n);
		LCD_Goto(1, 0);
		for(i = 0; i < 16; i++)
			LCD_Putc('-');
		LCD_Goto(1, n >> 8);
		LCD_Putc('+');
	}
}

⌨️ 快捷键说明

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