- #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;
- }
復(fù)制代碼
智能電子秤是日常生活中經(jīng)常使用的一個(gè)測(cè)重裝置,它采用了電子技術(shù),傳感器技術(shù)等,測(cè)量的誤差小,可以將“精確,快速,自動(dòng)”的要求很好的滿足。現(xiàn)實(shí)生活中,在學(xué)校,市場(chǎng),工廠,醫(yī)院等地方都得到了廣泛的推廣和應(yīng)用。本設(shè)計(jì)要求以stm32為中心模板,針對(duì)電子秤的自動(dòng)自重,自動(dòng)處理數(shù)據(jù),自動(dòng)顯示來(lái)進(jìn)行設(shè)計(jì)。本系統(tǒng)中的數(shù)據(jù)采集模塊主要負(fù)責(zé)將壓力這個(gè)非電量轉(zhuǎn)化為電量;信號(hào)處理模塊主要負(fù)責(zé)對(duì)信號(hào)的放大和模/數(shù)轉(zhuǎn)化;stm32開(kāi)發(fā)板控制模塊主要負(fù)責(zé)數(shù)據(jù)的進(jìn)一步處理,控制端口的輸出等;顯示模塊主要負(fù)責(zé)顯示重量,單價(jià),總價(jià)。通過(guò)對(duì)這些模塊的方案選擇以及硬件設(shè)計(jì),詳細(xì)的介紹了本系統(tǒng)是如何進(jìn)行數(shù)據(jù)采集,數(shù)據(jù)處理以及顯示的。 - #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);
- }
- }
復(fù)制代碼
|