原创 PR380D客户端示范板_软件篇

2010-9-30 16:51 1277 1 1 分类: MCU/ 嵌入式

 


 87708796-cdb2-483b-8537-9382f9d087ed.jpg


 


     在实际的系统集成时,不同的MCU可能会被主控制板选用,但采用C进行编程已经较普遍,这里提供的参考程序对设计师来说是有参考价值的。


  1)参考软件运行环境:       Atmel_AVR_ ATmega48;


  2)开发环境:                   AVR Studio 4;


  3)编译器:                       WinAVR_20071221


  主框架如下:


//---------------  MAIN  process   -----------------
int main( void )
{
  initial_pro();
  while( 1 )
    {
      option_reload_pro();

      if( !bit_is_clear( TIFR0,OCF0A) ) // time_base: 1ms
        {
          TIFR0 |= (1 << OCF0A );

          T_BASE0_R.BYTE ++;
          if( T_BASE0_R.BYTE == 0 ) T_BASE1_R.BYTE ++;

          lem_drive_pro();
          communicate_in_pro();
                                                                                         // loop_time_base: 4ms
          switch( T_BASE0_R.BYTE & 0X03 )
            {
              case 0: time_base_pro();
                            break;

              case 1: key_pro();
                            break;

              case 2: display_pro();
                            break;

               case 3:
               default:
                             break;
            }
        }
    }
  } 


 


  客户端示范板通过communicate_in_pro();接收来自PR380D的电源系统数据,并在四位数码管上显示出来,通过按键来选择要显示的电源数据。


 


//---------------  communicate_in_pro / 数据通讯_接收   -----------------
void communicate_in_pro( void )
{
  uchar Buff;

  if( I_COMMUNICATE_PORT & (1<<I_COMMUNICATE_B ))
    {
      if( COM_IN_ONE_R != 0XFF )
        COM_IN_ONE_R ++;

      F_IN_LAST_B = 1;
    }
  else
    {
      if( F_IN_LAST_B )
        {                                                                                                // COM bit process
          if( COM_IN_ONE_R >= 100 )
            {
              COM_IN_CNT_R = 0 ; // start new receive
              COM_IN_BUFF_R.FULL = 0;
            }
          else
            {                                                                                               // new bit
              COM_IN_BUFF_R.FULL <<= 1;                                               // ROL@AVR = RLF@PIC
              if( COM_IN_ZERO_R < COM_IN_ONE_R )                               // just like in IAR for easy migarate
                COM_IN_BUFF_R.BYTE.BYTE_3 |= 0B00000001;

              if( COM_IN_CNT_R != 0XFF )
                COM_IN_CNT_R ++;
                                                                                                            // one frame over
              if( COM_IN_CNT_R == COM_DATA_SIZE_D )
                {
                  if(   (( COM_IN_BUFF_R.BYTE.BYTE_3^COM_IN_BUFF_R.BYTE.BYTE_2 ) == 0XFF )
                    &&(( COM_IN_BUFF_R.BYTE.BYTE_1^COM_IN_BUFF_R.BYTE.BYTE_0 ) == 0XFF ) )
                    {
                      Buff = COM_IN_BUFF_R.BYTE.BYTE_1;

                      if( Buff & 0b10000000 )    fSystem = 1;
                      else                                  fSystem = 0;

                      Buff >>= 2;
                      Buff &= 0x7;

                      DataBuffH[ Buff ] = COM_IN_BUFF_R.BYTE.BYTE_1;
                      DataBuffL[ Buff ] = COM_IN_BUFF_R.BYTE.BYTE_3;

                      COM_INVALIDE_CNT_R = 0;
                    }
                 else
                   {
                     if( COM_INVALIDE_CNT_R != 0XFF )
                       COM_INVALIDE_CNT_R++;
                   }
               }
           }

        COM_IN_ZERO_R = 0;
        COM_IN_ONE_R = 0;
      }

    if( COM_IN_ZERO_R != 0XFF )
      COM_IN_ZERO_R ++;

    F_IN_LAST_B = 0;
  }
}


 


 

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
1
关闭 站长推荐上一条 /3 下一条