|
本帖最后由 二哲科技 于 2024-3-21 15:57 编辑
1、介绍
正常的称重设备都只能计算物体的重量,输入价格计算出总价,这种设备比较单一,可能不太适合目前的多数应用场景,今天设计的一款多功能称重器他具有计价、计数和曲线功能,话不多说,我们来看一下怎么设计的。
2、硬件准备
4英寸迪文科技COF超薄智能串口屏一体化触摸液晶 DMG48480F040_01W【https://www.dwin.com.cn/product_detail_4840449.html】
3、设计 首先是设计素材,我采用Adobe Illustrator软件进行设计,本次设计没有其余控件,都是采用页面形式,素材如下。
第一个是首页,有产品标题和进入按钮,首页右上角会显示传感器的数值。
之后是菜单页面,菜单页面有四个选项,计价,计数,曲线和矫正,矫正功能主要是为了矫正传感器的基数。
来看看计价功能的界面,会显示重量、单价和总价,右边是对价格的一个输入,同时还有去皮按钮,进入计价界面时,会默认去皮一次。
再来看看计数功能的界面,这个功能主要是用于计算物品的个数,根据单个物品的重量来计算整个物品的个数,可以用于串串香的数签,或者计算硬币数量等。
最后就是曲线功能的界面,曲线功能主要是为了直观查看到物品挥发过程中的重量变化,比数字更加直观,可以用于一些科学研究的场景。
矫正功能就是矫正称重器的准度,因为不同的传感器会有些许的区别,所以需要进行矫正。
计价功能主要是重量的显示,价格输入的显示和总价的显示,主要代码如下: - //计价页面===================
- #define VALUATION_UNIT_PRICE_ADDR 0x1010
- #define VALUATION_GRAM_ADDR 0x1000
- #define VALUATION_TOTAL_PRICES_ADDR 0x1020
- uint32_t valuation_decorticate = 0; //计价去皮重量
- uint32_t valuation_unit_price = 0; //单价
- //单价刷新
- void page_valuation_unit_price_refresh()
- {
- uint8_t test_display[10] = {0};
- if(valuation_unit_price < 1000)
- {
- test_display[0] = valuation_unit_price / 100 % 10 + 0x30;
- test_display[1] = '.';
- test_display[2] = valuation_unit_price / 10 % 10 + 0x30;
- test_display[3] = valuation_unit_price / 1 % 10 + 0x30;
- dgus_show_text_value_set(VALUATION_UNIT_PRICE_ADDR, test_display, 4);
- }
- else if(valuation_unit_price < 10000)
- {
- test_display[0] = valuation_unit_price / 1000 % 10 + 0x30;
- test_display[1] = valuation_unit_price / 100 % 10 + 0x30;
- test_display[2] = '.';
- test_display[3] = valuation_unit_price / 10 % 10 + 0x30;
- test_display[4] = valuation_unit_price / 1 % 10 + 0x30;
- dgus_show_text_value_set(VALUATION_UNIT_PRICE_ADDR, test_display, 4);
- }
- else if(valuation_unit_price < 100000)
- {
- test_display[0] = valuation_unit_price / 10000 % 10 + 0x30;
- test_display[1] = valuation_unit_price / 1000 % 10 + 0x30;
- test_display[2] = valuation_unit_price / 100 % 10 + 0x30;
- test_display[3] = '.';
- test_display[4] = valuation_unit_price / 10 % 10 + 0x30;
- test_display[5] = valuation_unit_price / 1 % 10 + 0x30;
- dgus_show_text_value_set(VALUATION_UNIT_PRICE_ADDR, test_display, 4);
- }
- else if(valuation_unit_price < 1000000)
- {
- test_display[0] = valuation_unit_price / 100000 % 10 + 0x30;
- test_display[1] = valuation_unit_price / 10000 % 10 + 0x30;
- test_display[2] = valuation_unit_price / 1000 % 10 + 0x30;
- test_display[3] = valuation_unit_price / 100 % 10 + 0x30;
- test_display[4] = '.';
- test_display[5] = valuation_unit_price / 10 % 10 + 0x30;
- test_display[6] = valuation_unit_price / 1 % 10 + 0x30;
- dgus_show_text_value_set(VALUATION_UNIT_PRICE_ADDR, test_display, 4);
- }
- }
- //重量刷新
- void page_valuation_weight_refresh()
- {
- uint8_t test_display[10] = {0x30};
- uint32_t gram_display = 0;
- if(gram_value >= valuation_decorticate)
- {
- gram_display = gram_value - valuation_decorticate;
- if(gram_display < 10)
- {
- test_display[0] = gram_display / 1 % 10 + 0x30;
- dgus_show_text_value_set(VALUATION_GRAM_ADDR, test_display, 3);
- }
- else if(gram_display < 100)
- {
- test_display[0] = gram_display / 10 % 10 + 0x30;
- test_display[1] = gram_display / 1 % 10 + 0x30;
- dgus_show_text_value_set(VALUATION_GRAM_ADDR, test_display, 3);
- }
- else if(gram_display < 1000)
- {
- test_display[0] = gram_display / 100 % 10 + 0x30;
- test_display[1] = gram_display / 10 % 10 + 0x30;
- test_display[2] = gram_display / 1 % 10 + 0x30;
- dgus_show_text_value_set(VALUATION_GRAM_ADDR, test_display, 3);
- }
- else if(gram_display < 10000)
- {
- test_display[0] = gram_display / 1000 % 10 + 0x30;
- test_display[1] = gram_display / 100 % 10 + 0x30;
- test_display[2] = gram_display / 10 % 10 + 0x30;
- test_display[3] = gram_display / 1 % 10 + 0x30;
- dgus_show_text_value_set(VALUATION_GRAM_ADDR, test_display, 3);
- }
- else if(gram_display < 100000)
- {
- test_display[0] = gram_display / 10000 % 10 + 0x30;
- test_display[1] = gram_display / 1000 % 10 + 0x30;
- test_display[2] = gram_display / 100 % 10 + 0x30;
- test_display[3] = gram_display / 10 % 10 + 0x30;
- test_display[4] = gram_display / 1 % 10 + 0x30;
- dgus_show_text_value_set(VALUATION_GRAM_ADDR, test_display, 3);
- }
- }
- else
- {
- dgus_show_text_value_set(VALUATION_GRAM_ADDR, test_display, 3);
- }
- }
- //总价刷新
- void page_valuation_price_refresh()
- {
- uint32_t price_value = 0;
- uint8_t test_display[10] = {0x30, '.', 0x30, 0x30};
- if(gram_value >= valuation_decorticate)
- {
- price_value = (gram_value - valuation_decorticate) * valuation_unit_price * 2 / 1000;
- if(price_value < 1000)
- {
- test_display[0] = price_value / 100 % 10 + 0x30;
- test_display[1] = '.';
- test_display[2] = price_value / 10 % 10 + 0x30;
- test_display[3] = price_value / 1 % 10 + 0x30;
- dgus_show_text_value_set(VALUATION_TOTAL_PRICES_ADDR, test_display, 4);
- }
- else if(price_value < 10000)
- {
- test_display[0] = price_value / 1000 % 10 + 0x30;
- test_display[1] = price_value / 100 % 10 + 0x30;
- test_display[2] = '.';
- test_display[3] = price_value / 10 % 10 + 0x30;
- test_display[4] = price_value / 1 % 10 + 0x30;
- dgus_show_text_value_set(VALUATION_TOTAL_PRICES_ADDR, test_display, 4);
- }
- else if(price_value < 100000)
- {
- test_display[0] = price_value / 10000 % 10 + 0x30;
- test_display[1] = price_value / 1000 % 10 + 0x30;
- test_display[2] = price_value / 100 % 10 + 0x30;
- test_display[3] = '.';
- test_display[4] = price_value / 10 % 10 + 0x30;
- test_display[5] = price_value / 1 % 10 + 0x30;
- dgus_show_text_value_set(VALUATION_TOTAL_PRICES_ADDR, test_display, 4);
- }
- else if(price_value < 1000000)
- {
- test_display[0] = price_value / 100000 % 10 + 0x30;
- test_display[1] = price_value / 10000 % 10 + 0x30;
- test_display[2] = price_value / 1000 % 10 + 0x30;
- test_display[3] = price_value / 100 % 10 + 0x30;
- test_display[4] = '.';
- test_display[5] = price_value / 10 % 10 + 0x30;
- test_display[6] = price_value / 1 % 10 + 0x30;
- dgus_show_text_value_set(VALUATION_TOTAL_PRICES_ADDR, test_display, 4);
- }
- }
- else
- {
- dgus_show_text_value_set(VALUATION_TOTAL_PRICES_ADDR, test_display, 4);
- }
- }
- void page_valuation_decorticate()
- {
- valuation_decorticate = gram_value;
- page_valuation_weight_refresh();
- }
- void page_valuation_1()
- {
- if(valuation_unit_price < 100000)
- {
- valuation_unit_price = valuation_unit_price * 10 + 1;
- page_valuation_unit_price_refresh();
- }
- }
- void page_valuation_2()
- {
- if(valuation_unit_price < 100000)
- {
- valuation_unit_price = valuation_unit_price * 10 + 2;
- page_valuation_unit_price_refresh();
- }
- }
- void page_valuation_3()
- {
- if(valuation_unit_price < 100000)
- {
- valuation_unit_price = valuation_unit_price * 10 + 3;
- page_valuation_unit_price_refresh();
- }
- }
- void page_valuation_4()
- {
- if(valuation_unit_price < 100000)
- {
- valuation_unit_price = valuation_unit_price * 10 + 4;
- page_valuation_unit_price_refresh();
- }
- }
- void page_valuation_5()
- {
- if(valuation_unit_price < 100000)
- {
- valuation_unit_price = valuation_unit_price * 10 + 5;
- page_valuation_unit_price_refresh();
- }
- }
- void page_valuation_6()
- {
- if(valuation_unit_price < 100000)
- {
- valuation_unit_price = valuation_unit_price * 10 + 6;
- page_valuation_unit_price_refresh();
- }
- }
- void page_valuation_7()
- {
- if(valuation_unit_price < 100000)
- {
- valuation_unit_price = valuation_unit_price * 10 + 7;
- page_valuation_unit_price_refresh();
- }
- }
- void page_valuation_8()
- {
- if(valuation_unit_price < 100000)
- {
- valuation_unit_price = valuation_unit_price * 10 + 8;
- page_valuation_unit_price_refresh();
- }
- }
- void page_valuation_9()
- {
- if(valuation_unit_price < 100000)
- {
- valuation_unit_price = valuation_unit_price * 10 + 9;
- page_valuation_unit_price_refresh();
- }
- }
- void page_valuation_0()
- {
- if(valuation_unit_price < 100000)
- {
- valuation_unit_price = valuation_unit_price * 10 + 0;
- page_valuation_unit_price_refresh();
- }
- }
- void page_valuation_back()
- {
- valuation_unit_price = valuation_unit_price / 10;
- page_valuation_unit_price_refresh();
- }
- void page_valuation_clear()
- {
- valuation_unit_price = 0;
- page_valuation_unit_price_refresh();
- }
复制代码
计数功能和计价功能类似,都需要进行数值的显示,不过不同的是需要计算物品的数量,计算物品数量的代码如下: - //计数页面================================
- #define COUNTER_GRAM_ADDR 0x1100
- #define COUNTER_CNT_ADDR 0x1110
- #define COUNTER_SINGLE_GRAM_ADDR 0x1120
- uint32_t counter_decorticate = 0; //计价去皮重量
- uint32_t counter_unit_gram = 10; //单个重量
- //重量刷新
- void page_counter_weight_refresh()
- {
- uint8_t test_display[10] = {0x30};
- uint32_t gram_display = 0;
- if(gram_value >= counter_decorticate)
- {
- gram_display = gram_value - counter_decorticate;
- if(gram_display < 10)
- {
- test_display[0] = gram_display / 1 % 10 + 0x30;
- dgus_show_text_value_set(COUNTER_GRAM_ADDR, test_display, 3);
- }
- else if(gram_display < 100)
- {
- test_display[0] = gram_display / 10 % 10 + 0x30;
- test_display[1] = gram_display / 1 % 10 + 0x30;
- dgus_show_text_value_set(COUNTER_GRAM_ADDR, test_display, 3);
- }
- else if(gram_display < 1000)
- {
- test_display[0] = gram_display / 100 % 10 + 0x30;
- test_display[1] = gram_display / 10 % 10 + 0x30;
- test_display[2] = gram_display / 1 % 10 + 0x30;
- dgus_show_text_value_set(COUNTER_GRAM_ADDR, test_display, 3);
- }
- else if(gram_display < 10000)
- {
- test_display[0] = gram_display / 1000 % 10 + 0x30;
- test_display[1] = gram_display / 100 % 10 + 0x30;
- test_display[2] = gram_display / 10 % 10 + 0x30;
- test_display[3] = gram_display / 1 % 10 + 0x30;
- dgus_show_text_value_set(COUNTER_GRAM_ADDR, test_display, 3);
- }
- else if(gram_display < 100000)
- {
- test_display[0] = gram_display / 10000 % 10 + 0x30;
- test_display[1] = gram_display / 1000 % 10 + 0x30;
- test_display[2] = gram_display / 100 % 10 + 0x30;
- test_display[3] = gram_display / 10 % 10 + 0x30;
- test_display[4] = gram_display / 1 % 10 + 0x30;
- dgus_show_text_value_set(COUNTER_GRAM_ADDR, test_display, 3);
- }
- }
- else
- {
- dgus_show_text_value_set(COUNTER_GRAM_ADDR, test_display, 3);
- }
- }
- //个数刷新
- void page_counter_cnt_refresh()
- {
- uint32_t cnt_value = 0;
- uint8_t test_display[10] = {0x30, '.', 0x30, 0x30};
- if(gram_value >= counter_decorticate)
- {
- cnt_value = (gram_value - counter_decorticate) * 100 / counter_unit_gram;
- if(cnt_value < 1000)
- {
- test_display[0] = cnt_value / 100 % 10 + 0x30;
- test_display[1] = '.';
- test_display[2] = cnt_value / 10 % 10 + 0x30;
- test_display[3] = cnt_value / 1 % 10 + 0x30;
- dgus_show_text_value_set(COUNTER_CNT_ADDR, test_display, 4);
- }
- else if(cnt_value < 10000)
- {
- test_display[0] = cnt_value / 1000 % 10 + 0x30;
- test_display[1] = cnt_value / 100 % 10 + 0x30;
- test_display[2] = '.';
- test_display[3] = cnt_value / 10 % 10 + 0x30;
- test_display[4] = cnt_value / 1 % 10 + 0x30;
- dgus_show_text_value_set(COUNTER_CNT_ADDR, test_display, 4);
- }
- else if(cnt_value < 100000)
- {
- test_display[0] = cnt_value / 10000 % 10 + 0x30;
- test_display[1] = cnt_value / 1000 % 10 + 0x30;
- test_display[2] = cnt_value / 100 % 10 + 0x30;
- test_display[3] = '.';
- test_display[4] = cnt_value / 10 % 10 + 0x30;
- test_display[5] = cnt_value / 1 % 10 + 0x30;
- dgus_show_text_value_set(COUNTER_CNT_ADDR, test_display, 4);
- }
- else if(cnt_value < 1000000)
- {
- test_display[0] = cnt_value / 100000 % 10 + 0x30;
- test_display[1] = cnt_value / 10000 % 10 + 0x30;
- test_display[2] = cnt_value / 1000 % 10 + 0x30;
- test_display[3] = cnt_value / 100 % 10 + 0x30;
- test_display[4] = '.';
- test_display[5] = cnt_value / 10 % 10 + 0x30;
- test_display[6] = cnt_value / 1 % 10 + 0x30;
- dgus_show_text_value_set(COUNTER_CNT_ADDR, test_display, 4);
- }
- }
- else
- {
- dgus_show_text_value_set(COUNTER_CNT_ADDR, test_display, 4);
- }
- }
- //单个克数刷新
- void page_counter_single_gram_refresh()
- {
- uint8_t test_display[10] = {0x30};
- if(counter_unit_gram < 10)
- {
- test_display[0] = counter_unit_gram / 1 % 10 + 0x30;
- dgus_show_text_value_set(COUNTER_SINGLE_GRAM_ADDR, test_display, 2);
- }
- else if(counter_unit_gram < 100)
- {
- test_display[0] = counter_unit_gram / 10 % 10 + 0x30;
- test_display[1] = counter_unit_gram / 1 % 10 + 0x30;
- dgus_show_text_value_set(COUNTER_SINGLE_GRAM_ADDR, test_display, 2);
- }
- else if(counter_unit_gram < 1000)
- {
- test_display[0] = counter_unit_gram / 100 % 10 + 0x30;
- test_display[1] = counter_unit_gram / 10 % 10 + 0x30;
- test_display[2] = counter_unit_gram / 1 % 10 + 0x30;
- dgus_show_text_value_set(COUNTER_SINGLE_GRAM_ADDR, test_display, 2);
- }
- else if(counter_unit_gram < 10000)
- {
- test_display[0] = counter_unit_gram / 1000 % 10 + 0x30;
- test_display[1] = counter_unit_gram / 100 % 10 + 0x30;
- test_display[2] = counter_unit_gram / 10 % 10 + 0x30;
- test_display[3] = counter_unit_gram / 1 % 10 + 0x30;
- dgus_show_text_value_set(COUNTER_SINGLE_GRAM_ADDR, test_display, 2);
- }
- }
- //去皮
- void page_counter_decorticate()
- {
- counter_decorticate = gram_value;
- page_counter_weight_refresh();
- }
- void page_counter_gram_dec()
- {
- if(counter_unit_gram > 1)
- {
- counter_unit_gram--;
- page_counter_single_gram_refresh();
- }
- }
- void page_counter_gram_add()
- {
- if(counter_unit_gram < 10000)
- {
- counter_unit_gram++;
- page_counter_single_gram_refresh();
- }
- }
复制代码
4、总结 这个项目让称重器的功能不再单一,可以根据使用场景进行功能切换,如果配合上国标的称重仪器,可以让产品更加正规完善。
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
|