完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#include
#include #include #include #define uchar unsigned char #define uint unsigned int #define ulong unsigned long int weight; double money; uint temp; uchar button; ***it lcdrs=P0^7; ***it lcdwr=P0^6; ***it lcden=P0^5; ***it hx711_dout=P0^0; ***it hx711_sck=P0^1; ***it spk=P3^6; //LCD1602 显示程序 void delayms(uint k) { uint i,j; for(i=k;i>0;i--) for(j=110;j>0;j--); } void write_com(uchar com) { lcdrs=0; P0=com; delayms(5); lcden=1; delayms(5); lcden=0; } void write_date(uchar date) { lcdrs=1; P0=date; delayms(5); lcden=1; delayms(5); lcden=0; } void init_1602() { lcden=0; lcdwr=0; write_com(0x38); write_com(0x0c); write_com(0x06); write_com(0x01); } void displaywpm(void) { uchar num; uchar code table[]="W:kgP:$Money:$"; write_com(0x80); write_date(table[0]); write_date(table[1]); write_com(0x80+0x07); write_date(table[2]); write_date(table[3]); write_com(0x80+0x0a); write_date(table[4]); write_date(table[5]); write_com(0x80+0x0f); write_date(table[6]); write_com(0x80+0x40); for(num=0;num<6;num++) write_date(table[num+7]); write_com(0x80+0x4a); write_date(table[13]); } void weight_shuzhi(uint aaa) { uchar idata weighttable[4]={0,0,0,0}; weighttable[3]=aaa%10; weighttable[2]=aaa/10%10; weighttable[1]=aaa/100%10; weighttable[0]=aaa/1000; write_com(0x80+0x02); write_date(0x30+weighttable[0]); write_com(0x80+0x03); write_date('.'); write_com(0x80+0x04); write_date(0x30+weighttable[1]); write_com(0x80+0x05); write_date(0x30+weighttable[2]); write_com(0x80+0x06); write_date(0x30+weighttable[3]); write_com(0x0c); } // hx711 程序 void Delay__hx711_us(void) { _nop_(); _nop_(); } ulong ReadCount(void) //增益128 { ulong count; uchar i; hx711_dout=1; Delay__hx711_us(); hx711_sck=0; count=0; while(hx711_dout); for(i=0;i<24;i++) { hx711_sck=1; count=count<<1; hx711_sck=0; if(hx711_dout) count++; } hx711_sck=1; count=count^0x800000;//第25个脉冲下降沿来时,转换数据 Delay__hx711_us(); hx711_sck=0; return(count); } //皮重,获得重量的程序 void get_pizhong() //获取皮重,秤盘重量 { uint j; ulong hx711_dat; for(j=0;j<5;j++) delayms(1); hx711_dat=ReadCount(); temp=(uint)(hx711_dat/100); } void get_weight() //获取被测物体重量 { ulong hx711_data,a; uint get,aa; hx711_data=ReadCount(); get=(uint)(hx711_data/100); if(get<(temp+4)) { while(1) { weight=0; weight_shuzhi(weight); hx711_data=ReadCount(); get=(uint)(hx711_data/100); if(get>(temp+4))break; } } a=ReadCount(); aa=(uint)(a/100)-temp; weight=(uint)((float)aa/2.15+0.05); } //蜂鸣器 void delayus(uint z) { while(z--) { _nop_(); } } void sound() { uint j; for(j=0;j<200;j++) { delayus(200); spk=!spk; } spk=0; for(j=0;j<200;j++) { delayms(1); } } void main() { get_pizhong(); init_1602(); displaywpm(); while(1) { get_weight(); if(weight>0) { weight_shuzhi(weight); } else { weight_shuzhi(0); } if(weight>2000) sound(); } } 在过重情况下蜂鸣器会响,lcd接上电源就会亮,但是没有显示。求大神解答,十分感谢!!! |
|
相关推荐
2 个讨论
|
|
《DNESP32S3使用指南-IDF版_V1.6》第三十章 DHT11数字温湿度传感器
522 浏览 0 评论
656 浏览 0 评论
【敏矽微ME32G070开发板免费体验】之原厂2812测试例程解析
978 浏览 0 评论
1042 浏览 2 评论
《DNESP32S3使用指南-IDF版_V1.6》第二十六章 INFRARED_RECEPTION实验
735 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
12044 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-27 10:09 , Processed in 1.050013 second(s), Total 54, Slave 41 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号