|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
一、开发板使用说明
3 b8 A+ J. k# N, E j1. 功能
" Q* V0 W4 G% z4 V" @5 k2 S; h序号
$ t9 Q* |0 y- |3 O, T m | 功能
, i( @8 D7 x2 f' O1 O | 描述7 F, y' G3 ^3 _' a0 X. J
| 1
4 z- J' i9 M* v$ B$ X, n8 Z2 u | mcu2 q0 P9 P. O, Z3 ? J1 K
| ATMEGA2560-16AU
3 Z6 _1 ]+ Y* {' p | 24 e2 f$ U6 s0 `' p* Q
| I/O
8 j( o) q$ ]3 V1 M, }9 _ | 1路I/O/ X; o' ?; Q# L+ t* [
|
. ^: X6 a3 W; @) g. H4 B | + I( X5 ^2 e) n# u% X' z. E4 }" p/ G
| IO检测:检测闸刀的导通还是断开
( Y4 \# G$ G1 `% v | 3
2 s& Q( K5 \ k& E. k | ADC; y- M4 m& J4 e' B! V
| 3路AD) w ~- x; H8 @. K; q# v4 j
|
6 u6 l" f# w( ]' K |
' b; s4 W; K- n8 _ | CH1:电压采集(模拟数据采集)* \8 k5 w' W4 O3 \( J) t' ]) f4 C
|
3 U( D% ]( v% M x |
9 }0 r: R. a0 D. U$ B, T% G3 l | CH2:电流采集(模拟数据采集)
. U% e" O0 U1 Y1 s1 R: k- _ | ( Z; e6 ^$ N: R. V- p- q1 V
|
% ?5 }) N. k9 _; X1 R | Temp:温度采集(模拟数据采集)
+ L5 H! s1 r, p3 w | 4
# S L# D6 b5 L1 x3 H* X( @ | LED# Q5 C* \9 c# F8 p' ~' h9 K2 r
| 工作指示灯
! S+ H; `0 O4 P4 W! |8 I/ Y | 5
! r+ N* j" z e( P G1 |( e4 m | 按键
+ w M# ^5 y m7 X% c# f | 复位按键
' f0 `* p% [6 F ` | 6# p. S" R$ C4 u$ i( V
| 电源
. p/ \7 m+ l( _- y& L | USB 5V电源输入0 y y- U- w7 c- q0 D
|
( `5 l% O: r9 P: W! F- Y% I/ t; c注:实现的功能:
5 w( D' b0 T' p# S( @+ s# sa.上电后发送指令屏的握手指令给T5UIC1屏,T5UIC1屏收到指令后回返回应答信息,当MCU没有收到应答信息时,T5UIC1屏显示开机界面同时MCU的LED灯为常亮。) [0 V S4 t9 W8 i
b. 当MCU收到T5UIC1屏的握手回应后,MCU通过页面转换指令进入“初始化系统”页面,显示倒计时5秒钟。
# T9 s( @3 Z: u4 c8 ]6 q) X- zc. 当倒计时页面到达5秒后便进入主界面,此时MCU LED工作指示灯以200ms间隔闪烁以示工作正常状态,主界面显示当前MCU采集ADC通道的数据值,同时显示闸刀开关的状态。8 c C/ t/ {- j! c6 l* s9 F
d. MCU每3秒采用一次AD数据并更新到T5UIC1屏上。5 x9 I- |* k: j7 o0 _$ }6 K) I5 e6 ^
f4 u- u1 k) T/ x2 X7 I! I, A
* m) J: i; W( Z) ]
" d* g! @+ V7 H2 l
0 Y8 S; F5 |' _/ V& X5 t8 L9 }$ ~' t$ w: {8 _% f' l7 O( G6 E
2. 需使用的工具- j$ H3 ^! E8 o! M" f( f1 N
a.硬件:arduino-mega2560_R3学习板(MCU为atmega2560,串口TTL电平)。
; T3 J! a1 I4 u. hb.软件:Arduino-IDE。
% v0 f; C' G% k( q( C' l# E/ y. T! T( ~* Cc.原理图:详见“硬件原理图”文件夹。% K; p E; W7 W1 A
d.程序:T5UIC1屏工程配置文件在“T5UIC1屏 配置文件与图片”文件夹中,通过SD卡下载DWIN_SET导入屏中即可。 mega2560_R3程序在“mega2560 源码”文件夹。$ j7 ]0 g9 ]5 i. }% {. e8 v
0 N# ?6 x1 i4 G7 E
二、评估板硬件和软件部分详细介绍
7 P. @9 t! ` z3 K5 w' R1. 硬件原理图
/ c6 ?8 O# `/ a4 I(1)硬件接口定义
: K+ X! i- P z4 l' l" g0 ?功能1 t \" Y5 _+ B/ ~; a' K% v
| 对应ATMEGA2560的IO
# l4 b( g X, c: S* O6 |3 |1 K |
4 H8 j- h: h4 ]% i- x k | LED
3 p3 F8 @3 ^+ C: T( l. G( d. ~ | PL5 | + R, D* D* Q( X6 ~5 P& h' ^* E/ V
| ADC1
8 Z" P. s2 ?% w | 数据模拟产生 | 3 d9 A, G/ E) C3 j' {5 X
| ADC2' B# }3 k) P5 O* ^- K5 y& \
| 数据模拟产生 |
5 V' T; S3 b+ \+ Y | TXD1(触摸屏端子显示)
& B2 {+ |; ]: S0 s | TXD1 | 9 E3 Q; ?, a1 p* L
| RXD1(触摸屏端子显示)
$ G6 n+ L$ l7 Q: {# l | RXD1 | 5 P0 h8 b% |# s8 G) A
|
0 J1 k. s1 s9 o, S9 N(2)硬件原理图: ?, M/ m' }# w' z
硬件原理图详情见附件
& a' I( k7 v" T# Z* C6 ]
4 t3 I* g J, d7 u' x! T+ u2. 软件程序
2 L: m/ `' M' N$ s- l- {- a界面工程配置文件在“T5UIC1屏 配置文件与图片”文件夹中。
4 W- J4 {% P! V ~! G7 y/ o/ gmega2560_R3程序在“mega2560 源码”文件夹中。8 O; W; z7 h3 }5 V! q2 H7 k
1 H% T* A! p$ ^(1)界面工程, m* p: a ^- H8 c6 }1 g5 E/ |2 B
0 开机界面:0X1000/ C( [6 J9 g; w' \" N
; V+ {9 e# p# _+ \% ]
(2)MCU程序$ o! k V+ N" N) ?# h8 R) P
: C# z5 \3 Q5 u# ^ E3 H0 Q' `
) U% D p! X& \1 \- F' W- 0)数据结构体与宏定义
- // 指令数据发送宏操作
- #define SEND_DATA(P) Serial1.write(P)
- #define TX_8(P1) SEND_DATA((P1)&0xFF) // send one byte
- #define TX_16(P1) TX_8((P1)>>8);TX_8(P1) // send two byte
- #define TX_32(P1) TX_16((P1)>>16);TX_16((P1)&0xFFFF) // send four byte
- #define BEGIN_CMD() TX_8(FRAME_HRAD)
- #define END_CMD() TX_32(FRAME_TAIL)
- // 文本属性结构体
- typedef struct{
- us08 mode; // 显示模式
- us16 sx, sy; // 字符串显示的左上角坐标
- us16 f_color, b_color; // 字符显示颜色 && 字符背景显示颜色
- us08 num_i; // 显示的整数位数,0x01-0x14
- us08 num_f; // 显示的小数位数,0x00-0x14,Num_I+Num_F 之和不能超过20
- us08 p_len; // 待发送的数据字节数
- us08 *p_data; // 指向数据缓存区的指针
- }DWIN_TEXT_STR;
- // dwin操作类
- class DWIN_LIB{
- public:
- /*
- * 配置与接口
- *******************************************************************************/
- void dwin_shake(void);
- void dwin_set_backlight(us08 level);
- void dwin_write_storage(us08 type,us16 addr, us08 *data, us08 len);
- void dwin_write_sram(us16 addr, us08 *data, us08 len);
- void dwin_write_flash(us16 addr, us08 *data, us08 len);
- void dwin_read_storage(us08 type,us16 addr, us08 len);
- void dwin_read_sram(us16 addr, us08 len);
- void dwin_read_flash(us16 addr, us08 len);
- void dwin_pic_storage(us08 pic_id);
- /*
- * 绘图相关
- *******************************************************************************/
- void dwin_clear_screen(us16 color);
- void dwin_set_point_color(us16 x, us16 y, us16 color);
- void dwin_draw_line(us16 sx, us16 sy, us16 ex, us16 ey, us16 color);
- void dwin_draw_rect(us16 sx, us16 sy, us16 ex, us16 ey, us16 color);
- void dwin_fill_rect(us16 sx, us16 sy, us16 ex, us16 ey, us16 color);
- void dwin_xor_rect(us16 sx, us16 sy, us16 ex, us16 ey, us16 color);
- void dwin_move_rect(us16 sx, us16 sy, us16 ex, us16 ey, us16 color, us16 distance, us08 dir, us08 mode);
- /*
- * 文本相关
- *******************************************************************************/
- void dwin_disp_string(DWIN_TEXT_STR *pstr);
- void dwin_disp_num(DWIN_TEXT_STR *pstr);
- /*
- * 图标、图片相关
- *******************************************************************************/
- void dwin_show_qr(us16 sx, us16 sy, us08 qr_pixel, us08 *data, us08 len);
- void dwin_show_pic_from_storage(us08 jpg_id);
- void dwin_show_ico_from_storage(us16 sx, us16 sy, us08 ico_addr, us08 ico_id, us08 mode);
- void dwin_show_ico_from_sram(us16 sx, us16 sy, us16 sram_addr, us08 mode);
- void dwin_show_pic_from_virtual1(us08 jpg_id);
- void dwin_copy_pic_from_virtual1(us16 sx, us16 sy, us16 ex, us16 ey, us16 x, us16 y);
- void dwin_copy_pic_from_virtual(us08 mode, us16 sx, us16 sy, us16 ex, us16 ey, us16 x, us16 y);
- void dwin_draw_ico_animation(us08 mode, us16 sx, us16 sy, us08 ico_addr, us08 icos_id, us08 icoe_id, us08 timer);
- void dwin_ico_animation(us08 ico_addr, us08 sw);
- us08 dwin_frame_read(us08 indata, DWIN_DATA_STR *frameT);
- private:
- };
- // 处理dwin 2d画图类
- class DWIN_PROCESS{
- public:
- void init_dwin(void);
- void dwin_handle_porcess(void);
- void show_temperature(float data, us08 num_f);
- void show_voltage(float data, us08 num_f);
- void show_currents(float data, us08 num_f);
- void show_gate_switch(us08 sw);
- private:
- DWIN_LIB dwin_lib;
- void dwin_proc_shake(void);
- void create_gui_A(void);
- void create_gui_B(void);
- };
- 1)loop ():程序主体运行程序
- void loop() {
- // put your main code here, to run repeatedly:
- delay(1);
- dwin_process.dwin_handle_porcess();
- count++;
- timeC++;
- if(count >= 200){
- count = 0;
- if(!record){
- record = 1;
- digitalWrite(LED_BUILTIN, LOW);
- }
- else{
- record = 0;
- digitalWrite(LED_BUILTIN, HIGH);
- }
- }
- if(timeC >= 3000){
- timeC = 0;
- temp_v += 0.1f;
- vol_v += 0.01f;
- cur_v += 0.01f;
- if(sw_v) sw_v = 0;
- else sw_v = 1;
- dwin_process.show_temperature(temp_v, 1);
- dwin_process.show_voltage(vol_v, 2);
- dwin_process.show_currents(cur_v, 2);
- dwin_process.show_gate_switch(sw_v);
- }
- }
- 2). setup ():接口和变量的初始化函数
- void setup() {
- // put your setup code here, to run once:
- pinMode(LED_BUILTIN, OUTPUT);
- Serial1.begin(115200);
- Serial.begin(115200);
- while (!Serial) {}
- dwin_process.init_dwin();
- Serial.println("OK");
- }
- 3). create_gui_A ():界面1显示函数
- void DWIN_PROCESS::create_gui_A(void){
- DWIN_TEXT_STR textStr;
- us08 text[14] = {0xCF,0xB5,0xCD,0xB3,0xB3,0xF5,0xCA,0xBC,0xBB,0xAF,0x2E,0x2E,0x2E,0x2E};
- // 显示二维码
- us08 qr_data[22] = {
- 0x68,0x74,0x74,0x70,0x3A,0x2F,0x2F,0x77,0x77,0x77,0x2E,
- 0x64,0x77,0x69,0x6E,0x2E,0x63,0x6F,0x6D,0x2E,0x63,0x6E
- };
- //dwin_show_qr(5,5,1,qr_data,22);
- //dwin_show_qr(5,220,1,qr_data,22);
- //dwin_show_qr(425,5,1,qr_data,22);
- dwin_lib.dwin_show_qr(425,220,1,qr_data,22);
- textStr.mode = 0;
- textStr.mode = DISABLE_TEXT_RESIZE|DISABLE_TEXT_BCOLOR|FONT1632;
- textStr.f_color = ASSEMBLE_RGB(0, 0, 255);
- textStr.p_len = 14;
- textStr.p_data = text;
- textStr.sx = 100; textStr.sy = 120;
- dwin_lib.dwin_disp_string(&textStr);
- text[0] = 0x05;
- while(1){
- delay(1000);
- textStr.sx = 315; textStr.sy = 125;
- dwin_lib.dwin_fill_rect(textStr.sx, textStr.sy, textStr.sx+60, textStr.sy+50, ASSEMBLE_RGB(31, 33, 33));
- textStr.mode = 0;
- textStr.mode = FONT1224|DISABLE_NUM_BCOLOR|ENABLE_SIGNED_NUM|DISABLE_NUM_ZERO|DISABLE_NUM_ZERO_S;
- textStr.f_color = ASSEMBLE_RGB(0, 0, 255);
- textStr.p_len = 1;
- textStr.p_data = text;
- textStr.num_i = 2;
- textStr.num_f = 0;
- dwin_lib.dwin_disp_num(&textStr);
- text[0] -= 1;
- if(text[0] == 0xFF){
- //dwin_fill_rect(textStr.sx, textStr.sy, textStr.sx+60, textStr.sy+50, ASSEMBLE_RGB(31, 33, 33));
- break;
- }
- }
- dwin_lib.dwin_clear_screen(ASSEMBLE_RGB(31,33,33));
- }
- 4). create_gui_B ():界面2显示函数
- void DWIN_PROCESS::create_gui_B(void){
- DWIN_TEXT_STR textStr;
- us08 text0[7] = {0x41,0x50,0x50,0xB2,0xD9,0xD7,0xF7};
- us08 text1[12] = {0x20,0xB5,0xE7,0xD1,0xB9,0xBC,0xEC,0xB2,0xE2,0xD2,0xC7,0x20};
- us08 text2[10] = {0xB5,0xB1,0xC7,0xB0,0xCE,0xC2,0xB6,0xC8,0xA3,0xBA};
- us08 text3[10] = {0xB5,0xB1,0xC7,0xB0,0xB5,0xE7,0xD1,0xB9,0xA3,0xBA};
- us08 text4[10] = {0xB5,0xB1,0xC7,0xB0,0xB5,0xE7,0xC1,0xF7,0xA3,0xBA};
- us08 text5[10] = {0xD5,0xA2,0xB5,0xB6,0xBF,0xAA,0xB9,0xD8,0xA3,0xBA};
- // 显示二维码
- us08 qr_data[22] = {
- 0x68,0x74,0x74,0x70,0x3A,0x2F,0x2F,0x77,0x77,0x77,0x2E,
- 0x64,0x77,0x69,0x6E,0x2E,0x63,0x6F,0x6D,0x2E,0x63,0x6E
- };
- dwin_lib.dwin_clear_screen(ASSEMBLE_RGB(31,33,33));
- dwin_lib.dwin_draw_line(0,18,479,18,ASSEMBLE_RGB(255,255,0));
- dwin_lib.dwin_draw_rect(337, 40, 449, 185, ASSEMBLE_RGB(255,255,0));
- dwin_lib.dwin_show_qr(347,80,2,qr_data,22);
- // APP
- textStr.mode = 0;
- textStr.mode = DISABLE_TEXT_RESIZE|ENABLE_TEXT_BCOLOR|FONT1224;
- textStr.f_color = ASSEMBLE_RGB(255, 255, 0);
- textStr.b_color = ASSEMBLE_RGB(31,33,33);
- textStr.p_len = 3;
- textStr.p_data = text0;
- textStr.sx = 375; textStr.sy = 48;
- dwin_lib.dwin_disp_string(&textStr);
- // 电压检测仪
- textStr.mode = 0;
- textStr.mode = DISABLE_TEXT_RESIZE|ENABLE_TEXT_BCOLOR|FONT1632;
- textStr.f_color = ASSEMBLE_RGB(0, 0, 255);
- textStr.b_color = ASSEMBLE_RGB(31,33,33);
- textStr.p_len = 12;
- textStr.p_data = text1;
- textStr.sx = 145; textStr.sy = 0;
- dwin_lib.dwin_disp_string(&textStr);
- // 当前温度
- textStr.mode = 0;
- textStr.mode = DISABLE_TEXT_RESIZE|DISABLE_TEXT_BCOLOR|FONT1428;
- textStr.f_color = ASSEMBLE_RGB(255, 255, 0);
- textStr.p_len = 10;
- textStr.p_data = text2;
- textStr.sx = 5; textStr.sy = 50;
- dwin_lib.dwin_disp_string(&textStr);
- // 当前电压
- textStr.mode = 0;
- textStr.mode = DISABLE_TEXT_RESIZE|DISABLE_TEXT_BCOLOR|FONT1428;
- textStr.f_color = ASSEMBLE_RGB(255, 255, 0);
- textStr.p_len = 10;
- textStr.p_data = text3;
- textStr.sx = 5; textStr.sy = 100;
- dwin_lib.dwin_disp_string(&textStr);
- // 当前电流
- textStr.mode = 0;
- textStr.mode = DISABLE_TEXT_RESIZE|DISABLE_TEXT_BCOLOR|FONT1428;
- textStr.f_color = ASSEMBLE_RGB(255, 255, 0);
- textStr.p_len = 10;
- textStr.p_data = text4;
- textStr.sx = 5; textStr.sy = 150;
- dwin_lib.dwin_disp_string(&textStr);
- // 刀闸开关
- textStr.mode = 0;
- textStr.mode = DISABLE_TEXT_RESIZE|DISABLE_TEXT_BCOLOR|FONT1428;
- textStr.f_color = ASSEMBLE_RGB(251, 146, 0);
- textStr.p_len = 10;
- textStr.p_data = text5;
- textStr.sx = 5; textStr.sy = 200;
- dwin_lib.dwin_disp_string(&textStr);
- }
- 5). dwin_disp_string ():显示字符的函数
- void DWIN_LIB::dwin_disp_string(DWIN_TEXT_STR *pstr){
- us08 i = 0;
- BEGIN_CMD();
- TX_8(0x11);
- TX_8(pstr->mode);
- TX_16(pstr->f_color);
- TX_16(pstr->b_color);
- TX_16(pstr->sx);
- TX_16(pstr->sy);
- //while(pstr->p_len--) TX_8(*(pstr->p_data++));
- while(pstr->p_len--) TX_8(pstr->p_data[i++]);
- END_CMD();
- }
- 6). dwin_disp_num ():显示数字的函数
- void DWIN_LIB::dwin_disp_num(DWIN_TEXT_STR *pstr){
- us08 i = 0;
- BEGIN_CMD();
- TX_8(0x14);
- TX_8(pstr->mode);
- TX_16(pstr->f_color);
- TX_16(pstr->b_color);
- TX_8(pstr->num_i);
- TX_8(pstr->num_f);
- TX_16(pstr->sx);
- TX_16(pstr->sy);
- //while(pstr->p_len--) TX_8(*(pstr->p_data++));
- while(pstr->p_len--) TX_8(pstr->p_data[i++]);
- END_CMD();
- }
- 7). show_temperature ():显示温度数据,文本显示
- void DWIN_PROCESS::show_temperature(float data, us08 num_f){
- us32 value;
- us08 text[4];
- DWIN_TEXT_STR textStr;
- switch(num_f){
- case 1:
- value = data*10;
- break;
- case 2:
- value = data*100;
- break;
- case 3:
- value = data*1000;
- break;
- default: return;
- }
- text[0] = value>>24;
- text[1] = value>>16;;
- text[2] = value>>8;;
- text[3] = value;
- textStr.sx = 130; textStr.sy = 50;
- dwin_lib.dwin_fill_rect(textStr.sx, textStr.sy, textStr.sx+80, textStr.sy+50, ASSEMBLE_RGB(31, 33, 33));
- textStr.mode = 0;
- textStr.mode = FONT1632|DISABLE_NUM_BCOLOR|ENABLE_SIGNED_NUM|DISABLE_NUM_ZERO|DISABLE_NUM_ZERO_S;
- textStr.f_color = ASSEMBLE_RGB(0, 0, 255);
- textStr.p_len = 4;
- textStr.p_data = text;
- textStr.num_i = 8;
- textStr.num_f = num_f;
- dwin_lib.dwin_disp_num(&textStr);
- }
- 8). show_gate_switch ():显示闸刀状态量,2D画图形式
- void DWIN_PROCESS::show_gate_switch(us08 sw)
- {
- us08 text1[2] = {0xBF, 0xAA};
- us08 text0[2] = {0xB9, 0xD8};
- DWIN_TEXT_STR textStr;
- dwin_lib.dwin_fill_rect(150, 199, 250, 231, ASSEMBLE_RGB(251, 146, 0));
- dwin_lib.dwin_fill_rect(151, 200, 249, 230, ASSEMBLE_RGB(31, 33, 33));
- if(sw == 1){
- dwin_lib.dwin_fill_rect(199, 201, 248, 229, ASSEMBLE_RGB(0, 255, 0));
- textStr.mode = 0;
- textStr.mode = DISABLE_TEXT_RESIZE|DISABLE_TEXT_BCOLOR|FONT1224;
- textStr.f_color = ASSEMBLE_RGB(0, 0, 0);
- textStr.p_len = 2;
- textStr.p_data = text1;
- textStr.sx = 215; textStr.sy = 203;
- dwin_lib.dwin_disp_string(&textStr);
- }
- else{
- dwin_lib.dwin_fill_rect(152, 201, 200, 229, ASSEMBLE_RGB(255, 0, 0));
- textStr.mode = 0;
- textStr.mode = DISABLE_TEXT_RESIZE|DISABLE_TEXT_BCOLOR|FONT1224;
- textStr.f_color = ASSEMBLE_RGB(0, 0, 0);
- textStr.p_len = 2;
- textStr.p_data = text0;
- textStr.sx = 165; textStr.sy = 203;
- dwin_lib.dwin_disp_string(&textStr);
- }
- }
1 J8 L* W6 R9 Y5 T- u) [
' c4 I/ ?, |! a$ ?
/ |9 Z9 k' e7 S4 ?
# n# D P. ]; k% U m( ^2 z' ~: ?& ^' D2 ` e
' b/ s6 I7 O7 U- q3 C
+ K# d. } @& ]! j4 D
* Q! |9 w) R G; V, o7 R |
|