模数转换.c
来自「模数转换的相关代码,调试正在进行!希望能对大家有些帮助@」· C语言 代码 · 共 59 行
C
59 行
#define uint unsigned int
#define uchar unsigned char
#include <iom16v.h>
#include <macros.h>
#include "SP027法度.h"
void port_init(void)
{
PORTA = 0x00;
DDRA = 0x00;
PORTC = 0x00; //m103 output only
DDRC = 0xFF;
PORTD = 0x00;
DDRD = 0xFF;
}
uint ADC_Convert(void)
{
uint temp;
uchar temph,templ;
templ=ADCL;
temph=ADCH;
temp=temph;
temp<<=8;
temp=temp+templ;
return temp;
}
//
void main(void)
{
uint temp,v;
double m;
uchar temph,templ;
port_init();
/*ADMUX=0X00;
ADCSRA=0XE3;*/
ADCSR = 0x00; //disable adc
ADMUX = 0x40; //select adc input 0
ACSR = 0x80;
ADCSR = 0xec;
SFIOR=0x00;
while(1)
{
templ=ADCL;
temph=ADCH;
temp=temph;
temp=(temp*256+templ);
m=(double)temp;
v=(uint)(5*m*1000/1024);
CLS();
DispNum(v);
Delay(200);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?