Demo entry 6569954

cc

   

Submitted by anonymous on Jun 03, 2017 at 07:38
Language: C. Code size: 2.1 kB.

#include<stdio.h>
#include<reg51.h>
#include<intrins.h>
#include<absacc.h>
#define uchar unsigned char 
#define uint unsigned int
#define en_low1 XBYTE[0x87FF] 		 //¶¨ÒåÈý¸ö±àÂëÆ÷µÄµØÖ·
#define en_high1 XBYTE[0x8FFF] 
#define en_low2 XBYTE[0x97FF] 
#define en_high2 XBYTE[0x9FFF] 
#define en_low3 XBYTE[0xaA7FF] 
#define en_high3 XBYTE[0xAFFF]

uchar down[3]={0xFD,0xF7,0xDF};	   //¶¨Òåµ¥µç»ú¿ØÖƵÄÐźÅÊý×é
uchar up[3]={0xFE,0xFB,0xEF};
P1=0x11;					        //p1¿Ú³õʼ»¯£¬È«½Ó¸ßµçƽ£¬Çý¶¯Æ÷¶ËûÓÐѹ²î
int depul_number[3]={1000,1000,-1000};	 //Èý¸ö¶æ»úµÄÔ¤¶¨Êä³öÁ¿£¬ÕâÀïÒÔÔ¤ÉèÖµ´úÌæ
sbit flag=0;							 //Âö³åÐźÅ
int encoder[3]={0,0,0};				//¼ÆÊýÆ÷ÏòÁ¿¡¢ÇåÁã
int i=0;						    //µÚi¸öµç»ú
int repul_number[3]={0,0,0};		//Õæʵ×ßÁ˵ÄÂö³åÊý
int wapul_number[3]					//µÈ´ýÏìÓ¦µÄÂö³åÊý

 void timer0(void) interrupt 1		 //1-3    0-1  ¼ÆÊýÆ÷0ÖжÏ×Ó³ÌÐò
{
	TH0 =(65536-500)/256;			   //
	TL0 =(65536-500)%256;
	if(flag==1)
	{
	P1=0x11;
	}
	else
	{
	P1=m[0]&m[1]&m[2];
	i=0;                     //ÔÚÿ´ÎÐèÒªÂö³åµÄʱºò£¬¾ÍÊÇÏÂÒ»´ÎflagΪ0ʱ£¬½øÐÐiÖµÖØÖ㬼´¿É½øÐгÌÐò¿ØÖÆ
	}
	flag=~flag;
	
}

void T0_init(void)	  //T0É趨³õʼֵ¡¢Æô¶¯¡¢¿ªÖжÏ
{
	TMOD=0x01;        //0¼ÆʱÆ÷ÉèÖÃ
	TH0 =(65536-500)/256;			   //
	TL0 =(65536-500)%256;			   //
	EA  =1;					 //ÖжÏ×Ü¿ª¹Ø
	ET0 =1;			   //ÔÊÐíÖжÏ
	TR0 =1; 			//Æô¶¯
}
								  //»ñÈ¡¼ÆÊýÆ÷16λ¼ÆÊýÖµ£¬ÒòΪÊÇÔÚƬÄÚËùÒÔûÓбØÒª¼ÓƬÍâ´æ´¢Æ÷
uint fetch_encoder(void)
{
	encoder[0]=(uint)(en_high1<<8)+(en_low1&0x0F);
	encoder[1]=(uint)(en_high2<<8)+(en_low2&0x0F);
	encoder[2]=(uint)(en_high3<<8)+(en_low3&0x0F);
}


void main(void)
{
	T0_init();							  //Æô¶¯¶¨Ê±Æ÷
while(1)
{
	if(flag==0)
	{
	fetch_encoder();
	for(i=0;i<3;i++)					 //ÕâÀïi²»ÄÜΪ0£¬·ñÔòÿ´Î¶¼»áÖ´ÐвÙ×÷£¬¶øÊÇÔÚÖÐ
	{
	repul_number[i]=encoder[i]*2.5        //Ò»¸ö¶à¸öºÃÇø·Ö
	wapul_number[i]=depulnumber[i]-repul_number[i];
	if(wapul_number[i]>0)
	{
	 m[i]=up[i];
	}
	else if(wapul_number<0)
	{
	m[i]=down[i];
	}
	else {m[i]=0xFF;}    //Èç¹û¶¼ÊÇ1µÄ»°¾Í¶¼Í£ÁË
	}


}
}
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).