螺旋桨显示代码使用89c51-需要帮助

螺旋桨显示代码使用89c51-需要帮助,c,microcontroller,8051,C,Microcontroller,8051,下面是我为螺旋桨显示器编写的代码,当在马达上运行时,它会显示“HELLO”。用于LED的逻辑为低电平,连接至端口1,端口1声明为输出端口。端口3.2被声明为由红外传感器触发的输入端口。 我用Keil编译这个程序并生成它的十六进制文件,但是当我在我的微控制器上烧录并运行它时,引脚3.2不会触发端口1上输出的任何更改。在评论中提出任何你怀疑的问题并帮助我。多谢各位 #include <reg52.h> void delay_us(long num){ //function to del

下面是我为螺旋桨显示器编写的代码,当在马达上运行时,它会显示“HELLO”。用于LED的逻辑为低电平,连接至端口1,端口1声明为输出端口。端口3.2被声明为由红外传感器触发的输入端口。 我用Keil编译这个程序并生成它的十六进制文件,但是当我在我的微控制器上烧录并运行它时,引脚3.2不会触发端口1上输出的任何更改。在评论中提出任何你怀疑的问题并帮助我。多谢各位

#include <reg52.h>

void delay_us(long num){ //function to delay 1 microsecond using tic
    long i;
    for(i=0;i<=num;i++){    
        TMOD = 0x01;
        TH0 = 0xFF;
        TL0 = 0xFE;
        TR0 =  1;
        while(TF0 == 0);
        TF0 = 0;
        TR0 = 0;
    }
}

void print_char(char input, long time) //function to print HELLO!
{
    if (input == 'H')
    {
        P1 = 0x3E;
        delay_us(time);
                P1 = 0x00;
        delay_us(time);
                P1 = 0x36;
        delay_us(time);
                P1 = 0x00;
        delay_us(time);
                P1 = 0x3E;
        delay_us(time);
    }
    else if (input == 'E')
    {
        P1 = 0x3E;
        delay_us(time);
                P1 = 0x00;
        delay_us(time);
                P1 = 0x14;
        delay_us(time);
                P1 = 0x1C;
        delay_us(time);
                P1 = 0x3E;
        delay_us(time);
    }
        if (input == 'L')
    {
        P1 = 0x3E;
        delay_us(time);
                P1 = 0x3E;
        delay_us(time);
                P1 = 0x00;
        delay_us(time);
                P1 = 0x3E;
        delay_us(time);
                P1 = 0x3E;
        delay_us(time);
    }
        if (input == 'O')
    {
        P1 = 0x3E;
        delay_us(time);
                P1 = 0x22;
        delay_us(time);
                P1 = 0x1C;
        delay_us(time);
                P1 = 0x22;
        delay_us(time);
                P1 = 0x3E;
        delay_us(time);
    }
}

//Declare Prototypes
int get_rpu();
sbit LED1 = P1^0;
sbit LED2 = P1^1;
sbit LED3 = P1^2;
sbit LED4 = P1^3;
sbit LED5 = P1^4;
sbit LED6 = P1^5;
sbit LED7 = P1^6;
sbit IR = P3^2;

void main()
{
    long delay_time; //degrees per microsecond

    P1 = 0x10; 
    P3 = 0x00; 

    //Initialize all LED's to be zero
    LED1 = 1;
    LED2 = 1;
    LED3 = 1;
    LED4 = 1;
    LED5 = 1;
    LED6 = 1;
    LED7 = 1;

    //get the amount of delay
   delay_us(1000);

    delay_time = (get_rpu() * 100) / 360;

    while (1) {
        //Wait for the sensor to start at reference point
        while (!IR);

        print_char('H',delay_time);
        delay_us(delay_time);
        print_char('E',delay_time);
        delay_us(delay_time);
        print_char('L',delay_time);
        delay_us(delay_time);
        print_char('L',delay_time);
        delay_us(delay_time);
        print_char('O',delay_time);

        //recalculate the spin rate
    delay_time = (get_rpu() * 100) / 360;
    }
}

int get_rpu() //function to calculate time per revolution
{
    int count = 0;

    while (!IR); //wait for first pass of the rate snesor

    //begin counting how many microseconds are there before the next pass
    while(IR)
    {
        delay_us(1);
        count++;
    }
    return count;
}
#包括
void delay_us(long num){//函数使用tic延迟1微秒
龙我;

对于(i=0;i您想用P1^6做什么?^是互斥的或。您想检查第6位吗?是的。我试图访问各个PIN,但我意识到keil不支持此功能,因此现在我编辑了程序,如您所见。使用(P1&(1)该关键字具有许多不熟悉Keil的人可能不理解的行为。您想用P1^6做什么?^是独占的或。您想检查第6位吗?是的。我试图访问各个PIN,但我意识到Keil不支持此操作,因此现在我编辑了程序,如您所见。使用(P1&(1)该关键字具有许多不熟悉Keil的人可能无法理解的行为。