|
|
View previous topic :: View next topic |
Author |
Message |
Adek Guest
|
How to use i2c with PIC16F84A and PIC12F675 ? |
Posted: Sun Jan 22, 2006 4:36 am |
|
|
i'm use 16F84A is master and use 12F675 is slave.
master connect with mmc card via rs232.
my master will read parameter from slave and keep parameter to temp and then pass that value to mmc card.
i'm wanna to know how stretegy to read and write.
Thanks. |
|
|
Adek Guest
|
|
Posted: Sun Jan 22, 2006 1:08 pm |
|
|
This is main of slave.
/***********************************************************/
void main(void)
{
int16 value;
int i;
float volt;
char val[9];
setup_port_a(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
value = Read_ADC();
volt = Vbe * (float) value;
sprintf(val,"<%0.5f>",volt);
for(i=0;i<7;i++)
i2c_write(val[i]);
delay_ms(1);
}
/***********************************************************/
and this main of master.
/***********************************************************/
#use i2c(master, sda=PIN_A0, scl=PIN_A1)
#use rs232 ( baud=9600, xmit=TxD, rcv=RxD, stream=memory)
void main()
{
char tmp[12];
char begin[4] ={0x0A,0x0D,0x3E};
char write[3] =":";
char fmane[13]="TEST0001.TXT";
char val_sen;
int i,j,k,l,test;
while (!kbhit());
for(i=0;i<3;i++) tmp[i]=getc();
for(j=0;j<3;j++) if(tmp[j]!=begin[j])reset_cpu();
putc('W');
while(!kbhit());
for(k=0;k<1;k++) tmp[k]=getc();
for(k=0;k<1;k++) if(tmp[k]==write[k]) test=1;
for(l=0;l<12;l++) putc(fmane[l]);
putc(13);
while(TRUE)
{ i2c_start();
i2c_write(0x01);
for(i=0;i<7;i++)
tmp[i] = i2c_read();
i2c_stop();
putc(',');
for(i=0;i<7;i++)
putc(tmp[i]);
delay_ms(1);
}
}
/***********************************************************/
Now it can write file to mmc card, but data put to mmc card it wrong. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
|
|
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
|