找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 1521|回復(fù): 3
收起左側(cè)

stm32關(guān)于ADC數(shù)模轉(zhuǎn)換查詢方式Proteus仿真的問題

[復(fù)制鏈接]
ID:1076644 發(fā)表于 2023-6-2 11:17 | 顯示全部樓層 |閱讀模式
不知道代碼有什么問題,一開始仿真什么都不顯示,但是將主函數(shù)中 ‘ADC_ResetCalibration(ADC1);’注釋后,就開始顯示一串0,后來就覺得是不是上拉電阻的問題,就加上了上拉電阻,然后就不是直接顯示的一串0,而是閃爍著顯示。也檢測(cè)不到滑動(dòng)變阻器的改變。求助大佬,不知道是哪的問題。
代碼如下:
  1. #include "stm32f10x.h"

  2. void GPIO_Config(void);
  3. void ADC_Config(void);
  4. void Delay(void);
  5. void seven(uint16_t value);
  6. void Display(unsigned char * digit);
  7. unsigned char discode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8, 0x80,0x90};
  8. unsigned char digit[4] = {0XC0,0XC0,0XC0,0XC0};
  9. int main(void)
  10. {
  11.                 uint16_t ad_v=0;  //存放轉(zhuǎn)換值
  12.                 GPIO_Config();
  13.                 ADC_Config();
  14.           GPIO_ResetBits(GPIOA, GPIO_Pin_0 | GPIO_Pin_1 |GPIO_Pin_2 |GPIO_Pin_3);
  15.           GPIO_Write(GPIOB, 0xc0);
  16.                 ADC_Cmd(ADC1, ENABLE);
  17.                
  18. //                ADC_ResetCalibration(ADC1);  //重置ADC1校準(zhǔn)寄存器         
  19.                 while(ADC_GetResetCalibrationStatus(ADC1));  //等待重置完成
  20.                 ADC_StartCalibration(ADC1);  //開始校準(zhǔn)ADC1        
  21.                 while(ADC_GetCalibrationStatus(ADC1));  //等待校準(zhǔn)完成
  22.                 ADC_SoftwareStartConvCmd(ADC1, ENABLE);//開始軟件觸發(fā)轉(zhuǎn)換
  23.                 while(1)
  24.                         {
  25.                                 Display(digit);         
  26.                                 if(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC == SET))
  27.                                 {
  28.                                          ad_v = ADC_GetConversionValue(ADC1); //獲取轉(zhuǎn)換數(shù)值
  29.                                          ad_v&=0x0fff; //保留右對(duì)齊的12位}
  30.                                         seven(ad_v);
  31.                                 }
  32.                         }

  33.         }        


  34. void GPIO_Config(void)
  35. {               
  36.         //結(jié)構(gòu)體
  37.         GPIO_InitTypeDef   GPIO_InitStructure;
  38.         
  39.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOA, ENABLE);
  40.         
  41.         //七段數(shù)碼管
  42.         GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_0 | GPIO_Pin_1 |GPIO_Pin_2 |GPIO_Pin_3 |GPIO_Pin_4 |GPIO_Pin_5 |GPIO_Pin_6 |GPIO_Pin_7);
  43.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  44.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  45.         GPIO_Init(GPIOB, &GPIO_InitStructure);
  46.         
  47.         GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_0 | GPIO_Pin_1 |GPIO_Pin_2 |GPIO_Pin_3);
  48.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  49.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  50.         GPIO_Init(GPIOA, &GPIO_InitStructure);
  51.         
  52.         //外部滑動(dòng)變阻器
  53.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
  54.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  55.         GPIO_Init(GPIOC, &GPIO_InitStructure);
  56.         
  57. }

  58. void ADC_Config(void)
  59. {        
  60.                 ADC_InitTypeDef ADC_InitStructure;
  61.                 RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
  62.                 ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;  
  63.                 ADC_InitStructure.ADC_ScanConvMode = DISABLE;                  
  64.                 ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;   
  65.                 ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
  66.                 ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;   
  67.                 ADC_InitStructure.ADC_NbrOfChannel = 1;         
  68.                 ADC_Init(ADC1, &ADC_InitStructure);
  69.                 ADC_RegularChannelConfig(ADC1, ADC_Channel_13,1, ADC_SampleTime_55Cycles5);
  70. }

  71. void seven(uint16_t value){
  72.         
  73.                          digit[0] = value % 10;  //個(gè)
  74.                 digit[1] = (value % 100) /10; //十
  75.                 digit[2] = (value % 1000)/100;  //百
  76.                 digit[3] = value / 1000 ;  //千
復(fù)制代碼
仿真如下:
910804920c7ea655eb29386574693f9e.png



回復(fù)

使用道具 舉報(bào)

ID:94031 發(fā)表于 2023-6-2 13:42 | 顯示全部樓層
回復(fù)

使用道具 舉報(bào)

ID:1076644 發(fā)表于 2023-6-8 10:34 | 顯示全部樓層
xuyaqi 發(fā)表于 2023-6-2 13:42
protus版本問題,參看http://www.torrancerestoration.com/bbs/dpj-158502-1.html

我換了8.8版本,發(fā)現(xiàn)還是不行,就剛打開那一瞬間亮了一下,然后也不閃爍了
回復(fù)

使用道具 舉報(bào)

ID:493026 發(fā)表于 2023-7-26 23:45 | 顯示全部樓層
xuyaqi 發(fā)表于 2023-6-2 13:42
protus版本問題,參看http://www.torrancerestoration.com/bbs/dpj-158502-1.html

確實(shí)存在版本問題。我的AD程序在8.9上能運(yùn)行,在8.13上跑不起來。
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表