Pic18F4550 mit EEprom 24lc25
Dienstag, 22. Mai 2012
 
 

PIC Mikrocontroller Forum  |  PIC Mikrocontroller  |  CCS Compiler  |  Schnittstellen (CCS)  |  Pic18F4550 mit EEprom 24lc25 « vorheriges nächstes »
Seiten: [1] Nach unten Drucken
Autor Thema: Pic18F4550 mit EEprom 24lc25  (Gelesen 1273 mal)
 
gertschi
Gast
« am: August 09, 2009, 07:54:29 »

Hi Leute Ich hänge fest und komm auf den kleinen Fehler nicht drauf:


Ich hab dieses Programm geschreiben bzw. wollte es mal ausprobieren:


Code:
#include <18F4550.h>
#include "usb_bootloader.h"
#Fuses
NOPROTECT,NOBROWNOUT,NOPUT,NOPBADEN,HSPLL,PLL5,VREGEN,USBDIV,WRTB,NOLVP
#use delay(clock=20000000)
#include "icons.h"
//#include "icon_off.h"

#INT_SSP //I2C or SPI activity
#INT_BUSCOL //Bus Collision

#define EEPROM_SDA PIN_B0
#define EEPROM_SCL PIN_B1
#include "24256.c"

main()
{
  unsigned int16 i = 0;

  init_ext_eeprom();

  for(i=0; i<128; i++)
    write_ext_eeprom(i, cygwin_icon[i]);     //byte 0-127

  for(i=0; i<128; i++)
    write_ext_eeprom(i+128, flash_icon[i]);   //byte 128-255

  for(i=0; i<128; i++)
    write_ext_eeprom(i+256, outlook_icon[i]);   //byte 256-383

//  for(i=0; i<72; i++) write_ext_eeprom(i+384, Dog_row1[i]);  //offset
= 384, byte 0-71
//  for(i=0; i<72; i++) write_ext_eeprom(i+456, Dog_row2[i]);
//  for(i=0; i<72; i++) write_ext_eeprom(i+528, Dog_row3[i]);
//  for(i=0; i<72; i++) write_ext_eeprom(i+600, Dog_row4[i]);
//  for(i=0; i<72; i++) write_ext_eeprom(i+672, Dog_row5[i]);
//  for(i=0; i<72; i++) write_ext_eeprom(i+744, Dog_row6[i]);
//  for(i=0; i<72; i++) write_ext_eeprom(i+816, Dog_row7[i]);
//  for(i=0; i<72; i++) write_ext_eeprom(i+888, Dog_row8[i]);

  for(;;){

  }
}

Mein Problem ist nun, dass am EEPROM nix drinnen steht!

Harwaremäßig hab ich ein 20MHz Quarz mit PLL (USB) das heißt ich hab
einen internen Takt von 48Mhz.

Ich glaub es stimmt was nicht mit der Taktfrequenz aber ich komm nicht
drauf!

Bitte hilfe

Ich verwende auch einen Bootloader vielleicht liegts auch an den
Interrupts oder Config Bits!

Ich steh an bitte hilfe:

Angefügt hab ich noch 24256.c weil die ja wichtig ist für das EEPROM.

SDA und SCL hängen natürlich richtig am PIC und EEPROM!

Anbei findet ihr noch die include 24256.c:

Code:
///////////////////////////////////////////////////////////////////////////
////   Library for a 24LC256 serial EEPROM                             ////
////                                                                   ////
////   init_ext_eeprom();    Call before the other functions are used  ////
////                                                                   ////
////   write_ext_eeprom(a, d);  Write the byte d to the address a      ////
////                                                                   ////
////   d = read_ext_eeprom(a);   Read the byte d from the address a    ////
////                                                                   ////
////   The main program may define eeprom_sda                          ////
////   and eeprom_scl to override the defaults below.                  ////
////                                                                   ////
///////////////////////////////////////////////////////////////////////////
////        (C) Copyright 1996,2003 Custom Computer Services           ////
//// This source code may only be used by licensed users of the CCS C  ////
//// compiler.  This source code may only be distributed to other      ////
//// licensed users of the CCS C compiler.  No other use, reproduction ////
//// or distribution is permitted without written permission.          ////
//// Derivative programs created using this software in object code    ////
//// form are not restricted in any way.                               ////
///////////////////////////////////////////////////////////////////////////


#ifndef EEPROM_SDA

#define EEPROM_SDA  PIN_B0
#define EEPROM_SCL  PIN_B1

#endif

#use i2c(master, sda=EEPROM_SDA, scl=EEPROM_SCL)

#define EEPROM_ADDRESS long int
#define EEPROM_SIZE   32768

void init_ext_eeprom()
{
   output_float(EEPROM_SCL);
   output_float(EEPROM_SDA);

}


void write_ext_eeprom(long int address, BYTE data)
{
   short int status;
   i2c_start();
   i2c_write(0xA0);
   i2c_write(address>>8);
   i2c_write(address);
   i2c_write(data);
   i2c_stop();
   i2c_start();
   status=i2c_write(0xA0);
   while(status==1)
   {
   i2c_start();
   status=i2c_write(0xA0);
   }
   i2c_stop();
}


BYTE read_ext_eeprom(long int address) {
   BYTE data;
   i2c_start();
   i2c_write(0xA0);
   i2c_write(address>>8);
   i2c_write(address);
   i2c_start();
   i2c_write(0xA1);
   data=i2c_read(0);
   i2c_stop();
   return(data);
}


Edit:
Bitte Code-Tags verwenden!
Stampede


« Letzte Änderung: August 11, 2009, 15:21:09 von Stampede » Gespeichert
Coltfisch
Sr. Member
****
Offline Offline

Beiträge: 496



Profil anzeigen WWW
« Antworten #1 am: August 11, 2009, 15:14:09 »

Hallo,

ich vermisse noch "CPUDIV2" (PLL Postscaler) bei den Fuses und natürlich muss es
Code: (c)
#use delay(clock=48000000)

heißen, wenn Dein PIC mit 48 MHz laufen soll.

Die #INT_xxx Schlüsselwörter werden normalerweise beim CCS Compiler vor Interrupt-Funktionen gesetzt. Das scheint bei Dir aber nicht der Fall zu sein (jedenfalls fehlen die Interrupt-Funktionen). Die Zeilen
Code: (c)
#INT_SSP //I2C or SPI activity
#INT_BUSCOL //Bus Collision
solltest Du also besser weglassen.


Abgesehen davon machen die Zeilen
Code: (c)
 
  for(i=0; i<128; i++)
    write_ext_eeprom(i, cygwin_icon);     //byte 0-127

  for(i=0; i<128; i++)
    write_ext_eeprom(i+128, flash_icon);   //byte 128-255

  for(i=0; i<128; i++)
    write_ext_eeprom(i+256, outlook_icon);   //byte 256-383
auch ohne den Datentyp von cygwin_icon usw. zu kennen, keinen Sinn. Für jeden Wert von i wird der gleiche Wert nur an eine andere Adresse geschrieben.

Gruß
Daniel

P.S.: bitte demnächst Code-Tags verwenden!
Gespeichert
Seiten: [1] Nach oben Drucken 
« vorheriges nächstes »
Gehe zu:  

Powered by MySQL Powered by PHP Made for Mozilla (Firefox) Made for Internet Explorer
Seite erstellt in 0.036 Sekunden mit 18 Zugriffen.
 
Top! Top!