⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 基于MCS-51的电子指南针完整程序包 如果需要原理图的
💻 C
📖 第 1 页 / 共 2 页
字号:
**备    注:                                                                                                                 **
******************************************************************************************************************************/
void DisCurDirc(unsigned int Dir)
{
    unsigned char tempx, tempy;
    unsigned char Dir1, Dir2, Dir3;
    
    Dir1 = Dir/100 +'0';                                                /* 提取其各位                                       */
    Dir2 = (Dir%100)/10 + '0';
    Dir3 = (Dir%100)%10 + '0';
    WriteEN(122, Dir1);
    WriteEN(123, Dir2);
    WriteEN(124, Dir3);
    
    Dir = Dir/3;                                                        /* 不满3的倍数的按3的倍数算                         */
    tempx = DirTbl[(Dir<<1)];
    tempy = DirTbl[((Dir<<1)+1)];
    LineClr(113, 70, oldtempx, oldtempy);
    Line(113, 70, tempx, tempy, 0); 
    oldtempx = tempx;
    oldtempy = tempy;
}

/******************************************************************************************************************************
**函数名称:SendAngle()                                                                                                      **
**函数功能:向串口送当前角度值                                                                                               **   
**入口参数:当前角度                                                                                                         **
**出口参数:无                                                                                                               **
**具体资源:无                                                                                                               **
**调用程序:UartSendStr(), UartSendByte()                                                                                    **
**备    注:                                                                                                                 **
******************************************************************************************************************************/
void SendAngle(unsigned int Dir)
{
    unsigned char Dir1, Dir2, Dir3;    
    unsigned char Str[] = "Current angle = 360 degree !";

    Dir1 = Dir/100 +'0';                                                /* 提取其各位                                       */
    Dir2 = (Dir%100)/10 + '0';
    Dir3 = (Dir%100)%10 + '0'; 
    
    sprintf(Str, "Current angle = %c%c%c degree !", Dir1,Dir2,Dir3);
    UartSendStr(Str);
    UartSendByte(0x0d);
    UartSendByte(0x0a); 
}

/******************************************************************************************************************************
**函数名称:外部中断0 ISR                                                                                                    **
**函数功能:获取键值                                                                                                         **   
**入口参数:无                                                                                                               **
**出口参数:无                                                                                                               **
**具体资源:无                                                                                                               **
**调用程序:无                                                                                                               **
**备    注:                                                                                                                 **
******************************************************************************************************************************/
INT0IRQ (void) interrupt 0
{
    unsigned char keytmp;
    EA = 0;
    delay(10);
    keytmp = (P1 & 0xf8);                                               /* 保留高5位                                        */
    if (keytmp == 0xf8) {                                               /* 抖动                                             */
    EA = 1;
    }else {
        switch (keytmp) {                                               /* Key1                                             */
            case 0x78 : 
                keyflag = 1;
                break;                                                  /* Key2                                             */
            case 0xb8 : break;                                          /* Key3                                             */
            case 0xd8 : break;                                          /* Key4                                             */
            case 0xe8 : break;                                          /* Key5                                             */
            case 0xf0 : break;
            default : break;
        }
    EA = 1;
    }
}



/******************************************************************************************************************************
**函数名称:定时器0 ISR                                                                                                      **
**函数功能:定时器0中断服务程序                                                                                              **   
**入口参数:无                                                                                                               **
**出口参数:无                                                                                                               **
**具体资源:无                                                                                                               **
**调用程序:无                                                                                                               **
**备    注:                                                                                                                 **
******************************************************************************************************************************/
T0IRQ (void) interrupt 1
{
    EA  = 0;
    TR0 = 0;
    T0IRQCNT++;
    TR0 = 1;
    EA  = 1;
}


/******************************************************************************************************************************
**函数名称:GetAngle()                                                                                                       **
**函数功能:获取方向角度                                                                                                     **   
**入口参数:无                                                                                                               **
**出口参数:无                                                                                                               **
**具体资源:无                                                                                                               **
**调用程序:无                                                                                                               **
**备    注:                                                                                                                 **
******************************************************************************************************************************/
void GetAngle(void)
{
    unsigned char Dir1, Dir2, Dir3;    
                                    
    Dir1 = COMBUF[0] - '0';
    if (Dir1 > 3) {
        
    }else {
        Dir2 = COMBUF[1] - '0';
        Dir3 = COMBUF[2] - '0'; 
        Angle = Dir1 * 100 + Dir2 * 10 + Dir3;
    }
}


/******************************************************************************************************************************
**函数名称:主测试函数                                                                                                       **
**函数功能:                                                                                                                 **   
**入口参数:无                                                                                                               **
**出口参数:无                                                                                                               **
**具体资源:无                                                                                                               **
**调用程序:无                                                                                                               **
**备    注:                                                                                                                 **
******************************************************************************************************************************/

void main(void)
{
    InitScreen();
    
    InitCOM();
    DisMain();
    EX0 = 1;                                                            /* 外部中断0开                                      */
    IT0 = 1;                                                            /* 外部中断0为边沿触发                              */

    DisCurDate(0, 15);                                                  /* 显示系统日期                                     */
    Angle = 1;
    while(1)
	{
        GetAngle();
        if (T0IRQCNT == 5) {
            DisCurDirc(Angle);
        }
        DisCurTime(11, 15);                                             /* 显示系统时间                                     */	                       
        switch (keyflag) {
            case 1 : 
                SendAngle(Angle);
                keyflag = 0;
                break;
            default : break;
        }                                               
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -