`
一、评估板使用说明
1. 功能
序号
| 功能
| 描述
| 1
| MCU
| Arduino
| 2
| I/O
| 9路I/O
| 3
| LED
| 工作指示灯
| 4
| 按键
| 复位按键
| 5
| 电源
| 5V电源输入
|
注:可实现的功能:
a.称重,通过屏幕显示物品质量
b.计价,通过屏幕显示金额
d.校准称功能,可以随意更换称台
2. 需使用的工具
a.硬件:arduino最小系统,HX711电子秤专用AD模块,电阻应变片式称台。
b. 软件: arduino 1.6.8。
c.原理图:详见“硬件原理图”文件夹。
d.程序: arduino程序在“arduino程序”文件夹。
二、硬件和软件部分详细说明 1. 硬件原理图:详见“硬件原理图”文件夹 (1)硬件接口定义 功能
| 对应arduino的IO
|
| TXD(屏端子显示)
| Tx1 | | RXD(屏端子显示)
| Tx1 | | 独立按键
| D3-D7
| | HX711_SCK时钟信号
| D11
| | HX711_DATA数据信号
| D10
| |
(2)硬件原理图
图1:HX711原理图 2. 软件程序
- #include "dwin.h"
- #include
- #include
- #include
- #define u8 unsigned char
- #define u16 unsigned int
- int LCD_printf(unsigned char mode,unsigned int Color,unsigned int Bcolor,unsigned int x,unsigned int y,const char *format, ...)
- {
- unsigned char l;
- char tmp[200];
- va_list arg;
- va_start(arg, format);
- vsprintf(tmp,format,arg);
- va_end(arg);
- l=0;
- Serial.write(0xAA);
- Serial.write(0x11);
- Serial.write(mode);//模式
- Serial.write(Color/256);
- Serial.write(Color%256);//前景颜色
- Serial.write(Bcolor/256);
- Serial.write(Bcolor%256);//背景颜色
- Serial.write(x/256);
- Serial.write(x%256);//横坐标
- Serial.write(y/256);
- Serial.write(y%256);//Y坐标
-
- while(tmp[l])
- Serial.write(tmp[l++]) ;
-
- Serial.write(0xcc);
- Serial.write(0x33);
- Serial.write(0xc3);
- Serial.write(0x3c);
-
- }
- /****************显示二维码函数*****************/
- /*参数:mode:D7********************************/
- void erweima(u16 x,u16 y,u8 QR_Pixel,const char *format, ...)
- {
- unsigned char l;
- char tmp[200];
- va_list arg;
- va_start(arg, format);
- vsprintf(tmp,format,arg);
- va_end(arg);
- l=0;
- Serial.write(0xaa);
- Serial.write(0x21);
- Serial.write(x/256);
- Serial.write(x%256);//横坐标
- Serial.write(y/256);
- Serial.write(y%256);//Y坐标
- Serial.write(QR_Pixel);//二维码每个点的大小
-
- while(tmp[l])
- Serial.write(tmp[l++]) ;
-
- Serial.write(0xcc);
- Serial.write(0x33);
- Serial.write(0xc3);
- Serial.write(0x3c);
- }
- /****************绘图清屏函数*****************/
- /*参数:mode:D7********************************/
- void clr(u16 Color)
- {
- Serial.write(0xaa);
- Serial.write(0x01);
- Serial.write(Color/256);
- Serial.write(Color%256);//颜色
- Serial.write(0xcc);
- Serial.write(0x33);
- Serial.write(0xc3);
- Serial.write(0x3c);
- }
- /****************绘图直线插入函数*****************/
- /*参数:mode:D7********************************/
- void Linear_interpolation(u8 num,u16 Color,...)
- {
- va_list arg_ptr;
- int tempValue;
- num*=2;
- Serial.write(0xaa);
- Serial.write(0x03);
- Serial.write(Color/256);
- Serial.write(Color%256);
- va_start(arg_ptr,Color);
- while(num--)
- {
- tempValue=va_arg(arg_ptr,int);
- Serial.write(tempValue/256);
- Serial.write(tempValue%256);
- }
- va_end(arg_ptr);
- Serial.write(0xcc);
- Serial.write(0x33);
- Serial.write(0xc3);
- Serial.write(0x3c);
- }
- /****************绘图打点插入函数*****************/
- /*参数:mode:D7********************************/
- void Place_point(u8 num,u16 Color,u16 nx,u16 ny,...)
- {
- va_list arg_ptr;
- int tempValue;
- num*=2;
- Serial.write(0xaa);
- Serial.write(0x02);
- Serial.write(Color/256);
- Serial.write(Color%256);
- Serial.write(nx%256);
- Serial.write(ny%256);
- va_start(arg_ptr,ny);
- while(num--)
- {
- tempValue=va_arg(arg_ptr,int);
- Serial.write(tempValue/256);
- Serial.write(tempValue%256);
- }
- va_end(arg_ptr);
- Serial.write(0xcc);
- Serial.write(0x33);
- Serial.write(0xc3);
- Serial.write(0x3c);
- }
- /****************屏幕背光亮度设置*****************/
- /*参数:mode:D7********************************/
- void DIM_Set(u8 Set)
- {
- Serial.write(0xaa);
- Serial.write(0x30);
- Serial.write(Set);
- Serial.write(0xcc);
- Serial.write(0x33);
- Serial.write(0xc3);
- Serial.write(0x3c);
- }
- /****************设置扩展串口波特率**************/
- /*参数:mode:D7********************************/
- void Bode_Set(u16 Set)//调节扩展串口波特率
- {
- Serial.write(0xaa);
- Serial.write(0x38);
- Serial.write(15667200/Set/256);
- Serial.write(15667200/Set%256);
- Serial.write(0xcc);
- Serial.write(0x33);
- Serial.write(0xc3);
- Serial.write(0x3c);
- }
- /****************从扩展串口发送字符串**************/
- /*参数:mode:D7********************************/
- void UART_TX(const char *format, ...)//串口发送字符串
- {
- u8 l;
- char tmp[200];
- va_list arg;
- va_start(arg, format);
- vsprintf(tmp,format,arg);
- va_end(arg);
- l=0;
- Serial.write(0xaa);
- Serial.write(0x39);
- while(tmp[l])
- Serial.write(tmp[l++]) ;
- Serial.write(0xcc);
- Serial.write(0x33);
- Serial.write(0xc3);
- Serial.write(0x3c);
- }
- /****************显示ICO图标**************/
- /*参数:mode:D7********************************/
- void dis_ico(u16 x,u16 y,u8 mode,u8 ids)//显示ico图标
- {
- Serial.write(0xaa);
- Serial.write(0x23);
- Serial.write(x/256);
- Serial.write(x%256);
- Serial.write(y/256);
- Serial.write(y%256);
- Serial.write(y%256);
- Serial.write(mode);
- Serial.write(ids);
- Serial.write(0xcc);
- Serial.write(0x33);
- Serial.write(0xc3);
- Serial.write(0x3c);
- }
- /****************设置动态图标*******************/
- /*参数:mode:D7********************************/
- void disd_ico(u16 x,u16 y,u8 mode,u8 Icon_lib,u8 Icon_IDs,u8 Icon_0IDe,u8 Delay_time)//显示ico图标
- {
- Serial.write(0xaa);
- Serial.write(0x28);
- Serial.write(x/256);
- Serial.write(x%256);
- Serial.write(y/256);
- Serial.write(y%256);
- Serial.write(y%256);
- Serial.write(mode);
- Serial.write(Icon_lib);
- Serial.write(Icon_IDs);
- Serial.write(Icon_0IDe);
- Serial.write(Delay_time);
- Serial.write(0xcc);
- Serial.write(0x33);
- Serial.write(0xc3);
- Serial.write(0x3c);
- }
- /****************设置动态图标*******************/
- /*参数:mode:D7********************************/
- void disc_ico(u16 set)//控制ico动态图标
- {
- Serial.write(0xaa);
- Serial.write(0x29);
-
- Serial.write(set/256);
- Serial.write(set%256);
- Serial.write(0xcc);
- Serial.write(0x33);
- Serial.write(0xc3);
- Serial.write(0x3c);
- }
- /****************写存储器***********************/
- /*参数:mode:D7********************************/
- void writ_sram_flsh(u16 Length,u8 Type,u16 Address)//写数据存储器
- {
- Serial.write(0xaa);
- Serial.write(0x31);
- Serial.write(Type);
- Serial.write(Address/256);
- Serial.write(Address%256);
- while(Length--)
- {
- Serial.write(Address++);
- }
- Serial.write(0xcc);
- Serial.write(0x33);
- Serial.write(0xc3);
- Serial.write(0x3c);
- }
- /****************读存储器***********************/
- /*参数:mode:D7********************************/
- void read_sram_flsh(u16 Length,u8 Type,u16 Address)//写数据存储器
- {
- Serial.write(0xaa);
- Serial.write(0x32);
- Serial.write(Type);
- Serial.write(Address/256);
- Serial.write(Address%256);
- Serial.write(Length);
- Serial.write(0xcc);
- Serial.write(0x33);
- Serial.write(0xc3);
- Serial.write(0x3c);
- }
- #define N_KEY 3//调用按键检测函数N_KEY次,均获取同一个按键信息,说明该按键的确按下
- #define F_KEY 3//按下按键不放时的按键测试频率,小于N_KEY值,越小频率越快。
- u8 key_check(void)
- {
- static u8 NewKey,OldKey,nKey = 0;
-
- NewKey = 0;
- if(digitalRead(3))NewKey=1;
- // if(digitalRead(4))NewKey=2;
- if(digitalRead(5))NewKey=3;
- //if(digitalRead(6))NewKey=4;
- if(digitalRead(7))NewKey=5;
- if(NewKey)//有按键按下,状态保存至newkey中
- {
- if(OldKey != NewKey) //如果是新的按键信息,保存至oldkey中
- { //每次有新按键按下,均判断成立一次。
- OldKey = NewKey; //包含组合按键的情况
- nKey = 0;
- // SysLed = 0;
- return(0);
- }
- else
- {
- nKey++;
- if(nKey >= N_KEY)//调用此函数N_KEY次,均获取此按键信息,说明按键的确按下
- {
- if(nKey == N_KEY)
- return(NewKey);
- if(nKey == 10 + F_KEY)
- {
- nKey = nKey - F_KEY;
- return(NewKey);
- }
- }
- return(0);
- }
- }
- OldKey = 0;
- nKey = 0;
- return(0); //返回0,没有按键按下
- }
- void delay_us(short i)
- {
- for(;i>0;i--) {
- unsigned char x;
- x=x;
- x=x;
- x=x;
- }
- }
- long int hx711_read_data(void)
- {
- unsigned char i;
- long int Count;
- Count=0;
- digitalWrite(11,0);//ADSK = 0; // ??AD(PD_SCK??)
- while(digitalRead(10));
- for (i=0;i<24;i++)
- {
- digitalWrite(11,1);; // PD_SCK??(????)
- Count = Count<<1; // ???????????????,??count????,????
- digitalWrite(11,0);
- if(digitalRead(10)) Count++;
- }
- for(i=0;i<1;i++)
- {
- digitalWrite(11,1);
- delay_us(4);
- digitalWrite(11,0);
- delay_us(4);
- }
- Count=Count&(u32)0x7fffff;
- return Count ;
- }
复制代码
`
|