完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#define F_CPU 4000000UL
#include #include til/delay.h> #include #define uchar unsigned char #define uint unsigned int #define uint32 unsigned long const uchar SEG_CODE[] ={"0123456789"}; extern void Write_LCD_Command (uchar cmd); extern void Write_LCD_Data(uchar dat); extern void Initialize_LCD(); extern void LCD_ShowString(uchar x, uchar y,char *str); void DePley(uint x,uint c) { uint a=0,b=0 ; uint32 p; a=(int)x*5000.0/1023.0; // b=(int)c*50000.0/1023.0; b=b-293; p=(long)(a*(b/10.0)); Write_LCD_Command(0x80); if ((a/1000)==0) { Write_LCD_Data(' '); } else { Write_LCD_Data(SEG_CODE[a/1000]); } Write_LCD_Data(SEG_CODE[a%1000/100]); Write_LCD_Data('.'); Write_LCD_Data(SEG_CODE[a%100/10]); Write_LCD_Data(SEG_CODE[a%10]); Write_LCD_Data('V'); Write_LCD_Command(0x8a); Write_LCD_Data(SEG_CODE[b/1000]); Write_LCD_Data('.'); Write_LCD_Data(SEG_CODE[b%1000/100]); Write_LCD_Data(SEG_CODE[b%100/10]); Write_LCD_Data(SEG_CODE[b%10]); Write_LCD_Data('A'); Write_LCD_Command(0xC0); if ((p%10000000/1000000) == 0)Write_LCD_Data(' '); else Write_LCD_Data(SEG_CODE[p%10000000/1000000]); if(((p%1000000/100000) == 0)&&((p%10000000/1000000) == 0)) Write_LCD_Data(' '); else Write_LCD_Data(SEG_CODE[p%1000000/100000]); Write_LCD_Data(SEG_CODE[p%100000/10000]); Write_LCD_Data('.'); Write_LCD_Data(SEG_CODE[p%10000/1000]); Write_LCD_Data(SEG_CODE[p%1000/100]); Write_LCD_Data('W'); p=(long)((a*10)/b); Write_LCD_Command(0xCB); if ((p%10000/1000)>0) { Write_LCD_Data(' '); Write_LCD_Data('O'); Write_LCD_Data('L'); Write_LCD_Data(' '); } else { Write_LCD_Data(SEG_CODE[p%10000/1000]); Write_LCD_Data(SEG_CODE[p%1000/100]); Write_LCD_Data(SEG_CODE[p%100/10]); Write_LCD_Data(SEG_CODE[p%10]); } Write_LCD_Data('R'); } uint ADC_Convert(uchar CH) { uint addata; //SFIOR =0; //连续转换模式 ADMUX=(CH); //AVCC,AREF引脚外加滤波电容 _delay_us(100); //右对齐,ADC0单端输入 //ADCSRA =0X80; //启动ADC转换 ADCSRA |=_BV(ADSC); //开始转换 _delay_us(1000); while(!(ADCSRA&(_BV(ADIF)))); //等待转换结束,ADIF置1 addata=ADCL+(ADCH<<8);//addata=(int)(ADCL+(ADCH<<8))*5000.0/1023.0; ADCSRA |=_BV(ADIF); //对ADIF写”1”,ADIF清0 //ADCSRA =0X00; //关闭ADC转换 ADCSRA &=~_BV(ADSC); return addata; }//*/ int main() { uint a=1234,b; DDRD = 0xFF;PORTD=0xFF; DDRB = 0xFF;PORTB=0xFF; DDRC = 0xFF;PORTC=0xFF; DDRA = 0x00;PORTA=0x00; Initialize_LCD(); LCD_ShowString(0,0," Hi VA p1-1 "); ADCSRA = 0xC6; _delay_ms(30000); Write_LCD_Command(0x01); while(1) { a=ADC_Convert(0); b=ADC_Convert(1); DePley(a,b); } }
|
|
相关推荐
7 个讨论
|
|
此帖仅作者可见
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
AVR Atmega16 Bootloader程序与上位机LabView程序
5140 浏览 6 评论
#include <ioavr.h>这个头文件我应该下什么编译器
7774 浏览 0 评论
3038 浏览 2 评论
3111 浏览 1 评论
10068 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-1 03:13 , Processed in 0.901980 second(s), Total 58, Slave 43 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号