[tr][td=1,1,81%]#include
#include
#include
#define uchar unsigned char
#define uint unsigned int
uchar valueL;
uchar valueH;
uchar TAB[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //数字编码
uchar TABD[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10}; //带小数点的编码
void delay_1us(void) //1us延时函数
{
asm("nop");
}
void delay_nus(unsigned int n) //N us延时函数
{
unsigned int i=0;
for (i=0;i
delay_1us();
}
void delay_1ms(void) //1ms延时函数
{
unsigned int i;
for (i=0;i<1140;i++);
}
void delay_nms(unsigned int n) //N ms延时函数
{
unsigned int i=0;
for (i=0;i
delay_1ms();
}
void adc_init(void)
{
ADCSR = 0x00; //disable adc
ADMUX = 0x20; //select adc input 0 选择ADC1
ACSR = 0x80; //关模拟比较器
ADCSR = 0xE6;//ADSC
}
void m16_init()
{
DDRA=0X00;
PORTA=0XFF;
DDRB=0XFF;
PORTB=0X00;
DDRC=0XFF;
PORTC=0X00;
DDRD=0X00;
PORTD=0XFF;
}
void main()
{
float v;uint v0;
uchar s,g;
adc_init();
m16_init();
while(1)
{
valueL=ADCL;//读取AD的低位
valueH=ADCH;//读取AD的高位
v=valueH*4.8/256; //只用高八位求取电压(十位AD用八位)
v0=v*10;
s=v0/10;
g=v0%10;
PORTC=0X40; PORTB=TABD;delay_nms(5);
PORTC=0X80; PORTB=TAB[g];delay_nms(5);
}
}[/td][/tr]
好资料
学习了,
以后学习时候用
QQ:1289535315
淘宝:http://feixue008.taobao.com
论坛:http://dianzhen.5d6d.com/bbs.php