STM32F103ZET6在kail5上的AD转换代码
时间: 2024-04-29 16:19:28 浏览: 121
STM32F103ZET6+USART1+ADC(模数转换)
以下是STM32F103ZET6在Kali Linux 5上的AD转换代码示例:
```c
#include "stm32f10x.h"
#include <stdio.h>
#define ADC1_DR_Address ((uint32_t)0x4001244C)
__IO uint16_t ADC_RegularConvertedValueTab[16];
void RCC_Configuration(void);
void GPIO_Configuration(void);
void ADC_Configuration(void);
int main(void)
{
RCC_Configuration();
GPIO_Configuration();
ADC_Configuration();
while (1)
{
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC));
printf("ADC Value: %d\r\n", ADC_GetConversionValue(ADC1));
}
}
void RCC_Configuration(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_ADC1, ENABLE);
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void ADC_Configuration(void)
{
ADC_InitTypeDef ADC3,h4,h5,h6 {font-family: "Raleway", sans-serif}
.w3-row-padding img {margin-bottom: 12px}
.bgimg {
background-repeat: no-repeat;
background-size: cover;
background-image: url('/w3images/forestbridge.jpg');
min-height: 90%;
}
</style>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/echarts/dist/echarts.min.js"></script>
</head>
<body class="w3-light-grey">
<!-- Navbar (sit on top) -->
<div class="w3-top">
<div class="w3-bar w3-white w3-padding w3-card" style="letter-spacing:4px;">
<a href="#home" class="w3-bar-item w3-button">Temperature Monitor</a>
<!-- Right-sided navbar links. Hide them on small screens -->
<div class="w3-right w3-hide-small">
<a href="#temperature" class="w3-bar-item w3-button">Temperature</a>
<a href="#history" class="w3-bar-item w3-button">History</a>
<a href="#analysis" class="w3-bar-item w3-button">Analysis</a>
</div>
</div>
</div>
<!-- Header -->
<header class="bgimg w3-display-container w3-grayscale-min" id="home">
<div class="w3-display-middle w3-center" style="padding:48px">
<span class="w3-text-white" style="font-size:90px">Temperature<br>Monitor</span>
</div>
</header>
<!-- temperature Section -->
<div class="w3-container w3-light-grey" style="padding:128px 16px" id="temperature">
<h3 class="w3-center">Real-time Temperature</h3>
<div class="w3-row-padding" style="margin-top:64px">
<div class="w3-col l4 m6 w3-margin-bottom">
<div class="w3-display-container">
<div class="w3-display-middle w3-large w3-padding w3-grey" id="temperature_value"></div>
</div>
</div>
</div>
</div>
<!-- History Section -->
<div class="w3-container" style="padding:128px 16px" id="history">
<h3 class="w3-center">Temperature History</h3>
<div class="w3-row-padding" style="margin-top:64px">
<div class="w3-col l12 m12 w3-margin-bottom">
<table class="w3-table w3-striped w3-bordered w3-border w3-hoverable">
<thead>
<tr class="w3-grey">
<th>Time</th>
<th>Temperature</th>
</tr>
</thead>
<tbody id="history_data"></tbody>
</table>
</div>
</div>
</div>
<!-- Analysis Section -->
<div class="w3-container w3-light-grey" style="padding:128px 16px" id="analysis">
<h3 class="w3-center">Temperature Analysis</h3>
<div class="w3-row-padding" style="margin-top:64px">
<div class="w3-col l6 m6 w3-margin-bottom">
<div id="chart_1" style="height: 400px;"></div>
</div>
<div class="w3-col l6 m6 w3-margin-bottom">
<div id="chart_2" style="height: 400px;"></div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
setInterval(getData, 5000);
getHistoryData();
getAnalysisData();
});
function getData() {
$.ajax({
url: "https://iot-as-mqtt.cn-shanghai.aliyuncs.com:443",
type: "POST",
data: '{"id":"123","version":"1.0","params":{"Temperature":null},"method":"thing.event.property.post"}',
headers: {
"Content-Type": "application/json",
"Authorization": "MQTT your_product_key&your_device_name&your_timestamp&your_sign"
},
success: function(data) {
var temperature = data.data.Temperature;
$("#temperature_value").html(temperature + "C");
},
error: function() {
console.log("Failed to get data!");
}
});
}
function getHistoryData() {
$.ajax({
url: "http://your_server_address/get_history_data.php",
type: "GET",
dataType: "json",
success: function(data) {
var html = "";
for (var i = 0; i < data.length; i++) {
var time = data[i].time;
_InitStructure;
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_InitStructure var temperature = data[i].temperature;
html += "<tr><td>" + time + "</td><td>" + temperature +.ADC_ContinuousConvMode = DISABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 1;
ADC_Init( "C</td></tr>";
}
$("#history_data").html(html);
},
error: function() {
console.logADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime("Failed to get history data!");
}
});
}
function getAnalysisData() {
$.ajax({
url: "_55Cycles5);
ADC_Cmd(ADC1, ENABLE);
ADC_ResetCalibration(ADC1);
while(ADC_Gethttp://your_server_address/get_analysis_data.php",
type: "GET",
dataType: "json",
success: function(data)ResetCalibrationStatus(ADC1));
ADC_StartCalibration(ADC1);
while(ADC_GetCalibrationStatus(ADC1));
{
var chart_1 = echarts.init(document.getElementById("chart_1"));
var chart_2 = echarts.init(document.getElementById}
```
这段代码使用了ADC1和GPIOC的通道0进行AD转换。在主循环中,通过调用`ADC_SoftwareStartConvCmd`函数启动ADC转换,然后等待转换完成并获取转换值("chart_2"));
var option_1 = {
title: {
text: "Temperature Trend",
textStyle: {
。注意,此处仅启用了单次转换模式,如果需要连续转换模式,需要将`ADC color: "#666",
fontSize: 14
}
},
tooltip: {
trigger: "axis"
},
_InitStructure.ADC_ContinuousConvMode`设置为`ENABLE`。
阅读全文