Interfacing with MAX6674 / MAX6675 K_Thermocouple to Digital Converter - 18X

copyright, Peter H Anderson, Baltimore, MD, Jan, '04


Discussion

In preparation.


' MAX6674_1.Bas - PICAXE 18X
'
' PICAXE 18X                  MAX6674 / 6675
' CS (term 10) ------------ /CS (term 6)
' SCK (term 11) ----------- SCK (term 5)
' MISO (term 18) <------- SO (term 7)
'
' Uses 179 of 2048 bytes
'
' copyright, Peter H Anderson, Baltimore, MD, Jan , '04


Symbol  CS = Output4	' define terminal associated with MAX6674 / 6675
Symbol  SCK = OutPut5
Symbol  MISO = Input1

Symbol Val = W0
Symbol WholePart = W1
Symbol FractPart = B4
Symbol Dig = B5

Symbol N = B6

TOP:
     GoSub MeasTemp
     GoSub DisplayTemp
     Wait 1
     Goto TOP

MeasTemp:
     High CS	' idle
     Low SCK

     Low CS	' start transmission sequence

     Val = 0
     For N = 1 to 16
        High SCK
        Val = Val * 2 + MISO
        Low SCK
     Next

     High CS	' terminate the transmission

     Val = Val / 32	' use only the 11 most sig bits
     Return

DisplayTemp:

     WholePart = Val / 8
     FractPart = Val & $0007	' three least significant bits - fraction


     If WholePart > 99 Then DisplayTemp_3	' Three places
     ' else				        ' Two or One places
     SerTxD (#WholePart)

Fract:
     SerTxD (".")
     Branch FractPart, (Fract0, Fract1, Fract2, Fract3, Fract4, Fract5, Fract6, Fract7)

Fract0:
     SerTxD ("00", 13, 10)
     Return

Fract1:
     SerTxD ("12", 13, 10)
     Return

Fract2:
     SerTxD ("25", 13, 10)
     Return

Fract3:
     SerTxD ("37", 13, 10)
     Return

Fract4:
     SerTxD ("50", 13, 10)
     Return

Fract5:
     SerTxD ("62", 13, 10)
     Return

Fract6:
     SerTxD ("75", 13, 10)
     Return

Fract7:
     SerTxD ("87", 13, 10)
     Return


DisplayTemp_3:
       Dig = WholePart / 100	' hundreds
       SerTxD (#Dig)
       WholePart = WholePart % 100

       Dig = WholePart / 10	' tens
       SerTxD (#Dig)
       WholePart = WholePart % 10

       Dig = WholePart 		' units
       SerTxD (#Dig)

       Goto Fract


' MAX6675_1.Bas - PICAXE 18X
'
' PICAXE 18X                  MAX6674 / 6675
' CS (term 10) ------------ /CS (term 6)
' SCK (term 11) ----------- SCK (term 5)
' MISO (term 18) <------- SO (term 7)
'
' Uses 155 of 2048 bytes
'
' copyright, Peter H Anderson, Baltimore, MD, Jan , '04


Symbol  CS = Output4	' define terminal associated with MAX6674 / 6675
Symbol  SCK = OutPut5
Symbol  MISO = Input1

Symbol Val = W0
Symbol WholePart = W1
Symbol FractPart = B4
Symbol Dig = B5

Symbol N = B6

TOP:
     GoSub MeasTemp
     GoSub DisplayTemp
     Wait 1
     Goto TOP

MeasTemp:
     High CS	' idle
     Low SCK

     Low CS	' start transmission sequence

     Val = 0
     For N = 1 to 16
        High SCK
        Val = Val * 2 + MISO
        Low SCK
     Next

     High CS	' terminate the transmission

     Val = Val / 8	' use only the 13 most sig bits
     Return

DisplayTemp:

     WholePart = Val / 4
     FractPart = Val & $0003	' two least significant bits


     If WholePart > 999 Then DisplayTemp_4	' Four places
     If WholePart > 99 Then DisplayTemp_3	' Three places
     ' else				        ' Two or One places
     SerTxD (#WholePart)

Fract:
     SerTxD (".")
     Branch FractPart, (Fract0, Fract1, Fract2, Fract3)

Fract0:
     SerTxD ("00", 13, 10)
     Return

Fract1:
     SerTxD ("25", 13, 10)
     Return

Fract2:
     SerTxD ("50", 13, 10)
     Return

Fract3:
     SerTxD ("75", 13, 10)
     Return

DisplayTemp_4:

       Dig = WholePart / 1000	' thousands
       SerTxD (#Dig)
       WholePart = WholePart % 1000

DisplayTemp_3:
       Dig = WholePart / 100	' hundreds
       SerTxD (#Dig)
       WholePart = WholePart % 100

       Dig = WholePart / 10	' tens
       SerTxD (#Dig)
       WholePart = WholePart % 10

       Dig = WholePart 		' units
       SerTxD (#Dig)

       Goto Fract