EEPROM User Manual

81 downloads 183 Views 2MB Size Report
mikroC, mikroBasic and mikroPascal programming languages. The PIC16F887 ... Example 1: Program written in the mikroC PRO for PIC compiler. Figure 5: ...
All Mikroelektronika’s development systems feature a large number of peripheral modules expanding microcontroller’s range of application and making the process of program testing easier. In addition to these modules, it is also possible to use numerous additional modules linked to the development system through the I/O port connectors. Some of these additional modules can operate as stand-alone devices without being connected to the microcontroller.

Manual

Additional Board

EEPROM



MikroElektronika

EEPROM Board EEPROM Additional Board The EEPROM board is used as additional EEPROM memory used to store data that has to be saved even when the power supply goes off. This board features a 1Kbit memory chip 24C02 that exchanges data with the microcontroller via I2C communication. The EEPROM board is connected to the microcontroller’s I/O port intended for I2C communication via a 10-pin IDC connector. The presence of the power supply voltage on the board is indicated by a LED.

Figure 1: EEPROM additional board

Figure 2: EEPROM board connected to a development system

Jumpers provided on the back of the EEPROM board are used to select a microcontroller that will use EEPROM memory. When jumpers are set to the PIC position, the EEPROM board can be connected to all Mikroelektronika’s development systems supporting PIC microcontrollers. When jumpers are set to the AVR position, the EEPROM board can be connected to all Mikroelektronika’s development systems supporting AVR microcontrollers.

Figure 3: EEPROM board’s back side

Figure 4: EEPROM board connection schematic

NOTE:

Instead of the memory chip mentioned above, Mikroelektronika may built in other memory chips of higher capacity into EEPROM additional boards. Except this feature, these additional boards have the same features as the EEPROM boards described herin.

MikroElektronika

EEPROM Board

Figure 5: Additional EEPROM memory module 24C02 and microcontroller connection schematic

This simple example shows you how to use functions for reading and writing data from/to additional EEPROM memory. These functions are stored in the program libraries. When I2C communication with the 24C02 EEPROM memory chip is established, the microcontroller writes data into some memory location, then reads it and sends it to port PORTB. The same program is written in mikroC, mikroBasic and mikroPascal programming languages. The PIC16F887 microcontroller is used in all examples. Example 1: Program written in the mikroC PRO for PIC compiler

void main(){ ANSEL = 0; ANSELH = 0; C1ON_bit = 0; C2ON_bit = 0; PORTB = 0; TRISB = 0;

// configure AN pins as digital I/O // disable comparators

// configure PORTB as output

I2C1_Init(100000); I2C1_Start(); I2C1_Wr(0xA2); I2C1_Wr(2); I2C1_Wr(0xAA); I2C1_Stop();





// initialize I2C communication // issue I2C start signal // send byte via I2C (device address + W) // send byte (address of EEPROM location) // send data (data to be written) // issue I2C stop signal

Delay_100ms();

}

I2C1_Start(); // issue I2C start signal I2C1_Wr(0xA2); // send byte via I2C (device address + W) I2C1_Wr(2); // send byte (data address) I2C1_Repeated_Start(); // issue I2C signal repeated start I2C1_Wr(0xA3); // send byte (device address + R) PORTB = I2C1_Rd(0u); // read the data (NO acknowledge) I2C1_Stop(); // issue I2C stop signal

MikroElektronika

EEPROM Board Example 2: Program written in the mikroBasic PRO for PIC compiler

program I2C_Simple main: ANSEL = 0 ANSELH = 0 PORTB = 0 TRISB = 0

‘ configure AN pins as digital I/O ‘ configure PORTB as output

I2C1_Init(100000) I2C1_Start() I2C1_Wr(0xA2) I2C1_Wr(2) I2C1_Wr(0xAA) I2C1_Stop()

‘ initialize I2C communication ‘ issue I2C start signal ‘ send byte via I2C (device address + W) ‘ send byte (address of EEPROM location) ‘ send data (data to be written) ‘ issue I2C stop signal

Delay_100ms() I2C1_Start() I2C1_Wr(0xA2) I2C1_Wr(2) I2C1_Repeated_Start() I2C1_Wr(0xA3) PORTB = I2C1_Rd(0) I2C1_Stop() end.

‘ issue I2C start signal ‘ send byte via I2C (device address + W) ‘ send byte (data address) ‘ issue I2C signal repeated start ‘ send byte (device address + R) ‘ read the data (NO acknowledge) ‘ issue I2C stop signal

Example 3: Program written in the mikroPascal PRO for PIC compiler

program I2C_Simple; begin ANSEL := 0; // configure AN pins as digital I/O ANSELH := 0; PORTB := 0; TRISB := 0; // configure PORTB as output I2C1_Init(100000); I2C1_Start(); I2C1_Wr(0xA2); I2C1_Wr(2); I2C1_Wr(0xAA); I2C1_Stop();

// initialize I2C communication // issue I2C start signal // send byte via I2C (device address + W) // send byte (address of EEPROM location) // send data (data to be written) // issue I2C stop signal

Delay_100ms(); I2C1_Start(); // issue I2C start signal I2C1_Wr(0xA2); // send byte via I2C (device address + W) I2C1_Wr(2); // send byte (data address) I2C1_Repeated_Start(); // issue I2C signal repeated start I2C1_Wr(0xA3); // send byte (device address + R) PORTB := I2C1_Rd(0); // read the data (NO acknowledge) I2C1_Stop(); // issue I2C stop signal end.

MikroElektronika