Autor Tema: problema con la uart  (Leído 3824 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado WALTER ALEJANDRO

  • PIC12
  • **
  • Mensajes: 64
problema con la uart
« en: 18 de Abril de 2016, 09:28:58 »
hola, estoy tratando de enviar ocho variables y leerlas en un display a traves del modulo uart ,aqui el display, aclaro que uso PSI en basic y los micros 16f877a
Define CONF_WORD = 0x3f72

AllDigital
TRISA = 0x0f
TRISB = 0xff
TRISC = 0
TRISD = 0
TRISC.6 = 1
OPTION.7 = 0  'pullup
''''''''''''''''''''''''''''''''''''''''''''''''''
Define SIMULATION_WAITMS_VALUE = 1
Define CLOCK_FREQUENCY = 20
'ADCON1 = 0x0e

'''''''


'+++++++++++++++++++++++?*************USART++++++++++++++++++++++++++++++++++++++
INTCON.7 = 1
INTCON.6 = 1
PIE1.5 = 1  'hab interrupcion x Rx
PIR1.5 = 0  'limpio la interrupcion
RCSTA.7 = 1  'configuro rx ytx

Dim paso As Byte  'inc para seleccionar donde guarda el dato recibido
   Dim papelera As Byte
   Hseropen 9600  'Velocidad del puerto serie, configura Usart
   RCSTA.CREN = 0  'Disable
   Hserget papelera  'Limpia bufer Uart
   Hserget papelera
   Hserget papelera
   RCSTA.CREN = 1  'Enable, Continuous Receive Enable bit*/
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'++++++++++++++++++++++++++++++++++++++++++++++++++++
'+++++variables que toman en estado actual de la temperatura
Dim tcero As Byte
Dim tuno As Byte
Dim tdos As Byte
Dim ttres As Byte
Dim tcuatro As Byte
Dim tcinco As Byte
Dim tseis As Byte
Dim tsiete As Byte
Dim tocho As Byte
Dim tnueve As Byte
Dim tdiez As Byte
Dim tonce As Byte
Dim tdoce As Byte
Dim ttrece As Byte
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
''+++++++++variables de manejo''''''''''''''''''''''''''''''
Symbol cambio = RB3  'cambia la pantalla



Define LCD_LINES = 4
Define LCD_CHARS = 20
Define LCD_BITS = 4
Define LCD_DREG = PORTD
Define LCD_DBIT = 4
Define LCD_RSREG = PORTD
Define LCD_RSBIT = 2
Define LCD_EREG = PORTD
Define LCD_EBIT = 3
'Define LCD_RWREG = PORTD
'Define LCD_RWBIT = 2
Define LCD_COMMANDUS = 2000
Define LCD_INITMS = 100
'Gosub trans
Lcdinit 0
'WaitMs 500

inicio:
Lcdcmdout LcdClear
WaitMs 200
While cambio = 1

'Lcdcmdout LcdClear
Lcdcmdout LcdLine1Home
Lcdout "numero 1)" "---" #tuno, "       "
Lcdcmdout LcdLine2Home
Lcdout "numero 2)"" - -- " #tdos, "        "
Lcdcmdout LcdLine3Home
Lcdout "numero 3)"" - -- " #ttres, " """
Lcdcmdout LcdLine4Home
Lcdout "numero 4)"" - -- " #tcuatro, " """

'WaitMs 100

'++++++++++++++++++++++++++++++++++++

Wend
''''''''''''''''''''''''''''''''''''''''''''''''
Lcdcmdout LcdClear
WaitMs 200
While cambio = 1
'Lcdcmdout LcdClear
Lcdcmdout LcdLine1Home
Lcdout "numero 5)" " - -- " #tcinco, "    "
Lcdcmdout LcdLine2Home
Lcdout "numero 6)"" - -- " #tseis, "      "
Lcdcmdout LcdLine3Home
Lcdout "numero 7)"" - -- " #tsiete, "     "
Lcdcmdout LcdLine4Home
Lcdout "numero 8)"" - -- " #tocho, "      "

Wend
'''''''''''''''''''''''''''''''''''''

'+++++++++++++++++++++++++++++++++++++++++++

Goto inicio
End                                               



On Interrupt
Save System
If PIR1.5 = 1 Then
paso = paso + 1
'''''''''''''''''''''''''''''''''''

If paso = 1 Then Hserget tuno
'''''''''''''''''''''''''''''''''''''''''''''
If paso = 2 Then Hserget tdos
If paso = 3 Then Hserget ttres
If paso = 4 Then Hserget tcuatro
If paso = 5 Then Hserget tcinco
If paso = 6 Then Hserget tseis
If paso = 7 Then Hserget tsiete
If paso = 8 Then Hserget tocho


''''''''''''''''''''''''''''''''''

''''''''''''''''''''''''''''''''''''''''

If paso >= 8 Then paso = 0  'sienvio ocho datos salgo
PIR1.5 = 0  'se incrementa hasta la cantidad de bytes a enviar,limpio la rx

Endif
Resume                                           
End                                               

End                                               

aqui dejo el tx
Define CLOCK_FREQUENCY = 20
TRISA = 0x0f
TRISB = 0
TRISB.6 = 1
OPTION.7 = 0
TRISC.7 = 1
TRISC.6 = 0
INTCON.7 = 1
INTCON.6 = 1
PIE1.5 = 1  'hab interrupcion x Rx
PIR1.5 = 0  'limpio la interrupcion
RCSTA.7 = 1  'configuro rx ytx
ADCON1 = 0x0e

Define SIMULATION_WAITMS_VALUE = 1
   Dim papelera As Byte
   Hseropen 9600  'Velocidad del puerto serie, configura Usart
   RCSTA.CREN = 0  'Disable
   Hserget papelera  'Limpia bufer Uart
   Hserget papelera
   Hserget papelera
   RCSTA.CREN = 1  'Enable, Continuous Receive Enable bit*/
''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''
Dim uno As Byte
Dim dos As Byte


''''''''''''''''''''''''''''''''''''''''
Dim tres As Byte


''''''''''''''''''''''''''''''''''''''''
Dim cuatro As Byte


'''''''''''''''''''''''''''''''''''''''''''
Dim cinco As Byte


''''''''''''''''''''''''''''''''''''''''''''
Dim seis As Byte

''''''''''''''''''''''''''''''''''''''''''''''''
Dim siete As Byte


'''''''''''''''''''''''''''''''''''''''''''''''''''
Dim ocho As Byte

Dim nueve As Byte


'''''''''''''''''''''''''''''''''''''''''''
Dim diez As Byte


''''''''''''''''''''''''''''''''''''''''''''
Dim once As Byte

''''''''''''''''''''''''''''''''''''''''''''''''
Dim doce As Byte


'''''''''''''''''''''''''''''''''''''''''''''''''''
Dim trece As Byte


'''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''
Define ADC_CLOCK = 1
Define ADC_SAMPLEUS = 1
inicio:
Toggle RD0
Adcin 0, uno
dos = uno + 10
tres = dos + 10
cuatro = tres + 10
cinco = cuatro + 10
seis = cinco + 10
siete = seis + 10
ocho = siete + 10
Toggle RD2
WaitMs 1  '000
Toggle RD2
Hserout uno

Toggle RD2
WaitMs 100  '000
Hserout dos

WaitMs 100  '000
Hserout tres

WaitMs 100  '000
Hserout cuatro
WaitMs 100  '000
Hserout cinco

WaitMs 100  '000
Hserout seis

WaitMs 100  '000
Hserout siete

WaitMs 100  '000
Hserout ocho
'Limpia bufer Uart
WaitMs 2000


'WaitMs 4000
While RB6 = 1
Wend
WaitMs 2000
Goto inicio
End                                               

como veran es un codigo muy simple, tan simple que en el simulador funciona pero en la realidad no, es como si desplazaran las lecturas, tx y rx de ambos micros estan puenteados x cables en el protoboard.Agradeceria hacia donde arrancar ya que estoy trabado y no se para donde ir, desde 
ya muchas gracias







Desconectado dogflu66

  • Moderador Local
  • DsPIC30
  • *****
  • Mensajes: 3549
Re:problema con la uart
« Respuesta #1 en: 19 de Abril de 2016, 19:52:22 »
Dejo un ejemplo con las rutinas basicas para poder almacenar multiples datos recibidos por el puerto serie.

Código: Visual Basic
  1. Define CONFIG = 0x2f50
  2. Define CONFIG2 = 0x3ffc
  3. '********************************************************************************
  4. 'Ejemplo de Buffer Serie *************************************************************
  5. 'Puerto serie 38400 Baudios, almacena en un vector los bytes recibidos ************************
  6. 'By COS, 20/04/2016, Pic Simulator IDE v7.40 *******************************************
  7. 'Pic EBasic con 16F88 **************************************************************
  8. '********************************************************************************
  9. Define CLOCK_FREQUENCY = 8  'Clock a 8Mhz
  10. Define SIMULATION_WAITMS_VALUE = 1
  11. 'Biblioteca de funciones
  12. Include "_FuncionesPic16F88.bas"
  13. '-------------------------------------Puertos del LCD---------------------------------------
  14. Define LCD_BITS = 4  'Indicamos que el bus de datos del lcd sera de 4bit
  15. Define LCD_DREG = PORTA  'Bus de datos sera el puerto A
  16. Define LCD_DBIT = 0  'Bus de datos seran los 4 bit menos significativos del puerto A
  17. Define LCD_RSREG = PORTB  'Bit de control RS sera del puerto B
  18. Define LCD_RSBIT = 7  'Se usara el RB7 como RS
  19. Define LCD_EREG = PORTB  'Bit de control E sera del puerto B
  20. Define LCD_EBIT = 6  'Se usara el RB6 como E
  21. Define LCD_COMMANDUS = 2000  'Tiempo de espera despues de ejecutar un comando del lcd en uSeg.
  22. Define LCD_DATAUS = 50  'Tiempo de espera despues de enviar un dato al LCD en uSeg.
  23. Define LCD_INITMS = 50  'Tiempo de espera despues de inicializar el Display.
  24. '-------------------------------------------------------------------------------------------
  25. AllDigital  'Pin analogicos como digitales
  26. CMCON = 0x07  'Comparador a off
  27. Call _setup_oscillator(_osc_8mhz)
  28. Call _setup_oscillator_mode_select_bit(_oscillator_mode_defined_by_fosc)
  29. TRISA = 0x00  'Puerto A como salidas
  30. TRISB = 0x00  'Puerto B como salidas
  31. TRISA.4 = 1  'Como entrada (RA4, adc)
  32. TRISA.6 = 1  'Como entrada (RA6, tecla S1)
  33. TRISA.5 = 1  'Como entrada (RA5, tecla S2)
  34. TRISB.5 = 0  'Como salida(RB5,Tx RS232)
  35. TRISB.2 = 1  'Como entrada (RB2, Rx RS232)
  36. TRISB.4 = 1  'Como entrada (RHT03 inicio)
  37. PORTB.3 = 1  'Luz lcd a ON (RB3)
  38. PORTA.7 = 1  'Led amarillo a OFF
  39. PORTB.0 = 1  'Led verde a OFF
  40. PORTB.1 = 0  'LED RHT03 a OFF
  41. Lcdinit  'Activa el LCD
  42. '-----------------------------------------------
  43. Hseropen 38400  'Selecciona la velocidad del puerto serie RS232
  44. Lcdout "Test Buffer"  'Datos al Lcd
  45. Hserout CrLf  'Linea en blanco al hyperterminal
  46. WaitMs 100
  47. Symbol _buffer = PIR1.RCIF  'Se pone a 1 cuando hay datos en el buffer usart Rx
  48. Dim indice As Byte
  49. indice = 0
  50. Dim dato(8) As Byte  'Buffer serie de 8 elementos (0... 7)
  51. '**************************************************************************************
  52. main:
  53.         'Desbloquea la Usart en modo Rx
  54.         If RCSTA.OERR = True Then  'Hay error en la Usart, entraron más datos de los que se extrajero (está bloqueada)
  55.                 Dim papelera As Byte
  56.                 RCSTA.CREN = 0  'Disable, continua recepción
  57.                 Hserget papelera  'Vacía registros usart
  58.                 Hserget papelera
  59.                 RCSTA.CREN = 1  'Enable, Continuous Receive Enable bit*/
  60.         Endif
  61.         'Va almacenando los bytes recibidos en el vector de 8 elementos DATO
  62.         If _buffer = True Then  'Si hay caracteres en el puerto serie (registro de la Usart)
  63.                 Hserget dato(indice)
  64.                 indice = indice + 1
  65.         Endif
  66.         'Envia los bytes recibidos al puerto serie en orden inverso
  67.         If indice > 7 Then
  68.                 While indice > 0
  69.                         indice = indice - 1
  70.                         Hserout #dato(indice), CrLf
  71.                 Wend
  72.         Endif
  73. Goto main
  74. End
Saludos desde Granada, España.

Desconectado dogflu66

  • Moderador Local
  • DsPIC30
  • *****
  • Mensajes: 3549
Re:problema con la uart
« Respuesta #2 en: 20 de Abril de 2016, 10:55:45 »
Las asignaciones de los datos puedes realizarlos de la siguiente manera:

'Envia los bytes recibidos al puerto serie en orden inverso
If indice > 7 Then
   While indice > 0
      indice = indice - 1
      Hserout #dato(indice), CrLf
   Wend
   'Asignaciones de valores
   temp_0 = dato(0)
   temp_1 = dato(1)
   temp_2 = dato(2)
   temp_3 = dato(3)
   temp_4 = dato(4)
   temp_5 = dato(5)
   temp_6 = dato(6)
   temp_7 = dato(7)
Endif

O si prefieres puedes cambiar el nombre al vector dato y ponerle uno más apropiado Dim temp(8 ) as byte y
trabajar con sus nombres directamente temp(0)... temp(7).

Tambien de esta otra manera:

Symbol temp_0 = dato(0)
Symbol temp_1 = dato(1)
Symbol temp_2 = dato(2)
.
.
Symbol nombre = dato(7)

Este último ahorra memoria ram.
« Última modificación: 20 de Abril de 2016, 10:59:41 por dogflu66 »
Saludos desde Granada, España.

Desconectado dogflu66

  • Moderador Local
  • DsPIC30
  • *****
  • Mensajes: 3549
Re:problema con la uart
« Respuesta #3 en: 20 de Abril de 2016, 13:27:12 »
Se me olvidaba, si insistes en seguir con tu sistema de buffer el problema al parecer está en que lees el buffer demasiado rápido, antes de que entren los datos (por eso funciona en simulación, esto último la simulación no lo tiene en cuenta).
Puedes sustituir el comando Hserget por Hserin que se para hasta recibir el dato. Recuerda que Hserin te bloquea el código hasta recibir el dato, si cometes algún error y se pierde algún dato el código se queda parado esperando la recepción del byte.

Si quieres puedes experimentar con esta función que sigue sin ser el mejor modo pero mejora el comando Hserin:

http://www.todopic.com.ar/foros/index.php?topic=14917.msg346098#msg346098
Saludos desde Granada, España.

Desconectado WALTER ALEJANDRO

  • PIC12
  • **
  • Mensajes: 64
Re:problema con la uart
« Respuesta #4 en: 22 de Abril de 2016, 06:24:13 »
gracias x el momento,me va  a llevar unos dias pasarlo a mi programa y luego al protoboard,en cuanto lo tenga les informo los resultados.Un abrazo desde argentina!

Desconectado WALTER ALEJANDRO

  • PIC12
  • **
  • Mensajes: 64
Re:problema con la uart
« Respuesta #5 en: 22 de Abril de 2016, 15:18:28 »
me siento luchando contra molinos de viento
aca los nuevos codigos
Define CONF_WORD = 0x3f72







Define CLOCK_FREQUENCY = 20
AllDigital
TRISA = %000001
TRISB = 0
TRISE.0 = 0
TRISE.1 = 0
TRISE.2 = 0
TRISC = %00000011
TRISD = 0
'OPTION_REG.7 = 0
TRISD = 0
ADCON1 = 0x0e
Dim posicion As Byte
posicion = 0
'Define SIMULATION_WAITMS_VALUE = 1
TRISC.7 = 1
TRISC.6 = 0
INTCON.7 = 1
INTCON.6 = 1
PIE1.5 = 1  'hab interrupcion x Rx
PIR1.5 = 0  'limpio la interrupcion
RCSTA.7 = 1  'configuro rx ytx

Dim papelera As Byte
Hseropen 9600  'Velocidad del puerto serie, configura Usart
RCSTA.CREN = 0  'Disable
Hserget papelera  'Limpia bufer Uart
Hserget papelera
Hserget papelera
RCSTA.CREN = 1  'Enable, Continuous Receive Enable bit*/
Hserout CrLf  'limpia el buffer








Dim tempp(8) As Byte  'temperatura programada , la que manda el display
Dim templ(8) As Byte  'temperatura leida,la que transmito al micro del display
'''''''''''''''''''''''''''''''VARIABLES DE TX Y RX'''''''''''''''''''''''''''''''
Dim indice As Byte
Dim array As Byte
Dim paso As Byte
Dim contar As Byte

''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''
Define ADC_CLOCK = 2
Define ADC_SAMPLEUS = 5
'Symbol buzer = RC3
'WaitMs 1000  ''''''''''''''''''''''''''''''''''''''''
't1 a 50ms
''''''''''''''''''''''''''''''''''''''''''''''
Dim seguir As Byte  'este cada x cantidad va a adquirir los datos de lectura de adc
Dim toglear As Byte  'este cada 2 seg cambia para cuando se aproxima a la lectura
Dim pulsos As Bit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Dim temp(10) As Byte  'temp  byte de temp leidas

'''''''''''''''''''''''''''
Dim warning As Byte
warning = 0
Dim aviso As Bit
aviso = 0
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim espera As Word
espera = 40
'''''''''''''''''''''''''''''''''''''
'valores de alarma x sobretemp
Dim offset As Byte
offset = 5
Dim falta As Byte
falta = 5  'cuando falta este empieza a toglear
Dim casi As Byte  'aca guardo la diferencia para generar los pulsos
Dim dif As Byte
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim ascii As Byte
ascii = 223

inicio:
'INTCON.4 = 1  'externa x flanco de subida
'INTCON.1 = 0  'limpio el flag de int externa
'WaitMs 1000
'Low buzer
mostrar:
'''''''''''''''''''''''''''''''''''''''''''
Low RB6

ciclo:
seguir = 0  'lo reseteo y adquiero datos
PORTD = 0
WaitUs espera  'a que se estabilice
Adcin 0, templ(0)
If tempp(0) = 0 Then
RA1 = 0  'si programe cero grado de pedido entonces lo apago
Goto estadodos
Endif
If templ(0) >= tempp(0) Then
RA1 = 0  'si es >tambien lo apago
Goto salto1
'''''''''''''''''''''''''''''''''''''''
Endif
If templ(0) < tempp(0) Then casi = tempp(0) - falta
If templ(0) >= casi Then
RA1 = pulsos
Else
High RA1
Endif
estadodos:
offset = 5  'recupero datos
casi = 0
dif = 0
'falta = 10
salto1:
'salto1:
''''''''''''''''''''''''''''''''''''''''''
PORTD = 1
WaitUs espera  'a que se estabilice
Adcin 0, templ(1)
If tempp(1) = 0 Then
RA2 = 0  'si programe cero grado de pedido entonces lo apago
Goto estadotres
Endif
If templ(1) >= tempp(1) Then
RA2 = 0  'si es >tambien lo apago
Goto salto2
''''''''''''''''''''''''''''''''''''''''''''''''
Endif

If templ(1) < tempp(1) Then casi = tempp(1) - falta
If templ(1) >= casi Then
RA2 = pulsos
Else
High RA2
Endif
estadotres:
offset = 5  'recupero datos
casi = 0
dif = 0
salto2:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
PORTD = 2
WaitUs espera  'a que se estabilice
Adcin 0, templ(2)
If tempp(2) = 0 Then
RC4 = 0  'si programe cero grado de pedido entonces lo apago
Goto estadocuatro  'salto al siguiente eswtado
Endif
If templ(2) >= tempp(2) Then
RA4 = 0  'si es >tambien lo apago
Goto salto3

Endif
If templ(2) < tempp(2) Then casi = tempp(2) - falta
If templ(2) >= casi Then
RC4 = pulsos
Else
High RC4
Endif
estadocuatro:
offset = 5  'recupero datos
casi = 0
dif = 0
salto3:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

PORTD = 3
WaitUs espera  'a que se estabilice
Adcin 0, templ(3)
If tempp(3) = 0 Then
RA5 = 0  'si programe cero grado de pedido entonces lo apago
Goto estadocinco  'salto al siguiente eswtado
Endif
If templ(3) >= tempp(3) Then
RA5 = 0  'si es >tambien lo apago
Goto salto4

Endif
If templ(3) < tempp(3) Then casi = tempp(3) - falta
If templ(3) >= casi Then
RA5 = pulsos
Else
High RA5
Endif
estadocinco:
offset = 5  'recupero datos
casi = 0
dif = 0
salto4:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
PORTD = 4
WaitUs espera  'a que se estabilice
Adcin 0, templ(4)
If tempp(4) = 0 Then
RE0 = 0  'si programe cero grado de pedido entonces lo apago
Goto estadoseis  'salto al siguiente eswtado
Endif
If templ(4) >= tempp(4) Then
RE0 = 0  'si es >tambien lo apago
Goto salto5

Endif
If templ(4) < tempp(4) Then casi = tempp(4) - falta
If templ(4) >= casi Then
RE0 = pulsos
Else
High RE0
Endif
estadoseis:
offset = 5  'recupero datos
casi = 0
dif = 0
salto5:
''''''''''''

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
PORTD = 5
WaitUs espera  'a que se estabilice
Adcin 0, templ(5)
If tempp(5) = 0 Then
RE1 = 0  'si programe cero grado de pedido entonces lo apago
Goto estadosiete  'salto al siguiente eswtado
Endif
If templ(5) >= tempp(5) Then
RE1 = 0  'si es >tambien lo apago
Goto salto6

Endif
If templ(5) < tempp(5) Then casi = tempp(5) - falta
If templ(5) >= casi Then
RE1 = pulsos
Else
High RE1
Endif
estadosiete:
offset = 5  'recupero datos
casi = 0
dif = 0
salto6:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
PORTD = 6
WaitUs espera  'a que se estabilice
Adcin 0, templ(6)
If tempp(6) = 0 Then
RE2 = 0  'si programe cero grado de pedido entonces lo apago
Goto estadoocho  'salto al siguiente eswtado
Endif
If templ(6) >= tempp(6) Then
RE2 = 0  'si es >tambien lo apago
Goto salto7

Endif
If templ(6) < tempp(6) Then casi = tempp(6) - falta
If templ(6) >= casi Then
RE2 = pulsos
Else
High RE2
Endif

estadoocho:
offset = 5  'recupero datos
casi = 0
dif = 0
salto7:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
PORTD = 7
WaitUs espera  'a que se estabilice
Adcin 0, templ(7)
If tempp(7) = 0 Then
RC3 = 0  'si programe cero grado de pedido entonces lo apago
Goto estadonueve  'salto al siguiente eswtado
Endif
If templ(7) >= tempp(7) Then
RC3 = 0  'si es >tambien lo apago
Goto salto8
Endif
If templ(7) < tempp(7) Then casi = tempp(7) - falta
If templ(7) >= casi Then
RC3 = pulsos
Else
High RC3
Endif
estadonueve:
offset = 5  'recupero datos
casi = 0
dif = 0
salto8:
High RB6
WaitMs 100
Toggle pulsos
Goto mostrar
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
End                                               


On Interrupt
Save System
'Toggle pulsos
If RCSTA.1 = 1 Then

   RCSTA.CREN = 0  'Disable
   Hserget papelera  'Limpia bufer Uart
   Hserget papelera
   Hserget papelera
   RCSTA.CREN = 1
Endif
If PIR1.5 = 1 Then
Hserget tempp(indice)
indice = indice + 1
Endif
If indice < 7 Then  'indice = 0


Hserout #templ(indice), CrLf

Else
indice = 0
Endif

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'Endif  ''''''''''''''''''''''''''''''''''''''''''''''
Resume                                           
End                                               
y ahora el display con el teclado

Define CONF_WORD = 0x3f72

AllDigital
TRISA = 0x0f
TRISB = 0xff
TRISC = 0
TRISD = 0x00
TRISC.6 = 1
OPTION.7 = 0  'pullup
''''''''''''''''''''''''''''''''''''''''''''''''''
'Define SIMULATION_WAITMS_VALUE = 1
Define CLOCK_FREQUENCY = 20
TRISC.7 = 1
TRISC.6 = 0
INTCON.7 = 1
INTCON.6 = 1
PIE1.5 = 1  'hab interrupcion x Rx
PIR1.5 = 0  'limpio la interrupcion
RCSTA.7 = 1  'configuro rx ytx

Dim papelera As Byte
Hseropen 9600  'Velocidad del puerto serie, configura Usart
RCSTA.CREN = 0  'Disable
Hserget papelera  'Limpia bufer Uart
Hserget papelera
Hserget papelera
RCSTA.CREN = 1  'Enable, Continuous Receive Enable bit*/
Hserout CrLf  'limpia el buffer



'''''''

Dim indice As Byte
'+++++++++++++++++++++++?*************USART++++++++++++++++++++++++++++++++++++++
'+++++++++++++++++++++++++++++++++++++++++++++++++++
Dim templ(8) As Byte  'igual que el otro temperatura leida
Dim tempp(8) As Byte  'temperatura programada '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tempp(0) = 100
tempp(1) = 110
tempp(2) = 120
tempp(3) = 130
tempp(4) = 140
tempp(5) = 150
tempp(6) = 160
tempp(7) = 170
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
''+++++++++variables de manejo''''''''''''''''''''''''''''''
Symbol cambio = RB3  'cambia la pantalla
Dim ciclo As Byte
Dim i As Byte
Dim guardar As Byte

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dim offset As Byte
offset = 5
Dim alarma As Word
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
''+++++++++variables de manejo''''''''''''''''''''''''''''''

Dim posicion As Byte  'lo incremento para selecconar una pantalla
Symbol sube = RB1
Symbol baja = RB2
Symbol enter = RB4
Symbol volver = RB5
Symbol habtx = RA0
Define LCD_LINES = 4
Define LCD_CHARS = 20
Define LCD_BITS = 4
Define LCD_DREG = PORTD
Define LCD_DBIT = 4
Define LCD_RSREG = PORTD
Define LCD_RSBIT = 2
Define LCD_EREG = PORTD
Define LCD_EBIT = 3
'Define LCD_RWREG = PORTD
'Define LCD_RWBIT = 1
Define LCD_COMMANDUS = 2000
Define LCD_INITMS = 50
'Gosub trans
Lcdinit 0
'T1CON.TMR1ON = 1  'lo prendo despues del display
Hserout #tempp(0), #tempp(1), #tempp(2), #tempp(3), #tempp(4), #tempp(5), #tempp(6), #tempp(7), Lf, CrLf
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
inicio:

While cambio = 1
'Lcdcmdout LcdClear
WaitMs 100



'Lcdcmdout LcdClear
Lcdcmdout LcdLine1Home

Lcdout "MANGUERA 1)" #tempp(0), "---" #templ(0), "       "
Lcdcmdout LcdLine2Home
Lcdout "PISTOLA  1)" #tempp(1), "---" #templ(1), "        "
Lcdcmdout LcdLine3Home
Lcdout "MANGUERA 2)" #tempp(2), "---" #templ(2), "       "
Lcdcmdout LcdLine4Home
Lcdout "PISTOLA  2)" #tempp(3), "---" #templ(3), "        "
'Gosub control
WaitMs 100
If enter = 0 Then Gosub prog
'++++++++++++++++++++++++++++++++++++
Goto inicio

Wend
''''''''''''''''''''''''''''''''''''''''''''''''
Lcdcmdout LcdClear
WaitMs 200
While cambio = 1
Lcdcmdout LcdClear
Lcdcmdout LcdLine1Home
Lcdout "MANGUERA 3)" #tempp(4), "---" #templ(4), "       "
Lcdcmdout LcdLine2Home
Lcdout "PISTOLA  3)" #tempp(5), "---" #templ(5), "        "
Lcdcmdout LcdLine3Home
Lcdout "MANGUERA 4)" #tempp(6), "---" #templ(6), "       "
Lcdcmdout LcdLine4Home
Lcdout "PISTOLA  4)" #tempp(7), "---" #templ(8), "        "
'Gosub control
WaitMs 100
If enter = 0 Then Gosub prog
Wend
'''''''''''''''''''''''''''''''''''''
'Lcdcmdout LcdClear
'WaitMs 200
'While cambio = 1
''Lcdcmdout LcdClear
'Lcdcmdout LcdLine1Home
'Lcdout "MANGUERA 5)" #nueve, "---" #tnueve, "       "
'Lcdcmdout LcdLine2Home
'Lcdout "PISTOLA  5)" #diez, "---" #tdiez, "        "
'Lcdcmdout LcdLine3Home
'Lcdout "MANGUERA 6)" #once, "---" #tonce, "       "
'Lcdcmdout LcdLine4Home
'Lcdout "PISTOLA  6)" #doce, "---" #tdoce, "        "
'Gosub control


'If enter = 0 Then Gosub prog
'Wend
'WaitMs 250
'+++++++++++++++++++++++++++++++++++++++++++++
'Lcdcmdout LcdClear
'WaitMs 200
'While cambio = 1
''Lcdcmdout LcdClear
'Lcdcmdout LcdLine1Home
'Lcdout "TANQUE    " #trece, "---" #ttrece, "          "
'Lcdcmdout LcdLine2Home
'Lcdout "++++++++++++"
'Lcdcmdout LcdLine3Home
'Lcdout "++++++++++++++"
'Lcdcmdout LcdLine4Home
'Lcdout "++++++++++++"
'Gosub controlIf enter = 0 Then Gosub prog
'Wend
'+++++++++++++++++++++++++++++++++++++++++++
'T1CON.TMR1ON = 1
Goto inicio
End                                               

prog:
Lcdcmdout LcdClear

WaitMs 200
'T1CON.TMR1ON = 0  'lo apago para prgramar
While enter = 1
'Lcdcmdout LcdClear
Lcdcmdout LcdLine1Home
Lcdout "MANGUERA 1  " #tempp(0), "       "
If sube = 0 Then tempp(0) = tempp(0) + 1
If baja = 0 Then tempp(0) = tempp(0) - 1
WaitMs 100
Wend
'++++++++++++++++++++++++++++++++++++++++

WaitMs 200
Lcdcmdout LcdClear
While enter = 1
'Lcdcmdout LcdClear
Lcdcmdout LcdLine1Home
Lcdout "PISTOLA 1  " #tempp(1), "        "
If sube = 0 Then tempp(1) = tempp(1) + 1
If baja = 0 Then tempp(1) = tempp(1) - 1
WaitMs 100
Wend
'''+++++++++++++++++++++++++++++++++++++++

WaitMs 200
Lcdcmdout LcdClear
While enter = 1
'Lcdcmdout LcdClear
Lcdcmdout LcdLine1Home
Lcdout "MANGUERA 2  " #tempp(2), "       "
If sube = 0 Then tempp(2) = tempp(2) + 1
If baja = 0 Then tempp(2) = tempp(2) - 1
WaitMs 100
Wend
'+++++++++++++++++++++++++++++++++++++++++++++++++

WaitMs 200
Lcdcmdout LcdClear
While enter = 1
'Lcdcmdout LcdClear
Lcdcmdout LcdLine1Home
Lcdout "PISTOLA  2  " #tempp(3), "        "
If sube = 0 Then tempp(3) = tempp(3) + 1
If baja = 0 Then tempp(3) = tempp(3) - 1
WaitMs 100
Wend
'+++++++++++++++++++++++++++++++++++++++++++++++++++

WaitMs 200
Lcdcmdout LcdClear
While enter = 1
'Lcdcmdout LcdClear
Lcdcmdout LcdLine1Home
Lcdout "MANGUERA 3  " #tempp(4), "      "
If sube = 0 Then tempp(4) = tempp(4) + 1
If baja = 0 Then tempp(4) = tempp(4) - 1
WaitMs 100
Wend
'+++++++++++++++++++++++++++++++++++++++++++++++++++

WaitMs 200
Lcdcmdout LcdClear
While enter = 1
'Lcdcmdout LcdClear
Lcdcmdout LcdLine1Home
Lcdout "PISTOLA 3  " #tempp(5), "        "
If sube = 0 Then tempp(5) = tempp(5) + 1
If baja = 0 Then tempp(5) = tempp(5) - 1
WaitMs 100
Wend
'+++++++++++++++++++++++++++++++++++

WaitMs 200
Lcdcmdout LcdClear
While enter = 1
'Lcdcmdout LcdClear
Lcdcmdout LcdLine1Home
Lcdout "MANGUERA 4  " #tempp(6), "       "
If sube = 0 Then tempp(6) = tempp(6) + 1
If baja = 0 Then tempp(6) = tempp(6) - 1
WaitMs 100
Wend
'++++++++++++++++++++++++++++++++++++++++++++

WaitMs 200
Lcdcmdout LcdClear
While enter = 1
'Lcdcmdout LcdClear
Lcdcmdout LcdLine1Home
Lcdout "PISTOLA 4  " #tempp(7), "        "
If sube = 0 Then tempp(7) = tempp(7) + 1
If baja = 0 Then tempp(7) = tempp(7) - 1
WaitMs 100
Wend
'+++++++++++++++++++++++++++++++++++++++++++
'++++++++++++++++++++++++++++++++++++++++++++++

Hserout #tempp(0), #tempp(1), #tempp(2), #tempp(3), #tempp(4), #tempp(5), #tempp(6), #tempp(7), Lf, CrLf
WaitMs 200
Goto inicio
Return                                           
End                                               



On Interrupt
Save System
If RCSTA.1 = 1 Then

   RCSTA.CREN = 0  'Disable
   Hserget papelera  'Limpia bufer Uart
   Hserget papelera
   Hserget papelera
   RCSTA.CREN = 1
Endif
If PIR1.5 = 1 Then
Hserget templ(indice)
indice = indice + 1
Endif
If indice < 7 Then  'indice = 0


Hserout #tempp(indice), CrLf
Else
indice = 0
Endif


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'Endif  ''''''''''''''''''''''''''''''''''''''''''''''
Resume                                           
'+++++++++++++++++++++++++++++++++


'''''''''''''''''''''''''''''''''''
End                                               
no hay nada que hacer , el tipo sigue sin andar,puede ser mas ayuda?












Desconectado dogflu66

  • Moderador Local
  • DsPIC30
  • *****
  • Mensajes: 3549
Re:problema con la uart
« Respuesta #6 en: 23 de Abril de 2016, 08:57:34 »
Este es el mismo que el tuyo pero adaptado a mi hardware y funciona OK:

Código: Visual Basic
  1. 'Practicas con RS232_20160423
  2. 'Pic Simulator IDE, v7.41
  3. 'Pic16F88
  4. '------------------------------------------
  5. Define CONFIG = 0x2f50
  6. Define CONFIG2 = 0x3ffc
  7. Define CLOCK_FREQUENCY = 8
  8. 'Define SIMULATION_WAITMS_VALUE = 1
  9. 'Config LCD -----------------------------
  10. Define LCD_BITS = 4  'Indicamos que el bus de datos del lcd sera de 4bit
  11. Define LCD_DREG = PORTA  'Bus de datos sera el puerto A
  12. Define LCD_DBIT = 0  'Bus de datos seran los 4 bit menos significativos del puerto A
  13. Define LCD_RSREG = PORTB  'Bit de control RS sera del puerto B
  14. Define LCD_RSBIT = 7  'Se usara el RB7 como RS
  15. Define LCD_EREG = PORTB  'Bit de control E sera del puerto B
  16. Define LCD_EBIT = 6  'Se usara el RB6 como E
  17. Define LCD_COMMANDUS = 2000  'Tiempo de espera despues de ejecutar un comando del lcd en uSeg.
  18. Define LCD_DATAUS = 50  'Tiempo de espera despues de enviar un dato al LCD en uSeg.
  19. Define LCD_INITMS = 50  'Tiempo de espera despues de inicializar el Display.
  20. '--------------------------------------------
  21. AllDigital
  22. CMCON = 0x07  'Comparador a off
  23. OSCCON = 0x7e  'Reloj interno a 8Mhz
  24. TRISA = 0xff
  25. TRISB = 0xff
  26. OPTION.7 = 0  'Pullup
  27. 'Configuración puerto serie ---------
  28. TRISB.5 = 0  'Como salida(RB5,Tx RS232)
  29. TRISB.2 = 1  'Como entrada (RB2, Rx RS232)
  30. Hseropen 9600  'Velocidad del puerto serie, configura Usart
  31. Dim paso As Byte  'Inc para seleccionar donde guarda el dato recibido
  32. paso = 0
  33. Dim papelera As Byte
  34. RCSTA.CREN = 0  'Disable
  35. Hserget papelera  'Limpia bufer Uart
  36. Hserget papelera
  37. Hserget papelera
  38. RCSTA.CREN = 1  'Enable, Continuous Receive Enable bit*/
  39. '------------------------------------
  40. 'Activa puerto LCD
  41. Lcdinit
  42. Lcdout "Ready"
  43. 'Control LCD
  44. Dim cambio As Byte
  45. cambio = 1
  46. 'Interrupciones
  47. PIE1.RCIE = 1  'Activa la interrup. de la usart en modo rx*/
  48. INTCON.PEIE = 1  'Bit habilita interrupciones perifericos
  49. Enable  'INTCON.GIE habilita las interrupciones globales
  50. '------------------------------------
  51. 'Variables que toman en estado actual de la temperatura
  52. Dim tcero As Byte
  53. Dim tuno As Byte
  54. Dim tdos As Byte
  55. Dim ttres As Byte
  56. Dim tcuatro As Byte
  57. Dim tcinco As Byte
  58. Dim tseis As Byte
  59. Dim tsiete As Byte
  60. Dim tocho As Byte
  61. Dim tnueve As Byte
  62. Dim tdiez As Byte
  63. Dim tonce As Byte
  64. Dim tdoce As Byte
  65. Dim ttrece As Byte
  66. WaitMs 3000
  67. 'Subrutina principal -------------------------------------
  68. main:
  69.         If cambio = 1 Then
  70.                 Lcdcmdout LcdLine1Home
  71.                 Lcdout #tuno
  72.                 Lcdout " ", #tdos
  73.                 Lcdout " ", #ttres
  74.                 Lcdout " ", #tcuatro, "    "
  75.         Endif
  76.         '-----------------------------------------------------
  77.         WaitMs 200
  78.         If cambio = 1 Then
  79.                 Lcdcmdout LcdLine2Home
  80.                 Lcdout #tcinco
  81.                 Lcdout " ", #tseis
  82.                 Lcdout " ", #tsiete
  83.                 Lcdout " ", #tocho, "    "
  84.         Endif
  85.         WaitMs 200
  86. Goto main
  87. End                                              
  88. 'Subrutinas y funciones
  89. '*****************************************
  90. On Interrupt
  91. Save System
  92.         If PIR1.RCIF = 1 Then
  93.                 paso = paso + 1
  94.                 '------------------------------------------
  95.                 If paso = 1 Then Hserget tuno
  96.                 If paso = 2 Then Hserget tdos
  97.                 If paso = 3 Then Hserget ttres
  98.                 If paso = 4 Then Hserget tcuatro
  99.                 If paso = 5 Then Hserget tcinco
  100.                 If paso = 6 Then Hserget tseis
  101.                 If paso = 7 Then Hserget tsiete
  102.                 If paso = 8 Then Hserget tocho
  103.                 '------------------------------------------
  104.                 If paso >= 8 Then paso = 0  'Si envio ocho datos salgo
  105.         Endif
  106. Resume
Saludos desde Granada, España.

Desconectado dogflu66

  • Moderador Local
  • DsPIC30
  • *****
  • Mensajes: 3549
Re:problema con la uart
« Respuesta #7 en: 23 de Abril de 2016, 09:15:38 »
Esta otra forma es igual pero más amigable a la hora de hacer cambios:

Código: Visual Basic
  1. 'Practicas con RS232_20160423
  2. 'Pic Simulator IDE, v7.41
  3. 'Pic16F88
  4. '------------------------------------------
  5. Define CONFIG = 0x2f50
  6. Define CONFIG2 = 0x3ffc
  7. Define CLOCK_FREQUENCY = 8
  8. 'Define SIMULATION_WAITMS_VALUE = 1
  9. 'Config LCD -----------------------------
  10. Define LCD_BITS = 4  'Indicamos que el bus de datos del lcd sera de 4bit
  11. Define LCD_DREG = PORTA  'Bus de datos sera el puerto A
  12. Define LCD_DBIT = 0  'Bus de datos seran los 4 bit menos significativos del puerto A
  13. Define LCD_RSREG = PORTB  'Bit de control RS sera del puerto B
  14. Define LCD_RSBIT = 7  'Se usara el RB7 como RS
  15. Define LCD_EREG = PORTB  'Bit de control E sera del puerto B
  16. Define LCD_EBIT = 6  'Se usara el RB6 como E
  17. Define LCD_COMMANDUS = 2000  'Tiempo de espera despues de ejecutar un comando del lcd en uSeg.
  18. Define LCD_DATAUS = 50  'Tiempo de espera despues de enviar un dato al LCD en uSeg.
  19. Define LCD_INITMS = 50  'Tiempo de espera despues de inicializar el Display.
  20. '--------------------------------------------
  21. AllDigital
  22. CMCON = 0x07  'Comparador a off
  23. OSCCON = 0x7e  'Reloj interno a 8Mhz
  24. TRISA = 0xff
  25. TRISB = 0xff
  26. OPTION.7 = 0  'Pullup
  27. 'Configuración puerto serie ---------
  28. TRISB.5 = 0  'Como salida(RB5,Tx RS232)
  29. TRISB.2 = 1  'Como entrada (RB2, Rx RS232)
  30. Hseropen 9600  'Velocidad del puerto serie, configura Usart
  31. Dim paso As Byte  'Inc para seleccionar donde guarda el dato recibido
  32. paso = 0
  33. '------------------------------------
  34. 'Activa puerto LCD
  35. Lcdinit
  36. Lcdout "Ready"
  37. 'Control LCD
  38. Dim cambio As Byte
  39. cambio = 1
  40. 'Interrupciones
  41. PIE1.RCIE = 1  'Activa la interrup. de la usart en modo rx*/
  42. INTCON.PEIE = 1  'Bit habilita interrupciones perifericos
  43. Enable  'INTCON.GIE habilita las interrupciones globales
  44. '------------------------------------
  45. 'Variables que toman en estado actual de la temperatura
  46. Dim temp(15) As Byte
  47. Dim n As Byte
  48. For n = 0 To 14
  49.         temp(n) = 0
  50. Next n
  51. WaitMs 3000
  52. 'Subrutina principal -------------------------------------
  53. main:
  54.         If cambio = 1 Then
  55.                 Lcdcmdout LcdLine1Home
  56.                 For n = 1 To 4
  57.                         Lcdout #temp(n), " "
  58.                 Next n
  59.                 Lcdout "    "
  60.         Endif
  61.         '-----------------------------------------------------
  62.         WaitMs 200
  63.         If cambio = 1 Then
  64.                 Lcdcmdout LcdLine2Home
  65.                 For n = 5 To 8
  66.                         Lcdout #temp(n), " "
  67.                 Next n
  68.                 Lcdout "    "
  69.         Endif
  70.         WaitMs 200
  71. Goto main
  72. End                                              
  73. 'Subrutinas y funciones
  74. '*****************************************
  75. 'Control bloqueo del buffer hardware usart Rx
  76. error_buffer:
  77. Dim papelera As Byte
  78.         RCSTA.CREN = 0  'Disable
  79.         Hserget papelera  'Limpia bufer Uart
  80.         Hserget papelera
  81.         Hserget papelera
  82.         RCSTA.CREN = 1  'Enable, Continuous Receive Enable bit*/
  83. Return                                            
  84. '------------------------------------------------------
  85. On Interrupt
  86. Save System
  87.         If PIR1.RCIF = 1 Then
  88.                 paso = paso + 1
  89.                 '------------------------------------------
  90.                 Hserget temp(paso)
  91.                 '------------------------------------------
  92.                 If paso >= 8 Then paso = 0  'Si envio ocho datos salgo
  93.                 If RCSTA.OERR = True Then Gosub error_buffer
  94.         Endif
  95. Resume
Saludos desde Granada, España.

Desconectado WALTER ALEJANDRO

  • PIC12
  • **
  • Mensajes: 64
Re:problema con la uart
« Respuesta #8 en: 23 de Abril de 2016, 15:04:07 »
quizas alguna pata del 16f877a me este haciendo una jugarreta,viste que en algunos pics cuando usas el timer 1 algunas patas solo se pueden usar como entradas,voy a probar el mismo programa con el 16f88 y vere que pasa,pero mejos el lunes.Un abrazo

Desconectado WALTER ALEJANDRO

  • PIC12
  • **
  • Mensajes: 64
Re:problema con la uart
« Respuesta #9 en: 27 de Abril de 2016, 16:49:20 »
hola , lo hice con el 16f88 y funciona de maravillas,gracias x tu tiempo y conocimiento. Un abrazo desde Argentina


 

anything