bhaven
Joined: 26 Sep 2005 Posts: 10
|
Writing in 24LC256(i2c) with PIC 16F877 |
Posted: Sat Jan 07, 2006 1:08 pm |
|
|
i have used Microchip's 24LC256 ic for data storage with PIC16F877. the connection to this is through pin no. 18 & 24. I am using proteus v6.5 for simulation purpose still the data is not written in 24LC256 chip. the command for writing is give by pressing the keys. the simulation is continued but there is no effect of pressing other keys.
i have attached the code hereby . Pls can anyone tell me what is wromng & what correction is to be made. The version of picc is 3.150. Pls reply . i ned it for my project urgently.
#if defined(__PCM__)
#include <16F877.h>
#device *=16
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_A2,rcv=PIN_A3)
#endif
#include <lcd.c>
#include <kbd.c>
#include<stdio.h>
#include<stdlib.h>
#use i2c (master, sda=PIN_C4, scl=PIN_C3)
#use delay(clock = 4000000)
int i=0;
int p[50],k,temp;
CHAR key;
void keyscan( );
void scankeypad();
void func(char);
void func1(char);
void number(int);
void preab(int);
void rec();
char cmd;
char data;
void main ()
{
CHAR keycodes[12] = {'1','2','3','4','5','6','7','8','9','0','a','b'};
set_tris_B(0xf8);
lcd_init();
lcd_putc("\fAttendanceLogger\n");
while(1)
{
key = keyscan();
func(key);
}
}
void func( char key)
{
funct:
key = keyscan();
if(key == '1')
{
disp:
i++;
delay_ms(50);
lcd_putc("\fRoll no. Status\n");
printf(lcd_putc,"%d",i);
lcd_gotoxy(12,2);
lcd_putc('P');
cmd = 'P';
key = keyscan();
goto funct;
}
if(key == '2')
{
lcd_gotoxy(12,2);
lcd_putc('P');
cmd = 'P';
if(cmd == 'P')
{
temp = 1;
}
else
{
temp = 0;
}
goto funct;
}
if(key == '3')
{
lcd_gotoxy(12,2);
lcd_putc('A');
cmd = 'A';
if(cmd == 'P')
{
temp = 0;
}
else
{
temp = 1;
}
goto funct;
}
if(key == '4')
{
lcd_putc("\f4 Print\n");
}
if(key == '5')
{
lcd_putc("\f5 Print");
}
if(key == '6')
{
i2c_start();
//i2c_write(0);
i2c_write(i);
i2c_write(temp);
i2c_stop();
lcd_putc("\f Complete\n");
key = keyscan();
goto funct;
}
if (key == '7')
{
i2c_start();
i2c_write(0);
putc('*');
data = i2c_read();
putc(data);
i2c_stop();
putc('*');
key = keyscan();
goto funct;
}
if(key == '8')
{
lcd_putc("\f8 Print\n");
}
if(key == '9')
{
lcd_putc("\f9 Print\n");
}
if(key == '0')
{
lcd_putc("\f0 Print\n");
}
end:
goto funct;
}
keyscan()
{
for(;;)
{
output_high(PIN_B2);
output_low(PIN_B1);
output_low(PIN_B0);
if( input(PIN_B3) )
{
return '1';
}
if( input(PIN_B4) )
{
return '4';
}
if( input(PIN_B5) )
{
return '7';
}
if( input(PIN_B6) )
{
return 'a';
}
output_low(PIN_B2);
output_high(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B0);
if( input(PIN_B3) )
{
return '2';
}
if( input(PIN_B4) )
{
return '5';
}
if( input(PIN_B5) )
{
return '8';
}
if( input(PIN_B6) )
{
return '0';
}
output_low(PIN_B1);
output_high(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);
if( input(PIN_B3) )
{
return '3';
}
if( input(PIN_B4) )
{
return '6';
}
if( input(PIN_B5) )
{
return '9';
}
if( input(PIN_B6) )
{
return 'b';
}
output_low(PIN_B0);
}
} |
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 08, 2006 12:32 am |
|
|
Don't write your own driver for the 24LC256. Use the driver that comes
with the compiler. It's called 24256.C, and it's in this folder:
c:\Program Files\Picc\Drivers
Also, delete your double post. View the post and click the little "X"
box in the upper right corner to delete it. |
|