基本信息
源码名称:单片机控制绕线机.c
源码大小:6.48KB
文件格式:.c
开发语言:C/C++
更新时间:2020-12-26
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
利用STC89C52控制绕线机,可以正转、反转并显示绕线的圈数
绕线机数码管记录圈数.c

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


#include <reg51.h>
#include <intrins.h>

#define uchar unsigned char  
    unsigned char table1[]={0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F};        //1-8的字模
    unsigned char table2[]={0x7F,0xbF,0xdF,0xeF,0xf7,0xFb,0xFd,0xFe};          //选通码  
    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() //减小当前计数器显示的数字
    {
      if (table1[7]== 0x3f)
         {
            table1[7]=0x6f;
            if (table1[6]== 0x3f)
               {
                  table1[6]=0x6f;
                  if (table1[5]== 0x3f)
                     {
                        table1[5]=0x6f;                                                  
                        if (table1[4]== 0x3f)
                           {
                              table1[4]=0x6f;
                            }
                         else
                            {
                               previous(4);
                             }
                       }
                   else
                      {
                         previous(5);
                       }
                  }
              else
                 {
                    previous(6);
                  } 
           }
       else
          {
               previous(7);
           }
     }

void  Adjust() //设定匝数时调整对应位的字模
    {
       if (thousand_up==0)
          {
             //while(!thousand_up); //等待按键松开
             next(0);
           }
       if (hundred_up==0)
          {
             //while(!hundred_up);           //等待按键松开
             next(1);
           }
       if (decade_up==0)
          {
             //while(!decade_up);           //等待按键松开
             next(2);
           }
       if (unit_up==0)
          {
             //while(!unit_up);           //等待按键松开
             next(3);
           }          
       if (thousand_down==0)
          {
             //while(!thousand_up);           //等待按键松开
             previous(0);
           }
       if (hundred_down==0)
          {
             //while(!thousand_up);           //等待按键松开
             previous(1);
           }
       if (decade_down==0)
          {
             //while(!thousand_up);           //等待按键松开
             previous(2);
           }
       if (unit_down==0)
          {
             //while(!thousand_up);           //等待按键松开
             previous(3);
           }
     }
 
void inrpt() interrupt 0        //中断处理,根据转向计数
    {
      if (forward==1)            
          {