1、void SendIRdata(char p_irdata);void delay();void main(void) count = 0; flag = 0; OP = 0; P3_4 = 0; EA = 1; /允许CPU中断 TMOD = 0x11; /设定时器0和1为16位模式1 ET0 = 1; /定时器0中断允许 TH0 = 0xFF; TL0 = 0xE6; /设定时值0为38K 也就是每隔26us中断一次 TR0 = 1;/开始计数 iraddr1=3; iraddr2=252; do delay(); SendIRdata(12); while(1); /定时器0中断处理 v
2、oid timeint(void) interrupt 1 TH0=0xFF; TL0=0xE6; /设定时值为38K 也就是每隔26us中断一次 count+; if (flag=1) OP=OP; else P3_4 = OP;void SendIRdata(char p_irdata) int i; char irdata=p_irdata; /发送9ms的起始码 endcount=223; flag=1; count=0; dowhile(countendcount); /发送4.5ms的结果码 endcount=117 flag=0; /发送十六位地址的前八位 irdata=irad
3、dr1; for(i=0;i1; /发送十六位地址的后八位 irdata=iraddr2;endcount=10;flag=1;dowhile(count /发送八位数据的反码 irdata=p_irdata;endcount=15;void delay() int i,j;400; for(j=0;j100;j+)制作的实物如下图所示:步进电机#include#define uint unsigned int#define uchar unsigned char#define ms *77/ f = 12 M#define LEDLen 4#define Dj_star() IE=0x81;
4、 pri_dj=0;#define Dj_stop() IE=0x00; pri_dj=1; P1=0xff; shache=0; delay(800ms);delay(400ms); shache = 1;#define Chilun_Num 8/* 齿轮数 8 个*/#define set_display_num() LEDBuf0 = tmp / 1000; LEDBuf1 = tmp / 100 % 10; LEDBuf2 = tmp / 10 % 10; LEDBuf3 = tmp % 10;uchar LEDBufLEDLen = 0,0,0,0;void read_num ();
5、 /* 读播码盘 到 set_round_num * 8 */void display ();void delay(uint delay_time) uint i; for (i=0; i = set_round_num ) Dj_stop(); EA = 0x81;void display() uchar i; uint tmp = 0; for(i = 0; LEDLen ; i +) P0 = P0 | LEDBufi ; if(i=0) led_1000 = 0; /P04 if(i=1) led_100 = 0; /P05 if(i=2) led_10 = 0; /P06 if(i=
6、3) led_1 = 0; /P07void read_num() /* 读播码盘 到 set_round_num ,set_pwm_width */ uchar tmp; P2 = 0xFF; P2 = 0xEF; / 1110 1111 delay ( 1ms ); tmp = (P2 | 0xF0); P2 = 0xDF; / 1101 1111 tmp = (P2 | 0xF0 ) * 10 + tmp; set_round_num = tmp; P2 = 0xBF; / 1011 1111 tmp = (P2 | 0xF0); P2 = 0x7F; / 0111 1111 tmp =
7、 (P2 | 0xF0) * 10 + tmp; set_round_num = set_round_num + tmp * 100; set_round_num = set_round_num * Chilun_Num; P1 = 0xbF; tmp = (P2 | 0xF0) ; P1 = 0xFF; P1 &= 0x7F; tmp = (P2 | 0xF0) * 10 + tmp ; set_pwm_width = tmp ;void fx_run() #define f_Delay_time 180 while ( bujin_fx_stop ) /* 反向 回车 直到 传感器 动作*/ /0011 delay ( f_Delay_time ); /0110 /1100 /1001
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1