|
自己搜罗的一些资料希望对有需要的人有所帮助!
用的是stm32单片机芯片,可以根据自己需要进行调试更改。
电子设计大赛D题:简易电子秤
芯片:stm32c8
显示屏:12864
部分源码预览:
- #include "test.h"
- #include "sys.h"
- #include "delay.h"
- #include "12864.h"
- #include "adc.h"
- #include "key.h"
- #include "usart.h"
- #include "led.h"
- #include "beep.h"
- float all = 0;
- u16 adc=0;
- u16 adc_value=0;
- u16 last_adc=0;
- float weight=0;
- float last_weight=0;
- float money=0;
- float money_one=0;
- float f1=0.0,f2=0.0;
- u8 key_value=0;
- u8 key_count=0;
- float price=0;
- u16 last_price=0;
- u8 port_flag=0;
- u8 count = 0;
- u8 peel_flag=0;
- u8 money_flag=0;
- u8 money_count=0;
- u8 save_flag=0;
- u8 error=0;
- u8 price_f=0;
- u16 start_value=180;
- u8 start_flag=0;
- float abss(float x)
- {
- if(x>0.0)
- return x;
- else
- return -x;
- }
- void start_measure(void)
- {
-
- adc = Get_Adc_Average(ADC_Channel_8,100);
-
- adc_value=adc;
- if(adc_value<190&&adc_value>170)
- {
- LED = 0;
- }
- else
- {
- LED = 1;
- }
- //write_num(0x9B,adc_value);
-
- //printf("%d\r\n",adc_value);
- last_adc = adc;
- }
- void price_set(void)
- {
- write_com(0x93);
- write_data(0x20);
- write_data(0x20);
- write_data(0x20);
- write_data(0x20);
- price=0;
- while(key_count==1||key_count==3)
- {
- if(key_value==15)
- {
- if(price<100)
- {
- write_data(0x2e);
- port_flag=1;
- }
- else
- display4();
- }
- if(key_value<10||key_value==15)
- price_value();
- key_value = KEY_Scan(0);
- if(key_value!=99)
- {
- BEEP=0;
- delay_ms(100);
- BEEP=1;
- }
- if(key_value==13) //确定
- {
- key_count = 0;
- port_flag = 0;
- money = price * weight;
- if(money>9999)
- display4();
- else
- write_decimal(0x8B,0x8E,money);
- }
- }
- }
- void ADD(void)
- {
- error=0;
- if(money_flag ==1)
- {
- money_one = money;
-
- }
- price_set();
- if(money_flag ==1)
- {
- all=money+money_one+all;
- }
- else
- {
- all=money+all;
- }
-
- write_decimal(0x9B,0x9E,all);
- key_count = 0;
-
- }
- void PEEL(void)
- {
- if(peel_flag==1)
- {
- last_weight = weight;
- peel_flag=2;
- }
- key_count = 0;
- }
- void DEL(void)
- {
- all=0;
- price = 0;
- money_flag = 0;
- peel_flag = 0;
- key_count = 0;
- write_com(0x93);
- write_data(0x20);
- write_data(0x20);
- write_data(0x20);
- write_data(0x20);
- error=0;
- write_num(0X93,price);
- write_decimal(0x8B,0x8E,0);
- write_decimal(0x9B,0x9E,0);
- }
- void Unit_price(void)
- {
-
- key_value = KEY_Scan(0);
- if(key_value!=99)
- {
- BEEP=0;
- delay_ms(100);
- BEEP=1;
- }
- if(key_value==12) //单价
- key_count=1;
- if(key_value==13) //确定
- key_count=0;
- if(key_value==10&&weight<100) //去皮
- {
- key_count=2;
- peel_flag = 1;
- }
- if(key_value==11)//累加
- {
- key_count = 3;
- money_flag++;
- }
- if(key_value==14)
- {
- key_count=4;
- start_flag++;
- if(start_flag ==1)
- {
- start_value = adc_value;
- }
- if((start_flag > 1)&&(weight<5))
- {
- start_value = adc_value;
- }
- }
-
-
- if(key_count==1) //设置单价
- {
- price_set();
- }
- else if(key_count==2)
- {
- PEEL();
- }
- else if(key_count==3)
- {
- ADD();
- }
- else if(key_count==4)
- {
- DEL();
- }
- if(adc_value<740)
- {
- if(peel_flag==2)
- {
- weight =(float)(((adc_value-start_value)/5.88025)- last_weight); //关系待测
- }
- else
- {
- weight = (float)(((adc_value-start_value)/5.88025)); //关系待测
- }
- write_decimal(0x83,0x86,weight);
- }
- else if(adc_value<1000)
- {
- if(peel_flag==2)
- {
- weight =(float)(((adc_value-start_value)/5.84025)- last_weight); //关系待测
- }
- else
- {
- weight = (float)(((adc_value-start_value)/5.84025)); //关系待测
- }
- write_decimal(0x83,0x86,weight);
- }
- else if(adc_value<1300)
- {
- if(peel_flag==2)
- {
- weight =(float)(((adc_value-start_value)/5.80025)- last_weight); //关系待测
- }
- else
- {
- weight = (float)(((adc_value-start_value)/5.80025)); //关系待测
- }
- write_decimal(0x83,0x86,weight);
- }
- else if(adc_value<1600)
- {
- if(peel_flag==2)
- {
- weight =(float)(((adc_value-start_value)/5.76)- last_weight); //关系待测
- }
- else
- {
- weight = (float)(((adc_value-start_value)/5.76)); //关系待测
- }
- write_decimal(0x83,0x86,weight);
- }
- else if(adc_value<1784)
- {
- if(peel_flag==2)
- {
- weight =(float)(((adc_value-start_value)/5.74)- last_weight); //关系待测
- }
- else
- {
- weight = (float)(((adc_value-start_value)/5.74)); //关系待测
- }
- write_decimal(0x83,0x86,weight);
- }
- else if(adc_value<2025)
- {
- if(peel_flag==2)
- {
- weight =(float)(((adc_value-start_value)/5.70)- last_weight); //关系待测
- }
- else
- {
- weight = (float)(((adc_value-start_value)/5.70)); //关系待测
- }
- write_decimal(0x83,0x86,weight);
- }
- else if(adc_value<2350)
- {
- if(peel_flag==2)
- {
- weight =(float)(((adc_value-start_value)/5.655)- last_weight); //关系待测
- }
-
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
完整代码下载:
电子秤 完结版.rar
(299.95 KB, 下载次数: 173)
|
评分
-
查看全部评分
|