程序解释,stc12c2052ad
#include<intrins.h>#include<stdio.h>typedefunsignedcharuchar;typedefunsignedintuint;#...
#include <intrins.h>
#include <stdio.h>
typedef unsigned char uchar;
typedef unsigned int uint;
#define Vref (5.0)
//#define LED_CTR_BY_BYTE
#define LED_CTR_BY_BITS
#ifdef LED_CTR_BY_BITS
sbit LED_SEGP_A = P1^1;
bit AD_TREN_FLAG;
uchar FLED_SHOW_SEGS[4] = {LED_SEG_OFF,LED_SEG_OFF,LED_SEG_OFF,LED_SEG_OFF};//
#define ADC_POWER 0x80 // ADC power control bit
#define ADC_FLAG 0x10 // ADC complete flag
#define ADC_START 0x08 // ADC start control bit
#define ADC_SPEEDLL 0x00 // 1080 clocks
void main(){
unsigned int sum;
unsigned char max,min,ad,i;
P1M0 = 0xC0; //
tr1_cnt = 0;
AD_TREN_FLAG = 1;
LED_NUM_0 = 1;
ADC_CONTR = ADC_SPEEDH | 0x07 | ADC_POWER; // 第七通道,P1^7
TMOD = 0x10;
TH1 = 249;
TL1 = 125;
EA = 1;
ET1 = 1;
TR1 = 1;
while(1){
if(AD_TREN_FLAG){
sum = 0;
max = 0x00;
min = 0xFF;
EA = 0; // 为提高精度暂停中断,实测不影响数码管的动态扫描
for(i = 0; i < 34; i++){
ADC_CONTR |= ADC_START;
_nop_();
_nop_();
while(!(ADC_CONTR & ADC_FLAG));
ad = ADC_DATA;
ADC_CONTR &= 0xE7;
if(ad > max)
max = ad;
if(ad < min)
min = ad;
sum += ad;
}
EA = 1;
sum -= min;
sum -= max;
uchar c;
#endif
TH1 = 249;
TL1 = 125;
i = tr1_cnt & 0x03;
switch(i){
case 3: LED_NUM_2 = 1; LED_NUM_3 = 0;break;
default: ;
}
AD_TREN_FLAG = 1;
#ifdef LED_CTR_BY_BYTE
FLED_SEG_P = FLED_SHOW_SEGS[i]; // 段选
#endif
#if LED_SEGP_H = c & 0x01;
#endif
tr1_cnt++; 展开
#include <stdio.h>
typedef unsigned char uchar;
typedef unsigned int uint;
#define Vref (5.0)
//#define LED_CTR_BY_BYTE
#define LED_CTR_BY_BITS
#ifdef LED_CTR_BY_BITS
sbit LED_SEGP_A = P1^1;
bit AD_TREN_FLAG;
uchar FLED_SHOW_SEGS[4] = {LED_SEG_OFF,LED_SEG_OFF,LED_SEG_OFF,LED_SEG_OFF};//
#define ADC_POWER 0x80 // ADC power control bit
#define ADC_FLAG 0x10 // ADC complete flag
#define ADC_START 0x08 // ADC start control bit
#define ADC_SPEEDLL 0x00 // 1080 clocks
void main(){
unsigned int sum;
unsigned char max,min,ad,i;
P1M0 = 0xC0; //
tr1_cnt = 0;
AD_TREN_FLAG = 1;
LED_NUM_0 = 1;
ADC_CONTR = ADC_SPEEDH | 0x07 | ADC_POWER; // 第七通道,P1^7
TMOD = 0x10;
TH1 = 249;
TL1 = 125;
EA = 1;
ET1 = 1;
TR1 = 1;
while(1){
if(AD_TREN_FLAG){
sum = 0;
max = 0x00;
min = 0xFF;
EA = 0; // 为提高精度暂停中断,实测不影响数码管的动态扫描
for(i = 0; i < 34; i++){
ADC_CONTR |= ADC_START;
_nop_();
_nop_();
while(!(ADC_CONTR & ADC_FLAG));
ad = ADC_DATA;
ADC_CONTR &= 0xE7;
if(ad > max)
max = ad;
if(ad < min)
min = ad;
sum += ad;
}
EA = 1;
sum -= min;
sum -= max;
uchar c;
#endif
TH1 = 249;
TL1 = 125;
i = tr1_cnt & 0x03;
switch(i){
case 3: LED_NUM_2 = 1; LED_NUM_3 = 0;break;
default: ;
}
AD_TREN_FLAG = 1;
#ifdef LED_CTR_BY_BYTE
FLED_SEG_P = FLED_SHOW_SEGS[i]; // 段选
#endif
#if LED_SEGP_H = c & 0x01;
#endif
tr1_cnt++; 展开
1个回答
意法半导体(中国)投资有限公司
2023-06-12 广告
2023-06-12 广告
STM32F103是一款高性能的嵌入式芯片,由意法半导体(STMicroelectronics)公司生产。它是STM32系列芯片之一,具有紧凑、低功耗、高性能等特点,被广泛应用于嵌入式系统中。STM32F103的主要特点包括:1. 集成了A...
点击进入详情页
本回答由意法半导体(中国)投资有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询