1、“悬挂物体运动系统” (单片机)设计了一个以两块 AT89S 系列单片机为核心的悬挂运动控制系统。AT89S52 为主机和AT89S51 为从机作为控制器实现物体运动的自动控制,主从机之间采用 RS-232 通讯,利用反射式红外光电传感器检测纸面曲线轨迹。系统由检测、控制、电机驱动、键盘显示等部分组成,采用 C 语言编程实现了任意设定坐标参数、按设定曲线运动、画圆、曲线寻轨、断点检测等功能,增设了由 ISD4004 语音录放集成芯片为核心的语音提示功能。经过严格测试,系统工作稳定、运动曲线较平滑、寻轨精度较高,运行时间较短,实现了设计的全部功能要求,并扩展了语音提示功能。1 主程序清单/*/*
2、主控程序*/*功能*/*切换子程序,调整坐标,显示实时坐标和目标坐标,计时*/#include#include#include#define uint unsigned int#define uchar unsigned charlong time,t0;/秒钟计时参数uchar lcdc=0x0f,place=0x94;/液晶控制字和光标闪烁地址bit enter=0,cancle=0,l=1,set=1;/输入,取消,液晶刷新,设置uint stat=0;/状态指示uint time14=0,0,0,0;/目标坐标uint bitcount=0;uint xc=0,yc=0,xt,yt,x
3、s,ys;/当前坐标,中间坐标,最终坐标uchar llt,lrt;/当前左右绳长,需改变长,最终长bit ok=1;/指示下位机运行成功uint bittemp;/在作图,画圆状态下的取位变量uint x0,y0;/圆心uint cnt;/作图和画圆时设定点的变量uint ccnt;/作图时候坐标显示uchar begin2=0,0;uchar string102;bit xungui=0;sbit sa=P02;/上sbit sb=P03;/右sbit sc=P01;/下sbit sd=P00;/左寻轨时的 4 个传感器/*液晶显示*/sbit scl=P07;/液晶显示时钟线sbit s
4、id=P06;/数据线sbit cs=P05;/使能端uchar code line112=“画笔: , “;/第一行显示数据uchar code line211=“坐标: , “;/第二行uchar code line312=“时间: .秒 “;uchar code line412=“状态: “;uchar code yuan1412= 0, 25, 0, 24, 0, 23, 0, 22, 0, 21, 1, 20, 1, 19, 1, 18, 1, 17, 2, 16, 2, 15, 3, 14, 3, 13, 4, 12, 4, 11, 5, 10, 6, 9, 7, 8, 8, 7,
5、 9, 6,10, 5,11, 4,12, 4,13, 4,14, 3,15, 2,16, 2,17, 2,18, 1,19, 1,20, 1,21, 0,22, 0,23, 0,24, 0,25, 0,26, 0,27, 0,28, 0,29, 0,30, 0,31, 1,32, 1,33, 1,34, 2,35, 2,36, 3,37, 3,38, 4,39, 4,40, 5,41, 6,42, 7,43, 8,44, 9,45, 10,46, 11,46, 12,47, 13,47, 14,48, 15,48, 16,49, 17,49, 18,49, 19,49, 20,50, 21,
6、50, 22,50, 23,50, 24,50, 25,50, 26,50, 27,50, 28,50, 29,50, 30,49, 31,49, 32,49, 33,48, 34,48, 35,48, 36,47, 37,46, 38,46, 39,45, 40,44, 41,43, 42,42, 43,41, 44,40, 45,39, 46,38, 46,37, 47,36, 47,35, 48,34, 48,33, 49,32, 49,31, 49,30, 49,29, 50,28, 50,27, 50,26, 50,25, 50,24, 50,23, 50,22, 50,21, 50
7、,20, 50,19, 49,18, 49,17, 49,16, 48,15, 48,14, 47,13, 47,12, 46,11, 46,10, 45, 9, 44, 8, 43, 7, 42, 6, 41, 5, 40, 4, 39, 4, 38, 3, 37, 3, 36, 2, 35, 2, 34, 1, 33, 1, 32, 1, 31, 1, 30, 0, 29, 0, 28, 0, 27, 0, 26, 0, 25;uchar line444=“坐标 “;void sendcom();void delay(uint v)/延时程序while(v!=0)v-;void write
8、lcd(uchar date,bit k)/液晶写数据uchar temp;uint i=0;temp=date;for(i=0;i=8av=0;l=1;elseav=0;xs=time10*10+time11;ys=time12*10+time13;if(enter)set=set;if(set)lcdc=0x0f;TR0=0;time=0;l=1;elselcdc=0x0c;TR0=1;enter=0;break;case 1 : line440=0xd7;line441=0xf7;line442=0xcd;line443=0xbc;keyprocess();/作图状态if(bitcoun
9、t=4)bitcount=0;av=0;l=1;if(cancle)if(cnt8)cnt=0;elsecnt+;stringcnt0=time10*10+time11;stringcnt1=time12*10+time13;cancle=0;ccnt=cnt;elseccnt=bittemp;av=0;xs=stringbittemp0;ys=stringbittemp1;time10=xs/10;time11=xs%10;time12=ys/10;time13=ys%10;if(enter)set=set;bitcount=0; if(set)lcdc=0x0f;TR0=0;time=0;
10、l=1;elselcdc=0x0c;TR0=1;enter=0;break;case 2 : line440=0xbb;line441=0xad;line442=0xd4;line443=0xb2;keyprocess();/画圆状态if(bitcount=4)bitcount=0;av=0;l=1;elseav=0;x0=time10*10+time11;y0=time12*10+time13;if(x055|x075|y025)enter=1;TR0=0;xs=yuanbittemp0+x0-25;ys=yuanbittemp1+y0-25;if(enter)set=set;bitcount=0;if(set)lcdc=0x0f;TR0=0;time=0;l=1;elselcdc=0x0c;TR0=1;