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

📄 nbt_main.c

📁 tiMSP430F147体能监测设备源码
💻 C
📖 第 1 页 / 共 2 页
字号:
//--------------------------------------------------------------------------------------------------
//     _   _  ____  _____     __  __     _     ___  _   _
//    | \ | || __ )|_   _|   |  \/  |   / \   |_ _|| \ | |
//    |  \| ||  _ \  | |     | |\/| |  / _ \   | | |  \| |
//    | |\  || |_) | | |     | |  | | / ___ \  | | | |\  |
//    |_| \_||____/  |_|_____|_|  |_|/_/   \_\|___||_| \_|
//                     |_____|
//
// (c) 2003, 2004 Altium
// Started: 06.11.2003 Ch.Weimann
// Production Functional Tester for the Altium Nanoboard
// It assumes that all cables and the RTC adapter PCB are present and a second Nanoboard
// is connected running the Memory Tester application for CAN bus echo testing
// 06.01.2004: Ch.W. V0.90 sped up Ok messages and Knight rider display
// 13.01.2004: Ch.W. V0.91 added #defines for various timings
// 16.01.2004: Ch.W. V0.92 added PS2 keyboard read interrupt service routine
// 27.01.2004: Ch.W. V0.93 fixed bug in LCD_GotoXY, enhanced LCD functionality, added bargraph code
//--------------------------------------------------------------------------------------------------

#include <regtsk51a.sfr>

#include "hware.h"
#include "uart.h"
#include "nbt_kbd.h"
#include "nbt_timer.h"
#include "nbt_lcd.h"
#include "nbt_i2c.h"
#include "nbt_adda.h"
#include "nbt_spi.h"
#include "nbt_ps2.h"
#include "nbt_rtc.h"
#include "nbt_bargraph.h"
#include <stdio.h>

#define REVISION 0x0093

#define VOLUME 100           // internal buzzer volume for operational sounds
#define STATUS_VOLUME 250    // internal buzzer volume for success/failure sounds

#define ERRORBEEP_ACTIVE     // activates that annoying error beep

#define OK_SHOWTIME 400      // display time for -OK- message in ms

#define print printf         // use Tasking library function for character output

const unsigned int TestVoltages[] = {250,500,750,1000,0};   // voltages DA/AD for loopback test [2mV/bit]

static unsigned int ErrorCount;   // tallies the number of errors

static volatile unsigned char c = 0x55;  // for debugging

// ----------------------------------------------------------
// Does the 'Knightrider Thing' with the LEDs on the NanoBoard
// ----------------------------------------------------------
void KnightRider(unsigned int OnTimeMs, unsigned char count)
{
  __bit direction = 0;
  register unsigned char pattern = 1;
  Nanoboard_TestModeOn(pattern);     // select spartan 100 mode for spi access to LEDs
  while(count--)
  {
    LED_PORT = pattern;              // set LED[0..7] to pattern
    Nanoboard_TestModeOn(pattern);   // set SL[1..8] to pattern
    DelayMs(OnTimeMs);
    if(0 == direction)  // move right
    {
       pattern <<= 1;
       if(0==pattern)
       {
          direction = 1;
          pattern = 0x40;
       }
    }
    else                // move left
    {
       pattern >>= 1;
       if(0==pattern)
       {
          direction = 0;
          pattern = 0x02;
       }
    }
  }
  LED_PORT = 0;               // turn all LEDs off when exiting
  Nanoboard_TestModeOn(0);    // same for status leds
}

//-----------------------------------------------------------
// Prints status message and plays with LEDs
//-----------------------------------------------------------
void Hello(void)
{
  register unsigned char i;
  __bit line = 0;
  LCD_ClrScr();
  LCD_BACKLIGHT = 1;
  LCD_ClrScr();
  print(__DATE__);
  LCD_GotoXY(0,1);
  print(__TIME__);
  DelayMs(500);
  LCD_ClrScr();
  print("NANOBOARD TESTER");
  LCD_GotoXY(0,1);
  print(" (c)2004 ALTIUM ");
  LCD_BACKLIGHT = 1;
  DelayMs(300);
  LCD_GotoXY(0,1);
  print("VERSION %X.%X    ",REVISION>>8,REVISION&0xFF);
  DelayMs(500);
  for(i=0; i<255; i++)
  {
    if(0==(i & 0x0F))
    {
      LCD_GotoXY(0,line);
      line ^=1;
      if(line)
      {
        KnightRider(30,15);
      }
    }
    LCD_WriteChar(i);
  }
  LCD_ClrScr();
  DelayMs(200);
}

//-------------------------------------------------------------
// gets called by print
//-------------------------------------------------------------
void putch(unsigned char c)
{
  LCD_WriteChar(c);
}

//-------------------------------------------------------------------------
// Beeps the internal squawker
// Volume [0..255], 0 = off, 255 = loudest
// Pitch: smaller number = higher pitch
// Duration: number of cycles
//-------------------------------------------------------------------------
void Beep(unsigned char Volume, unsigned char Pitch, unsigned int Duration)
{
  Timer[TIMER_BEEP] = Duration;
  __bit OnOff = 0;
  __bit OldEA = EA;
  EA = 0;
  while(Duration--)
  {
    volatile unsigned char d;
    SPK_PORT = OnOff ? Volume : 0;
    OnOff = OnOff ? 0 : 1;
    for(d=0;d<Pitch;d++);
    {
       __asm( "NOP\n\t");
    }
  }
  EA = OldEA;
}

//------------------------------------------------------------------------------------
// Outputs walking pattern of ones on user Header A and reads it back on user Header B
// returns     0 : OK
//         non-0 : bit at which error occurred
//------------------------------------------------------------------------------------
unsigned char TestUserIO(void)
{
  unsigned long OutValue = 0x01L;
  unsigned long InValue  = 0;
  unsigned char bit = 1;
  do
  {
    OutValue &= 0x0003FFFFL;  // only 18 significant bits
    U1H0_PORT = OutValue  & 0xFF;
    U1H1_PORT = (OutValue >> 8 ) & 0xFF;
    U1H2_PORT = (OutValue >> 16) & 0xFF;
    DelayMs(1);
    InValue   = U1H2_PORT & 0x03;
    InValue <<= 8;
    InValue  |= U1H1_PORT;
    InValue <<= 8;
    InValue  |= U1H0_PORT;
    if(InValue != OutValue)
      return(bit);
    OutValue<<=1;
    bit++;
    DelayMs(10);
  }
  while (0 != OutValue);
  return 0;
}

//--------------------------------------------------------------------------------
// Plays with LEDs on Keyboards attached to PS2 ports
// returns: 0 = OK
//          Bit 0 set: error on PORT0  (KB)
//          Bit 1 set: error on PORT1  (MOUSE)
//--------------------------------------------------------------------------------
unsigned char TestPS2(void)
{
  unsigned char retval = 0;
  static unsigned char pattern = 1;
  pattern >>= 1;
  if(pattern == 0) pattern = 4;
  if(PS2_SetLEDs(0,pattern))
    retval |=1;
  if(PS2_SetLEDs(1,pattern ^ 0x07))
    retval |=2;
  return (retval);
}


//-----------------------------------------------------------------
// Tests Master-Slave IO pins
// Assumes that Master I/O and Slave I/O ports are connected via
// 10-way ribbon cable
// Outputs walking pattern of 1 and verifies input of same pattern
// Leaves port with all bits set to 0
// returns: 0     : success
//          non-0 : bit pattern at error point: High Nibble: Output Pattern
//                                              Low Nibble:  Input Pattern
//-----------------------------------------------------------------
unsigned char TestMasterSlaveIO(void)
{
  register unsigned char TestPattern = 1;
  register unsigned char c;
  do
  {
    MASTERIO_PORT = TestPattern;   // output test pattern
    __asm( "NOP\n\t");             // give it some time to stabilise
    c =  MASTERIO_PORT & 0x0F;
    if(TestPattern !=  c)
    {
      MASTERIO_PORT = 0;
      return TestPattern | (c<<4);
    }
    TestPattern <<= 1;            // next test pattern
    TestPattern &= 0x0F;
  } while(0 != TestPattern);
  MASTERIO_PORT = 0;
  return 0;
}

//-------------------------------------------------------------------------
// Beeps and asks for keypress if 'code' is non-0
// prints OK for 1s and exits if 'code is 0
// increases global variable 'ErrorCount' if 'code' is non-0
//-------------------------------------------------------------------------
void ErrorBeep(unsigned int code)
{
  LCD_GotoXY(0,1);
  if(0 == code)
  {
    print(" - OK -         ");
//    print(" - OK -    %d   ",ErrorCount);      // DEBUG only
    DelayMs(OK_SHOWTIME);
  }
  else
  {
    ErrorCount++;
    print("FAILED: %04X    ",code);
    while(KbHit) GetKey(KEY_FORMAT_ASCII);
    while(!(KbHit))
    {
#ifdef ERRORBEEP_ACTIVE
      Beep(STATUS_VOLUME,100,40);
      DelayMs(200);
#endif
    }
    while(KbHit) GetKey(KEY_FORMAT_ASCII);
  }
  LCD_ClrScr();
}

//---------------------------------------------------------------------------
// Outputs a characteristic beep for each key
//---------------------------------------------------------------------------
inline void KeyBeep(void)
{
  Beep(VOLUME, 0xFF - (150 + LastKey * 4), 100);
}


//-------------------------------------------------------------------------
// makes sure every key on keypad was pressed individually
// Test/Reset key aborts test, exept when prompted
// returns 0: success 1: aborted
//----------------------------------------------------------
unsigned char TestKeypad(void)
{
  register unsigned char c,i;
  __bit abort;
  unsigned char Keys[]="123C456D789EA0BF";
  LCD_ClrScr();
  print("Press All Keys");
  while(KbHit)GetKey(0); // Clear all pending keypresses
  do
  {
    abort = 1;
    LCD_GotoXY(0,1);
    for(i=0;i<sizeof(Keys)-1;i++)
    {
      c=Keys[i];
      if(c != ' ') abort = 0;  // still more to go?
      LCD_WriteChar(c);
    }
    if(KbHit)
    {
      c  = GetKey(KEY_FORMAT_ASCII);
      KeyBeep();
      if('T' == c)       // abort if Test/Reset Key was pressed prematurely
      { LCD_ClrScr();
        print("Keyboard Test");
        return 1;
      }
      for(i=0;i<sizeof(Keys);i++)
      {
        if (Keys[i] == c)
          Keys[i] = ' ';
      }
    }
  }
  while(!abort);
  LCD_ClrScr();
  print("Press TEST/RESET");
  LCD_GotoXY(0,1);
  print("Key to continue");
  c = 0;
  do
  {
    if(KbHit)
    {
      c  = GetKey(KEY_FORMAT_ASCII);
      KeyBeep();
    }
  } while(c != 'T');
  return 0;
}


//----------------------------------------------------------
// Makes sure every dip switch is activated individually
// Test/Reset key aborts test
// returns 0: success 1: aborted
//----------------------------------------------------------
unsigned char TestDipSwitches(void)
{
  __bit finished;
  register unsigned char c,i, jumpers = 0;
  unsigned char patterns[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
  LCD_ClrScr();
  print("  DIP-Switches");
  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;

⌨️ 快捷键说明

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