1、#include#include#include#define uint unsigned int#define uchar unsigned char#define COM1 XBYTE0x5800#define C01 XBYTE0x4000#define C11 XBYTE0x4800#define C21 XBYTE0x5000#define COM2 XBYTE0x3800#define C02 XBYTE0x2000#define C12 XBYTE0x2800#define C22 XBYTE0x3000sbit k1=P32;/电机复位按钮sbit k2=P33;/电机选择按钮
2、sbit k3=P34;/电机正转sbit k4=P35;/电机反转sbit rs=P20;sbit rw=P21;sbit en=P22;uint m=0,i=0;void reservo();void lcd(uint i);void timer(uint n);void delay(uint n);void lcd_init();void lcd_wcom(uchar com);void lcd_wdat(uchar dat);void lcd_wndat(uint dat);void delay(uint n);void init(void);void EXT1_INT(void) E
3、X1=1;IT1=1;EA=1;void EXT0_INT() EX0=1;IT0=1;EA=1;void EXT1_INT_SRV() interrupt 2 i+;/主程序void main() while(1)if(k1=0)reservo();/电机复位程序break;EXT1_INT();/中断初始化if(i!=0elsei=i%6;lcd(i);timer(i);/电机复位程序void reservo()EXT0_INT();delay(200);void EXT0_INT_SRV() interrupt 0TMOD=0x01;TH0=0xB1;TL0=0xE0;ET0=1;EA=
4、1;TR0=1;COM1=0x30;C01=0xdc; C01=0x05;COM1=0x70;C11=0xdc; C11=0x05;COM1=0xB0;C21=0xdc; C21=0X05;COM2=0x30;C02=0xdc; C02=0x05;COM2=0x70;C12=0xdc; C12=0x05;COM2=0xB0;C22=0xdc; C22=0X05;/显示屏程序void lcd(uint i) uint n;uchar code table=“servo“;lcd_init();lcd_wcom(0x80);for(n=0;n0;x-)for(y=110;y0;y-);void l
5、cd_wcom(uchar com)/1602写命令程序rs=0;rw=0;P0=com;delay(5);en=1;en=0;void lcd_wdat(uchar dat)/1602写数据程序rs=1;rw=0;P0=dat;delay(5);en=1;en=0;void lcd_wndat(uint dat)/1602写数据程序rs=1;rw=0;P0=dat;delay(5);en=1;en=0;void lcd_init()lcd_wcom(0x38);lcd_wcom(0x0c);lcd_wcom(0x06);lcd_wcom(0x01);/舵机程序void timer(uint
6、n)init();uint n; for(n=1;n=10;n+)if(k3=0) servozheng();elsebreak;n=1;for(;n=10;n+)if(k4=0) void servofan();void init(void)TMOD=0x01;TH0=0xB1;TL0=0xE0;ET0=1;EA=1;TR0=1;void servozheng() interrupt 1TH0=0xB1;TL0=0xE0;switch(i)case1: com1=0x30;c01=0x(dc+64*n); c01=0x05;break;case2: com1=0x70;c11=0x(dc+6
7、4*n); c11=0x05;break;case3: com1=0xB0;c21=0x(dc+64*n); c21=0x05;break;case4: com1=0x30;c02=0x(dc+64*n); c02=0x05;break;case5: com1=0x70;c12=0x(dc+64*n); c12=0x05;break;case6: com1=0xB0;c22=0x(dc+64*n); c22=0x05;void servofan() interrupt 1TH0=0xB1;TL0=0xE0;switch(i)case1: com1=0x30;c01=0x(dc-64*n); c01=0x05;break;case2: com1=0x70;c11=0x(dc-64*n); c11=0x05;break;case3: com1=0xB0;c21=0x(dc-64*n); c21=0x05;break;case4: com1=0x30;c02=0x(dc-64*n); c02=0x05;break;case5: com1=0x70;c12=0x(dc-64*n); c12=0x05;break;case6: com1=0xB0;c22=0x(dc-64*n); c22=0x05;