#include <iom16v.h>
#include <macros.h>
#define 芹派 uchar unsigned char
#define uint unsigned int
#include "xianshi.c"
uint mega16_ad()
{
uint addata
DDRA&=~BIT(PA0)
PORTA&=~BIT(PA0)
ADMUX=0
ADCSR=0X80
ADCSR|=BIT(ADSC)
while(!(ADCSR&(BIT(ADIF))))
addata=ADCL
addata=addata+ADCH*256
return addata
}
void main()
{
uint ada,i,ad[4]
while(1)
{
ada=mega16_ad()//999 0999
for(i=0i<吵卜4i++)
{
ad[3-i]=ada%10
ada=ada/10
}
for(i=0i<4i++)
{
show(ad[i],i)
delay(2) DDRA|=BIT(3)
DDRA|=BIT(4)
DDRB=0XFF
}
}
}
=================================================================
<xianshi.c>
#pragma data:code
const table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d, 0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}
void delay(uint ms)
{
uint i,j
for(i=0i<msi++)
{
for(j=0j<1141j++)
}
}
void show(uchar j,uchar k)
{
DDRA|=BIT(3)
DDRA|=BIT(4)
DDRB=0XFF
PORTA|=BIT(3)
PORTB=table[j]
PORTA&=~BIT(3)
PORTB=0XFF
PORTB&=~BIT(k)
PORTA|=BIT(4)
PORTA&嫌碰贺=~BIT(4)
delay(1)
#define sbi(io,bit) ( io |= (1<渗首春丛耐<bit) ) //example: sbi(PORTA,0)sbi(DDRA,0)#define cbi(io,bit) ( io &= ~(1<<bit) ) //example: cbi(PORTA,0)cbi(DDRA,0)
#define gbi(pin ,bit) ( pin &(1<<bit) ) //芹姿example: gbi(PINA,0)
我来告诉你标准答案!假设一次ADC转换的结果是017CH,那么ADCL就是7CH,ADCH就是帆谈01H,所以在程序里要得到这个誉轿毁数值,就是那庆备计算方法了,明吧?乘以256实际就是左移8位,就是把01H编程0100H,再加上7CH就是017CH了。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)