CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Writing in 24LC256(i2c) with PIC 16F877

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bhaven



Joined: 26 Sep 2005
Posts: 10

View user's profile Send private message

Writing in 24LC256(i2c) with PIC 16F877
PostPosted: Sat Jan 07, 2006 1:08 pm     Reply with quote

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);
}


}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group