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

📄 nbt_main.c

📁 tiMSP430F147体能监测设备源码
💻 C
📖 第 1 页 / 共 2 页
字号:
      };
    }
    LCD_GotoXY(0,1);
    print("    ");
    finished = 1;
    for(i=0; i<8; i++)
    {
      if(0 == patterns[i])
      {
        LCD_WriteChar(0xFF);
      }
      else
      {
        LCD_WriteChar(0x30+i+1);
        finished = 0;
      }
    }
    c = ~DIP_PORT;
    LED_PORT = c;                                  // mirror DIP-switches on LEDs
    jumpers =  Nanoboard_TestModeOn(~jumpers);     // mirror Jumpers on SL LEDs
    for(i=0; i<8; i++)
    {
      if (c == patterns[i])
      {
        if(patterns[i] != 0)  // new valid pattern?
        {
          patterns[i] = 0;    // mark in pattern array as done
          Beep(VOLUME,100,20);
        }
      }
    }
    DelayMs(10);
  } while (finished == 0);
  return 0;
}

//-----------------------------------------------------------------
// Makes sure every configuration jumper is activated individually
// Test/Reset key aborts test
// returns 0: success 1: aborted
//-----------------------------------------------------------------
unsigned char TestJumpers(void)
{
  __bit finished;
  register unsigned char i, jumpers = 0;
  unsigned char patterns[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
  LCD_ClrScr();
  print(" Config Jumpers ");
  while(KbHit) GetKey(0);      // clear Keyboard buffer
  do
  {
    if(KbHit)                  // abort if Test/Reset key was pressed
    {
      if('T'==GetKey(KEY_FORMAT_ASCII))
      {
        return 1;
      };
    }
    LCD_GotoXY(0,1);
    print("    ");
    finished = 1;
    for(i=0; i<8; i++)
    {
      if(0 == patterns[i])
      {
        LCD_WriteChar(0xFF);
      }
      else
      {
        LCD_WriteChar(0x30+i+1);
        finished = 0;
      }
    }
    LED_PORT = ~DIP_PORT;                          // mirror DIP-switches on LEDs
    jumpers =  ~Nanoboard_TestModeOn(jumpers);     // mirror Jumpers on SL LEDs
    for(i=0; i<8; i++)
    {
      if (jumpers == patterns[i])
      {
        if(patterns[i] != 0)  // new valid pattern?
        {
          patterns[i] = 0;    // mark in pattern array as done
          Beep(VOLUME,100,20);
        }
      }
    }
    DelayMs(10);
  } while (finished == 0);
  return 0;
}

//--------------------------------------------------------------
// Tests CAN bus
// sends out 'TestCharacter'
// monitors own echo
// TestCharacter is XORed with 'MagicMask (0xAA) and sent back
// by a second Nanoboard
//
// returns: 0 : success
//          1 : no local echo received
//          2 : local echo scrambled
//          3 : response timeout
//          4 : response scrambled
//--------------------------------------------------------------
unsigned char TestCAN(unsigned char TestCharacter)
{
  unsigned char MagicMask = 0xAA;
  unsigned char InChar;
  UART_Select(SER_SEL_CAN);    // select multiplexer to CAN bus
  RI = 0;                      // clear RI flag to empty any pending characters
  UART_TxChar_Poll(TestCharacter);  // send out Test Character
  DelayMs(1);                  // wait for local echo to be clocked in
  if(0==RI)
    return 1;          // make sure echo is received
  if(SBUF != TestCharacter)
    return 2;          // make sure the right character is echoed
  RI = 0;
  DelayMs(100);                // wait for echo
  if(0== RI)
    return 3;                  // nothing at all came back
  InChar = SBUF;               // read character
  RI = 0;                      // clear flag
  InChar ^=MagicMask;          // unscramble
  if(InChar != TestCharacter)  // wrong character?
    return 4;
  return 0;                    // if we get to here everything has worked as expected
}

//---------------------------------------------------------------
// Uses RTC to time 1s to measure Variable system clock [kHz]
// assumes that Philips PCF8583 is connected to external I2C bus
// programs RTC to all 0s, then polls for 1 s elapsed at 100th second resolution
// This is not terribly accurate, but ensures we can detect if
// the wrong crystal is fitted
// Verifies that the NanoBoard on-board oscillator crystal frequency is
// 'TargetFrequency' +- 'Tolerance' [KHz]
// returns     0: success
//         non-0: absolute of deviation from TargetFrequency
//---------------------------------------------------------------
unsigned int MeasureClockFrequency(unsigned int TargetFrequency, unsigned int Tolerance)
{
  unsigned int retval;
  FREQMODE_PORT = FREQ_MODE_RESET;
  FREQMODE_PORT = FREQ_MODE_COUNT;
  if( ACK != RTC_SetTimeHundredths(0L))
    return -1;  // Error: No RTC found
  while (100L > RTC_GetTimeHundredths());  // wait for 1s to elapse
  FREQMODE_PORT = FREQ_MODE_STOP;
  retval = FREQ1_PORT;      // read high byte
  retval <<=8;              // shift into position
  retval += FREQ0_PORT;     // add low byte
  FREQMODE_PORT = FREQ_MODE_AUTO;  // frequency counter to measure variable clock output again
  if(retval > TargetFrequency)     // check tolerance
    retval -= TargetFrequency;
  else
    retval = TargetFrequency - retval;
  if(retval <= Tolerance)
  {
    return 0;
  }
  return retval;
}

//---------------------------------------------------------
// this gets called by the Tasking printf function
//---------------------------------------------------------
size_t _write(int fd, char * base, size_t size)
{
   size_t i;
   for (i = 0; i < size; i++)
   {
      LCD_WriteChar(base[i]);
   }
   return size;
}


/*------------------------------------------------
MAIN C function
------------------------------------------------*/
void main (void)
{
  register unsigned char jumpers = 0;            // stores jumper configuration of NanoBoard
  register signed int temp=0;
  register unsigned int Count=0;
  unsigned long l=1;
  FREQMODE_PORT = FREQ_MODE_AUTO;  // frequency counter to measure variable clock frequency
RESTART:
  ErrorCount = 0;
  Timer0Init();
  EA = 1;                       // Global Interrupt Enable
  IT0 = 1;                      // Configure interrupt 0 for falling edge on /INT0 (P3.2)
                                // used for PS2 port clock
  EX0 = 1;                      // External Interrupt 0 Enable
  PX0 = 1;                      // assign high priority to External Interrupt 0

  Nanoboard_TestModeOn(0);      // switch Status LEDs to normal function
  SPEAKER_ENABLE = 1;
  ICS307_ProgramW(ICS307_30MHZ);  // run with a known frequency: 30MHz
  Beep(VOLUME,80,200);            // Sound 'I am awake' beep just in case everything else is dead
  Beep(VOLUME,70,200);
  UART_Init();
  PS2_Init();
  LCD_Init();          // initialise LCD
  LCD_SetCursor(0,0);  // turn cursor off
  GenerateBarGraphCustomCharacters();  // Load Custom Characters into CG ram
  c = DAC_Init();
  if(NACK==c)
  {
    print("NO DAC COMMS");
    DelayMs(1000);
  };
  ErrorCount = 0;
  Hello();
  print("ADC Init");
  ErrorBeep(ADC_Init());
  print("ADC Config");
  ErrorBeep(ADC_Config(0));
  print("On-Board FLASH");
  ErrorBeep(TestM25P40Signature());
  print("Clock Generator");
  ErrorBeep(TestICS307());
  ErrorBeep(TestKeypad());
  ErrorBeep(TestDipSwitches());
  ErrorBeep(TestJumpers());
  print("PS2 Ports");
  ErrorBeep(TestPS2());
  print("RS-232 TXD->RXD");
  UART_Select(SER_SEL_RXDTXD);
  ErrorBeep(TestSerial(0x5A, 0x5F));
  print("RS-232 RTS->CTS");
  UART_Select(SER_SEL_RTSCTS);
  ErrorBeep(TestSerial(0x5A, 0x5F));
  print("User IO");
  ErrorBeep(TestUserIO());
  print("Master-Slave I/O");
  ErrorBeep(TestMasterSlaveIO());
  print("Audio Codec Adj.");
  MAX1104_Adjust();
  print("CAN-BUS");
  ErrorBeep(TestCAN('*'));
  print("Crystal Osc Freq");
  ErrorBeep(MeasureClockFrequency(20000,100));
  print("ADC/DAC Test");
  ErrorBeep(DAC_ADC_Test(16,TestVoltages));
  if(ErrorCount)
  {
    print("Total Errors: %d",ErrorCount);
    Beep(STATUS_VOLUME,250,500);  // play failure sound
  }
  else
  {
    print("SUCCESS");
    Beep(STATUS_VOLUME,200,100);  // play success sound
    Beep(STATUS_VOLUME,150,100);
  }
  for (;;)  // main loop, and embedded program never ends
  {
    jumpers =  Nanoboard_TestModeOn(~jumpers);     // mirror Jumpers on SL LEDs
    LED_PORT = ~DIP_PORT;                          // mirror DIP-Switches on LEDs
    if(!Timer[TIMER_1])
    {
      __xdata unsigned int i;
      Timer[TIMER_1] = TIMER_SECONDS(0.05);
      if(KbHit)   // has anyone pressed a key?
      {
        i  = GetKey(KEY_FORMAT_ASCII);     // read it and convert to ASCII equivalent
        LCD_ClrScr();
        LCD_BACKLIGHT = 1;
        switch(i)
        {
          case 'T':         // start whole test series again
            goto RESTART;
          case '1':         // all these keys allow repeating an individual test item
            Hello();
          break;
          case '2':
            print("On-Board FLASH");
            ErrorBeep(TestM25P40Signature());
          break;
          case '3':
            print("Clock Generator");
            ErrorBeep(TestICS307());
          break;
          case 'C':
            ErrorBeep(TestKeypad());
          break;
          case '4':
            ErrorBeep(TestDipSwitches());
          break;
          case '5':
            ErrorBeep(TestJumpers());
          break;
          case '6':
            print("PS2 Ports");
            ErrorBeep(TestPS2());
          break;
          case 'D':
            print("RS-232 TXD->RXD");
            UART_Select(SER_SEL_RXDTXD);
            ErrorBeep(TestSerial(0x5A, 0x5F));
          break;
          case '7':
            print("RS-232 RTS->CTS");
            UART_Select(SER_SEL_RTSCTS);
            ErrorBeep(TestSerial(0x5A, 0x5F));
          break;
          case '8':
            print("User IO");
            ErrorBeep(TestUserIO());
          break;
          case '9':
            print("Master-Slave I/O");
            ErrorBeep(TestMasterSlaveIO());
          break;
          case 'E':
            print("Audio Codec Adj.");
            MAX1104_Adjust();
          break;
          case 'A':
            print("CAN-BUS");
            ErrorBeep(TestCAN('*'));
          break;
          case '0':
            print("Crystal Osc Freq");
            ErrorBeep(MeasureClockFrequency(20000,100));
          break;
          case 'B':
            print("ADC/DAC Test");
            ErrorBeep(DAC_ADC_Test(16,TestVoltages));
          break;
          case 'F':
            Hello();
          break;
          default:
            print("Key='%c' No=%02X",i,LastKey);
            KeyBeep();
          break;
        }
        print("T/R to Restart");
        LCD_GotoXY(0,1);
        print("Key->Indiv.Test");
      }
      c++;
      {
        static unsigned char Cnt = 5;
        if(0==Cnt--)   // play with status LEDs on attached PS2 Keyboards
        {              // every 5th time round the main loop
          Cnt = 5;
          TestPS2();                               // play with Keyboard LEDs
          LCD_BACKLIGHT = LCD_BACKLIGHT ? 0 : 1;   // play with LCD backlight
        }
      }
    }  // if
  } // for(;;)
}


⌨️ 快捷键说明

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