' CCARC.Bas - Carroll County Fest, Oct 25, '09
'
' PICAXE-20X2
'
' Peter H Anderson, Oct 24, '09

  Symbol N = B1
  Symbol ADval = W10 ' B2 & B3
  Symbol Sum = W11
  Symbol Tc_10 = W12
  Symbol Whole = B2
  Symbol Fract = B3
  Symbol J = B4

  DirsB = %11111111
  ADCSetup = %0000000000001000 ' ADC3
  HSerSetup B9600_8, %00

  HSerOut 0, ("?c0"); ' no cursor on LCD
  Pause 10

  Do


     HSerOut 0, ("?f")
     HSerOut 0, ("?<")  ' exit big number mode
     Pause 100

     ' display some stuff
     HSerOut 0, ("Serial LCD 117 9600")
     Pause 10
     HSerOut 0, ("  CCARC - Hamfest?n");
     Pause 10
     HSerOut 0, ("    Oct 25, '09");
     Pause 10
     HSerOut 0, ("?y3?x00 Westminster, MD");

     ' flash LED demo
     For N = 1 to 5
        High B.0
        Pause 250
        Low B.0
        Pause 250
     Next


     Pause 2000
     'tune demo
     Tune 7, 5, ($00,$05,$05,$47,$49,$05,$05,$47,$49,$10,$10,$12,$CA,$47,$49,$0A,$0A,$10,$09,$09,$45,$49,$07)
     ',$02,$05,$C4,$00,$05,$05,$47,$49,$05,$05,$49,$4A,$10,$10,$12,$CA,$47,$49,$0A,$0A,$10,$09,$09,$45,$49,$07,
     ' $02,$04,$C5)


     For J = 1 to 10			' meas and display temperature Tc - MCP9701A

        GoSub ADConv
        GoSub CalcTcelcius

        Whole = Tc_10 / 10		' Tc whole
        Fract = Tc_10 % 10		' Tc tenths of a degree
        HSerOut 0, ("?y2?l?x05")
        HSerOut 0,  ("Tc = ", #Whole, ".", #Fract, "?n")

        Pause 200
     Next

     For J = 1 to 5

        GoSub ADConv
        GoSub CalcTcelcius

        HSerOut 0, ("?f")
        HSerOut 0, ("?x02?>4")

        Whole = Tc_10 / 10		' Tc whole
        Fract = Tc_10 % 10		' Tc tenths of a degree

        HSerOut 0,  (#Whole, ".", #Fract)

        Pause 1000
     Next
     HSerOut 0, ("?<")

   Loop

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