' SelmaWare.Bas   (PICAXE-20X2)
'
' Illustrates some of the basic capabilities of Selmaware Stamp Plot
' data plotting utility.  http://www.stampplot.com
'
' Continually reads temperature using a Microchip MCP9701A and sends 
' the temperature in degrees C on SerOut to the PC.
'
' I configured Selmaware for the "no-frills Plot".
'
' Once you have completely debugged your application, close out the PICAXE 
' terminal to release the COM port for use by the Stamp Plot software.
'
' Configure Selmaware for the appropriate port, 9600 baud.  Connect.
'
' Then reboot the PICAXE by momentarily removing power.
'
' Although I used the 20X2, much the same could have been done with the -18X or 
' even the -08M.  The one diference is the baud rate of the SerTxd.  It is 9600
' for the PICAXE-20X2 and 4800 for the -18X and -08M.
'
'
'  MCP9701			PICAXE-20X2
'
'   Out (2) ------------ ADC3 (term 3)
'
'
' copyright, Peter H Anderson, Baltimore, MD, Nov 1, '09

  Symbol N = B1
  Symbol ADval = W10 
  Symbol Sum = W11
  Symbol Tc_10 = W12
  Symbol Whole = B2
  Symbol Fract = B3
  

  DirsB = %11111111
  ADCSetup = %0000000000001000 ' ADC3
  

  Pause 5000

			     ' Send setup commands to Selmaware plot package
                       ' Note that I have only scratched the surface in 
                       ' working with this powerful package.
  
  SerTxD ("!NEWP", CR, LF)	     ' New Plot
  SerTxD ("!SPAN 20,30", CR, LF)   ' Analog range 20- 40
  SerTxD ("!TMAX 600", CR, LF)     ' 10 minute's worth of data
  SerTxD ("!PNTS 5000", CR, LF)   
  SerTxD ("!FAMT 25", CR, LF)     
  SerTxD ("!FLSH ON", CR, LF)     

  SerTxD ("!SAMT 25", CR, LF)      
  SerTxD ("!SHFT ON", CR, LF)     
  SerTxD ("!PLOT ON", CR, LF) 	
  
  Do
    
     Gosub MeasTemperature
     Gosub DisplayTemperature
               
     Pause 1000
     
  Loop
   
MeasTemperature:

     GoSub ADConv
     GoSub CalcTcelcius
     Return
       
DisplayTemperature:

       Whole = Tc_10 / 10		' Tc whole
       Fract = Tc_10 % 10		' Tc tenths of a degree
       SerTxD (#Whole, ".", #Fract, CR, LF)
       Return

ADConv:

   Sum = 0
   For N = 1 to 64			' sum 64 readings
      ReadADC10 3, ADVal
      Sum = Sum + ADVal
   Next

   ADVal = Sum / 64			' calculate the average

   Return

CalcTcelcius:

   Tc_10 = ADVal / 2			' 2.5 * ADVal - 205
   Tc_10 = 2 * ADVal + Tc_10
   Tc_10 = Tc_10 - 205
   Return