|
|
View previous topic :: View next topic |
Author |
Message |
Will Reeve
Joined: 30 Oct 2003 Posts: 209 Location: Norfolk, England
|
9386 driver? |
Posted: Tue Sep 28, 2004 10:18 am |
|
|
Has anyone modified 9366.c to work with a 9386?
I am trying to get my head around the code as I type! I can’t see why they shift_left at the beginning of the write and read routines?
Keep well,
Will |
|
|
Will Reeve
Joined: 30 Oct 2003 Posts: 209 Location: Norfolk, England
|
|
Posted: Tue Sep 28, 2004 1:24 pm |
|
|
Hi guys, here is my commented and modified code to try and make the 93LC86 I have work! I can confirm that a 93LC66 soldered in it's place works (with the 94LC66 driver code, I have left the original code commented out) so I think the hardware is OK. Must be something I have missed in my modifications. I would appreciate it if someone could spot the mistake! I now understand how the driver code works and I think I have modified it correctly but I get garbage out of the EEPROM!
As always help much appreciated,
Will
Code: | ///////////////////////////////////////////////////////////////////////////
//// Library for a MicroChip 93C86 configured for a x8 org ////
//// ////
//// init_ext_eeprom(); Call before the other functions are used ////
//// ////
//// write_ext_eeprom(a, d); Write the byte d to the address a ////
//// ////
//// d = read_ext_eeprom(a); Read the byte d from the address a ////
//// ////
//// The main program may define eeprom_select, eeprom_di, eeprom_do ////
//// and eeprom_clk to override the defaults below. ////
//// ////
///////////////////////////////////////////////////////////////////////////
//// (C) Copyright 1996,2003 Custom Computer Services ////
//// Modified 93C66 driver to run 93C86 EEPROM ////
///////////////////////////////////////////////////////////////////////////
#ifndef EEPROM_SELECT
#define EEPROM_SELECT PIN_E2
#define EEPROM_CLK PIN_A2
#define EEPROM_DI PIN_A5
#define EEPROM_DO PIN_A4
#endif
#define EEPROM_ADDRESS long int
#define EEPROM_SIZE 2048
#define hi(x) (*(&x+1))
void init_ext_eeprom() {
BYTE cmd[2];
BYTE i;
output_low(EEPROM_DI);
output_low(EEPROM_CLK);
output_low(EEPROM_SELECT);
// cmd[0]=0xc0;
// cmd[1]=0x4; // send EWEN ?????100 11XXXXXX
cmd[0]=0x80;
cmd[1]=0x09; // send EWEN ????1001 1XXXXXXX
// for(i=1;i<=5;++i)
for(i=1;i<=4;++i) // shift out ? marks
shift_left(cmd,2,0);
output_high(EEPROM_SELECT);
// for(i=1;i<=12;++i) {
for(i=1;i<=13;++i) { // 13 clocks of EWAL command
output_bit(EEPROM_DI, shift_left(cmd,2,0));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);
}
output_low(EEPROM_DI);
output_low(EEPROM_SELECT);
}
void write_ext_eeprom(EEPROM_ADDRESS address, BYTE data) {
BYTE cmd[3];
BYTE i;
cmd[0]=data; // DDDDDDDD data
cmd[1]=(BYTE)address; // AAAAAAAA low bits of address
// cmd[2]=0xa|hi(address); // ????101A high bit of address
cmd[2]=0x28|hi(address); // ??101AAA high three bits of address
// giving total command to send ??101AAA AAAAAAAA DDDDDDDD
// for(i=1;i<=4;++i)
for(i=1;i<=2;++i) // shift out ?
shift_left(cmd,3,0);
output_high(EEPROM_SELECT);
// for(i=1;i<=20;++i) {
for(i=1;i<=22;++i) { // 22 clocks of WRITE command
output_bit(EEPROM_DI, shift_left(cmd,3,0));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);
}
output_low(EEPROM_DI);
output_low(EEPROM_SELECT);
delay_ms(11);
}
BYTE read_ext_eeprom(EEPROM_ADDRESS address) {
BYTE cmd[3];
BYTE i,data;
cmd[0]=0; // DDDDDDDD
cmd[1]=(BYTE)address; // AAAAAAAA
// cmd[2]=0xc|hi(address); // ????110A
cmd[2]=0x30|hi(address); // ??110AAA
// giving command to send ??110AAA AAAAAAAA DDDDDDDD
// for(i=1;i<=4;++i)
for(i=1;i<=2;++i) // shift out ?
shift_left(cmd,3,0);
output_high(EEPROM_SELECT);
// for(i=1;i<=20;++i) {
for(i=1;i<=22;++i) { // 22 clocks of READ command
output_bit(EEPROM_DI, shift_left(cmd,3,0));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);
// if(i>12)
if(i>14) // last 8 bits are to be read
shift_left(&data,1,input(EEPROM_DO));
}
output_low(EEPROM_SELECT);
return(data);
} |
|
|
|
Will Reeve
Joined: 30 Oct 2003 Posts: 209 Location: Norfolk, England
|
|
Posted: Tue Sep 28, 2004 1:33 pm |
|
|
I love it when I fix it myself :-) I hope you guys don't mind me using the board to think out loud! I present a new driver file 9386.c :-)
My mistake was not sending enough bits for the EWEN command (should be 14!). Might be handy for someone looking for a 9386 driver with the search facility later. Have a good night I am off to find a cork screw!
Keep well,
Will
Full file follows (I've left the comments in so it's easier to see what the code does!)
Code: | ///////////////////////////////////////////////////////////////////////////
//// Library for a MicroChip 93C66 configured for a x8 org ////
//// ////
//// init_ext_eeprom(); Call before the other functions are used ////
//// ////
//// write_ext_eeprom(a, d); Write the byte d to the address a ////
//// ////
//// d = read_ext_eeprom(a); Read the byte d from the address a ////
//// ////
//// The main program may define eeprom_select, eeprom_di, eeprom_do ////
//// and eeprom_clk to override the defaults below. ////
//// ////
///////////////////////////////////////////////////////////////////////////
//// (C) Copyright 1996,2003 Custom Computer Services ////
//// Modified 93C66 driver to run 93C86 EEPROM by Will ////
//// hopefully ccs won't mind :-) ////
///////////////////////////////////////////////////////////////////////////
#ifndef EEPROM_SELECT
#define EEPROM_SELECT PIN_E2
#define EEPROM_CLK PIN_A2
#define EEPROM_DI PIN_A5
#define EEPROM_DO PIN_A4
#endif
#define EEPROM_ADDRESS long int
#define EEPROM_SIZE 2048
#define hi(x) (*(&x+1))
void init_ext_eeprom() {
BYTE cmd[2];
BYTE i;
output_low(EEPROM_DI);
output_low(EEPROM_CLK);
output_low(EEPROM_SELECT);
// cmd[0]=0xc0;
// cmd[1]=0x4; // send EWEN ?????100 11XXXXXX
cmd[0]=0x80;
cmd[1]=0x09; // send EWEN ????1001 1XXXXXXX
// for(i=1;i<=5;++i)
for(i=1;i<=4;++i) // shift out ? marks
shift_left(cmd,2,0);
output_high(EEPROM_SELECT);
// for(i=1;i<=12;++i) {
for(i=1;i<=14;++i) { // 14 clocks of EWAL command
output_bit(EEPROM_DI, shift_left(cmd,2,0));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);
}
output_low(EEPROM_DI);
output_low(EEPROM_SELECT);
}
void write_ext_eeprom(EEPROM_ADDRESS address, BYTE data) {
BYTE cmd[3];
BYTE i;
cmd[0]=data; // DDDDDDDD data
cmd[1]=(BYTE)address; // AAAAAAAA low bits of address
// cmd[2]=0xa|hi(address); // ????101A high bit of address
cmd[2]=0x28|hi(address); // ??101AAA high three bits of address
// giving total command to send ??101AAA AAAAAAAA DDDDDDDD
// for(i=1;i<=4;++i)
for(i=1;i<=2;++i) // shift out ?
shift_left(cmd,3,0);
output_high(EEPROM_SELECT);
// for(i=1;i<=20;++i) {
for(i=1;i<=22;++i) { // 22 clocks of WRITE command
output_bit(EEPROM_DI, shift_left(cmd,3,0));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);
}
output_low(EEPROM_DI);
output_low(EEPROM_SELECT);
delay_ms(11);
}
BYTE read_ext_eeprom(EEPROM_ADDRESS address) {
BYTE cmd[3];
BYTE i,data;
cmd[0]=0; // DDDDDDDD
cmd[1]=(BYTE)address; // AAAAAAAA
// cmd[2]=0xc|hi(address); // ????110A
cmd[2]=0x30|hi(address); // ??110AAA
// giving command to send ??110AAA AAAAAAAA DDDDDDDD
// for(i=1;i<=4;++i)
for(i=1;i<=2;++i) // shift out ?
shift_left(cmd,3,0);
output_high(EEPROM_SELECT);
// for(i=1;i<=20;++i) {
for(i=1;i<=22;++i) { // 22 clocks of READ command
output_bit(EEPROM_DI, shift_left(cmd,3,0));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);
// if(i>12)
if(i>14) // last 8 bits are to be read
shift_left(&data,1,input(EEPROM_DO));
}
output_low(EEPROM_SELECT);
return(data);
} |
|
|
|
baron Guest
|
93lc66b怎样使用& |
Posted: Tue Sep 05, 2006 2:00 am |
|
|
///////////////////////////////////////////////////////////////////////////
//// Library for a MicroChip 93C66B configured for a x16 org ////
//// ////
//// init_ext_eeprom(); Call before the other functions are used ////
//// ////
//// write_ext_eeprom(a, d); Write the byte d to the address a ////
//// ////
//// d = read_ext_eeprom(a); Read the byte d from the address a ////
//// ////
//// The main program may define eeprom_select, eeprom_di, eeprom_do ////
//// and eeprom_clk to override the defaults below. ////
//// ////
///////////////////////////////////////////////////////////////////////////
//// (C) Copyright 1996,2003 Custom Computer Services ////
//// This source code may only be used by licensed users of the CCS C ////
//// compiler. This source code may only be distributed to other ////
//// licensed users of the CCS C compiler. No other use, reproduction ////
//// or distribution is permitted without written permission. ////
//// Derivative programs created using this software in object code ////
//// form are not restricted in any way. ////
///////////////////////////////////////////////////////////////////////////
#ifndef EEPROM_SELECT
#define EEPROM_SELECT PIN_C0
#define EEPROM_CLK PIN_C1
#define EEPROM_DI PIN_C2
#define EEPROM_DO PIN_C3
#endif
#define EEPROM_ADDRESS long int
#define EEPROM_SIZE 256
#define hi(x) (*(&x+1))
void init_ext_eeprom() {
BYTE cmd[2];
BYTE i;
output_low(EEPROM_DI);
output_low(EEPROM_CLK);
output_low(EEPROM_SELECT);
cmd[0]=0xc0;
cmd[1]=0x4;
for(i=1;i<=5;++i)
shift_left(cmd,2,0);
output_high(EEPROM_SELECT);
for(i=1;i<=11;++i) {
output_bit(EEPROM_DI, shift_left(cmd,2,0));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);
}
output_low(EEPROM_DI);
output_low(EEPROM_SELECT);
}
void write_ext_eeprom(EEPROM_ADDRESS address, int16 data) {
BYTE cmd[3];
BYTE i;
cmd[0]=data;
cmd[1]=(BYTE)address;
cmd[2]=0xa|hi(address);
for(i=1;i<=4;++i)
shift_left(cmd,3,0);
output_high(EEPROM_SELECT);
output_low(EEPROM_DO);
for(i=1;i<=27;++i) {
output_bit(EEPROM_DI, shift_left(cmd,3,0));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);
}
output_low(EEPROM_DI);
output_low(EEPROM_SELECT);
delay_ms(19);
output_high(EEPROM_DO);
}
BYTE read_ext_eeprom(EEPROM_ADDRESS address) {
BYTE cmd[3];
BYTE i;
int16 data;
cmd[0]=0;
cmd[1]=(BYTE)address;
cmd[2]=0xc|hi(address);
for(i=1;i<=4;++i)
shift_left(cmd,3,0);
output_high(EEPROM_SELECT);
for(i=1;i<27>11)
shift_left(&data,1,input(EEPROM_DO));
}
output_low(EEPROM_SELECT);
return(data);
} |
|
|
baron Guest
|
93lc66b怎样使用& |
Posted: Tue Sep 05, 2006 2:23 am |
|
|
///////////////////////////////////////////////////////////////////////////
//// Library for a MicroChip 93C66B configured for a x16 org ////
//// ////
//// init_ext_eeprom(); Call before the other functions are used ////
//// ////
//// write_ext_eeprom(a, d); Write the byte d to the address a ////
//// ////
//// d = read_ext_eeprom(a); Read the byte d from the address a ////
//// ////
//// The main program may define eeprom_select, eeprom_di, eeprom_do ////
//// and eeprom_clk to override the defaults below. ////
//// ////
///////////////////////////////////////////////////////////////////////////
//// (C) Copyright 1996,2003 Custom Computer Services ////
//// This source code may only be used by licensed users of the CCS C ////
//// compiler. This source code may only be distributed to other ////
//// licensed users of the CCS C compiler. No other use, reproduction ////
//// or distribution is permitted without written permission. ////
//// Derivative programs created using this software in object code ////
//// form are not restricted in any way. ////
///////////////////////////////////////////////////////////////////////////
#ifndef EEPROM_SELECT
#define EEPROM_SELECT PIN_C0
#define EEPROM_CLK PIN_C1
#define EEPROM_DI PIN_C2
#define EEPROM_DO PIN_C3
#endif
#define EEPROM_ADDRESS long int
#define EEPROM_SIZE 256
#define hi(x) (*(&x+1))
void init_ext_eeprom() {
BYTE cmd[2];
BYTE i;
output_low(EEPROM_DI);
output_low(EEPROM_CLK);
output_low(EEPROM_SELECT);
cmd[0]=0xc0;
cmd[1]=0x4;
for(i=1;i<=5;++i)
shift_left(cmd,2,0);
output_high(EEPROM_SELECT);
for(i=1;i<=11;++i) {
output_bit(EEPROM_DI, shift_left(cmd,2,0));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);
}
output_low(EEPROM_DI);
output_low(EEPROM_SELECT);
}
void write_ext_eeprom(EEPROM_ADDRESS address, int16 data) {
BYTE cmd[3];
BYTE i;
cmd[0]=data;
cmd[1]=(BYTE)address;
cmd[2]=0xa|hi(address);
for(i=1;i<=4;++i)
shift_left(cmd,3,0);
output_high(EEPROM_SELECT);
output_low(EEPROM_DO);
for(i=1;i<=27;++i) {
output_bit(EEPROM_DI, shift_left(cmd,3,0));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);
}
output_low(EEPROM_DI);
output_low(EEPROM_SELECT);
delay_ms(19);
output_high(EEPROM_DO);
}
BYTE read_ext_eeprom(EEPROM_ADDRESS address) {
BYTE cmd[3];
BYTE i;
int16 data;
cmd[0]=0;
cmd[1]=(BYTE)address;
cmd[2]=0xc|hi(address);
for(i=1;i<=4;++i)
shift_left(cmd,3,0);
output_high(EEPROM_SELECT);
for(i=1;i<27>11)
shift_left(&data,1,input(EEPROM_DO));
}
output_low(EEPROM_SELECT);
return(data);
} |
|
|
sjbaxter
Joined: 26 Jan 2006 Posts: 141 Location: Cheshire, UK
|
|
Posted: Tue Sep 05, 2006 2:42 am |
|
|
baron,
I can't belive you posted this in two different threads, especially since this one is over 2 years old !!!, however ....
1) You need to READ the forum policy about posting CCS code !
2) You need to READ the copyright notice at the top of the code
Code: |
(C) Copyright 1996,2003 Custom Computer Services ////
//// This source code may only be used by licensed users of the CCS C ////
//// compiler. This source code may only be distributed to other ////
//// licensed users of the CCS C compiler. No other use, reproduction ////
//// or distribution is permitted without written permission. ////
//// Derivative programs created using this software in object code ////
//// form are not restricted in any way. ////
|
3) It should be posted in the Code library, NOT in the general discussion forum. _________________ Regards,
Simon. |
|
|
baron Guest
|
|
|
|
|
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
|