- #include "LED.h"
- #define LED0 PCout(5)
- void Init_LEDpin(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure);
- GPIO_SetBits(GPIOC,GPIO_Pin_5);
-
- LED0 = 1;
- }
复制代码
智能电子秤是日常生活中经常使用的一个测重装置,它采用了电子技术,传感器技术等,测量的误差小,可以将“精确,快速,自动”的要求很好的满足。现实生活中,在学校,市场,工厂,医院等地方都得到了广泛的推广和应用。本设计要求以stm32为中心模板,针对电子秤的自动自重,自动处理数据,自动显示来进行设计。本系统中的数据采集模块主要负责将压力这个非电量转化为电量;信号处理模块主要负责对信号的放大和模/数转化;stm32开发板控制模块主要负责数据的进一步处理,控制端口的输出等;显示模块主要负责显示重量,单价,总价。通过对这些模块的方案选择以及硬件设计,详细的介绍了本系统是如何进行数据采集,数据处理以及显示的。 - #include "HX711.h"
- #include "delay.h"
- u32 HX711_Buffer;
- u32 Weight_Maopi;
- s32 Weight_Shiwu;
- u8 Flag_Error = 0;
- s32 z;
- #define GapValue 430
- void Init_HX711pin(void){
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- //HX711_DOUT
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- }
- u32 HX711_Read(void)
- {
- unsigned long count;
- unsigned char i;
- HX711_SCK=0;
- count=0;
- delay_us(1);
- while(HX711_DOUT);
- for(i=0;i<24;i++)
- {
- HX711_SCK=1;
- count=count<<1;
- delay_us(1);
- HX711_SCK=0;
- if(HX711_DOUT)
- count++;
- delay_us(1);
- }
- HX711_SCK=1;
- count=count^0x800000;
- delay_us(1);
- HX711_SCK=0;
- return(count);
- }
- void Get_Maopi(void)
- {
- Weight_Maopi = HX711_Read();
- }
- void Get_Weight(void)
- {
- HX711_Buffer = HX711_Read();
- if(HX711_Buffer > Weight_Maopi)
- {
- Weight_Shiwu = HX711_Buffer;
- Weight_Shiwu = Weight_Shiwu - Weight_Maopi;
- Weight_Shiwu = (s32)((float)Weight_Shiwu/GapValue);
- //z=(s32)((float)Weight_Shiwu/GapValue);
- }
- }
复制代码
|