PIC 12F675 ile ilgili bi sorun

Venomlord

Üye
Katılım
26 Nis 2012
Mesajlar
5
Puanları
1
Yaş
32
Merhabalar aşagıdaki kodları projemde kullandım ama gelen ısı degerleri -80 ve - 70 civarlarında neden böle kodda yanlışlkmı var ?Şimdiden teşekkür ediyorum.' MCU Selection
Device = 12F675
' 8.000Mhz Crystal
XTAL = 8
' Define Symbolic Pin References
Symbol DQ = GPIO.0 ' 1-Wire Net Pin
Symbol TX = GPIO.1 ' Bluetooth TX
Symbol RX = GPIO.2 ' Bluetooth RX

' Configuration Fuses: External Oscillator (High-Speed), Watchdog off, Code-Protect Off
Config HS_OSC, WDT_OFF, CP_OFF
' Define Variables
Dim temperature As Word
Dim C As Byte
Dim CPerD As Byte
Dim sample_count As Word
Dim sample_delay As Word
Dim tx_pace As Word
Dim temp_dec As Byte
Dim sign As Byte
' Inserts a small delay between the transmission of each character to prevent data loss
tx_pace = 80
' Sample Rate
sample_delay = 10000
' Set all pins as digital
ALL_DIGITAL = true
'Set pin directions
Output TX
Input RX
' 20-Second Boot Delay
DelayMS 20000
' Display "POST" information
SerOut TX, 84, tx_pace, [13, 10, 10, 10, "Bluetooth Thermometer - Power Up Sucessful", 13, 10]
SerOut TX, 84, tx_pace, [13, 10, "Hardware Version: R3.0"]
SerOut TX, 84, tx_pace, [13, 10, "Firmware Version: R1 B23"]
SerOut TX, 84, tx_pace, [13, 10, "Sample Spacing (seconds): ", Dec sample_delay/1000, 13, 10]

' SerOut Data Format: SerOut (pin)(Baudmode (9600 8N1 Inverted))(Pace)[Data]
' Blank Space
SerOut TX, 84, tx_pace, [13,10,10,10]
' Wait two seconds
DelayMS 2000
' Initialize Sample Counter to zero
sample_count = 0
' Print "START" to signal the begining of the data collection to the host
SerOut TX, 84, tx_pace, ["START", 13, 10,10]
' Main sampling/transmission loop
acquisition:
OWrite DQ, 1, fault, [$CC, $44] ' Send calculate temperature command
' If no 1-Wire sensor is found, jump to the "fault" function
' OWrite and ORead functions are quite comprehensive - See the PICBasic Library for details
Repeat
DelayMS 50 ' Wait for the conversion to complete
ORead DQ, 4, [C] ' Read the counter value from the DS18B20
Until C <> 0
OWrite DQ, 1, [$CC, $BE] ' Send "Read Scratchpad" command
ORead DQ, 2, [temperature.LowByte,temperature.HighByte, C, C, C, C, C, CPerD]
' Figure out if the value is positive or negative; flip the sign
' Bits 8-15 are 1 for a negative temperature and 0 for a positive
If temperature.8=1 Then
' If negative then drop the first bit, and invert the value
temperature=(temperature.LowByte ^ $FF) >> 1
' If Count = 0 then increment Temp
If C = 0 Then temperature = temperature + 1
' Change the sign to a negative
sign = "-"
Else
' If positive then drop the first byte
temperature = (temperature >> 1)
' And change the sign value to positive
sign = "+"
' Invert the decimal value
temp_dec = 100 - temp_dec
EndIf
' Each Count is 1/16 of a degree, therefore 100/16 = 6.25, and that's our decimal value (of the temperature)
temp_dec = (6.25 * C)
' Increment the sample counter
sample_count = (sample_count + 1)
' Transmit the data to the host over the Bluetooth Link
' Transmitting "" seems to prevent data loss
SerOut TX, 84, tx_pace, [""]
' Format: sample count, comma, sign, temperature whole, decimal place, temperature fraction, "c"
SerOut TX, 84, tx_pace, [Dec sample_count, ", ", sign, Dec temperature, ".", Dec Dig temp_dec, 1, 0, "c", 13, 10]
' Wait or the specified amount of time before sending the next sample
DelayMS sample_delay
' Restart the sampling acquisition process
GoTo acquisition


' If the 1-Wire sensor is not found, the first OWRITE command will fail and jump here to indicate the fault
fault:
SerOut TX, 84, tx_pace, [13, 10, "ERROR: 1-Wire Network Fault Detected - Check Sensor Wiring", 13, 10]
DelayMS 1000
' Try again - If the problem is fixed return to normal operation
GoTo acquisition
 

Forum istatistikleri

Konular
128,200
Mesajlar
915,785
Kullanıcılar
449,983
Son üye
ardaxsm

Yeni konular

Geri
Üst