资源描述:
《AVR模拟量程序》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、本程序经过测试,AVR单片机模拟量转换以及显示程序!ICCAVR软件编译!#include#includeunsignedcharled4[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};unsignedcharled4_buf[]={0,0,0,0,0};/*显示信息*///**********************************voiddelay_ms(unsignedinti){uns
2、ignedinta;unsignedcharb;for(a=1;a
3、it();/*显示初始化*/led4_buf[4]=3;/*小数点位置*/while(1){delay_ms(100);/*周期控制*/i=get_ad();/*获取电压*/i=(unsignedint)(((unsignedlong)i*5000)/1024);/*将AD结果转成电压值*/本程序经过测试,AVR单片机模拟量转换以及显示程序!ICCAVR软件编译!#include#includeunsignedcharled4[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80
4、,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};unsignedcharled4_buf[]={0,0,0,0,0};/*显示信息*///**********************************voiddelay_ms(unsignedinti){unsignedinta;unsignedcharb;for(a=1;a
5、ain(void){unsignedinti;DDRA=0x7F;/*方向输入*/PORTA=0xFF;/*打开上拉*/DDRB=0xFF;/*方向输出*/PORTB=0xFF;/*电平设置*/DDRC=0xFF;PORTC=0xFF;DDRD=0xFF;PORTD=0xFF;led4_init();/*显示初始化*/led4_buf[4]=3;/*小数点位置*/while(1){delay_ms(100);/*周期控制*/i=get_ad();/*获取电压*/i=(unsignedint)(((unsignedlong)i*5000)/1024);/*将AD
6、结果转成电压值*/int_to_bcd(i);/*将电压值提取出来*/}}//********************************voidled4_init(void){/*初始化定时器*/OCR1A=1000;/*计数周期为4mS,F=1M*/TIMSK
7、=(1<8、=(1<9、=(1<10、(1<11、OSI和SCK为输出,其他为输入*/SPCR=(1<12、=(1<13、=(1<14、(1<15、=(1<16、(1<17、(1<18、DCSRA=(1<19、(1<