附件是我的电子秤的实现程序,还加有关于32的无线传输是如何进行传输的。
单片机源程序如下:
[code]#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "lcd.h"
#include "spi.h"
#include "key.h"
#include "24l01.h"
#include "HX711.h"
#include "dht11.h"
//程序需要学习,学习永无止境
//要写入到W25Q16的字符串数组
const u8 TEXT_Buffer[]={"Explorer STM32F4 SPI TEST"};
#define SIZE sizeof(TEXT_Buffer)
void Send_Name();
char *itoa(); //
// int d=500; //
char buff[];
int main(void)
{
u8 humidity;
u8 jiage;
u8 temperature;
u8 key;
float mode;
u8 tmp_buf[33];
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置系统中断优先级分组2
delay_init(168); //初始化延时函数
uart_init(115200); //初始化串口波特率为115200
Init_HX711pin();
LED_Init(); //初始化LED
LCD_Init(); //LCD初始化
KEY_Init(); //按键初始化
NRF24L01_Init(); //初始化NRF24L01
Get_Maopi(); //称毛皮重量
delay_ms(1000);
delay_ms(1000);
Get_Maopi(); //重新获取毛皮重量
POINT_COLOR=RED;//设置字体为红色
LCD_ShowString(30,50,200,16,16,"Explorer STM32F4");
DHT11_Read_Data(&temperature,&humidity); //读取温湿度值
LCD_ShowString(30,230,200,16,16,"temperature");
LCD_ShowNum(130,230,temperature,7,16);//显示温度
// LCD_ShowString(30,70,200,16,16,"NRF24L01 TEST");
LCD_ShowString(30,110,200,16,16,"ATOM@ALIENTEK");
LCD_ShowString(30,130,200,16,16,"2014/5/9");
while(1)
{
while(1)
{
key=KEY_Scan(0);
if(key==KEY0_PRES)
{
delay_ms(5);
mode=0.8;
break;
}else if(key==KEY1_PRES)
{
delay_ms(5);
mode=0.5;
break;
}
break;
}
Get_Weight();
// LCD_ShowNum(30,70,(u8)Weight_Shiwu,7,16);
////////// printf("净重量 = %d g\r\n",Weight_Shiwu); //打印
////////// delay_ms(500);
////////// LCD_ShowString(30,70,200,16,16,"food weight");
Weight_Shiwu=Weight_Shiwu*0.25;
////////// LCD_Fill(130,70,lcddev.width,170+16*3,WHITE);
////////// LCD_ShowNum(130,70,Weight_Shiwu,7,16);
jiage=Weight_Shiwu*mode;
//// LCD_ShowString(30,90,200,16,16,"food price");
LCD_ShowNum(130,90,jiage,7,16);
itoa(jiage, buff, 10);
Send_Name(buff);//"buff"
delay_ms(50);
}
}
void Send_Name(u8 tmp_buf[36])
{
while(NRF24L01_Check())
{
LCD_ShowString(30,150,200,16,16,"NRF24L01 Error");
delay_ms(200);
LCD_Fill(30,150,239,130+16,WHITE);
delay_ms(200);
}
LCD_ShowString(30,150,200,16,16,"NRF24L01 OK");
LCD_Fill(10,170,240,166,WHITE);//清空上面的显示
POINT_COLOR=BLUE;//设置字体为蓝色
LCD_ShowString(30,170,200,16,16,"NRF24L01 TX_Mode");
NRF24L01_TX_Mode();
while(1)
{
if(NRF24L01_TxPacket(tmp_buf)==TX_OK)
{
LCD_Fill(0,210,lcddev.width,170+16*3,WHITE);//清空显示
LCD_ShowString(30,190,239,32,16,"Sended DATA:");
LCD_ShowString(30,210,lcddev.width-1,32,16,tmp_buf);
}else
{
LCD_Fill(0,190,lcddev.width,170+16*3,WHITE);//清空显示
LCD_ShowString(30,190,lcddev.width-1,32,16,"Send Failed ");
};
LED0=!LED0;
delay_ms(300);
break;
};
}
/******************************************************
??????????
char *itoa(int value, char *string, int radix)
radix=10 ???10?? ????,?????0;
?:d=-379;
?? itoa(d, buf, 10); ?
buf="-379"
**********************************************************/
char *itoa(int value, char *string, int radix)
{
int i, d;
int flag = 0;
char *ptr = string;
/* This implementation only works for decimal numbers. */
if (radix != 10)
{
*ptr = 0;
return string;
}
if (!value)
{
*ptr++ = 0x30;
*ptr = 0;
return string;
}
/* if this is a negative value insert the minus sign. */
if (value < 0)
{
*ptr++ = '-';
/* Make the value positive. */
value *= -1;
}
for (i = 10000; i > 0; i /= 10)
{
d = value / i;
if (d || flag)
{
*ptr++ = (char)(d + 0x30);
value -= (d * i);
flag = 1;
}
}
/* Null terminate the string. */
*ptr = 0;
return string;
}
int atoi_my(const char *str)
{
int s=0;
int falg=0;
while(*str==' ')
{
str++;
}
if(*str=='-'||*str=='+')
{
if(*str=='-')
falg=1;
str++;
}
while(*str>='0'&&*str<='9')
{
s=s*10+*str-'0';
……………………
…………限于本文篇幅 余下代码请从51黑下载附件…………
[/code]
所有资料51hei提供下载:
智能电子秤.7z
(350.78 KB, 下载次数: 12)
|