Programmable Systems-On-Chips
by Al Williams


Listing One
//----------------------------------------------------------------------------
// C main line
//----------------------------------------------------------------------------
#include <m8c.h>
#include "PSoCAPI.h"  

// bit of port 1 attached to LED
#define LEDMASK 0x20  
#define LOWPASS 0x100
#define HIGHPASS 0x120
#define LOWPASS2 0x7F
#define HIGHPASS2 0x99

void main()
{
    M8C_EnableGInt;  // turn on global interrupts
    InAmp_Start(InAmp_HIGHPOWER);
    ADC_Start(ADC_HIGHPOWER);
    DAC_Start(DAC_FULLPOWER);
    BaudRate_Start();
    CommPort_Start(CommPort_PARITY_NONE);
    ADC_GetSamples(0);  // get continuous samples
    while (1)
    {
       int v;
       CommPort_CPutString("Start test (space to complete)\r\n");
       DAC_WriteBlind(128);  // 2.5V output
       while (CommPort_cReadChar()==0)
       {
          while (ADC_fIsData()==0);
          v=ADC_iGetData()+2048;
          ADC_ClearFlag();
          CommPort_PutSHexInt(v);
          if (v>=LOWPASS && v<=HIGHPASS)
          {
            PRT1DR|=LEDMASK;  // turn on LED
            CommPort_PutChar('*');
          }
          else
          {
            PRT1DR&=~LEDMASK;  // turn off LED
          }
         CommPort_PutCRLF();
       }
     // phase 2
      if (v<LOWPASS || v>HIGHPASS)
        CommPort_CPutString("Warning! Device not calibrated\r\n");
      DAC_WriteBlind(64);
      CommPort_CPutString("Testing...\r\n");
      while (ADC_fIsData()==0); // get one sample
      ADC_ClearFlag(); // throw it away
      while (ADC_fIsData()==0);  // get another
      v=ADC_iGetData()+2048;
//  pass/fail logic
     if (v>=LOWPASS2 && v<=HIGHPASS2)
        CommPort_CPutString("Passed");
      else
        {
        CommPort_CPutString("Failed ");
        CommPort_PutSHexInt(v);
        }
      CommPort_CPutString("\r\nPress any key to continue\r\n");
      while (CommPort_cReadChar()==0);
     } 
}





1


