unsigned int const tab[]={1361 ,1405 ,1450 ,1495 ,1540 ,1587 ,1633 ,1681 ,1728 ,1776 ,//0~9
1824 ,1873 ,1921 ,1970 ,2019 ,2069 ,2118 ,2168 ,2217 ,2266 ,//10~19
2316 ,2365 ,2414 ,2463 ,2512 ,2560 ,2608 ,2656 ,2704 ,2751 ,//20~29
2798 ,2844 ,2890 ,2935 ,2980 ,3025 ,3068 ,3112 ,3155 ,3197 ,//30~39
3238 ,3279 ,3320 ,3359 ,3398 ,3437 ,3475 ,3512 ,3548 ,3584 ,//0~19
3619 ,3654 ,3688 ,3721 ,3753 ,3785 ,3816 ,3847 ,3877 ,3906 ,//10~19
3935 ,3963 ,3990 ,4017 ,4043 ,4069 ,4094 ,4118 ,4142 ,4165 ,//10~19
4188 ,4211 ,4232 ,4253 ,4274 ,4294 ,4314 ,4333 ,4352 ,4370 ,//10~19
4388 ,4405 ,4422 ,4439 ,4455 ,4470 ,4486 ,4501 ,4515 ,4529 ,4543};//10~19
uchar keymk(void);
void HC595store(void);
void HC595shift(void);
void HC595sent(uchar x);
void display(uchar dat);
void init(void);
void AD_Init(void);
//void readbyte(void);
//void outmode(void);
//void pwm(void);
unsigned int AD_GetData(void);
uchar keyval;
uint byte,bytev,shi,ge,keyad,Counter,count_2ms,count1,count2;
int main(void)//主函数
{
init();
AD_Init();
keyval=60;
//T/C0定时中断设置
TIMSK0 |= (1 << TOIE0); //T/C0溢出中断允许
TCCR0B |= (1 <<CS02) | (1 << CS00); // T/C0工作于普通模式,1024分频,
//定时器频率 = 1M/1024 = 976.5625Hz
TCNT0 = 255; //定时初值设置,定时时间 = (256-12)/976.5625=249.856ms
Counter = 0; // 1mS计时变量清零
count_2ms=0;
sei(); //使能全局中断
while(1)
{
keymk();
bytev=(AD_GetData()*5);
//byte=(int)(161-(377500/bytev));
for(uint i=0;i<91;i++)
{
if(bytev<=tab[i])
byte=i;
}
shi=byte/10;
ge=byte%100;
此帖出自
小平头技术问答
谢谢这位兄弟。问题找到了。
51的话用code放入rom
一周热门 更多>