Key code of the lower computer
int main(void)
{
double v,temp,Value;
/* System clocks configuration ---------------------------------------------*/
RCC_Configuration();
/* GPIO configuration ------------------------------------------------------*/
GPIO_Configuration();
/* USARTx configured as follow:
- BaudRate = 9600 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
/* Enable USART1 */
USART_Cmd(USART1, ENABLE);
/* DMA1 channel1 configuration --------------------------------------------------*/
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ADCConvertedValue;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_Buffer Size = 1;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
/* Enable DMA1 channel 1 */
DMA_Cmd(DMA1_Channel1, ENABLE );
/* ADC1 configuration ------------------------------------------------------*/
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 1;
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC1 regular channel 14 configuration */
//################changed to Channel 10 (potentiometer)###### internal temperature sensor changed to Channel 16 ####################
ADC_RegularChannelConfig(ADC1, ADC_Channel_16, 1, ADC_SampleTime_55Cycles5);
//内部温度传感器 添加这一句
/* Enable the temperature sensor and vref internal channel */
ADC_TempSensorVrefintCmd(ENABLE);
/* Enable ADC1 DMA */
ADC_DMACmd(ADC1, ENABLE);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
/* Enable ADC1 reset calibaration register */ //使用之前一定要校准
ADC_ResetCalibration(ADC1);
/* Check the end of ADC1 reset calibration register */
while(ADC_GetResetCalibrationStatus(ADC1));
/* Start ADC1 calibaration */
ADC_StartCalibration(ADC1);
/* Check the end of ADC1 calibration */
while(ADC_GetCalibrationStatus(ADC1));
/* Start ADC1 Software Conversion */
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
while (1)
{
//printf("The ADC1 Converted Value is %d \r\n",ADCConvertedValue);
//v= ADCConvertedValue*3.30/4096;
//printf("The Voltage is %f \r\n",v );
Value=ADC_Filter();
//printf("The ADC_Filter Value is %d \r\n",(int)Value);
temp=(1.42 - Value*3.3/4096)*1000/4.35 + 25;
//printf("The Temperature is %f \r\n",temp );
printf("%s%c%c%c%c%c%s","#**",(int)Value/256,(int)Value%256,'&',(int)((temp-(int)temp)*100),(int)temp,"**%");
for(v=0;v<5000;v++);for(v=0;v<5000;v++);for(v=0;v<5000;v++);
}
}
-------------------------------------------------------------------
上位机关键代码
procedure TMainForm.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
//iq :Integer;
p :Pchar;
begin
viewstring:=' ';
move(buffer^,pchar(@rbuf)^,bufferlength);
p := StrPos(pchar(@rbuf), '#**');
//if (p <> nil) and (p[9]='*') and ( p[10]='*') and (p[11]='%') then //
if (p <> nil) and (p[5]='&') and (p[8]='*') and ( p[9]='*') and (p[10]='%') then
begin
{
printf("%s%c%c%c%c%c%s",
"#**",
(int)Value/256,(int)Value%256,
'&',
(int)((temp-(int)temp)*100),(int)temp,
"**%");
}
Value :=Ord(p[3])*256 + Ord(p[4]) ; //Ord() 字符-->ASCII码
//Temp:= Float( Ord(p[7]) ) +Float( Ord(p[6]) ) /Float(100.0) ;
Temp:=(1.42 - (Value)*3.3/4096)*1000/4.35 + 25;
viewstring:='The ADC_Filter Value is:';
viewstring:=viewstring+IntToStr(Value);
viewstring:=viewstring+' '+'The Temperature is:';
viewstring:=viewstring+FloatToStr(Temp);
memo1.lines.add(viewstring);
memo1.lines.add(' ');
RzLEDDisplay.Caption := inttostr(Value)+' ';
Temp:=int(Temp*1000)/1000;
RzLEDDisplay1.Caption := floattostr(Temp);
end;
end;
Previous article:STM32 Product Unique Identification Register (96 bits) Flash Capacity Register
Next article:STM32 internal temperature sensor
Recommended ReadingLatest update time:2024-11-16 13:56
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Does it cost a lot to buy an on-load tapchanger tester?
- Requires 3-way hardware SPI
- Matter and Wi-Fi 6: An ideal combination
- Creativity + Focus | ADI Model of “Garage Innovation”
- 【XMC4800 Relax EtherCAT Kit Review】+ Getting started with DAVE, simple application of ADC module
- Half a year has passed, let’s share what we have gained in EEWORLD!
- MSP430F5529 generates PWM waves with CCS
- FPGA Multiplier
- Quartus2 simulation can not produce waveform
- 2. GD32L233C-START environment construction