Autor Tema: Problemas con ds1307 y pbp  (Leído 2846 veces)

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

Desconectado psicowifi

  • PIC12
  • **
  • Mensajes: 56
Problemas con ds1307 y pbp
« en: 28 de Marzo de 2011, 18:34:22 »
e posteado esto anteriormente pero no e logrado solucion alguna en aquella oportunidad y estoy retomando el tema del 1307 a ver si me saco el clavo ese.

tengo una variables
hora=11
min=21
seg=00
dia=12
mes=03
año=11
como hago para meter correctamente esos datos en el ds1307 y que el mismo los tome correctamente.

e trabajado metiendole los datos directamente con
rtchour = $10
etc etc
y ese si perfecto pero con la modalidad de pasar el dato desdde una variable nada que ver uso picbasic
alguien sabe como o un ejemplo saludos

Desconectado yesbond

  • PIC10
  • *
  • Mensajes: 11
Re: Problemas con ds1307 y pbp
« Respuesta #1 en: 11 de Abril de 2011, 23:51:12 »
Hola psicowifi ,

Cuando configuras el ds1307 con rtchour = $10 estas enviando un 10 en formato herxadecimal; pero al enviar la variable por ejemplo hora = 11 lo estas haciendo en formato decimal.
Puedes hacer que la variable se guarde el dato en formato hexadecimal, o puedes probar ha hacer la conversion dedecimal a hexa y asi seguramente te podra funcionar correctamente.

Saludos

Yesbond

Desconectado scrwld

  • PIC12
  • **
  • Mensajes: 56
Re: Problemas con ds1307 y pbp
« Respuesta #2 en: 17 de Mayo de 2011, 12:18:07 »
hola psicowifi: esto es lo hago

fecha var byte[8]

;************************  escritura reloj ds1307 ************************************************
'i2cwrite sda,scl,$d0,$00,[$00,$55,$01,$02,$02,$05,$211,$90]-->   fecha[7] ------> registro configura salida clock pin 7
'                       |   |  |    |   |   |  |   |------->     año 211= 2011      fecha[6]
'                       |   |  |    |   |   |  |----------->    mes                      fecha[5]
'                       |   |  |    |   |   |-------------->    dia= 2                  fecha[4]
'                       |   |  |    |   |------------------>   nombre del dia      fecha[3]
'                       |   |  |    |---------------------->  hora                     fecha[2]
'                       |   |  |---------------------------> minutos                 fecha[1]
'                       |   |------------------------------> segundos              fecha[0]
'                       |----------------------------------> direcion primer registro en ds1307

'************************************************************************************************
'conviertye de decimal a bcd y luego lo escribes al reloj registro por registro
' o guardas en el array fecha los valores convertidos y luego envias todo al ds1307

'convierto a bcd
fecha[0]=((segundo / 10) << 4) + (segundo // 10)
.
.
.
.
.
.
fecha[6]= ((año / 10) << 4) + (año // 10)

i2cwrite sda,scl,$d0,$00,[fecha[0],fecha[1],fecha[2],fecha[3],fecha[4],fecha[5],fecha[6],fecha[7]]


;************************ lectura reloj ds1307 *************************************************

i2cread sda,scl,$d1,$00,[str fecha\8]

'los datos leidos estan en bcd debes convertir a decimales

segundos= (fecha[0]>>4)*10+(fecha[0] & $0f)

'repetir lo anterior por cada valor leido en fecha


saludos


Desconectado Noelillo

  • PIC12
  • **
  • Mensajes: 94
Re: Problemas con ds1307 y pbp
« Respuesta #3 en: 13 de Julio de 2011, 06:49:27 »
'****************************************************************
'*  Name    : RelTerm.BAS                                       *
'*  Author  : Miguel Noe Garcia Perez                           *
'*  Notice  : Copyright (c) 2010 Iberica 2000                   *
'*          : All Rights Reserved                               *
'*  Date    : 09/03/2010                                        *
'*  Version : 1.0                                               *
'*  Notes   : Reloj Termometro                                  *
'*          :                                                   *
'****************************************************************
 
          Device 16F877a
        XTAL = 4
' LCD pin Configuracion
        lcd_type = 0
        LCD_LINES = 4
        LCD_DTPIN = PORTb.4
        LCD_RSPIN = PORTb.3
        LCD_ENPIN = PORTb.2
        LCD_INTERFACE = 4
       
       
       
       
         SCL_PIN   = PORTC.3
         SDA_PIN   = PORTC.4   
       
'***************************************************************************************
          Cls                        ' Clear LCD
        ALL_DIGITAL = True            ' Set ports to digital mode
        Clear                     ' Clear buffers
'******************************************************************************************
'*********************  SIMBOLOS DEL PROGRAMA *********************************************
'******************************************************************************************   
    Symbol DQ = PORTB.1 ' Pin de conexión 1-Wire®
    Symbol Seg = 0 ' Registro de Seg.
    Symbol Minu = 1 ' Registro de Min.
    Symbol Hora = 2 ' Registro de Horas
    Symbol Dia = 3 ' Registro de Día
    Symbol Dias = 4 ' Registro de Día
    Symbol Mes = 5 ' Registro de Mes
    Symbol Ano = 6 ' Registro de Año
    Symbol Control = 7
    Symbol SW1   =    PORTb.4 ' Interruptor Set
    Symbol SW2   =    PORTB.5 ' Interruptor Incre
    Symbol SW3   =    PORTB.6 ' Interruptor Intro
    Symbol SW4   =    PORTB.7 ' Interruptor Extra









'*******************************************************************************************
'*************************** VARIABLES A$ **************************************************
'*******************************************************************************************
    Dim Index As Byte        ' Variable de uso general
    Dim ROMCODE[8] As Byte   ' Arreglo almacena el serial
    Dim SERIAL[8] As Byte    ' Arreglo almacena serial
    Dim X As Word
    Dim Contador As Word
    Dim TEMPERATURA As Word  ' Variable alm. temperatura
    Dim FL_TEMP As Float     ' Variable alm. temperatura
     'Dim FL_TEMP As word    ' Variable alm. temperatur

    DIM Cifra as byte 
    Dim Sign as Byte
    Dim Cnt as Byte
    Dim Count_Per_Deg as Byte
    Dim Temp as Word
    Dim Temp_Dec as Byte
    DIM Puntero AS BYTE


    Dim RTC[8] As Byte ' Vector almacenamiento
    'Dim Index As Byte ' Variable uso general
    dim Btnvar     as byte ' Pulsadores
    dim Horas   as byte
    dim Minutos as Byte
    dim Day     As Byte
    dim Days    As Byte
    dim Meses   As Byte
    Dim Anos    As Byte



'**************************************************************************************
'************************* P R E S E N T A C I O N ************************************
'**************************************************************************************

'**************************************************************************************
'******************************* TERMOMETRO *******************************************
'**************************************************************************************
 MAIN:
    GoSub Conversion ' Rutina convertir Temperatura
    GoSub Mostrar ' Rutina mostrar los valores
    DelayMS 500
    'Gosub Text
    GoTo Main
    End
 Conversion2:
    OWrite DQ,1,[$44] ' Comando Convertir Temp
    High DQ ' DQ en alto por 750 ms
'******************* Tiempo de Conversion ************************
    DelayMS 200 'Nota: Para el DS 1820 200 ms y para el DS 18S20 750 ms
    OWrite DQ,1,[$CC,$BE] ' Comando leer SCRATCHPAD.
    ORead DQ,0,[TEMP.LowByte,TEMP.HighByte]
    Return

Conversion:
    OWrite DQ,1,[$CC,$44] ' Comando Convertir Temp
    'gosub Resete
    High DQ ' DQ en alto por 750 ms
'******************* Tiempo de Conversion ************************
    'DelayMS 200 'Nota: Para el DS 1820 200 ms y para el DS 18S20 750 ms
    OWrite DQ,1,[$CC,$BE] ' Comando leer SCRATCHPAD.
    'ORead DQ,0,[TEMP.LowByte,TEMP.HighByte]
    OREAD DQ,2,[Temp.LOWBYTE,Temp.HIGHBYTE,Cnt,Cnt,Cnt,Cnt,Cnt,Count_Per_Deg] 'Lee el scratchpad
    Return

Mostrar:
 Temp_Dec = (6.25 * Cnt)
    'Signo:   
    If Temp.8=1 Then
    Temp=(Temp.LowByte ^ $FF) >> 1
    If Cnt = 0 then Temp = Temp + 1
    Sign = "-"
    Else
   Temp=(Temp >> 1)
   Sign = " "             
   Temp_Dec = 100 - Temp_Dec                             
   Endif
     
 
   
    cls
    Print at 1,1, "T",Sign, Dec Temp,".", Dec DIG Temp_Dec,1
    'Print at 2,1, "T= ",dec TEMPERATURA

'Return

        cls
    GoSub RTC_INI ' Inicilizar el RTC
 
   
   
    GoSub FECHA_INI ' Cargar Fecha inicial
'    DelayMS 500 ' Retardo 500ms
Loop:
    GoSub LEER_RTC ' Leer registros RTC
    GoSub MOSTRAR_RTC ' Mostrat registros RTC
    gosub Pulsadores
    'DelayMS 1000
GoTo Loop

End

RTC_INI:
    BusIn $D1,0,[RTC[Seg]] ' Lee byte 0, RTC
    BusOut $D0,0,[RTC[Seg] & $7F] ' Pone 0 en bit CH
Return ' Para Activar RTC
     
   
FECHA_INI:
    RTC[Seg] =   $50 ' Ajusta los Seg. iniciales
    RTC[Minu]=   $59 ' Ajusta los Min. iniciales
    RTC[Hora]=   $0F ' Ajusta la Hora inicial
    RTC[Dia] =   $20 ' Ajusta el Día inicial
    rtc[Dias]=   $01 ' Ajuste del dia lunes Martes
    RTC[Mes] =   $02 ' Ajusta el Mes inicial
    RTC[Ano] =   $08 ' Ajusta el Año inicial
    rtc[Control]=$10 ' Ajunte Reg Control
BusOut $D0,0,[Str RTC\8] ' Escribe registros RTC

Return

LEER_RTC:
    For Index = 0 To 6
        BusIn $D1,Index,[RTC[Index]] ' Lee registros
       
    Next ' del RTC 0..6

GoSub BCD2BIN

Return

MOSTRAR_RTC:
    print at 1,1,DEC2 RTC[Hora], ":", DEC2 RTC[Minu],":", DEC2 RTC[Seg]
    print at 2,1,DEC2 RTC[Dia], "/", DEC2 RTC[Mes],"/20", DEC2 RTC[Ano]
    'print at 4,1,$FE,$10,$FE,$10,$FE,$10,$FE,$10,"Reloj"
    select rtc[Dias]
        case 1     
        print at 1,10,"Lunes"
        case 2     
        print at 1,10,"Martes"
        case 3      '23456
        print at 1,10,"Mierc."
        case 4      '23456
        print at 1,10,"Jueves"
        case 5      '23456
        print at 1,10,"Viernes"
        case 6      '23456
        print at 1,10,"Sabado"
        case 7      '23456
        print at 1,10,"Domingo"
    end select
   
    'print at 3,1,"DIAS:", dec2 rtc[Dias]
Return

BCD2BIN:
    For Index = 0 To 6
   
    RTC[Index] = (RTC[Index]/16)*10 + RTC[Index] & $0F
    Next
Return

Pulsadores:
 
 
NoPress2: button sw1,0,255,250,Btnvar,0,retur
          goto Ajuste
Retur:
 return 
'NoPress1: button sw2,0,255,250,Btnvar,0,NoPress3
'          ValorPantalla = ValorPantalla -1: goto Ver
'NoPress3: button sw3,0,255,250,Btnvar,0,NoPress2
'          GOTO EnterVer
' '          goto NoPress2 
Ajuste:
 'cls
  print at 1,1,DEC2 RTC[Hora], ":", DEC2 RTC[Minu],":", DEC2 RTC[Seg]
  print at 2,1,DEC2 RTC[Dia], "/", DEC2 RTC[Mes],"/20", DEC2 RTC[Ano]
  print at 3,1,$FE,$10,$FE,$10,$FE,$10,$FE,$10,"......SET......."
'HorasPut: print at 4,1,$FE,$10,$FE,$10,$FE,$10,$FE,$10,"Hora: ",dec2 RTC[Hora]

        if RTC[Hora] >= 24 then RTC[Hora]= $00

Seting: button sw4,0,255,250,Btnvar,0,Ae
        dec RTC[Hora]:delayms 200:Goto Ajuste
Ae:       
        button sw2,0,255,250,Btnvar,0,Be
        inc  RTC[Hora]:delayms 200:Goto ajuste
Be:
         
        button sw3,0,255,250,Btnvar,0,Ajuste
       
        BusOut $D0,2,[RTC[Hora]] ' Escribe registros RTC
        'DelayMS 500 ' Retardo 500ms
        'GoSub LEER_RTC ' Leer registros RTC
        cls
        GOTO loop
NoPull:         
Seting2: 
  delayms 200


   
   
   
 






'**************************************************************************************
'********* TODO ESTO ES DE MI AMIGO TRIGO TODOS LOS DERECHOS SON DE TRIGO *************
'**************************************************************************************

    'PRIMERO IMPRIMIMOS LAS DECENAS
   
    Cifra = dig temp, 1     'Decenas de grado.
    Puntero = 64            'Primer carácter de la CGRAM, numerado como 0
    Gosub Que_cifra
    print AT 1,9, 0,1
    print AT 2,9, 2,3
   
   
    'Y A CONTINUACIÓN LAS UNIDADES
       
    Cifra = dig temp, 0     'Unidades de grado.
    Puntero = 96            'Quinto carácter de la CGRAM, numerado como 4
    Gosub Que_cifra
    print AT 1,11, 4,5, "TEMP"
    print AT 2,11, 6,7, ".",Dec DIG Temp_Dec, 1, 223 'el 223 es el símbolo de grado
    return   
       
        Que_cifra:
           
            select Cifra.
                case 0: gosub cero: RETURN      'Rutinas para crear los gráficos correspondientes a esas cifras en gran formato
                CASE 1: GOSUB UNO: RETURN
                CASE 2: GOSUB DOS: RETURN
                CASE 3: GOSUB TRES: RETURN
                CASE 4: GOSUB CUATRO: RETURN
                CASE 5: GOSUB CINCO: RETURN
                CASE 6: GOSUB SEIS: RETURN
                CASE 7: GOSUB SIETE: RETURN
                CASE 8: GOSUB OCHO: RETURN
                CASE 9: GOSUB NUEVE: RETURN
            ENDSELECT
           
           
    'CARGANDO LOS CARACTERES PERSONALIZADOS EN LA CGRAM
   
   
   
CERO:
    'SI:
        Print 254,Puntero,$07,$0F,$1C,$18,$18,$18,$18,$18
    'SD:
        Print 254,Puntero + 8,$18,$1C,$0E,$06,$06,$06,$06,$06
    'II:
        Print 254,Puntero + 16,$18,$18,$18,$18,$18,$1C,$0F,$07
    'ID:
        Print 254,Puntero + 24,$06,$06,$06,$06,$06,$0E,$1C,$18
       
    RETURN
   
   
UNO:                   
    'SI:
        Print 254,Puntero,$00,$00,$00,$01,$01,$00,$00,$00
    'SD:
        Print 254,Puntero + 8,$0C,$1C,$1C,$1C,$1C,$0C,$0C,$0C
    'II:
        Print 254,Puntero + 16,$00,$00,$00,$00,$00,$00,$00,$00
    'ID:
        Print 254,Puntero + 24,$0C,$0C,$0C,$0C,$0C,$0C,$1E,$1E
       
    RETURN
   
DOS:
    'SI:
        Print 254,Puntero,$07,$0F,$1C,$18,$00,$00,$00,$00
    'SD:
        Print 254,Puntero + 8,$18,$1C,$0E,$06,$06,$06,$0E,$1C
    'II:
        Print 254,Puntero + 16,$01,$03,$07,$0E,$1C,$18,$1F,$1F
    'ID:
        Print 254,Puntero + 24,$18,$10,$00,$00,$00,$00,$1E,$1E
    RETURN
   
TRES:
    'SI:
        Print 254,Puntero,$07,$0F,$1C,$18,$00,$00,$01,$01
    'SD:
        Print 254,Puntero + 8,$18,$1C,$0E,$06,$06,$0E,$1C,$18
    'II:
        Print 254,Puntero + 16,$00,$00,$00,$18,$18,$1C,$0F,$07
    'ID:
        Print 254,Puntero + 24,$1C,$0E,$06,$06,$06,$0E,$1C,$18
    RETURN
   
CUATRO:
    'SI:
        Print 254,Puntero,$00,$00,$01,$01,$03,$03,$07,$06
    'SD:
        Print 254,Puntero + 8,$1C,$18,$18,$10,$10,$00,$00,$00
    'II:
        Print 254,Puntero + 16,$0E,$0C,$1C,$1F,$1F,$00,$00,$00
    'ID:
        Print 254,Puntero + 24,$0C,$0C,$0C,$1E,$1E,$0C,$0C,$0C
    RETURN
   
CINCO:
    'SI:
        Print 254,Puntero,$1F,$1F,$18,$18,$18,$18,$1F,$1F
    'SD:
        Print 254,Puntero + 8,$1E,$1E,$00,$00,$00,$00,$18,$1C
    'II:
        Print 254,Puntero + 16,$00,$00,$00,$00,$18,$1C,$0F,$07
    'ID:
        Print 254,Puntero + 24,$0E,$06,$06,$06,$06,$0E,$1C,$18
    RETURN
   
SEIS:
    'SI:
        Print 254,Puntero,$07,$0F,$1C,$18,$18,$18,$1B,$1F
    'SD:
        Print 254,Puntero + 8,$18,$1C,$0E,$06,$00,$00,$18,$1C
    'II:
        Print 254,Puntero + 16,$1C,$18,$18,$18,$18,$1C,$0F,$03
    'ID:
        Print 254,Puntero + 24,$0E,$06,$06,$06,$06,$0E,$1C,$18
    RETURN
   
SIETE:
    'SI:
        Print 254,Puntero,$1F,$1F,$00,$00,$00,$00,$00,$01
    'SD:
        Print 254,Puntero + 8,$1E,$1E,$06,$0E,$0C,$1C,$18,$18
    'II:
        Print 254,Puntero + 16,$01,$03,$03,$07,$06,$0E,$0C,$0C
    'ID:
        Print 254,Puntero + 24,$10,$10,$00,$00,$00,$00,$00,$00
    RETURN
   
OCHO:
    'SI:
        Print 254,Puntero,$07,$0F,$1C,$18,$18,$1C,$0F,$0F
    'SD:
        Print 254,Puntero + 8,$18,$1C,$0E,$06,$06,$0E,$1C,$18
    'II:
        Print 254,Puntero + 16,$1C,$18,$18,$18,$18,$1C,$0F,$03
    'ID:
        Print 254,Puntero + 24,$0E,$06,$06,$06,$06,$0E,$1C,$18
    RETURN
   
NUEVE:
    'SI:
        Print 254,Puntero,$07,$0F,$1C,$18,$18,$18,$18,$1C
    'SD:
        Print 254,Puntero + 8,$18,$1C,$0E,$06,$06,$06,$06,$0E
    'II:
        Print 254,Puntero + 16,$0F,$07,$00,$00,$18,$1C,$0F,$07
    'ID:
        Print 254,Puntero + 24,$1E,$16,$06,$06,$06,$0E,$1C,$18
    RETURN
   
    Resete:
 REPEAT
    DELAYMS 25                   ' Wait until conversion is complete     
    OREAD DQ,4,[Cnt]             ' Keep reading low pulses until
 UNTIL Cnt=0                     '  the DS1820 is finished
 Return