Zur Übersicht - INFO - Neueste 50 Beiträge - Neuer Beitrag - Suchen - Zum C-Control-I-Forum - Zum C-Control-II-Forum

PCF8583 Kategorie: I²C-Bus (von Baltus - 12.11.2010 9:02)
Ich nutze:
CC-Pro 128 Application Board
Ausgäng SCL und SDA via 3k9 verbunden mit 5V.
Respons von I2C-bus ist immer  "103     103     23      23      3       103"(decimal).
Kan jemand mir sagen wie die I2C-bus zu controlieren ist? (die LEDs LD4 und LD5 leuchten
permanent auf). Oder ist meine Code flas?

Benutzte Code (in Basic):
' global variables
Dim  zeile1(17), zeile2(17) As Char          '2*16 char display
Dim  minute, hour, second As Byte
Dim  day, month, year As Byte
Dim cnt As Integer
'---------------------------------------------------------------------------------
Sub main()
'http://ccpro.cc2net.de/forum/index.php?show=2988
'Converted from C to Basic
LCD_Init()
LCD_ClearLCD()
I2C_Init(I2C_100kHz)
AbsDelay(100)

Do
    cnt=cnt+1
    second=Read_PCF(0x02)           'Sekunden
    minute=Read_PCF(0x03)           'Minuten
    hour=Read_PCF(0x04)
    hour=hour And &H3F              'Stunden mit Bitmaske
    day=Read_PCF(0x05)
    day=day And 0x3F                'Tag mit Bitmaske
    month=Read_PCF(0x06)
    month=month And 0x1F            'Monat mit Bitmaske
    year=Read_PCF(0x10)             'Jahr im RAM gespeichert

    Msg_WriteHex(second)
    Msg_WriteChar(9)                'Kontrollausgabe am PC
    'Msg_WriteHex(minute)
    'Msg_WriteChar(9)                'mit Tab
    'Msg_WriteHex(hour)
    'Msg_WriteChar(9)
    'Msg_WriteHex(day)
    'Msg_WriteChar(9)
    'Msg_WriteHex(month)
    'Msg_WriteChar(9)
    'Msg_WriteHex(year)
    'Msg_WriteChar(13)                              ' neue Zeile

    second=((second>>4)*10)+(second And 0x0F)   ' Hex to Dezimal
    minute=((minute>>4)*10)+(minute And 0x0F)
    hour=((hour>>4)*10)+(hour And 0x0F)
    day=((day>>4)*10)+(day And 0x0F)
    month=((month>>4)*10)+(month And 0x0F)
    year=((year>>4)*10)+(year And 0x0F)

    Msg_WriteInt(cnt)
    Msg_WriteChar(9)                'mit Tab
    Msg_WriteInt(second)
    Msg_WriteChar(9)                'mit Tab
    Msg_WriteInt(minute)
    Msg_WriteChar(9)                'mit Tab
    Msg_WriteInt(hour)
    Msg_WriteChar(9)                'mit Tab
    Msg_WriteInt(day)
    Msg_WriteChar(9)                'mit Tab
    Msg_WriteInt(month)
    Msg_WriteChar(9)                'mit Tab
    Msg_WriteInt(year)
    Msg_WriteChar(13)               ' neue Zeile

    Display_Buffer_Set()            'Convert to 2 text lines
    LCD_CursorOff()
    LCD_CursorPos(0x00+4)
    LCD_WriteText(zeile1)
    LCD_CursorPos(0x40+4)
    LCD_WriteText(zeile2)

    AbsDelay(1000)
    Loop While(1)
End Sub
'
'------------------------------------------------------------------------------
'
Sub Display_Buffer_Set()
'Source: http://ccpro.cc2net.de/forum/index.php?show=2988
'Converted from C to Basic
Dim sep(2) As Char
    sep=":"
    Str_WriteWord(hour,10,zeile1,0,2)    ' LCD erste Zeile xx:xx:xx
    Str_Copy(zeile1,sep,STR_APPEND)
    Str_WriteWord(minute,10,zeile1,STR_APPEND,2)
    Str_Copy(zeile1,sep,STR_APPEND)
    Str_WriteWord(second,10,zeile1,STR_APPEND,2)
    sep="."
    Str_WriteWord(day,10,zeile2,0,2)      ' LCD zweite Zeile xx.xx.xx
    Str_Copy(zeile2,sep,STR_APPEND)
    Str_WriteWord(month,10,zeile2,STR_APPEND,2)
    Str_Copy(zeile2,sep,STR_APPEND)
    Str_WriteWord(year,10,zeile2,STR_APPEND,2)
End Sub
'
'------------------------------------------------------------------------------
'Read out PCF8583 (Real time clock)
Sub Read_PCF(adr As Byte) As Byte
Dim PCF_DATA As Byte
    I2C_Start()
    I2C_Write(0xA2)              'Adresse des PCF 8583 (Pin A0 =1 address 0xA2,
                                 '    ist Pin A1=0 dann 0xA0)
    I2C_Write(adr)               'Adresse des zu lesenden Byte
    I2C_Stop()
    I2C_Start()
    I2C_Write(0xA3)              'Adresse des PCF mit Lesebit gesezt (* 0xA1)
    PCF_DATA=I2C_Read_NACK()   'lesen des Bytes Adresse adr
    I2C_Stop()
    'Msg_WriteHex(PCF_DATA)
    Return PCF_DATA              ' return I2C Data Register
End Sub



    Antwort schreiben


Antworten:

Re: PCF8583 (von Baltus - 13.11.2010 13:13)