mainMaster.c

gehe zur Dokumentation dieser Datei
00001 /****************************************************************************
00002 Title:    Access serial EEPROM 24C02 using I2C interace
00003 Author:   Peter Fleury <pfleury@gmx.ch> http://jump.to/fleury
00004 File:     $Id: test_i2cmaster.c,v 1.2 2003/12/06 17:07:18 peter Exp $
00005 Software: AVR-GCC 3.3
00006 Hardware: AT90S8515 at 4 Mhz, any AVR device can be used
00007 
00008 Description:
00009     This example shows how the I2C library i2cmaster.S can be used to 
00010     access a serial eeprom.
00011     Based on Atmel Application Note AVR300, adapted to AVR-GCC C interface
00012 
00013 *****************************************************************************/
00014 #include <avr/io.h>
00015 #include <string.h>                             // string methoden
00016 #include "i2cmaster.h"
00017 
00018 #define NDISPLAY_ADD  0x40      // device address of EEPROM 24C64, see datasheet
00019  #define TITELKURZ      12      // kurtzer Titel für Variablen
00020  #define TITELLANG      17      // langer Titel für überschriften
00021  
00022 enum enTWIRegisterAdr { INBUFFER=1, OUTBUFFER, INCOUNTER, OUTCoOUNTER, PAKETREQID, STATUS, GPIO };// Adressen der Register
00023 enum enElemtenTypen     {VARIABLE, MENUE, TEXT};
00024 
00025 
00026 typedef struct
00027 {
00028         uint8_t id;                                                                             // ID des Tabelleneintrages (muss eindeutig sein)
00029         char titel[TITELLANG+1];                        // Titel des Menüs
00030 }tstMenue;
00031 
00032 typedef struct
00033 {
00034         uint8_t id;                                                                     // ID des Elementes
00035         uint8_t pos;                                                            // Position innerhalb des Menüs
00036         void*   element;                                                        // Pointer auf das Element
00037         enum    enElemtenTypen elementType;             // Typ des Elementes
00038         uint8_t parent;                                                         // übergeortnetes Elemente
00039 }tstZeile;
00040 
00041 
00042 void i2c_writeData(uint8_t* data, uint8_t size);
00043 
00044 int main(void)
00045 {
00046     unsigned char ret;
00047     
00048 
00049     DDRB  = 0xff;                              // use all pins on port B for output 
00050     PORTB = 0b00000011;                        // (active low LED's )
00051 
00052     i2c_init();                                // init I2C interface
00053         
00054                 
00055         tstMenue menue;
00056         menue.id = 1;
00057         memcpy(menue.titel,"I2C Einstellungen", 18);
00058         tstZeile tabZeile;
00059         tabZeile.id = 1;
00060         tabZeile.pos = 1;
00061         tabZeile.element = 0;
00062         tabZeile.elementType = MENUE;
00063         tabZeile.parent = 0;
00064 
00065                 /* schreibe Daten in den INFifo des DisplayControllers */
00066     ret = i2c_start(NDISPLAY_ADD + I2C_WRITE);       // set device address and write mode
00067                 PORTB = 0b00000110;
00068     if ( ret ) {
00069                                 PORTB = 0b00001110;
00070         /* failed to issue start condition, possibly no device found */
00071         i2c_stop();
00072         PORTB = 0b00011100;                            // activate all 8 LED to show error */
00073     }else {
00074                                 PORTB = 0b00111000;
00075         /* issuing start condition ok, device accessible */
00076                                 i2c_write(INBUFFER);
00077                                 i2c_writeData((uint8_t*)&tabZeile, sizeof(tabZeile));
00078                                 i2c_writeData((uint8_t*) &menue, sizeof(menue));
00079         i2c_stop();                            // set stop conditon = release bus
00080                                 PORTB = 0b01110000;
00081                 }
00082     
00083                 /* schreibe die Anzahl der gesendeten Daten */
00084                 i2c_start_wait(NDISPLAY_ADD + I2C_WRITE);       // set device address and write mode
00085                 i2c_write(INCOUNTER);
00086                 i2c_write(sizeof(tabZeile) + sizeof(menue));
00087                 i2c_stop();
00088 
00089     for(;;);    
00090 }
00091 
00092 void i2c_writeData(uint8_t* data, uint8_t size)
00093 {
00094         uint8_t i=0;
00095 
00096         for( i=0; i<size; i++)
00097         {
00098                 i2c_write(*data++);
00099         }
00100 
00101 }

Erzeugt am Thu Oct 18 23:22:13 2007 für nDisply von  doxygen 1.5.1-p1