- #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);
- }
- }
復制代碼
|