📄 adc.c.svn-base
字号:
/******************************************************************************** **** Copyright (c) 2000 ST Microelectronics **** All rights reserved **** **** Filename : adc.c **** Author : Maurizio Costagliola **** Revision : 1.0 **** **** **** *********************************************************************************//******************************************************************************/#include "uart.h"#include "adc.h"#include "vic_pl190.h"#include "gpio.h"/************************ interrupt handler ************************/void adc_int_handler(){ unsigned int avarage; avarage = ADCCntl->AVERAGE_REG; ADCCntl->ADC_STATUS_REG &= INT_CLR; //interrupt clear UART_print_integer((int)avarage); while (!(UART_putc(13))); while (!(UART_putc(10))); UART_tx_vec("press s to stop r to run again ",strlen("press s to stop r to run again"));}/********************* registers configuration ********************/void adc_init(){ intctlIntRegister(ITC_ADC_int, adc_int_handler, 1); ADCCntl->ADC_STATUS_REG = 0x00000000; // select the channel '0 and disable converter by default ADCCntl->ADC_CLK_REG = 0x000002CB; // ADC clock setting fadc=3Mhz}/***************************** adc test ***************************/void adc_test(void){ static char schedule; static char channel,samples; schedule='r'; while ((schedule == 'r') && (schedule != 's')) { ADCCntl->ADC_STATUS_REG = 0x00000000; UART_tx_vec("Select Channel (0 - f) ",strlen("Select Channel (1 - 16) ")); while (!(UART_getc(&channel))); switch (channel) { case '0' : ADCCntl->ADC_STATUS_REG |= 0x00000000; break; case '1' : ADCCntl->ADC_STATUS_REG |= 0x00000002; break; case '2' : ADCCntl->ADC_STATUS_REG |= 0x00000004; break; case '3' : ADCCntl->ADC_STATUS_REG |= 0x00000006; break; case '4' : ADCCntl->ADC_STATUS_REG |= 0x00000008; break; case '5' : ADCCntl->ADC_STATUS_REG |= 0x0000000a; break; case '6' : ADCCntl->ADC_STATUS_REG |= 0x0000000c; break; case '7' : ADCCntl->ADC_STATUS_REG |= 0x0000000e; break; case '8' : ADCCntl->ADC_STATUS_REG |= 0x00000010; break; case '9' : ADCCntl->ADC_STATUS_REG |= 0x00000012; break; case 'a' : ADCCntl->ADC_STATUS_REG |= 0x00000014; break; case 'b' : ADCCntl->ADC_STATUS_REG |= 0x00000015; break; case 'c' : ADCCntl->ADC_STATUS_REG |= 0x00000018; break; case 'd' : ADCCntl->ADC_STATUS_REG |= 0x0000001a; break; case 'e' : ADCCntl->ADC_STATUS_REG |= 0x0000001c; break; case 'f' : ADCCntl->ADC_STATUS_REG |= 0x0000001e; break; } while (!(UART_putc(channel))); while (!(UART_putc(13))); while (!(UART_putc(10))); UART_tx_vec("Select number of samples for avarage",strlen("Select number of samples for avarage")); UART_tx_vec("O -> 0 samples",strlen("O -> 0 samples")); UART_tx_vec("1 -> 2 samples",strlen("1 -> 2 samples")); UART_tx_vec("2 -> 4 samples",strlen("2 -> 4 samples")); UART_tx_vec("3 -> 8 samples",strlen("3 -> 8 samples")); UART_tx_vec("4 -> 16 samples",strlen("4 -> 16 samples")); UART_tx_vec("5 -> 32 samples",strlen("5 -> 32 samples")); UART_tx_vec("6 -> 64 samples",strlen("6 -> 64 samples")); UART_tx_vec("7 -> 128 samples",strlen("7 -> 128 samples")); while (!(UART_getc(&samples))); samples='5'; switch (samples) { case '0' : ADCCntl->ADC_STATUS_REG |= 0x00000000; break; case '1' : ADCCntl->ADC_STATUS_REG |= 0x00000020; break; case '2' : ADCCntl->ADC_STATUS_REG |= 0x00000040; break; case '3' : ADCCntl->ADC_STATUS_REG |= 0x00000060; break; case '4' : ADCCntl->ADC_STATUS_REG |= 0x00000080; break; case '5' : ADCCntl->ADC_STATUS_REG |= 0x000000a0; break; case '6' : ADCCntl->ADC_STATUS_REG |= 0x000000c0; break; case '7' : ADCCntl->ADC_STATUS_REG |= 0x000000e0; break; } while (!(UART_putc(samples))); while (!(UART_putc(13))); while (!(UART_putc(10)));// APB_show_regs((unsigned int*)0x1200B000, (unsigned int*)0x00200000, 4); ADCCntl->ADC_STATUS_REG |= MASK_EN; //start conversion// APB_show_regs((unsigned int*)0x1200B000, (unsigned int*)0x00200010, 4); while (!(UART_getc(&schedule))); /* schedule='s'; */ while( (schedule != 's') && (schedule != 'r')) { while (!(UART_getc(&schedule))); } while (!(UART_putc(13))); while (!(UART_putc(10))); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -