发表于:2007-03-22 10:10:00
5楼
我要取的数值为0至359,即一个圆的一周中的角度值,用整型数值好像不够.
这是我最初的设计方案,如果有兴趣的话运行一下,给我指点指点,谢谢了.
#include<at89x51.h>
#include<stdio.h>
char IND[4];
char Num[]={0x01,0x79,0x12,0x30,0x68,0x24,0x04,0x61,0x7f,0x60};
char Add[]={0xfe,0xfd,0xfb};
int switchIND(int x);
int i,j;
void delay10ms(unsigned char time);
void main()
{
SCON=0X50;
TMOD=0X20;
TCON=0X40;
TH1=0xfd;
TI=1;
TR1=1;
while(1)
{
if(RI==1)
{
scanf("%S",&IND);
}
for(i=0;i<3;i++)
{
P2=Add[i];
P1=Num[switchIND(i)];
delay10ms(2);
P1=0xFF;
}
}
}
void delay10ms(unsigned char time)
{
unsigned char a,b,c;
for(a=0;a<=time;a++)
for(b=0;b<=10;b++)
for(c=0;c<=120;c++);
}
int switchIND(int x)
{
int X;
switch(IND[x])
{
case '0':
X=0;
break;
case '1':
X=1;
break;
case '2':
X=2;
break;
case '3':
X=3;
break;
case '4':
X=4;
break;
case '5':
X=5;
break;
case '6':
X=6;
break;
case '7':
X=7;
break;
case '8':
X=8;
break;
case '9':
X=9;
break;
}
return X;
}