完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
|
相关推荐
8个回答
|
|
#include
#include #include "define.h" #include "init.h" #include "AD.h" #include "yj1602.h" /*主函数/ void main() { init(); init1602(); battery_v=get_ad(); yj1602(); if(battery_v<108) {PWM=0; FuZai=1;} //µÚÒ»´ÎÖ±½Ó³åµç else {PWM=1;FuZai=0;} while(1) { delay(5000); battery_v=get_ad(); yj1602(); if(battery_v<0)//Ðîµç³Ø·´½Ó£¬¹Ø±Õ³äµç¡¢¸ºÔØÇÒ±¨¾¯ { PWM=1;FuZai=1;buzzer(); } if(battery_v>=108) { if(145<=battery_v) { guoya=0;//¿ªÆô¹ýѹָʾµÆ zhengchang=1; qianya=1; PWM=1; FuZai=0; buzzer(); } else if(120<=battery_v<145) { zhengchang=0; guoya=1; qianya=1; TR0=1; FuZai=0; if(count==4) { PWM=0; } if(count==12) { count=0; PWM=1; } } else if(battery_v<120) {zhengchang=0;guoya=1;qianya=1;FuZai=0; TR0=0; PWM=0; }} else {zhengchang=1;guoya=1; qianya=0; FuZai=1;PWM=0; buzzer(); } } } void timer0() interrupt 1 { TH0=(65536-50000)/256; TL0=(65536-50000)%256; count++; } /*定义函数/ #define uchar unsigned char #define uint unsigned int ***it PWM= P3^2; ***it FuZai=P3^3; ***it zhengchang=P2^3; ***it guoya=P2^4; ***it qianya=P2^5; ***it beep=P2^6; uchar count,battery_v; ***it csad=P2^7; ***it adwr=P3^6; ***it adrd=P3^7; unsigned char V1,V2,V3,adval,ad_vo; ***it RS=P2^0; ***it RW=P2^1; ***it EN=P2^2; unsigned char code table1[]=" HUANGZHIQIANG"; unsigned char code table2[]=" D:12.0 N:"; unsigned char code lcdd[]="0123456789"; uchar xs_vo,num; void init(); void delay(unsigned int t); void delay1(); void buzzer(); uchar get_ad(); void write_com(uchar com); void write_data(uchar date); void init1602(); void yj1602(); /*初始化函数/ void init() { TMOD=0x01; TH0=(65536-50)/256; TL0=(65536-50)%256; EA=1; ET0=1; PWM=1; FuZai=1; zhengchang=0; guoya=1; qianya=1; beep=1; } void delay(unsigned int t) { unsigned int j,i; for(i=0;i } void delay1() { _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); } void buzzer() { beep=0; delay(10); beep=1; } /*AD转化函数/ uchar get_ad() { csad=0; adwr=1; _nop_(); adwr=0; _nop_(); adwr=1; delay(2); P1=0xff; adrd=1; _nop_(); adrd=0; _nop_(); adval=P1; adrd=1; ad_vo=(float)adval*150.0/256.0; return(ad_vo); } /*LCD1602显示函数/ void init1602() { EN=0; write_com(0x38); write_com(0x0c); write_com(0x06); write_com(0x01); } void write_com(uchar com) { RW=0; delay1(); RS=0; delay1(); EN=1; delay1(); P0=com; delay1(); EN=0; delay1(); delay(5); } void write_data(uchar date) { RW=0; delay1(); RS=1; delay1(); EN=1; delay1(); P0=date; delay1(); EN=0; delay1(); delay(5); } void yj1602() { uchar xs_vo; init1602(); xs_vo=battery_v; V1=xs_vo/100; V2=xs_vo%100/10; V3=xs_vo%10; write_com(0x80+0x10); for(num=0;num<14;num++) { write_data(table1[num]); delay(5); } write_com(0x80+0x50); write_data(' '); delay(5); write_data('D'); delay(5); write_data(':'); write_data(' '); delay(5); write_data(lcdd[1]); delay(5); write_data(lcdd[2]); delay(5); write_data('.'); delay(5); write_data(lcdd[0]); delay(5); write_data(' '); delay(5); write_data(' '); delay(5); write_data('N'); delay(5); write_data(':');delay(5); write_data(lcdd[V1]); delay(5); write_data(lcdd[V2]); delay(5); write_data('.'); delay(5); write_data(lcdd[V3]); delay(5); for(num=0;num<16;num++) { write_com(0x1c); delay(1000); } } |
|
|
|
|
|
https://bbs.elecfans.com/forum.php?mod=attachment&aid=MzEwOTE0fDUyNWUxZjI0OGFmNzY3NGU5NWNkOTMyYmFmMjBkNGY1fDE3MjQ1MDU0OTc%3D&request=yes&_f=.rar
|
|
|
|
|
|
|
|
大神来看啊。。
|
|
|
|
|
|
|
|
仿真到硬件的实现还是有段距离的,看看是不是有些寄存器没有设置好
|
|
|
|
不错的文档,顶一下
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
串口发送中断中对发送I/O口定义为GPIO输出,出现发送数据不完整,缺少2个字节,求解答
863 浏览 3 评论
696 浏览 0 评论
【xG24 Matter开发套件试用体验】10-Bluetooth示例1
789 浏览 0 评论
870 浏览 0 评论
【xG24 Matter开发套件试用体验】power specification电源规格参数配置
694 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
10845 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-8-24 21:18 , Processed in 0.778815 second(s), Total 86, Slave 69 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191