Autor Tema: I2C CON PROTON IDE  (Leído 8255 veces)

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

Desconectado krizpin

  • PIC10
  • *
  • Mensajes: 32
I2C CON PROTON IDE
« en: 05 de Enero de 2015, 08:49:21 »
Holas a todos.
Queria pedir ayuda a ver si por favor alguien me puede explicar que comandos usar para trabajar con i2c.
yo uso proton y en el manual veo que puedo usar tanto el comando busin como el hbusin ,busout y hbusout y tambien la declaraciones
Declare SDA_Pin = PORTC.4
Declare SCL_Pin =PORTC.3
 pero no se cuando debo usar unas u otras ni tampoco si hay que usar las declaraciones. Por favor me puede decir alguien como se programa??
muchas gracias

Desconectado RALF2

  • Moderador Local
  • PIC24H
  • *****
  • Mensajes: 2062
Re: I2C CON PROTON IDE
« Respuesta #1 en: 05 de Enero de 2015, 12:25:02 »
Tal como te lo indica el manual, todo dependera si quieres utilizar el I2C por hardware (hbusin) o por software (busin), si piensas usar o no interrupciones entre otras.
Si tu micro tiene i2c por hardware y piensas usar interrupciones hsbusin es la opcion, pero si no piensas utilizar interrupciones y/o tu pic no posee i2c por hardware podrias usar busin.  :mrgreen:


Saludos

Desconectado krizpin

  • PIC10
  • *
  • Mensajes: 32
Re: I2C CON PROTON IDE
« Respuesta #2 en: 06 de Enero de 2015, 08:21:05 »
Muchas gracias por la respuesta. se trata de un 16f877 asi que aunque no tengo pensado usar interrupciones usare hbusin etc. Muchas gracias. un saludo

Desconectado RALF2

  • Moderador Local
  • PIC24H
  • *****
  • Mensajes: 2062
Re: I2C CON PROTON IDE
« Respuesta #3 en: 06 de Enero de 2015, 12:48:11 »
Ok krizpin el proton es por mucho, para mi, el mejor compilador en basic para pic  :mrgreen:
y con la ultima version 3.5.7.1 mejor aun!  :mrgreen:

Saludos

Desconectado krizpin

  • PIC10
  • *
  • Mensajes: 32
Re: I2C CON PROTON IDE
« Respuesta #4 en: 16 de Febrero de 2015, 05:16:32 »
Buenas...
He programado algo en i2c y me pasa algo curioso que no comprendo. usando un 16f877 y las lineas sda y scl si uso las instrucciones busin,bstart etc el programa corre bien pero si uso el i2c por hardware con comandos hbusin ,hbstart etc en programa hace cosas muy raras y no funciona... no entiendo porque ocurre esto..

Desconectado RALF2

  • Moderador Local
  • PIC24H
  • *****
  • Mensajes: 2062
Re: I2C CON PROTON IDE
« Respuesta #5 en: 16 de Febrero de 2015, 11:41:22 »
Estas conectando las resistencias del pull up en SDA y SCL?
Si es asi coloca el codigo que estas utilizando para poderte ayudar mejor  :mrgreen:

Saludos

Desconectado krizpin

  • PIC10
  • *
  • Mensajes: 32
Re: I2C CON PROTON IDE
« Respuesta #6 en: 16 de Febrero de 2015, 20:59:23 »
'****************************************************************
'*  Name    : UNTITLED.BAS                                      *
'*  Author  : PABLO DOMINGUEZ SUAREZ                            *
'*  Notice  : Copyright (c) 2014                                *
'*          : All Rights Reserved                               *
'*  Date    : 20/08/2014                                        *
'*  Version : 1.0                                               *
'*  Notes   : INSOLADORA LED SMD 5050                           *
'*          :                                                   *
'****************************************************************
Device = 16F877A
Xtal 8
Declare Reminders = Off        'Los errores o avisos que pueda haber entre reminders off y on son ignoradas y no se muestran como aviso
Config CP_OFF, DEBUG_OFF, WRT_OFF, CPD_OFF, LVP_OFF, BODEN_OFF, PWRTE_OFF, WDT_ON, HS_OSC
Declare Reminders = On
Declare LCD_Type 0
Declare LCD_DTPin PORTD.4
Declare LCD_RSPin PORTC.7
Declare LCD_ENPin PORTC.6
Declare LCD_Lines 2
Declare SDA_Pin PORTC.4
Declare SCL_Pin PORTC.3
Declare Slow_Bus no
All_Digital true     'COMPARADORES ANALOGICOS Y CONVERTIDOR A/D DESACTIVADOS
Dim seg As Byte
Dim minu As Byte
Dim hora As Byte
Dim semana As Byte
Dim dia As Byte
Dim mes As Byte
Dim anio As Byte
Dim temperatura As Byte
Dim temperatura1 As Byte
Dim temp1 As Byte
Dim temp2 As Byte
Dim temp As Byte
Dim x As Bit                    'bit para cambiar de formato 12/24H
Dim rebote As Bit
Dim posicion As Byte
Dim contador As Byte
Dim rhora As Bit
Dim rselec As Bit
Symbol leeclock=%11010001       '4 bits de mas peso indican la direccion fisica del RTC,el primer bit de menos peso"1" indica modo lectura
Symbol grabaclock=%11010000     '4 bits de mas peso indican la direccion fisica del RTC,el primer bit de menos peso"0" indica modo grabacion
Symbol formato=PORTE.2
Symbol selec=PORTE.1
TRISA = 0
TRISB = 0
TRISC = 0
TRISD = 0
TRISE = 1
'********************************
PORTA = 0
PORTB = 0
PORTC = 0
PORTD = 0
PORTE = 0
DelayMS 10
Cls
x=0
rebote=0
posicion=0
rselec=0
inicio:
'ESTABLECEMOS EL TIEMPO A MOSTRAR AL INICIO DEL PROGRAMA
        seg=00
        temp=seg
        GoSub BIN_TO_BCD
        seg=temp
        minu=20
        temp=minu
        GoSub BIN_TO_BCD         'Convertimos todos los datos decimales en BCD para posteriormente grabarlos en la memoria del ds3231
        minu=temp
        hora=3
        temp=hora
        GoSub BIN_TO_BCD
        hora=temp
        semana=4
        temp=semana
        GoSub BIN_TO_BCD
        semana=temp
        dia=5
        temp=dia
        GoSub BIN_TO_BCD
        dia=temp
        mes=2
        temp=mes
        GoSub BIN_TO_BCD
        mes=temp
        anio=15
        temp=anio
        GoSub BIN_TO_BCD
        anio=temp
configura:
        BStart
        BusOut grabaclock,14,[%00011100]         '%11010000 "ES LA DIRECCION DE CONTROL" EL ULTIMO "0" INDICA ESCRITURA,PARA LEER PONEMOS "1"
        DelayMS 15                               '14 EN DECIMAL ES LA DIRECCION DE MEMORIA DONDE ESCRIBIMOS
        BStop
        BStart
        BusOut grabaclock,$0h,[seg,minu,hora,semana,dia,mes,anio] 'SEG,MIN,HORAS:IMPORTANTE**ESTAN EN CODIGO BCD ,NO EN CODIGO BINARIO(01010101=55) OSEA 0101=5 0101=5 :->55
        DelayMS 15
        BStop   
       
'INICIO DE LA LECTURA DEL RELOJ       
 
Leer_tiempo:
        BStart
        BusIn leeclock,0,[seg,minu,hora,semana,dia,mes,anio]                    'ESTABLECEMOS EN LA DIRECCION QUE VAMOS A LEER"11010001", "0" LEEMOS DE LA POSICION CERO DEL REGISTRO QUE ES LA LECTURA DE LOS SEG
        DelayMS 15                               ' Y "T" LA VARIABLE DONDE ALMACENAMOS EL VALOR DE LA LECTURA (OJO VALOR EN BCD)
        BStop
        BStart
        BusIn %11010001,$11h,[temperatura]        'VALOR ENTERO
        DelayMS 15
        BStop
        BStart
        BusIn %11010001,$12h,[temperatura1]       'VALOR DECIMAL
        DelayMS 15
        BStop
        '*****AHORA CONVERTIMOS TODAS LAS LECTURAS QUE ESTAN EN BCD A BINARIO PARA PODER MOSTRARLAS POSTERIORMENTE EN VALOR DECIMAL EN EL LCD
        temp=seg
        GoSub BCD_TO_BIN
        seg=temp
        temp=minu
        GoSub BCD_TO_BIN
        minu=temp
        temp=hora
        GoSub BCD_TO_BIN
        hora=temp
        temp=semana
        GoSub BCD_TO_BIN
        semana=temp
        temp=dia
        GoSub BCD_TO_BIN
        dia=temp
        temp=mes
        GoSub BCD_TO_BIN
        mes=temp
        temp=anio
        GoSub BCD_TO_BIN
        anio=temp
Leer_temperatura:
        temperatura1=temperatura1>>6     'DS3231 TIENE UNA RESOLUCION DE 0.25ºC.ESTA ALOJADO EN LAS POSICIONES 6 Y 7,OSEA BIT 6 Y 7.POR LO TANTO DESPLAZAMOS LOS BIT 6 POSICIONES
        temperatura1=(temperatura1*25)   'PARA COLOCAR ESOS BIT EN LA POSICION 0 Y 1.LUEGO MULTIPLICAMOS POR 25 QUE ES LA RESOLUCION.MULTIPLICAMOS POR EL NUMERO ENTERO Y NO POR 0.25 PORQUE
        temperatura1=Dig temperatura1,1  'AL MOSTAR EN EL LCD MOSTRAMOS EN VALOR EN ENTERO,LUEGO UN PUNTO"."Y DESPUES EL VALOR DECIMAL COMO SI FUESE UN ENTERO.POR ULTIMO COGEMOS EL SEGUNDO NUMERO
      '  GoSub lcd                        'CON EL COMANDO DIG PARA MOSTRAR SOLO 1 NUMERO Y NO LOS 2.OSEA SI EL VALOR MEDIDO FUESE 50.SOLO MOSTRAMOS EL 5
       ' GoSub lcd

'cambio_hora:                             'cambio de formato 12/24H
'        If formato=1 And rebote=0 Then Toggle x:rebote=1
'        If x=0 And hora>=12 Then hora=hora-12    '*******AÑADIR ESTA LINEA SI QUEREMOS MOSTRAR LA HORA EN FORMATO 12H Y NO EN 24H
'       ' If x=0 And hora>=0 Then hora=hora+12
'        If hora=24 then hora=0                   'TENER EN CUENTA QUE POR DEFECTO ESTA CONFIGURADO EL REGISTRO PARA CONTAR EN FORMATO 24H
'        If formato=0 Then rebote=0
'        'Return
                GoSub lcd
                If selec=1 Then GoSub horas
         GoTo Leer_tiempo       

         
horas: 
        Cursor 1,6
        Print $FE,$0F     
        hora=hora+1
        temp=hora
        GoSub BIN_TO_BCD
        hora=temp
        BStart
        BusOut grabaclock,$2h,[hora]
        DelayMS 15
        BStop
rhoras:
        DelayMS 15
        If selec=1 Then rhoras
t:
        If selec=0 Then t
        Print $FE, $0C
GoTo Leer_tiempo

       
'******************************************************
BCD_TO_BIN:                         ' Convert the BCD values into BIN
        temp=((temp>>4)*10+(temp&%1111))
       ' seg=((seg>>4)*10+(seg&$0f))       'CUALQUIERA DE LAS 3 FORMAS ES VALIDA ,SOLO CAMBIAMOS EL VALOR FINAL EN DECIMAL,BIN Y HEX $0F
        'seg=((seg>>4)*10+(seg&15))
      '  hora=hora^%01000000)
        Return
'******************************************************
BIN_TO_BCD:
                            'EJEMPLO SI EL VALOR FUESE 42  "DIG (VALOR)"
temp1 = Dig temp, 0         '00000010    '10=2   COGEMOS EL DECIMAL EN LA POSICION CERO.OSEA EL 2
temp2 = Dig temp, 1         '00000100   '100=4  AHORA COGEMOS EL DECIMAL EN LA SEGUNDA POSICION OSEA EL 4
temp2 = temp2 << 4          '01000000   EL 4 EN BINARIO ES = A 100,DESPLAZAMOS 4 BIT A LA IZQUIERDA Y NOS QUEDA 1000000
temp = temp1 ^ temp2        ' XOR THEM TOGTHER TO MAKE THE WHOLE BCD NUMBER     YA TENEMOS EL CODIGO EN BCD
Return

lcd:
'        Cursor 1,6                      'COLOCA EL CURSOR EN LA LINEA 1 Y EN LA POSICION 5
'        Print $FE,$0F:DELAYMS 700
'        Print $FE, $0C
   ' Print At 1,6,$FE,$0F
       
        Print $FE,$48,$00,$00,$00,$00,$00,$00,$00,$1F
        Print $FE,$40,$1E,$12,$12,$1E,$00,$00,$00,$00        'SIMBOLO DE GRADOS C
        Print At 1,17,1
        Print At 1,5,Dec2 hora,":",Dec2 minu,":",Dec2 seg," "
        Print At 2,1,Dec2 dia,"/",Dec2 mes,"/",Dec2 anio,"  ",Dec temperatura,".",Dec1 temperatura1,0,"C"
Return
End

Desconectado krizpin

  • PIC10
  • *
  • Mensajes: 32
Re: I2C CON PROTON IDE
« Respuesta #7 en: 16 de Febrero de 2015, 21:02:38 »
Buenas el programa esta sin terminar ,lo tengo asi para ir probando cosas pero bueno mostrar el tiempo lo muestra bien. el caso es que segun tengo el codigo si cambio las instrucciones busin, bstart etc por hbusin,hbstart ..... no me funciona nada de nada y el lcd se vuelve loco. las resistencias pull up no las coloco porque vienen integradas creo en el rtc que compre que es uno ensamblado para arduino.

Desconectado RALF2

  • Moderador Local
  • PIC24H
  • *****
  • Mensajes: 2062
Re: I2C CON PROTON IDE
« Respuesta #8 en: 16 de Febrero de 2015, 23:36:33 »
Cuando utilizas el Hbusin y el Hbusout, debes configurar el: Declare Hserial_RCSTA el Declare Hserial_TXSTA.
Revisa si con eso se resuelve el problema.

Desconectado jansuini

  • Moderador Local
  • PIC24F
  • *****
  • Mensajes: 566
Re: I2C CON PROTON IDE
« Respuesta #9 en: 17 de Febrero de 2015, 10:53:17 »
Buenas:
Cuando yo he necesitado probar alguna rutina que tengo dudas ,lo que hago es compilar esarutina y el HEX cargarlo en PICSIMULATORIDE ,luego con el osciloscopio que trae picsimulator veo el comportamiento del micro .-
Directamente lo hago con la versión demo del picsimulatoride.-
Sds.
Jorge

Desconectado krizpin

  • PIC10
  • *
  • Mensajes: 32
Re: I2C CON PROTON IDE
« Respuesta #10 en: 17 de Febrero de 2015, 19:47:47 »
Ok compañeros.Seguire vuestros consejos y probare a ver que pasa :-)


 

anything