• 大小: 6.48KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2024-04-14
  • 语言: C/C++
  • 标签: 控制  

资源简介

利用STC89C52控制绕线机,可以正转、反转并显示绕线的圈数

资源截图

代码片段和文件信息



// 2016-7-15

//======================用int0中断处理计数,每中断一次,根据转动方向增加或减少显示实际匝数1匝=================


// *********** 驱动8位数码管 ************* 

#include 
#include 

#define uchar unsigned char  
    unsigned char table1[]={0x3F0x3F0x3F0x3F0x3F0x3F0x3F0x3F};        //1-8的字模
    unsigned char table2[]={0x7F0xbF0xdF0xeF0xf70xFb0xFd0xFe};          //选通码  
    unsigned char table[]={0x3F 0x06 0x5B 0x4F 0x66 0x6D 0x7D 0x07 0x7F 0x6F};   //0-9的字模       
    sbit  start=P3^0;
    sbit  forward=P3^1;
    sbit  back=P3^1;
    sbit  thousand_up=P1^0;
    sbit  hundred_up=P1^1;
    sbit  decade_up=P1^2;
    sbit  unit_up=P1^3;
    sbit  thousand_down=P1^4;
    sbit  hundred_down=P1^5;
    sbit  decade_down=P1^6;
    sbit  unit_down=P1^7;
    sbit  beep=P3^7;
    

void delay(unsigned int i)  //延时程序
    {
       unsigned int j;
       unsigned char k;
       for(j=i;j>0;j--)
          for(k=125;k>0;k--);
    }

void previous(unsigned int i) //把当前数的字模调整为比它小1的数的字模
   {
     unsigned int j;
     for(j=0;j<10;j++)
        {
          if(table[j]==table1[i])
             {
                if(j==0)
                   {
                       table1[i]=0x6f;
                    }
                 else
                    {
                       table1[i]=table[j-1];
                     }
                 return ;                                                                   
               }
          }
     }
          
void next(unsigned int i)       //把当前数的字模调整为比它大1的数的字模
    {
      unsigned int j;
      for(j=0;j<10;j++)
         {
           if (table[j]==table1[i])
              {
                 if(j==9)
                    {
                       table1[i]=0x3f;
                     }
                 else
                    {
                       table1[i]=table[j+1];
                     }
                 return ;                                                        
               }
          }
    }

void  real_num_up(          )   //增加当前计数器显示的数字
   {
     if (table1[7]== 0x6f)
        {
           table1[7]=0x3f;
           if (table1[6]== 0x6f)
              {
                 table1[6]=0x3f;
                 if (table1[5]== 0x6f)
                    {
                       table1[5]=0x3f;
                       if (table1[4]== 0x6f)
                          {
                             table1[4]=0x3f;
                           }
                       else
                          {
                             next(4);
                           }
                     }
                  else
                    {
                       next(5);
                     }
               }
            else
              {
                  next(6);
               }
         }
      else
         {
            next(7);
          }
     }

 void  real_num_down()  //减小当前计数器显示的数字
    {
  

评论

共有 条评论