完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
/**********************************************************************
***********************************************************************/ #include "main.h" #include "HX711.h" #include "uart.h" #include "LCD1602.h" #include #include #define N 8 unsigned long HX711_Buffer = 0; unsigned long Weight_Maopi = 0; long Weight_Shiwu = 0; unsigned char flag = 0; bit Flag_ERROR = 0; ***it speak= P1^7; //У׼²ÎÊý //ÒòΪ²»Í¬µÄ´«¸ÐÆ÷ÌØÐÔÇúÏß²»ÊǺÜÒ»Ö£¬Òò´Ë£¬Ã¿Ò»¸ö´«¸ÐÆ÷ÐèÒª½ÃÕýÕâÀïÕâ¸ö²ÎÊý²ÅÄÜʹ²âÁ¿ÖµºÜ׼ȷ¡£ //µ±·¢ÏÖ²âÊÔ³öÀ´µÄÖØÁ¿Æ«´óʱ£¬Ôö¼Ó¸ÃÊýÖµ¡£ //Èç¹û²âÊÔ³öÀ´µÄÖØÁ¿Æ«Ð¡Ê±£¬¼õС¸ÄÊýÖµ¡£ //¸ÃÖµ¿ÉÒÔΪСÊý #define GapValue 434 //**************************************************** //Ö÷º¯Êý //**************************************************** void main() { Uart_Init(); Send_Word("Welcome to use!n"); Send_Word("Made by Beetle Electronic Technology!n"); Init_LCD1602(); LCD1602_write_com(0x80); LCD1602_write_word("Welcome to use!"); Delay_ms(1000); //ÑÓʱ,µÈ´ý´«¸ÐÆ÷Îȶ¨ Get_Maopi(); //³ÆëƤÖØÁ¿ while(1) { EA = 0; Get_Weight(); char filter(); EA = 1; Scan_Key(); //ÏÔʾµ±Ç°ÖØÁ¿ if( Flag_ERROR == 1) { Send_Word("ERRORn"); LCD1602_write_com(0x80+0x40); LCD1602_write_word("ERROR "); speak=0; } else { speak=1; Send_ASCII(sum/1000000 + 0X30); Send_ASCII(sum%1000000/100000 + 0X30); Send_ASCII(sum%100000/10000 + 0X30); Send_ASCII(sum%10000/1000 + 0X30); //Send_ASCII(Weight_Shiwu%1000/100 + 0X30); // Send_ASCII(Weight_Shiwu%100/10 + 0X30); // Send_ASCII(Weight_Shiwu%10 + 0X30); Send_ASCII('.'); Send_ASCII(sum%1000/100 + 0X30); Send_ASCII(sum%100/10 + 0X30); Send_ASCII(sum%10 + 0X30); Send_Word(" gn"); LCD1602_write_com(0x80+0x40); LCD1602_write_data(sum/1000000 + 0X30); LCD1602_write_data(sum%1000000/100000 + 0X30); LCD1602_write_data(sum%100000/10000 + 0X30); LCD1602_write_data(sum%10000/1000 + 0X30); // LCD1602_write_data(Weight_Shiwu%1000/100 + 0X30); //LCD1602_write_data(Weight_Shiwu%100/10 + 0X30); // LCD1602_write_data(Weight_Shiwu%10 + 0X30); LCD1602_write_data('.'); LCD1602_write_data(sum%1000/100 + 0X30); LCD1602_write_data(sum%100/10 + 0X30); LCD1602_write_data(sum%10 + 0X30); LCD1602_write_word(" g"); } } } //ɨÃè°´¼ü void Scan_Key() { if(KEY1 == 0) { Delay_ms(5); if(KEY1 == 0) { while(KEY1 == 0); Get_Maopi(); //ȥƤ } } } //**************************************************** //³ÆÖØ //**************************************************** void Get_Weight() { Weight_Shiwu = HX711_Read(); Weight_Shiwu = Weight_Shiwu - Weight_Maopi; //»ñÈ¡¾»ÖØ if(Weight_Shiwu > 0) { Weight_Shiwu =(unsigned int) (((float)Weight_Shiwu/GapValue)*1000); //¼ÆËãʵÎïµÄʵ¼ÊÖØÁ¿ if(Weight_Shiwu > 5000000) //³¬Öر¨¾¯ { Flag_ERROR = 1; } else { Flag_ERROR = 0; } } else { Weight_Shiwu = 0; // Flag_ERROR = 1; //¸ºÖر¨¾¯ } } //**************************************************** //»ñȡëƤÖØÁ¿ //**************************************************** void Get_Maopi() { Weight_Maopi = HX711_Read(); } //**************************************************** //MSÑÓʱº¯Êý(12M¾§ÕñϲâÊÔ) //**************************************************** void Delay_ms(unsigned int n) { unsigned int i,j,sum; for(i=0;i } //shujuchuli char filter() { char value_buf[N];// char count,i,j,temp; for(count = 0,count < N,count++) { value_buf(count) = Get_Weight(); sum+=value_buf(count); Delay_ms(2); } for(j=0,j for(i=0,i if (value_buf[i]>value_buf[i+1]) { temp = value_buf[i]; value_buf[i] = value_buf[i+1]; value_buf[i+1] = temp; } } } return (char)(sum = (sum-(value_buf[0]+value_buf[N-1]))/n); } |
|
相关推荐
2 个讨论
|
|
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-初识设备树之Makefile修改
710 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-初识设备树之设备组织架构
1617 浏览 0 评论
1092 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-初识设备树之设备树组成和结构
1326 浏览 0 评论
【敏矽微ME32G070开发板免费体验】点亮WS2812B灯板
1783 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
12173 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-1-14 04:51 , Processed in 0.412809 second(s), Total 36, Slave 30 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号