单片机/MCU论坛
直播中

ZXC

7年用户 100经验值
擅长:EMC/EMI设计 嵌入式技术 制造/封装 接口/总线/驱动 处理器/DSP 控制/MCU EDA/IC设计
私信 关注
[文章]

Arduino系列:T5UIC1串口彩屏与HX711交互,实现常用功能(附例程)

`

一、评估板使用说明
1. 功能
序号
功能
描述
1
MCU
Arduino
2
I/O
9路I/O
3
LED
工作指示灯
4
按键
复位按键
5
电源
5V电源输入

注:可实现的功能:
a.称重,通过屏幕显示物品质量
b.计价,通过屏幕显示金额
d.校准称功能,可以随意更换称台
IMG_20181121_184223.jpg

IMG_20181121_184232.jpg

IMG_20181121_184236.jpg

IMG_20181121_184246.jpg



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)硬件原理图
hx711.png
图1:HX711原理图
2. 软件程序
  1. #include "dwin.h"
  2. #include
  3. #include
  4. #include
  5. #define u8 unsigned char
  6. #define u16 unsigned int
  7. int LCD_printf(unsigned char mode,unsigned int Color,unsigned int Bcolor,unsigned int x,unsigned int y,const char *format, ...)
  8. {
  9.    unsigned char l;
  10.   char tmp[200];
  11.   va_list arg;
  12.   va_start(arg, format);
  13.   vsprintf(tmp,format,arg);
  14.   va_end(arg);
  15.   l=0;
  16.   Serial.write(0xAA);
  17.   Serial.write(0x11);
  18.   Serial.write(mode);//模式
  19.   Serial.write(Color/256);
  20.   Serial.write(Color%256);//前景颜色
  21.   Serial.write(Bcolor/256);
  22.   Serial.write(Bcolor%256);//背景颜色
  23.   Serial.write(x/256);
  24.   Serial.write(x%256);//横坐标
  25.   Serial.write(y/256);
  26.   Serial.write(y%256);//Y坐标
  27.   
  28.   while(tmp[l])
  29.   Serial.write(tmp[l++]) ;
  30.   
  31.   Serial.write(0xcc);
  32.   Serial.write(0x33);
  33.   Serial.write(0xc3);
  34.   Serial.write(0x3c);
  35.   
  36. }
  37. /****************显示二维码函数*****************/
  38. /*参数:mode:D7********************************/
  39. void erweima(u16 x,u16 y,u8 QR_Pixel,const char *format, ...)
  40. {
  41.   unsigned char l;
  42.   char tmp[200];
  43.   va_list arg;
  44.   va_start(arg, format);
  45.   vsprintf(tmp,format,arg);
  46.   va_end(arg);
  47.   l=0;
  48.   Serial.write(0xaa);
  49.   Serial.write(0x21);
  50.   Serial.write(x/256);
  51.   Serial.write(x%256);//横坐标
  52.   Serial.write(y/256);
  53.   Serial.write(y%256);//Y坐标
  54.   Serial.write(QR_Pixel);//二维码每个点的大小
  55.   
  56.   while(tmp[l])
  57.   Serial.write(tmp[l++]) ;
  58.   
  59.   Serial.write(0xcc);
  60.   Serial.write(0x33);
  61.   Serial.write(0xc3);
  62.   Serial.write(0x3c);
  63. }
  64. /****************绘图清屏函数*****************/
  65. /*参数:mode:D7********************************/
  66. void clr(u16 Color)
  67. {
  68.   Serial.write(0xaa);
  69.   Serial.write(0x01);
  70.   Serial.write(Color/256);
  71.   Serial.write(Color%256);//颜色
  72.   Serial.write(0xcc);
  73.   Serial.write(0x33);
  74.   Serial.write(0xc3);
  75.   Serial.write(0x3c);
  76. }
  77. /****************绘图直线插入函数*****************/
  78. /*参数:mode:D7********************************/
  79. void Linear_interpolation(u8 num,u16 Color,...)
  80. {
  81.     va_list arg_ptr;
  82.     int tempValue;
  83.     num*=2;
  84.     Serial.write(0xaa);
  85.     Serial.write(0x03);
  86.     Serial.write(Color/256);
  87.     Serial.write(Color%256);
  88.     va_start(arg_ptr,Color);
  89.     while(num--)
  90.     {
  91.           tempValue=va_arg(arg_ptr,int);
  92.           Serial.write(tempValue/256);
  93.           Serial.write(tempValue%256);
  94.     }

  95.     va_end(arg_ptr);
  96.     Serial.write(0xcc);
  97.     Serial.write(0x33);
  98.     Serial.write(0xc3);
  99.     Serial.write(0x3c);
  100. }
  101. /****************绘图打点插入函数*****************/
  102. /*参数:mode:D7********************************/
  103. void Place_point(u8 num,u16 Color,u16 nx,u16 ny,...)
  104. {
  105.     va_list arg_ptr;
  106.     int tempValue;
  107.     num*=2;
  108.     Serial.write(0xaa);
  109.     Serial.write(0x02);
  110.     Serial.write(Color/256);
  111.     Serial.write(Color%256);
  112.     Serial.write(nx%256);
  113.     Serial.write(ny%256);
  114.     va_start(arg_ptr,ny);
  115.     while(num--)
  116.     {
  117.           tempValue=va_arg(arg_ptr,int);
  118.           Serial.write(tempValue/256);
  119.           Serial.write(tempValue%256);
  120.     }

  121.     va_end(arg_ptr);
  122.     Serial.write(0xcc);
  123.     Serial.write(0x33);
  124.     Serial.write(0xc3);
  125.     Serial.write(0x3c);
  126. }
  127. /****************屏幕背光亮度设置*****************/
  128. /*参数:mode:D7********************************/
  129. void DIM_Set(u8 Set)
  130. {

  131.     Serial.write(0xaa);
  132.     Serial.write(0x30);
  133.     Serial.write(Set);
  134.     Serial.write(0xcc);
  135.     Serial.write(0x33);
  136.     Serial.write(0xc3);
  137.     Serial.write(0x3c);
  138. }
  139. /****************设置扩展串口波特率**************/
  140. /*参数:mode:D7********************************/
  141. void Bode_Set(u16 Set)//调节扩展串口波特率
  142. {
  143.     Serial.write(0xaa);
  144.     Serial.write(0x38);
  145.     Serial.write(15667200/Set/256);
  146.     Serial.write(15667200/Set%256);
  147.     Serial.write(0xcc);
  148.     Serial.write(0x33);
  149.     Serial.write(0xc3);
  150.     Serial.write(0x3c);
  151. }
  152. /****************从扩展串口发送字符串**************/
  153. /*参数:mode:D7********************************/
  154. void UART_TX(const char *format, ...)//串口发送字符串
  155. {
  156.     u8 l;
  157.     char tmp[200];
  158.     va_list arg;
  159.     va_start(arg, format);
  160.     vsprintf(tmp,format,arg);
  161.     va_end(arg);
  162.     l=0;
  163.     Serial.write(0xaa);
  164.     Serial.write(0x39);
  165.      while(tmp[l])
  166.     Serial.write(tmp[l++]) ;
  167.     Serial.write(0xcc);
  168.     Serial.write(0x33);
  169.     Serial.write(0xc3);
  170.     Serial.write(0x3c);
  171. }
  172. /****************显示ICO图标**************/
  173. /*参数:mode:D7********************************/
  174. void dis_ico(u16 x,u16 y,u8 mode,u8 ids)//显示ico图标
  175. {
  176.     Serial.write(0xaa);
  177.     Serial.write(0x23);
  178.     Serial.write(x/256);
  179.     Serial.write(x%256);
  180.     Serial.write(y/256);
  181.     Serial.write(y%256);
  182.     Serial.write(y%256);
  183.     Serial.write(mode);  
  184.     Serial.write(ids);
  185.     Serial.write(0xcc);
  186.     Serial.write(0x33);
  187.     Serial.write(0xc3);
  188.     Serial.write(0x3c);
  189. }
  190. /****************设置动态图标*******************/
  191. /*参数:mode:D7********************************/
  192. void disd_ico(u16 x,u16 y,u8 mode,u8 Icon_lib,u8 Icon_IDs,u8 Icon_0IDe,u8 Delay_time)//显示ico图标
  193. {
  194.     Serial.write(0xaa);
  195.     Serial.write(0x28);
  196.     Serial.write(x/256);
  197.     Serial.write(x%256);
  198.     Serial.write(y/256);
  199.     Serial.write(y%256);
  200.     Serial.write(y%256);
  201.     Serial.write(mode);
  202.     Serial.write(Icon_lib);
  203.     Serial.write(Icon_IDs);
  204.     Serial.write(Icon_0IDe);
  205.     Serial.write(Delay_time);
  206.     Serial.write(0xcc);
  207.     Serial.write(0x33);
  208.     Serial.write(0xc3);
  209.     Serial.write(0x3c);
  210. }
  211. /****************设置动态图标*******************/
  212. /*参数:mode:D7********************************/
  213. void disc_ico(u16 set)//控制ico动态图标
  214. {
  215.     Serial.write(0xaa);
  216.     Serial.write(0x29);
  217.   
  218.     Serial.write(set/256);
  219.     Serial.write(set%256);

  220.     Serial.write(0xcc);
  221.     Serial.write(0x33);
  222.     Serial.write(0xc3);
  223.     Serial.write(0x3c);
  224. }

  225. /****************写存储器***********************/
  226. /*参数:mode:D7********************************/
  227. void writ_sram_flsh(u16 Length,u8 Type,u16 Address)//写数据存储器
  228. {
  229.     Serial.write(0xaa);
  230.     Serial.write(0x31);
  231.     Serial.write(Type);
  232.     Serial.write(Address/256);
  233.     Serial.write(Address%256);
  234.     while(Length--)
  235.     {
  236.       Serial.write(Address++);
  237.     }

  238.     Serial.write(0xcc);
  239.     Serial.write(0x33);
  240.     Serial.write(0xc3);
  241.     Serial.write(0x3c);
  242. }

  243. /****************读存储器***********************/
  244. /*参数:mode:D7********************************/
  245. void read_sram_flsh(u16 Length,u8 Type,u16 Address)//写数据存储器
  246. {
  247.     Serial.write(0xaa);
  248.     Serial.write(0x32);
  249.     Serial.write(Type);
  250.     Serial.write(Address/256);
  251.     Serial.write(Address%256);
  252.     Serial.write(Length);
  253.     Serial.write(0xcc);
  254.     Serial.write(0x33);
  255.     Serial.write(0xc3);
  256.     Serial.write(0x3c);
  257. }
  258. #define  N_KEY  3//调用按键检测函数N_KEY次,均获取同一个按键信息,说明该按键的确按下
  259. #define F_KEY  3//按下按键不放时的按键测试频率,小于N_KEY值,越小频率越快。
  260. u8 key_check(void)
  261. {
  262.   static  u8 NewKey,OldKey,nKey = 0;
  263.   
  264.   NewKey = 0;
  265.   if(digitalRead(3))NewKey=1;
  266. // if(digitalRead(4))NewKey=2;
  267.   if(digitalRead(5))NewKey=3;
  268.   //if(digitalRead(6))NewKey=4;
  269.   if(digitalRead(7))NewKey=5;
  270.   if(NewKey)//有按键按下,状态保存至newkey中
  271.   {
  272.     if(OldKey != NewKey)  //如果是新的按键信息,保存至oldkey中
  273.     {           //每次有新按键按下,均判断成立一次。
  274.       OldKey = NewKey;  //包含组合按键的情况
  275.       nKey = 0;
  276.     //  SysLed = 0;
  277.       return(0);
  278.     }
  279.     else
  280.     {
  281.       nKey++;
  282.       if(nKey >= N_KEY)//调用此函数N_KEY次,均获取此按键信息,说明按键的确按下
  283.       {
  284.         if(nKey == N_KEY)
  285.           return(NewKey);
  286.         if(nKey == 10 + F_KEY)
  287.         {
  288.           nKey = nKey - F_KEY;
  289.           return(NewKey);
  290.         }
  291.       }
  292.       return(0);
  293.     }   
  294.   }
  295.   OldKey = 0;
  296.   nKey = 0;
  297.   return(0);     //返回0,没有按键按下
  298. }
  299. void delay_us(short i)
  300. {
  301.   for(;i>0;i--) {
  302.                   unsigned char x;
  303.                   x=x;
  304.                   x=x;
  305.                   x=x;
  306.                 }
  307. }
  308. long  int  hx711_read_data(void)
  309. {
  310.   unsigned char i;
  311.   long  int Count;
  312.   Count=0;
  313.   digitalWrite(11,0);//ADSK = 0; // ??AD(PD_SCK??)
  314.   while(digitalRead(10));
  315.   for (i=0;i<24;i++)
  316.   {
  317.     digitalWrite(11,1);;       // PD_SCK??(????)
  318.     Count = Count<<1; // ???????????????,??count????,????
  319.     digitalWrite(11,0);   
  320.     if(digitalRead(10)) Count++;
  321.   }
  322.   for(i=0;i<1;i++)
  323.   {
  324.     digitalWrite(11,1);
  325.     delay_us(4);
  326.     digitalWrite(11,0);
  327.     delay_us(4);
  328.   }
  329.   Count=Count&(u32)0x7fffff;
  330.   return Count ;
  331. }

`
Arduino源程序.zip (3.6 KB)
(下载次数: 13, 2019-1-8 13:42 上传)
微信图片_20190108133234.png

回帖(6)

lee_st

2019-1-8 18:50:05
进来看看了
1 举报
  • ZXC: 欢迎 欢迎 ~~

lee_st

2019-1-8 18:50:13
很用心的资料
举报

lee_st

2019-1-8 18:50:23
加油了,资料
举报

lee_st

2019-1-11 11:00:34
客气了
举报

lee_st

2019-1-11 11:00:40
多支持
举报

lee_st

2019-1-11 11:00:47
多加油啊了
举报

更多回帖

发帖
×
20
完善资料,
赚取积分