>_<:引脚和前面几个连接一样,这里做了一个实用的动画效果,模拟起重机的2维视图。
9325tp.h
9325tp.c
1 #include<reg52.h> 2 #include"9325tp.h" 3 4 ///////////////////////////////////////////////////////////////////////////////// 5 /* LCD color */ 6 #define White 0xFFFF 7 #define Black 0x0000 8 #define Blue 0x001F 9 #define Red 0xF800 10 //#define Blue2 0x051F 11 //#define Magenta 0xF81F 12 //#define Green 0x07E0 13 //#define Cyan 0x7FFF 14 //#define Yellow 0xFFE0 15 16 unsigned char b_x,b_y,b_l,b_w; 17 unsigned char m_x,m_old_x,m_y,m_l,m_w,m_v,m_a,m_l_limit_p,m_r_limit_p; 18 unsigned char s_y,s_old_y,s_extre_part,s_v,s_a,s_u_limit_p,s_d_limit_p; 19 20 unsigned char h_x,h_y,h_w; 21 unsigned char move_x_v,move_y_v,move_a; 22 unsigned char line_x,line_old_x,line_y,line_l,line_old_l; 23 //-------------------------------------------------------------- 24 void init1() 25 { 26 b_x=10,b_y=20,b_l=80,b_w=220; 27 m_x=m_old_x=40,m_y=10,m_l=100,m_w=70,m_v=5,m_a=0,m_l_limit_p=40,m_r_limit_p=b_x+b_w-m_l_limit_p; 28 s_y=s_old_y=80,s_extre_part=10,s_v=1,s_a=0,s_u_limit_p=b_y+10,s_d_limit_p=b_y+b_l-10; 29 } 30 //---------------------------Draw------------------------------- 31 void drawBig() 32 { 33 Line(b_x,b_y,b_x+b_w,b_y,Black); 34 Line(b_x,b_y+b_l,b_x+b_w,b_y+b_l,Black); 35 }//主梁画 36 void drawMiddle() 37 { 38 if(m_x!=m_old_x)Line(m_old_x,m_y,m_old_x,m_y+m_l,White); 39 Line(m_x,m_y,m_x,m_y+m_l,Blue); 40 if(m_x!=m_old_x)Line(m_old_x+m_w,m_y,m_old_x+m_w,m_y+m_l,White); 41 Line(m_x+m_w,m_y,m_x+m_w,m_y+m_l,Blue); 42 }//画横梁 43 void drawSmall() 44 { 45 if(s_old_y!=s_y || m_x!=m_old_x)Line(m_old_x-s_extre_part,s_old_y,m_old_x+m_w+s_extre_part,s_old_y,White); 46 Line(m_x-s_extre_part,s_y,m_x+m_w+s_extre_part,s_y,Red); 47 }//画小车 48 void draw1() 49 { 50 drawBig();//画主梁 51 drawMiddle();//画横梁 52 drawSmall();//画小车 53 }//总画函数 54 //----------------------------run----------------------------- 55 void runMiddle() 56 { 57 m_old_x=m_x; 58 m_x+=m_v; 59 if(m_x+m_w>=m_r_limit_p || m_x<=m_l_limit_p)m_v*=-1;//达到警戒线 60 }//横梁移动 61 void runSmall() 62 { 63 s_old_y=s_y; 64 line_old_x=line_x; 65 s_y+=s_v; 66 line_x+=move_x_v; 67 if(s_y>=s_d_limit_p || s_y<=s_u_limit_p){ 68 s_v*=-1; 69 move_x_v*=-1; 70 }//达到警戒线 71 }//小车移动 72 void run1() 73 { 74 runMiddle(); 75 runSmall(); 76 }//运动函数 77 ///////////////////////////////////////////////////////////////////////////////// 78 79 80 void init2() 81 { 82 h_x=10,h_y=180,h_w=220; 83 move_x_v=s_v*11/4,move_y_v=2,move_a=0; 84 line_x=line_old_x=160,line_y=h_y+3,line_l=line_old_l=50; 85 } 86 //-------------------------draw-------------------------------- 87 void drawGou() 88 { 89 if(line_old_x!=line_x || line_old_l!=line_old_l){ 90 Rectangle(line_old_x-3,line_y+line_old_l,line_old_x+3,line_y+line_old_l+6,White); 91 Line(line_old_x,line_y+line_old_l+6,line_old_x,line_y+line_old_l+9,White); 92 Line(line_old_x,line_y+line_old_l+9,line_old_x+6,line_y+line_old_l+9,White); 93 Line(line_old_x+6,line_y+line_old_l+9,line_old_x+6,line_y+line_old_l+15,White); 94 Line(line_old_x+6,line_y+line_old_l+15,line_old_x-6,line_y+line_old_l+15,White); 95 Line(line_old_x-6,line_y+line_old_l+15,line_old_x-6,line_y+line_old_l+12,White); 96 } 97 Rectangle(line_x-3,line_y+line_l,line_x+3,line_y+line_l+6,Blue); 98 Line(line_x,line_y+line_l+6,line_x,line_y+line_l+9,Black); 99 Line(line_x,line_y+line_l+9,line_x+6,line_y+line_l+9,Black); 100 Line(line_x+6,line_y+line_l+9,line_x+6,line_y+line_l+15,Black); 101 Line(line_x+6,line_y+line_l+15,line_x-6,line_y+line_l+15,Black); 102 Line(line_x-6,line_y+line_l+15,line_x-6,line_y+line_l+12,Black); 103 }//画勾,x,y为绳的下端,r为大小 104 void drawH() 105 { 106 Line(h_x,h_y,h_x+h_w,h_y,Black); 107 }//画横梁 108 void drawHuaKuai() 109 { 110 if(line_old_x!=line_x)Rectangle(line_old_x-6*3/4,line_y-6,line_old_x+6*3/4,line_y,White); 111 Rectangle(line_x-6*3/4,line_y-6,line_x+6*3/4,line_y,Blue); 112 }//画滑块,x,y为绳的上端,r为大小 113 void drawLine() 114 { 115 if(line_old_l!=line_l || line_x!=line_old_x)Line(line_old_x,line_y,line_old_x,line_y+line_old_l,White); 116 Line(line_x,line_y,line_x,line_y+line_l,Black); 117 }//画线 118 void draw2() 119 { 120 drawH(); 121 drawHuaKuai(); 122 drawLine(); 123 drawGou(); 124 } 125 //------------------------run------------------------------- 126 main() 127 { 128 ILI9325_Initial(); //初始化LCD 129 CLR_Screen(White); //用背景色清屏 130 init1();//初始化1画面 131 init2();//初始化2画面 132 while(1) 133 { 134 run1(); 135 draw1(); 136 draw2(); 137 } 138 }