Theoretical Paper
- Computer Organization
- Data Structure
- Digital Electronics
- Object Oriented Programming
- Discrete Mathematics
- Graph Theory
- Operating Systems
- Software Engineering
- Computer Graphics
- Database Management System
- Operation Research
- Computer Networking
- Image Processing
- Internet Technologies
- Micro Processor
- E-Commerce & ERP
Practical Paper
Industrial Training
Eprom
{E2PROM expands to Electronically Erasable Programmable Read-only Memory. This is in the form of an IC ( Integrated Circuits ) or SMDs ( Surface Mount Devices ) whichever the variant the main purpose of it is to store data without power backup. That is, once data is written on it, it will remain written independent of any power supply. This is important in today’s world where identities are becoming more and more digital. People, Machines, Goods, need to be identified independent of one another and also independent of any human intervention. These devices are small and cheep, and can be used in almost any kind of environment. We are already living in a world full of these tiny gizmos.
An E2PROM is guaranteed to work for about 10000 read / write operations. It also promises to store data for at least a decade and in some cases up to 4 decades. In this article we will not be looking at how an E2PROM actually stores data or how it keeps it true for such a long time without batteries. What we are interested in here is how best we can use a home PC to take full advantage of this wonder chip.
Our test E2PROM is a small IC with 1024 bits (128 bytes) of EE memory. It works with a normal 5V DC supply and is simple to interface with a PC. For Electronics buffs the IC we are using is NM93C46 serial E2PROM. Our program will write an integer ( 16-bit value ) at a predetermined location in the memory and retrieve it. This IC has 64 registers each of size 16-bits. The IC will be interfaced with the LPT port of a PC. The circuit for the same is shown in
For our example we have not provided any separate power supply, instead we are using the Strobe pin (Pin 1) of the LPT as our power source. Ground for the source is the common ground on the LPT (Pins 18 – 25).
A few things about the E2PROM IC now: The IC has 8 pins, we will be using 6 of them. Pin number 6 and 7 will be left open. The functions of each pins are:
Pin 1: Clock Select.
Pin 2: Clock
Pin 3: Data In
Pin 4: Data Out.
Pin 5: Power Input
Pin 8: Ground.
In the circuit we have connected a diode in between strobe of the LPT and the power source pin of the IC. This arrangement is made to protect the IC from accidental reverse voltage and consequently reverse current. Reverse current will damage the IC in an unpredictable manner. A diode allows current to flow in one direction only and acts as an insulator for the reverse direction. This makes it ideal for this job. The other place where we have connected the diode is between the power pin and the ground pin. This arrangement also works as a safety mechanism to limit the amount of current flowing through the IC. Our first diode will not allow reverse current but it is helpless when excess current flows in. To protect our IC against this the power pin is connected to the ground pin via the 220-Ohm resistance. And the ground is connected to the ground of the LPT. Any excess current flowing into the circuit will be passed on through the resistance to ground, bypassing the IC.
Here is what each pin of the IC is intended to do:
Sending logic 1 ( +5 V signal ) to the Chip Select will tell the IC that it needs to be ready to perform some action. Logic 1 on the Clock will cause the chip to read / write data from / to the Data In / Data Out pins of the IC. Jobs of Data In and Data Out pins are self-explanatory.
On the LPT port side, we are interested in two of its ports the Data Port and the Status Port. The Data Port is being used to send signals and the Status Port is receiving information. We use pin number 13 of the LPT port connector. This is the pin on the status port, we use this to get data from the IC. Pins 2, 3, 4 are connected to Chip-Select, Clock and Data-In pins of the E2PROM IC respectively. Pin 1 on the LPT connector serves as the power source and is connected to the power pin of the E2PROM IC. All grounds are shorted.
Getting down to the programming part of this article, here is the source code:
#include#include #define PORTA 0x378 /* Address of LPT */ #define PORTB 0x379 #define CS 0x01 /* Chip Select */ #define STARTBIT 0x01 /* our address value can be changed */ #define DATA_ADD1 0x00
void write_bit ( unsigned int data ) { if ( data == 0 ) { data = ( CS ) ; outportb ( PORTA, data ) ; } else { data = ( CS | 0x02 ) ; /*mask all bits except data */ outportb ( PORTA, data ) ; } data = ( data | 0x04 ) ; outportb ( PORTA, data ) ; /* Give Clock Pulse */ data = ( data ^ 0x04 ) ; outportb ( PORTA, data ) ; /* Remove Clock Pulse */ data = ( CS ) ; outportb ( PORTA, data ) ; return; }
unsigned int read_bit( ) { unsigned int data, rv ; data = ( CS | 0x04 ) ; outportb ( PORTA, data ) ; /* Apply Clock Pulse */ rv = inportb ( PORTB ) ; /* Read Data From Input port */ data = ( data ^ 0x04 ) ; outportb ( PORTA, data ) ; /* Remove Clock Pulse */ rv = rv & 0x10 ; /* Mask Everything Except Data */ if ( rv == 0 ) data = 0x0 ; else data = 0x01 ; return data ; }
void enable_9346( ) { outportb ( PORTA, CS ) ; write_bit ( STARTBIT ) ; write_bit ( 0x00 ) ; write_bit ( 0x00 ) ; write_bit ( 0x01 ) ; write_bit ( 0x01 ) ; write_bit ( 0x00 ) ; write_bit ( 0x00 ) ; write_bit ( 0x00 ) ; write_bit ( 0x00 ) ; outportb ( PORTA, 0x00 ) ; }
void disable_9346( ) { outportb ( PORTA, CS ) ; write_bit ( STARTBIT ) ; write_bit ( 0x00 ) ; write_bit ( 0x00 ) ; write_bit ( 0x00 ) ; write_bit ( 0x00 ) ; write_bit ( 0x00 ) ; write_bit ( 0x00 ) ; write_bit ( 0x00 ) ; write_bit ( 0x00 ) ; outportb ( PORTA, 0x00 ) ; }
void write_9346 ( int my_add, unsigned int my_data ) { unsigned int i, new_add, new_data ; unsigned long int j ; outportb ( PORTA, CS ); /* Give Chip Select High To Write A Bit */ write_bit ( STARTBIT ) ; /* Give Start Bit TO Write A Bit */ write_bit ( 0x00 ) ; /* Give Mode Bit 1 For Writing Operation */ write_bit ( 0x01 ) ; /* Give Mode Bit 2 For Writing Operation */ j = 0x20 ; for ( i = 0 ; i < 6 ; i++ )