zaterdag 30 juli 2011

source code wireless sensor

Hierbij de source:

'****************************************************************
'*  Name    : 12f683.BAS                                        *
'*  Author  : VoXiT-Pro                                         *
'*  Notice  : Copyright (c) 2011                                *
'*          : All Rights Reserved                               *
'*  Date    : 29-7-2011                                         *
'*  Version : 1.0                                               *
'*  Notes   :                                                   *
'*          :                                                   *
'****************************************************************
Device = 12F683

Config MCLRE_ON, INTRC_OSC_NOCLKOUT, WDT_OFF, PWRTE_ON, BOD_ON

Xtal 4

ADCON0 = 0

CMCON0 = 7 ' comparators off
ANSEL = 0  ' all inputs digital
WPU = 0

OPTION_REG = %10000000 ' Pull-ups = off
GPIO = 000000       ' All outputs = 0 on boot
TRISIO = 111101     ' gpio.1 output rest input

INTCON = $90 ' Enable INTE interrupt   (GPIO.2 pen5 = int)
OPTION_REG.6=0 

Symbol zender       = 1
Symbol ds1820       = GPIO.0
Symbol zendout      = GPIO.1
Symbol startman     = $55
Symbol dataman      = $aa

Dim tempture As Word
Dim teller As Byte
Dim manchestin As Byte
Dim manchestout As Word
Dim tempdata As Bit
Dim manchesttl As Word
Dim manchestth As Word
Dim manchestck As Word
Dim manchestzd As Word
Dim checksum As Byte
Dim C_remain As Byte   
Dim C_per_c As Byte   
Dim Dum    As Byte

manchestin = zender
Call manchesterdata
manchestzd = manchestout

On Interrupt GoTo Meting 'Enable interrupts

Main:
@sleep
GoTo Main


Disable ' Disable interrupts in the handler

' data omzetten naar manchester
' invoer een byte
' output een word

manchesterdata:
For teller = 0 To 7
tempdata = GetBit manchestin,teller
If tempdata = 0 Then
        ClearBit manchestout,(teller*2)
        SetBit manchestout,(teller*2+1)
    Else
        SetBit manchestout,(teller*2)           
        ClearBit manchestout,(teller*2+1)
    EndIf
Next teller
Return

Meting:         

OWrite ds1820, 1, [$CC, $44]               ' Start temperature conversion
   
While ORead ds1820, 4 = 0 : Wend   

OWrite ds1820, 1, [$CC, $BE]            ' Read the temperature
ORead ds1820, 2, [tempture.LowByte, tempture.HighByte, Dum,Dum,Dum,Dum, C_remain, C_per_c]

tempture = (((tempture >> 1) * 100) - 25) + (((C_per_c - C_remain) * 100) / C_per_c)

manchestin = tempture.HighByte
Call manchesterdata
manchestth = manchestout

manchestin = tempture.LowByte
Call manchesterdata
manchesttl = manchestout

checksum = zender + tempture - 1

manchestin = checksum
Call manchesterdata
manchestck = manchestout

For teller = 0 To 1

SerOut zendout, 49965,[startman,startman,startman,startman,startman,startman,startman,startman,dataman,manchestzd.HighByte,manchestzd.LowByte,manchesttl.HighByte,manchesttl.LowByte,manchestth.HighByte,manchestth.LowByte]
SerOut zendout, 49965,[dataman,dataman,dataman,dataman,dataman,dataman,manchestck.HighByte,manchestck.LowByte]

DelayMS 70
Next

INTCON.1 = 0 ' Clear interrupt flag
Resume ' Return to main program
Enable ' Enable interrupts after the handler

Geen opmerkingen:

Een reactie posten