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

📄 q.c

📁 msp430单片机与dsp的同步通信及传输过程中的显示及编码
💻 C
📖 第 1 页 / 共 3 页
字号:
          }
    } 
               
void keyp(void) //按键处理子程序
  {
    char L1;
    if(status==10)
      { //status=10表明处于初始状态.此状态下只有选择键,上翻键,下翻键有效
        if(keybuf==0x0a) Pro_status10_20();//选择键被按下,准备设置总电流值 
        else if(keybuf==0x0e)
          {            //上翻键被按下
            if(string[5][1]!=0x20) status=60,Display(string[5]);//显示第六页
            else if(string[4][1]!=0x20) status=50,Display(string[4]);//显示第五页
            else if(string[3][1]!=0x20) status=40,Display(string[3]);//显示第四页
            else status=30,Display(string[2]);//显示第三页
            }
        else if(keybuf==0x0f)
          {          //下翻键被按下    
            status=20;
            Display(string[1]);//显示第二页
            }
        }
    else if(status==20)
      { //status=20表明处于第二页的初始状态.
        //此状态下只有选择键,上翻键,下翻键有效
        if(keybuf==0x0a) Pro_status10_20();//选择键被按下,准备设置总电流值
        else if(keybuf==0x0e)
          {           //上翻键被按下   
            status=10;
            Display(string[0]);//显示第一页
            }
        else if(keybuf==0x0f)
          {           //下翻键被按下   
            status=30;
            Display(string[2]);//显示第三页
            }
        }
    else if(status==22)
      { //status=22表明正在设置电流,此状态下只有
                 // 数字键,选择键,删除键,确认键有效
        if(((keybuf>=0x30)&&(keybuf<=0x39))||(keybuf==0x0b))
          Pro_status22();//调用函数,进行电流值设定的操作
        else if(keybuf==0x0a)
          {        //选择键被按下,光标移至电压设定值处闪烁
            status=24;//进入电压设置状态
            for(p1=string[1]+41;*p1!=0x56;p1++);
            p1--; //指针指电压值的最后一位,为电压值的输入做准备
            write_command(0x78+((p1-string[1]+1)>>1));
            //指定光标闪烁的位置.比使用指令(p1-string[1])/2少近90字个节
            write_command(0x0d);//闪烁反显
            }
        else if(keybuf==0x0c)
          {                 //按下的是确认键
            status=20;//表明在电流设置完毕,处于稳流工作模式
            Parameter[2]=0x41;//Parameter[3]=0x41表示进入稳流工作模式
            string[1][41]=0x30;//将电压设定值的缓冲区清0
            string[1][42]=0x56;
            string[1][43]=0x20;
            string[1][44]=0x20;
            string[1][45]=0x20;
            Parameter[3]=Value>>8;//计算电流指令值
            Parameter[4]=Value-(Parameter[3]<<8);
            VH=0;//将电压设定值清0
            VL=0;
            Dot=0;
            /*string[0][12]=0xce;//"稳"=0xcec8
            string[0][13]=0xc8;
            string[0][14]=0xc1;//"流"=0xc1f7
            string[0][15]=0xf7;*/
            Display(string[1]);
            SendTimes=5;//每个设定值发送五次
            }    
        }
    else if(status==24)
      { //status=24表明已进入电压设置状态.此状态下
               //只有小数点,数字键,选择键,删除键,确认键有效
        if(((keybuf>=0x2e)&&(keybuf<=0x39))||(keybuf==0x0b))
          Pro_status24();//按下的是小数点,数字键或删除键,
                         //调用函数,进行电压值设定的操作
        else if(keybuf==0x0a)//选择键被按下,光标移至电流设 
           Pro_status10_20();//定值处闪烁,准备设置总电流值 
        else if(keybuf==0x0c)
          {                 //按下的是确认键
            status=20;//电压设置完毕
            Parameter[2]=0x56;//Parameter[3]=0x56表示进入进入稳压工作模式
            string[1][9]=0x30;//将电流设定值的缓冲区清0
            string[1][10]=0x41;
            string[1][11]=0x20;
            string[1][12]=0x20;
            string[1][13]=0x20;
            string[1][14]=0x20;
            if((VH>12)||((VH==12)&&(VL>0)))//校验电压指令值的合法性 
              {    //电压指令值超过12V
                Parameter[3]=12,Parameter[4]=0,VH=12,VL=0;
                Dot=1; 
                string[1][41]=0x31;
                string[1][42]=0x32;
                string[1][43]=0x2e;
                string[1][44]=0x30;
                string[1][45]=0x56;
                }      
            if(string[1][42]==0x2e&&string[1][43]==0x56)
              {     //将x.V改为x.0V
                string[1][43]=0x30;
                string[1][44]=0x56;
                }
            else if(string[1][43]==0x2e&&string[1][44]==0x56)
              {     //将xx.V改为xx.0V
                string[1][44]=0x30;
                string[1][45]=0x56;
                }
            Parameter[3]=VH;
            if(((string[1][42]==0x2e)&&(string[1][44]==0x56))||((string[1][43]==0x2e)&&(string[1][45]==0x56)))
              {
                L1=VL<<1;//Parameter[4]=VL*10
                Parameter[4]=L1+(L1<<2);
                }
            else Parameter[4]=VL;
            Value=0;         //将电流设定值清0
            /*string[0][12]=0xce;//"稳"=0xcec8
            string[0][13]=0xc8;
            string[0][14]=0xd1;//"压"=0xd1b9
            string[0][15]=0xb9;*/
            Display(string[1]);
            SendTimes=5;//每个设定值发送五次
            }
        }
    else if(status==30)
      { //status=30表明正在显示第三页,此状态下只有上翻键,下翻键有效
        if(keybuf==0x0e)
          {           //上翻键被按下   
            status=20;
            Display(string[1]);//示第二页
            }
        else if(keybuf==0x0f)
          {          //下翻键被按下    
            if(string[3][1]==0x20) status=10,Display(string[0]);//显示第一页
            else status=40,Display(string[3]);//显示第四页
            }
        }
    else if(status==40)
      { //status=40表明正在显示第四页,此状态下只有上翻键,下翻键有效
        if(keybuf==0x0e)
          {            //上翻键被按下  
            status=30;
            Display(string[2]);//显示第三页
            }
        else if(keybuf==0x0f)
          {         //下翻键被按下
            if(string[4][1]==0x20) status=10,Display(string[0]); //显示第一页            
            else status=50,Display(string[4]);//显示第五页
            }
        }
    else if(status==50)
      { //status=50表明正在显示第五页,此状态下只有上翻键,下翻键有效
        if(keybuf==0x0e)
          {           //上翻键被按下   
            status=40;
            Display(string[3]);//显示第四页
            }
        else if(keybuf==0x0f)
          {       //下翻键被按下       
            if(string[5][1]==0x20) status=10,Display(string[0]);//显示第一页      
            else status=60,Display(string[5]);//显示第六页
            }
        }
    else if(status==60)
      { //status=50表明正在显示第六页,此状态下只有上翻键,下翻键有效
        if(keybuf==0x0e)
          {              
            status=50;//上翻键被按下
            Display(string[4]);//调用显示,显示第五页
            }
        else if(keybuf==0x0f)
          {              
            status=10;//下翻键被按下
            Display(string[0]);//调用显示,显示第一页
            }
        }
    }

void Pro_data()//接收数据的处理子程序
  {
    unsigned int L;
    int i,j;//定义计算时用到的变量
    if(NISP==1)
      {       //接收机号
        if(SendTimes&&bytes<=4) 
          {     //每个新的设定值只发送五次
            U0TXBUF=Parameter[bytes];
            if(bytes==4) SendTimes-=1;//,U0TXBUF=0x00
            }
        else U0TXBUF=0x00;//发完5轮数据后将发送缓存寄存器清0
        if(bytes&0x01)
          {     //收到奇数序号的字节 
            if((k==0xab)&&(m1==0xcd))
              {
                k=(bytes+1)/2;
                if(k>=0x0a) *p2=0x31,*(p2+1)=k+38;//0x30-10=0x26=38
                else *(p2+1)=k+0x30;
                *(p2+2)=0x3a;
                if(*(p2+4)==0x20);
                else for(i=4;i<16;i++)
                     *(p2+i)=0x20;//将过去的记录清除掉
                p2+=16;
                }
            }
        else k=m1;
        bytes+=1;
        if(bytes==32)
          {
            for(;(*(p2+1)!=0x20)&&((p2-string[2])<=255);p2+=16)
            for(i=0;i<16;i++)//将过去存在而现在已不存在的机号及其记录清除掉
            *(p2+i)=0x20;
            NISP=2,bytes=0,p2=string[2];//准备接收电流值
            }
        }
    else if(NISP==2)
      {       //接收电流值
        bytes+=1;
        if(bytes&0x01) k=m1;//收到偶数序号的字节,将电流值的高8位保存起来
        else
          {            //收到奇数序号的字节
            if(*p2==0x20) i=*(p2+1)-0x30;//计算相应的机号
            else 
              {       //机号=(*p2)*10+*(p2+1)
                i=(*p2-0x30)<<1;
                i=i+(i<<2)+*(p2+1)-0x30;
                }
            if(i!=(bytes>>1));//没有收到对应的机号则不处理收到的数
            else
              {
                k=(k<<8)+m1;//将电流值的高8位和低8位拼起来
                if(k>=4096) *(p2+3)=0x31,k-=4096;//千位
                else *(p2+3)=0x20;
                k=k<<1;//k*=10;
                k=k+(k<<2);
                L=k>>12;//L=k/4096;
                if(L) *(p2+4)=L+0x30,k-=(L<<12);//百位
                else if(*(p2+3)==0x20) *(p2+4)=0x20;
                  else *(p2+4)=0x30;
                k=k<<1;//k*=10;
                k=k+(k<<2);
                L=k>>12;//L=k/4096;
                if(L) *(p2+5)=L+0x30,k-=(L<<12);//十位
                else if(*(p2+4)==0x20) *(p2+5)=0x20;
                  else *(p2+5)=0x30;
                k=k<<1;//k*=10;
                k=k+(k<<2);
                L=k>>12;
                *(p2+6)=L+0x30; //*(p2+6)=k*10/4096+0x30;//个位
                *(p2+7)=0x41;
                p2+=16;
                }  
            if(bytes==32) NISP=3,bytes=0,p2=string[2];
            }
        }
    else if(NISP==3)
      {       //接收各台机器的运行状态
        bytes+=1;
        if(bytes&0x01);//状态只在奇数序号的字节中
        else 
          { 
            if(*p2==0x20) i=*(p2+1)-0x30;//计算相应的机号
            else 
              {
                i=(*p2-0x30)<<1;
                i=i+(i<<2)+*(p2+1)-0x30;
                }
            if(i!=(bytes>>1));//没有收到对应的机号则不处理收到的数
            else
              {
                if(m1&BIT4)
                  {
                    *(p2+3)=0x20;
                    *(p2+4)=0xc7,*(p2+5)=0xfd;//"驱"=0xc7fd
                    *(p2+6)=0xb6,*(p2+7)=0xaf;//"动"=0xb6af
                    *(p2+8)=0xb1,*(p2+9)=0xa3;//"保"=0xb1a3
                    *(p2+10)=0xbb,*(p2+11)=0xa4;//"护"=0xbba4
                    *(p2+12)=0x20,*(p2+13)=0x20;
                    }
                else if(m1&BIT3)
                  {
                    *(p2+3)=0x20;
                    *(p2+4)=0xca,*(p2+5)=0xe4;//"输"=0xcae4
                    *(p2+6)=0xb3,*(p2+7)=0xf6;//"出"=0xb3f6

⌨️ 快捷键说明

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