功能:
0.本系统采用STC89C52作为单片机
1.LCD1602液晶实时显示当前重量和重量报警阈值
2.重量超过报警阈值声光报警
3.按键功能介绍
'上’键——报警阈值加10g
'下’键——报警阈值减10g
4.系统上设计有eeprom芯片,可支持设置的报警阈值掉电不丢失
5.采用DC002作为电源接口可直接输入5V给整个系统供电
原理图:
PCB :
主程序:
#define __MIAN_C
#include "main.h"
#include "stdio.h"
#include "stm32f10x.h"
#include "stm32f10x_gpio.h"
#include "bsp_gpio.h"
#include "bsp_clkconfig.h"
#include "bsp_delay.h"
#include "bsp_lcd1602.h"
#include "bsp_key.h"
#include "bsp_GeneralTim.h"
#include "bsp_display.h"
#include "bsp_hx711.h"
#include "bsp_at24c02.h"
// 局部变量,用于保存转换计算后的电压值
CreatByte Flag;
uint8_t isNewFlag = 0x01;
uint16_t alarmWeight = 5000;
uint8_t alarmWeight_H;
uint8_t alarmWeight_L;
uint16_t alarmWeight_i = 0;
uint16_t alarmWeight_d = 0;
uint16_t alarmWeightBuf = 0;
uint32_t initialWeight = 0; //单位g
float objectWeight = 0; //单位g
uint32_t objectWeight_i = 0; //单位g
uint32_t objectWeight_d = 0; //单位g
int main(void)
{
// 使用HSI,SYSCLK = 4M * RCC_PLLMul_x, x:[2,3,...16],最高是64MH
HSI_SetSysClock(RCC_PLLMul_2); //使用内部8MHz晶振,并设置PLL输出为8MHz
// 端口初始化
GPIO_Config();
GENERAL_TIM_Init();
Key_GPIO_Config();
HX711_GPIO_Config();
EEPROM_Init();
isNewFlag = EEPROM_ReadByte(0x01);
if (isNewFlag != 0x00)
{
EEPROM_WriteByte(0x01, 0x00);
DelayMs(10);
EEPROM_WriteByte(0x02, (uint8_t)(alarmWeight>>8));
DelayMs(10);
EEPROM_WriteByte(0x03, (uint8_t)(alarmWeight & 0x00FF));
DelayMs(10);
}
isNewFlag = EEPROM_ReadByte(0x01);
DelayMs(10);
alarmWeight_H = EEPROM_ReadByte(0x02);
DelayMs(10);
alarmWeight_L = EEPROM_ReadByte(0x03);
DelayMs(10);
alarmWeight = ((uint16_t)alarmWeight_H<<8) + (uint16_t)alarmWeight_L;
LCD_GPIO_Init();
LCD_Init();
LCD_Clear();
DelayMs(200);
LCD_DispStr(0, 0, "Electronic Scale");
initialWeight = HX711_GetInitialWeight();
DelayMs(1000);
LCD_Clear();
while (1)
{
if (dispFlag == 1)
{
dispFlag = 0;
DispWeight();
}
KeyProcess();
}
}
/*********************************************END OF FILE**********************/