给位好!我看到书上有个测试电压的例子,用的是CCS的编译器,再处理读出的结果的时候用data =(data*0.5)/1204; 哪位大侠能否帮我解释一下呀!谢谢!!
下面是源程序:
#include <16f873.h>
#fuses HS,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP
////////////////////////////////////////////////////////////
//HS:High speed OSC(>4Mhz for PCM/PCH)(>10mhz for PCD) //
//NOWDT:No Watch Dog Timer //
//Noprotect:Code not protected from reading //
//PUT: Power up timer //
//Brownout:Reset when brownout delected //
////////////////////////////////////////////////////////////
#device ADC=10 //where ADC = 10 is the number of bits READ_ADC() should return.
#use delay(CLOCK=20000000)
#use fast_io(B)
//////液晶显示库函数使用设置
#define mode 0
#define input_x input_B
#define output_x output_B
#define set_tris_x set_tris_B
#define stb PIN_B3
#define rs PIN_B2
#include<lcd_lib.c>
void main()
{
float data;
setup_adc_ports(RA0_RA1_RA3_ANALOG);
setup_adc(ADC_CLOCK_DIV_32); //fosc/32最高速度
set_tris_b(0);
output_B(0);
/////液晶显示器初始化信息
lcd_init();
lcd_clear();
printf(lcd_data,"start!!");
//////测量显示循环
while(1)
{
/*
set_adc_channel(0); //选择通道0
delay(us(50); //采集等待
data = read_adc(); //A/D转换数据10位读入
data = (data*50.0)/1024; //温度数据刻度转换
lcd_cmd(0xc0); //移动到第二行行首
printf(lcd_data,"ondo=%2.1f DegC",data);
*/
//////电压测量
set_adc_channel(1); //选择通道1
delay_us(50); //采集等待
data=read_adc(); //以10位读入
data =(data*0.5)/1204; //以0.5伏特满量程转换
lcd_cmd(0xc0);
//lcd_cmd(0x94); //移动到第三行前面
printf(lcd_data,"volt=%1.3f V",data);
delay_ms(500);
}
} |