Haz una pregunta
  Foros de Electrónica » Diseño digital » Interfaces y Programación
Foros Registrarse ¿Olvidaste tu contraseña?

Temas similares

24/02/2012 #1


problema para recibir variables flotantes en comunicación serial.
Ante todo un cordial Saludo. estoy programando un Sensor Sht15 que permite determinar la temp. y la humedad, y un sensor MQ-6 que permite determinar concentraciones de GAS LP en Proton IDE, y quiero mandar esa información de los sensores de forma serial a otro PIC, el problema que tengo es que no logro enviar las variables flotantes a través de serout. alguien ha echo el intento de enviar variables flotantes a través del Proton y ha comprobado que los datos lleguen al receptor?


PDT: les dejo una copia de la programación que diseñe, en esta copia no dejo la rutina de la comunicación serial xq aun tengo muchas dudas con respecto a ella...




'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''divice''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''
Device = 16F876A
Xtal =10
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''
Print At 1,4, "Wellcome"
DelayMS 900
Cls
'
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''LCD'''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''
Declare LCD_DTPin PORTB.4 'puerto D del LCD
Declare LCD_ENPin PORTB.3 'puerto E del LCD
Declare LCD_RSPin PORTB.2 'puerto Rs del LCD
Declare LCD_Interface = 4 'Informar al compilador acerca de si una de 4 líneas o una interfaz de 8 líneas es requerido por la pantalla LCD.
Declare LCD_Lines =4
Declare LCD_Type= 0
Declare Adin_Res 10 ' 10-bit result required
Declare Adin_Tad FRC ' RC OSC chosen
Declare Adin_Stime 50 ' Allow 50us sample time




sht15: ' Measure Temp and Measure Humi

'-------------------------------------------------------
' I/O Definitions
'-------------------------------------------------------


Dim ShtDat As PORTA.2 'SHT Data Pin
Dim ShtClk As PORTA.1 'SHT Clock Pin

'-------------------------------------------------------
' ASstants
'-------------------------------------------------------


Dim ShtTemp As %00011 ' read temperature
Dim ShtHumi As %00101 ' read humidity
Dim ShtStatW As %00110 ' status register write
Dim ShtStatR As %00111 ' status register read
Dim ShtReset As %11110 ' reset
Dim Ack As 0
Dim NoAck As 1

'-------------------------------------------------------
' ASiables
'-------------------------------------------------------
All_Digital = true
Dim BT As Bit
Dim DS As Word
Dim SHT As Word
Dim Rec As Word
Dim ioByte As Word ' data input/output from SHT1x
Dim ackBit As Word ' ack/nak from/to SHT1x
Dim T_Delay As Byte ' timeout delay timer
Dim T_Out As Word ' timeout status
Dim soT As Word ' temp counts from SHT1x
Dim tC As Word ' temp for C
Dim CF As Word
Dim tC_tF As Word
Dim soRH As Word ' humidity counts from SHT1x
Dim rhLin As Word ' humidity; linearized
Dim rhTrue As Word ' humidity; temp compensated
Dim STATU As Byte ' SHT1x status byte




'--------------------------------------------------------
' Main program
'--------------------------------------------------------



Main:



ShowTH:
GoSub SHT_Measure_Temp
GoSub SHT_Measure_Humi

Print At 1,1, "T=", Dec tC/10, ".",Dec1 tC, " ", "C"
DelayMS 100
'Print At 1,10, Dec soT', ".", Dec2 tC, " ", "C"
'DelayMS 10000
Print At 2,1,"Hr=", Dec2 rhTrue/10, ".", Dec1 rhTrue," %RH"
DelayMS 1000
'Print At 2,11, Dec soRH ', ".", Dec2 soRH , " ", "C"
'DelayMS 10000


GoTo mq6


SHT_ASnection_Reset:
SHOut ShtDat, ShtClk, LsbFirst, [$FFF\9]
Return

SHT_Start:
Input ShtDat ' generates SHT start sequence
Low ShtClk ' _____ _____
High ShtClk ' ShtDat |_______|
Low ShtDat ' ___ ___
Low ShtClk ' Clock ___| |___| |___
High ShtClk
Input ShtDat
Low ShtClk
Return

SHT_Measure_Temp:
GoSub SHT_Start ' start device
ioByte = ShtTemp ' temperature command
GoSub SHT_Write_Byte ' send command
GoSub SHT_Wait
ackBit = Ack ' Ack = 1
GoSub SHT_Read_Byte ' get MSB
soT.HighByte = ioByte
ackBit = NoAck ' NoAck = 0
GoSub SHT_Read_Byte ' get LSB
soT.LowByte = ioByte
tC = soT/10 - 400 ' ASvert to tenths C

Return

SHT_Measure_Humi:
GoSub SHT_Start ' start device
ioByte = ShtHumi ' humidity command
GoSub SHT_Write_Byte ' send command
GoSub SHT_Wait
ackBit = Ack ' Ack = 1
GoSub SHT_Read_Byte ' get MSB
soRH.HighByte = ioByte
ackBit = NoAck ' NoAck = 0
GoSub SHT_Read_Byte ' get LSB
soRH.LowByte = ioByte


rhLin=(26542-(54722**soRH+soRH))**soRH-40 ' RH linear
rhTrue=655+(soRH*5)+(soRH**15917)
rhTrue=(rhTrue**(tC/10+2480))-(rhTrue**2730)+rhLin ' RH temp. compensated

Return

SHT_Write_Status:
GoSub SHT_Start ' start device
ioByte = ShtStatW ' reg command
GoSub SHT_Write_Byte ' send command
ioByte = STATU
GoSub SHT_Write_Byte
Return

SHT_Read_Status:
GoSub SHT_Start
ioByte = ShtStatW ' reg command
GoSub SHT_Read_Byte ' send command
ackBit = NoAck
GoSub SHT_Read_Byte
Return

SHT_Write_Byte:
SHOut ShtDat, ShtClk, MsbFirst, [ioByte] ' send data
SHIn ShtDat, ShtClk, LsbPre, [ackBit\1] ' get ack bit
Return

SHT_Read_Byte:
SHIn ShtDat, ShtClk, MsbPre, [ioByte] ' get data
SHOut ShtDat, ShtClk, LsbFirst, [ackBit\1] ' send ack bit
Input ShtDat ' data pin input
Return

SHT_Wait:
Input ShtDat ' data pin input
For T_Delay = 1 To 250
If ShtDat = 0 Then
Return
EndIf
DelayMS 5
Next
Return

SHT_Soft_Reset:
GoSub SHT_ASnection_Reset ' reset the connection
ioByte = ShtReset ' reset command
ackBit = NoAck ' NoAck = 0
GoSub SHT_Write_Byte ' send it
DelayMS 20
Return



mq6:'Measure gas LP

Declare Adin_Tad FRC ' RC OSC chosen

TRISA = %00000001 ' Configure AN0 (PORTA.0) as an input
ADCON1 = %10000000 ' Set analogue input on PORTA.0

Symbol Salida= PORTB.0
Dim Vrl As Float
Dim R As Float
Dim VAR1 As Float
Dim Rs As Float


Formulas:
VAR1 = ADIn 0 ' Place the conversion into variable VAR1
Dim y As Float


Vrl =(VAR1*5)/(1023)
R =(5-Vrl)/(Vrl)
Rs= (R) * 20000
Cls
Print Dec Rs
DelayMS 400
Cls
Print Dec Vrl
DelayMS 400
GoTo sht15
Respuesta
¿Tienes una mejor respuesta a este tema? ¿Quieres hacerle una pregunta a nuestra comunidad y sus expertos? Registrate

Buscar más temas sobre:
Lupa Interfaces y Programación

Lenguajes de programación, gestión y manejo de puertos

Cerrar
Foros de Electrónica » Diseño digital » Interfaces y Programación

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2011, Crawlability, Inc.