// Knihovna I2C


#ifndef _I2C_H_
#define _I2C_H_


#include "at89c51xd2.h"   


//********** MAX695X **********

#define SCL			P2_2    // I2C Clock pro display 
#define SDA			P2_3    // I2C Data pro display

#define WRITE	0
#define READ	1
// COMMAND
#define CONFIG			0x04	// Konfiguracni registr displeje
#define DISP_TST		0x07	// Registr pro zapnuti testu


//********** MAX6953 **********
// MATICOVY 5x7 LED DISPLAY DRIVER 
#define ADDR5300 	 0xA0
#define ADDR5301	 0xA2
#define ADDR5310	 0xA8
#define ADDR5311	 0xAA
// COMMAND
#define INTENS10	0x01	// Intenzita displeje 0 a 1
#define INTENS32	0x02	// Intenzita displeje 2 s 3
#define SCAN_LMT	0x03
#define USRDEFNT	0x05
#define D0P0		0x20
#define D1P0		0x21
#define D2P0		0x22
#define D3P0		0x23
#define D0P1		0x40
#define D1P1		0x41
#define D2P1		0x42
#define D3P1		0x43
#define D0P0P1		0x60
#define D1P0P1		0x61
#define D2P0P1		0x62
#define D3P0P1		0x63
// CONFIG FLAGS				bit 1       /    bit 0
#define NORMOP		0x01	// Normalni operace / Vypnuto
#define FSTBLNK		0x04	// Fast blink 2Hz   / Slow blink 1Hz
#define BLNKENBL	0x08	// Blink enable     / Blink disable
#define BLNKRST		0x10	// Blink reset	    / Blink casovani neovlivneno
#define CLRP0P1		0x20	// Clear P0 P1	    / Clear P0 P1 neovlivneno
#define P0PHASE		0x80	// P0 blink phase   / P1 blink phase
// CHARS
#define CH_NIC		0x20
#define CH_NAH		0x1E
#define CH_DOL		0x1F
#define CH_0		0x30
#define CH_1		0x31
#define CH_2		0x32
#define CH_3		0x33
#define CH_4		0x34
#define CH_5		0x35
#define CH_6		0x36
#define CH_7		0x37
#define CH_8		0x38
#define CH_9		0x39
#define CH_A		0x41
#define CH_B		0x42
#define CH_C		0x43
#define CH_D		0x44
#define CH_E		0x45
#define CH_F		0x46
#define CH_G		0x47
#define CH_H		0x48
#define CH_I		0x49
#define CH_J		0x4A
#define CH_K		0x4B
#define CH_L		0x4C
#define CH_M		0x4D
#define CH_N		0x4E
#define CH_O		0x4F
#define CH_P		0x50
#define CH_Q		0x51
#define CH_R		0x52
#define CH_S		0x53
#define CH_T		0x54
#define CH_U		0x55
#define CH_V		0x56
#define CH_W		0x57
#define CH_X		0x58
#define CH_Y		0x59
#define CH_Z		0x5A

#define CH_e		0x65
#define CH_r		0x72
#define CH_POML		0x2D
//********** MAX6955 **********
// SNIMAC 8x4 KLAVES
#define ADDR5500	0xC0
#define ADDR5501	0xC2
#define ADDR5510	0xC8
#define ADDR5511	0xCA
// COMMAND
#define SCAN_LIMT	0x03
#define PORT_CNFG	0x06
#define KEY_A_MSK	0x08	// Nastaveni masky klaves / Precteni zmacknute klavesy
#define KEY_B_MSK	0x09
#define KEY_C_MSK	0x0A
#define KEY_D_MSK	0x0B
#define KEY_A_PRS	0x0C	// Aktualne zmacknute klavesy
#define KEY_B_PRS	0x0D
#define KEY_C_PRS	0x0E
#define KEY_D_PRS	0x0F
// PORT_CONFIG
#define KEYS_8		0x20
#define KEYS_16		0x40
#define KEYS_24		0x60
#define KEYS_32		0x80


//********** MAX6956 **********
// 28 LED DRIVER
#define ADDR5600	0x80
#define ADDR5601	0x82
#define ADDR5610	0x88
#define ADDR5611	0x8A
// COMMAND
#define GLOB_CUR	0x02	// Global Current
#define PCM4		0x09	// Port Config Map P7, P6, P5, P4
#define PCM8		0x0A	// Port Config Map P11,P10,P9, P8
#define PCM12		0x0B	// Port Config Map P15,P14,P13,P12
#define PCM16		0x0C	// Port Config Map P19,P18,P16,P15
#define PCM20		0x0D	// Port Config Map P23,P22,P21,P20
#define PCM24		0x0E	// Port Config Map P27,P26,P25,P24
#define PCM28		0x0F	// Port Config Map P31,P30,P29,P28
#define ISC4		0x12	// Individual Segment Current P5, P4
#define ISC6		0x13	// Individual Segment Current P7, P6
#define ISC8		0x14	// Individual Segment Current P9, P8
#define ISC10		0x15	// Individual Segment Current P11,P10
#define ISC12		0x16	// Individual Segment Current P13,P12
#define ISC14		0x17	// Individual Segment Current P15,P14
#define ISC16		0x18	// Individual Segment Current P17,P16
#define ISC18		0x19	// Individual Segment Current P19,P18
#define ISC20		0x1A	// Individual Segment Current P21,P20
#define ISC22		0x1B	// Individual Segment Current P23,P22
#define ISC24		0x1C	// Individual Segment Current P25,P24
#define ISC26		0x1D	// Individual Segment Current P27,P26
#define ISC28		0x1E	// Individual Segment Current P29,P28
#define ISC30		0x1F	// Individual Segment Current P31,P30
#define RBP4		0x24	// Registr bit
#define RBP5		0x25
#define RBP6		0x26
#define RBP7		0x27
#define RBP8		0x28
#define RBP9		0x29
#define RBP10		0x2A
#define RBP11		0x2B
#define RBP12		0x2C
#define RBP13		0x2D
#define RBP14		0x2E
#define RBP15		0x2F
#define RBP16		0x30
#define RBP17		0x31
#define RBP18		0x32
#define RBP19		0x33
#define RBP20		0x34
#define RBP21		0x35
#define RBP22		0x36
#define RBP23		0x37
#define RBP24		0x38
#define RBP25		0x39
#define RBP26		0x3A
#define RBP27		0x3B
#define RBP28		0x3C
#define RBP29		0x3D
#define RBP30		0x3E
#define RBP31		0x3F
#define RBP4_7	 0x40
#define RBP6_13	 0x46
#define RBP10_17 0x4A
#define RBP18_25 0x52
#define RBP30_31 0x5E
// CONFIG FLAGS					bit 1       /    bit 0
#define INDICUR		0x40	// Idividual current / Global Current


//******* MAX6956 - Command *******
//*************
#define MSCL		P2_0    // I2C Clock pro EEPROM
#define MSDA		P2_1    // I2C Data pro EEPROM
//************


//void delay_us1(register unsigned char time);
void delay_us(void);
void delay(void);                             
void i2c_delay(void);                         // Wait for 5µs
void i2c_start(void);                         // Geneate I2C START condition
void i2c_stop(void);                          // Geneate I2C STOP condition
void i2c_ack(void);                           // Geneate I2C MASTER ACK
void i2c_nack(void);                          // Geneate I2C MASTER NACK
unsigned char i2c_check(void);                // Check an ACK from SLAVE
unsigned char i2c_write(unsigned char value); // Write a character via I2C
unsigned char i2c_read(void);                 // Read a character via I2C

 unsigned char MAX_read(unsigned char adress, unsigned char command);
 void MAX_write(unsigned char adress, unsigned char command, unsigned char rdata);


#endif   // _I2C_H_
