改了无数编代码还是用不了,官方的AI也试了还是不能用,大佬们帮看看啥情况
- /*---------------------------------------------------------------------*/
- /* --- STC MCU Limited ------------------------------------------------*/
- /* --- STC 1T Series MCU Demo Programme -------------------------------*/
- /* --- Mobile: (86)13922805190 ----------------------------------------*/
- /* --- Fax: 86-0513-55012956,55012947,55012969 ------------------------*/
- /* --- Tel: 86-0513-55012928,55012929,55012966 ------------------------*/
- /* --- Web: www.STCAI.com ---------------------------------------------*/
- /* --- BBS: www.STCAIMCU.com -----------------------------------------*/
- /* --- QQ: 800003751 -------------------------------------------------*/
- /* ���Ҫ�ڳ�����ʹ�ô˴���,���ڳ�����ע��ʹ����STC�����ϼ����� */
- /*---------------------------------------------------------------------*/
-
- #include "config.h"
- #include "STC8G_H_GPIO.h"
- #include "STC8G_H_ADC.h"
- #include "STC8G_H_UART.h"
- #include "STC8H_DMA.h"
- #include "STC8G_H_NVIC.h"
- #include "STC8G_H_Delay.h"
- #include "STC8G_H_Switch.h"
-
- /************* ����˵�� ***************
-
- ��������ʾ��·ADC DMA����.
-
- ��ʼ��ʱ�Ȱ�ҪADCת������������Ϊ��������.
-
- ����������������(DMA)���ܣ�����ͨ��һ��ѭ���ɼ��������Զ���ŵ�DMA�����xdata�ռ�.
-
- ͨ������1(P3.0 P3.1)��DMA�����xdata�ռ����յ������ݷ�����λ����������115200,N,8,1
-
- �ö�ʱ���������ʷ�����������ʹ��1Tģʽ(���ǵͲ�������12T)����ѡ��ɱ�������������ʱ��Ƶ�ʣ�����߾���.
-
- ����ʱ, ѡ��ʱ�� 22.1184MHz (�����������ļ�"config.h"����).
-
- ******************************************/
-
- /************* ���س������� **************/
-
- #define ADC_CH 1 /* ADCת��ͨ����, ����P1.1 */
- #define ADC_DATA 12 /* ÿ��ͨ��ADCת����������, 2*ת������+4 */
- #define ADC_CHANNEL_P11 0x0002 /* P1.1 ��Ӧ ADC ͨ��1, bit1 */
- #define VCC 3300UL /* ��ѹ��λmV, ������VCCʵ�ʵ�ѹ�� */
-
- /************* ���ر������� **************/
-
- u8 xdata DmaAdBuffer[ADC_CH][ADC_DATA];
-
- /************* �ⲿ�����ͱ������� *****************/
-
-
- /******************** IO������ ********************/
- void GPIO_config(void)
- {
- P1_MODE_IN_HIZ(GPIO_Pin_1); //P1.1 ������������
- P1_PULL_UP_DISABLE(GPIO_Pin_1); //����P1.1�ڲ�����
- P1_DIGIT_IN_DISABLE(GPIO_Pin_1); //�ر�P1.1�������룬��������ADC
- }
-
- /******************** UART���� ********************/
- void UART_config(void)
- {
- COMx_InitDefine COMx_InitStructure; //�ṹ����
-
- COMx_InitStructure.UART_Mode = UART_8bit_BRTx; //ģʽ, UART_ShiftRight,UART_8bit_BRTx,UART_9bit,UART_9bit_BRTx
- COMx_InitStructure.UART_BRT_Use = BRT_Timer1; //ѡ�����ʷ�����, BRT_Timer1,BRT_Timer2 (ע��: ����2�̶�ʹ��BRT_Timer2)
- COMx_InitStructure.UART_BaudRate = 115200ul; //������, 110 ~ 115200
- COMx_InitStructure.UART_RxEnable = ENABLE; //��������, ENABLE �� DISABLE
- UART_Configuration(UART1, &COMx_InitStructure); //��ʼ������ UART1,UART2,UART3,UART4
- NVIC_UART1_Init(ENABLE,Priority_1); //�ж�ʹ��, ENABLE/DISABLE; ���ȼ�(�͵���) Priority_0,Priority_1,Priority_2,Priority_3
-
- UART1_SW(UART1_SW_P30_P31); //UART1_SW_P30_P31,UART1_SW_P36_P37,UART1_SW_P16_P17,UART1_SW_P43_P44
- }
-
- /******************** ADC ���� ********************/
- void ADC_config(void)
- {
- ADC_InitTypeDef ADC_InitStructure; //�ṹ����
-
- ADC_InitStructure.ADC_SMPduty = 31; //ADC ģ���źŲ���ʱ�����, 0~31
- ADC_InitStructure.ADC_CsSetup = 1; //ADC ͨ��ѡ��ʱ����� 0(Ĭ��),1
- ADC_InitStructure.ADC_CsHold = 3; //ADC ͨ��ѡ��ʱ����� 0,1(Ĭ��),2,3
- ADC_InitStructure.ADC_Speed = ADC_SPEED_2X16T;
- ADC_InitStructure.ADC_AdjResult = ADC_RIGHT_JUSTIFIED;
- ADC_Inilize(&ADC_InitStructure);
- ADC_PowerControl(ENABLE);
- NVIC_ADC_Init(DISABLE,Priority_0);
-
- TSCTRL &= ~0x01; // �رմ�����
- LCDCFG = 0; // �ر�LCD����(TLCD�ͺſ���Ĭ�Ͽ���)
- }
-
- /******************** DMA ���� ********************/
- void DMA_config(void)
- {
- DMA_ADC_InitTypeDef DMA_ADC_InitStructure; //�ṹ����
-
- DMA_ADC_InitStructure.DMA_Enable = ENABLE; //DMAʹ�� ENABLE,DISABLE
- DMA_ADC_InitStructure.DMA_Channel = ADC_CHANNEL_P11; //ADCͨ��ʹ�ܼĴ���, bit1=P1.1
- DMA_ADC_InitStructure.DMA_Buffer = (u16)DmaAdBuffer; //ADCת�����ݴ洢��ַ
- DMA_ADC_InitStructure.DMA_Times = ADC_4_Times; //ÿ��ͨ��ת������, ADC_1_Times,ADC_2_Times,ADC_4_Times,ADC_8_Times,ADC_16_Times,ADC_32_Times,ADC_64_Times,ADC_128_Times,ADC_256_Times
- DMA_ADC_Inilize(&DMA_ADC_InitStructure); //��ʼ��
- NVIC_DMA_ADC_Init(ENABLE,Priority_0,Priority_0); //�ж�ʹ��, ENABLE/DISABLE; ���ȼ�(�͵���) Priority_0~Priority_3; �������ȼ�(�͵���) Priority_0~Priority_3
- DMA_ADC_TRIG(); //��������ת��
- }
-
- /******************** task A **************************/
- void main(void)
- {
- u16 adc_val;
- u32 volt;
-
- EAXSFR();
- GPIO_config();
- UART_config();
- ADC_config();
- EA = 1;
- while (1)
- {
- adc_val = Get_ADCResult(1);
- volt = (u32)adc_val * VCC / 4096;
- printf("CH1=%u (%umV) RES=%02bx RESL=%02bx\r\n",
- adc_val, (u16)volt, ADC_RES, ADC_RESL);
- delay_ms(500);
- }
- }
-
-
复制代码
|