View Single Post
  #7   Spotlight this post!  
Unread 06-12-2003, 15:24
Random Dude Random Dude is offline
Oregon State Head FTA
AKA: Chris
no team (Oregon Robotics Tournament & Outreach Program)
 
Join Date: Aug 2002
Rookie Year: 1998
Location: Oregon
Posts: 142
Random Dude will become famous soon enoughRandom Dude will become famous soon enough
Re: Autonomous Library!

Quote:
Originally Posted by Sachiel7
Random Dude, Can you explain how they work a little bit?
From what I uderstand, you send an x and y address to read/write, and a char variable to read/write.
You convert char to int with (int)Char (where char is the char variable) right?
So, how do you convert int to char?
And, am I mistaken about the x,y address? It would mean that there's a 256x256 bit "array" being used, no?
I'm just trying to understand a little bit more.
addrH, addrL are the high and low bytes of the address respectively. The memory address is 10 bits long. The lower 8 bits are in addrL. The upper 2 bits are in addrH (addrH.bit.2 through addrH.bit.7 should be 0).

So I suppose you could picture it as a 4x256 array if you want to.

I wrote the code with two seperate bytes, simply because i was lazy and didn't want to have to break the 16bit word into two bytes.I'll change the functions and put them at the end of this message.


----

Now as to typcasting (that is when you convert one variable type to another). You can use the

x = (int)y;

syntax for any type by simply replacing 'int' with the type in question.

so to typecast to a unsigned char

x = (unsigned char) y;



----

unsigned char readEE(unsigned short address) {


EEADRH = ((address>>8)&0x03);
EEADR =(address&0xFF);


EECON1bits.EEPGD =0;
EECON1bits.CFGS =0;
EECON1bits.RD =1;


return EEDATA;
}

void writeEE(unsigned short address,unsigned char data)
{
EEADRH = ((address>>8)&0x03);
EEADR =(address&0xFF);
EEDATA = data;

//following as per spec. sheet
EECON1bits.EEPGD =0;
EECON1bits.CFGS =0;
EECON1bits.WREN =1;
INTCONbits.GIE = 0;
EECON2 = 0x55;
EECON2 = 0xAA;
EECON1bits.WR = 1;
INTCONbits.GIE = 1;
EECON1bits.WREN = 0;
}

--

I don't have the EduBot with me, but the code should work...