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

16F874A and 24C64 problem with writting 1800-1FFF

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







16F874A and 24C64 problem with writting 1800-1FFF
PostPosted: Sun Jun 15, 2003 4:46 am     Reply with quote

PCM 3.091
16F874 + Atmel 24C64
I can't write data between address 1800-1FFF. On lower addresses 0000-17FF it work fine but higher not. Read function work, I can read data on this area, but I can't change it. I second 24C64 chip and it has this same.


#include <16f874a.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#define I2C_SDA PIN_C4
#define I2C_SCL PIN_C3

#use i2c(master,sda=I2C_SDA, scl=I2C_SCL)

#include <input.c>

void init_ext_eeprom() {
output_float(I2C_SCL);
output_float(I2C_SDA);
}


void write_ext_eeprom(long int address, byte data)
{
i2c_start();
i2c_write(0xa2);
i2c_write(address>>8);
i2c_write(address);
i2c_write(data);
i2c_stop();
delay_ms(10);
}


byte read_ext_eeprom(long int address)
{
byte data;
i2c_start();
i2c_write(0xa2);
i2c_write(address>>8);
i2c_write(address);
i2c_start();
i2c_write(0xa3);
data=i2c_read(0);
i2c_stop();
return(data);
}

main()
{byte value,cmd;
long address;


init_ext_eeprom();

while(1)
{ do
{ printf("\r\nRead or Write: ");
cmd=getc();
cmd=toupper(cmd);
putc(cmd);
} while ( (cmd!='R') && (cmd!='W') );

printf("\n\rLocation: ");

address = gethex();
address = (address<<8)+gethex();
if(cmd=='R')
printf("\r\nValue: \%X\r\n",READ_EXT_EEPROM( address ) );

if(cmd=='W')
{ printf("\r\nNew value: ");
value = gethex();
printf("\n\r");
WRITE_EXT_EEPROM( address, value );
}
}
}


Bieli
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515255
Tomi
Guest







Re: 16F874A and 24C64 problem with writting 1800-1FFF
PostPosted: Sun Jun 15, 2003 8:55 am     Reply with quote

I didn't use 24C64 in the last two years but as I remember this chip has a "block write protect" feature and the default page is somewhere in the upper address space. Check the datasheet.

:=PCM 3.091
:=16F874 + Atmel 24C64
:=I can't write data between address 1800-1FFF. On lower addresses 0000-17FF it work fine but higher not. Read function work, I can read data on this area, but I can't change it. I second 24C64 chip and it has this same.
:=
:=
:=#include <16f874a.h>
:=#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT
:=#use delay(clock=4000000)
:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=
:=#define I2C_SDA PIN_C4
:=#define I2C_SCL PIN_C3
:=
:=#use i2c(master,sda=I2C_SDA, scl=I2C_SCL)
:=
:=#include <input.c>
:=
:=void init_ext_eeprom() {
:= output_float(I2C_SCL);
:= output_float(I2C_SDA);
:=}
:=
:=
:=void write_ext_eeprom(long int address, byte data)
:={
:= i2c_start();
:= i2c_write(0xa2);
:= i2c_write(address>>8);
:= i2c_write(address);
:= i2c_write(data);
:= i2c_stop();
:= delay_ms(10);
:=}
:=
:=
:=byte read_ext_eeprom(long int address)
:={
:= byte data;
:= i2c_start();
:= i2c_write(0xa2);
:= i2c_write(address>>8);
:= i2c_write(address);
:= i2c_start();
:= i2c_write(0xa3);
:= data=i2c_read(0);
:= i2c_stop();
:= return(data);
:=}
:=
:=main()
:={byte value,cmd;
:=long address;
:=
:=
:= init_ext_eeprom();
:=
:=while(1)
:={ do
:= { printf("\r\nRead or Write: ");
:= cmd=getc();
:= cmd=toupper(cmd);
:= putc(cmd);
:= } while ( (cmd!='R') && (cmd!='W') );
:=
:= printf("\n\rLocation: ");
:=
:= address = gethex();
:= address = (address<<8)+gethex();
:= if(cmd=='R')
:= printf("\r\nValue: \%X\r\n",READ_EXT_EEPROM( address ) );
:=
:= if(cmd=='W')
:= { printf("\r\nNew value: ");
:= value = gethex();
:= printf("\n\r");
:= WRITE_EXT_EEPROM( address, value );
:= }
:=}
:=}
:=
:=
:=Bieli
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515258
Felix Althaus



Joined: 09 Sep 2003
Posts: 67
Location: Winterthur, Switzerland

View user's profile Send private message

Re: 16F874A and 24C64 problem with writting 1800-1FFF
PostPosted: Sun Jun 15, 2003 9:22 am     Reply with quote

Hello

From the datasheet:
WRITE PROTECT (WP): The write protect input, when tied to GND, allows normal write operations. When WP is tied high to VCC, all write operations to the upper quandrant (8/16K bits) of memory are inhibited. If left unconnected, WP is internally pulled down to GND.

mfg
Felix
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515259
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