00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <avr/io.h>
00015 #include <string.h>
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 };
00023 enum enElemtenTypen {VARIABLE, MENUE, TEXT};
00024
00025
00026 typedef struct
00027 {
00028 uint8_t id;
00029 char titel[TITELLANG+1];
00030 }tstMenue;
00031
00032 typedef struct
00033 {
00034 uint8_t id;
00035 uint8_t pos;
00036 void* element;
00037 enum enElemtenTypen elementType;
00038 uint8_t parent;
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;
00050 PORTB = 0b00000011;
00051
00052 i2c_init();
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
00066 ret = i2c_start(NDISPLAY_ADD + I2C_WRITE);
00067 PORTB = 0b00000110;
00068 if ( ret ) {
00069 PORTB = 0b00001110;
00070
00071 i2c_stop();
00072 PORTB = 0b00011100;
00073 }else {
00074 PORTB = 0b00111000;
00075
00076 i2c_write(INBUFFER);
00077 i2c_writeData((uint8_t*)&tabZeile, sizeof(tabZeile));
00078 i2c_writeData((uint8_t*) &menue, sizeof(menue));
00079 i2c_stop();
00080 PORTB = 0b01110000;
00081 }
00082
00083
00084 i2c_start_wait(NDISPLAY_ADD + I2C_WRITE);
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 }