Forum: Mikrocontroller und Digitale Elektronik I2C hilfeschrei


von Rolf (Gast)


Lesenswert?

Hallo zusammen
Ich habe noch fast keine erfahrung mit MC's.
Möchte mich aber gerne damitt auseinandersetzen.
Mein problem ist über die I2C zu Komunizieren.
Ich habe einen RTC (DS 1307) und einen MEGA 163.
Als Pull- UP für SCL und SDA  verwende ich 10K Ohm
als Compailer verwende ich Code Vision. Nun Ich möchte die aktuelle Zeit 
auf meinem Display angeben.
Wenn ich nun den RTC nach dem Beispil programmiere. Erhalte ich immer 
die gleichen Werte für Stunden, Minuten, Secunden, Tag Monat und Jahr 
namlich 165. Wo könnte mein Fehler liegen habe keine ahnung wer kann mir 
weiterhelfen?

bin für jede hilfe dankbar

gruss
Rolf

von Markus (Gast)


Lesenswert?

Vielleicht solltest Du mal den Source Code Posten. Vielleicht kann man 
dann besser helfen.

Gruß
Markus
http://www.elektronik-projekt.de/

von Rolf (Gast)


Lesenswert?

Tja Du hast wohl recht ich dachte ich hätte Ihn in den Anhang gelegt.
Aber Mittlerweilen bin ich einen schritt weiter gekommen.
Die Zeit kann ich jetzt zurücklesen aber leider bleibt sie stehen.

#include <mega163.h>
#include <stdio.h>
#include <delay.h>

// I2C Bus functions
#asm
   .equ __i2c_port=0x15
   .equ __sda_bit=1
   .equ __scl_bit=0
#endasm
#include <i2c.h>

// DS1307 Real Time Clock functions
#include <ds1307.h>

// Alphanumeric LCD Module functions
#asm
   .equ __lcd_port=0x18
#endasm
#include <lcd.h>

// Declare your global variables here
char lcd_buffer[81];

void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization
// Port A initialization
// Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In 
Func7=In
// State0=T State1=T State2=T State3=T State4=T State5=T State6=T 
State7=T
PORTA=0x00;
DDRA=0x00;

// Port B initialization
// Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In 
Func7=In
// State0=T State1=T State2=T State3=T State4=T State5=T State6=T 
State7=T
PORTB=0x00;
DDRB=0x00;

// Port C initialization
// Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In 
Func7=In
// State0=T State1=T State2=T State3=T State4=T State5=T State6=T 
State7=T
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In 
Func7=In
// State0=T State1=T State2=T State3=T State4=T State5=T State6=T 
State7=T
PORTD=0x00;
DDRD=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x00;
TCNT0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
TCCR2=0x00;
ASSR=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
GIMSK=0x00;
MCUCR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

UBRRHI=0x00;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
// Analog Comparator Output: Off
ACSR=0x80;
SFIOR=0x00;

// I2C Bus initialization
i2c_init();

// DS1307 Real Time Clock initialization
// Square wave output on pin SQW/OUT: Off
// SQW/OUT pin state: 0
rtc_init(0,0,0);

// LCD module initialization
lcd_init(40);

rtc_set_time(18,10,00);
rtc_set_date(23,7,02);



while (1)
      {
      // Place your code here
        char h,m,s,i,tag,monat,jahr;





      for (i=0;i<10;i++)
      {
       rtc_get_time(&h,&m,&s);
       rtc_get_date(&tag,&monat,&jahr);
      delay_ms(2000);
      sprintf(lcd_buffer,"**es ist %2d:%2d:%2d*** 
counter=%2d",h,m,s,i);
      lcd_gotoxy(0,0);
      lcd_puts(lcd_buffer);


      sprintf(lcd_buffer,"Datum %2d:%2d:%2d 
counter=%2d",tag,monat,jahr,i);
      lcd_gotoxy(0,1);
      lcd_puts(lcd_buffer);

      }
      };
}

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.