View previous topic :: View next topic |
Author |
Message |
yym05
Joined: 25 Mar 2007 Posts: 6 Location: South, Korea
|
24lc32a Ext EEPROM |
Posted: Tue Apr 03, 2007 10:33 am |
|
|
Hello .
I am learnning '24LC32A' that is external EEPROM.
However, something is wrong!
Used 2432.c driver and taking 10k ohm Pull-up both SDL, SCA pin.
Please show me relation sample.
Thanks many.
Compailer Version : 4.023
DEVICE : PIC16F877A
code
///header file
#include <16F877A.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Crystal osc <= 4mhz
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#use delay(clock=4000000)
///source code
#include "bb.h"
#include <LCD.C>
#include <2432.c>
void port_init(){
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
set_tris_d(0x0f);
}
void write_eeprom_data(long int address, char *string){
while(*string){
write_ext_eeprom(address,*string);
string++;
address++;
}
}
char *read_data="0123456789ABCDEF";
void read_eeprom_data(long int address, char len){
char i=0;
while(len){
read_data[i]=read_ext_eeprom(address);
i++;
len--;
}
read_data[i]=0;
}
void lcd_puts(char *ptr){
char len=0;
while(*ptr){
lcd_putc(*ptr++);
len++;
if(len>15) lcd_gotoxy(1,2);
}
}
void main(){
long int address=0x00;
char *ee_char="Hello World!";
port_init();
lcd_init();
init_ext_eeprom();
lcd_gotoxy(1,1);
lcd_puts(read_data);
while(TRUE){
write_eeprom_data(address,ee_char);
lcd_gotoxy(1,2);
read_eeprom_data(address,16);
lcd_puts(read_data);
}
} _________________ Yeongmo Yang
Last edited by yym05 on Tue Apr 03, 2007 8:16 pm; edited 5 times in total |
|
|
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Tue Apr 03, 2007 11:13 am |
|
|
Yeongmo,
What are A0-A2 connected to on the EEPROM?
They are the address pins. I think if you are using the example code they should be connected to Vss (gnd).
John |
|
|
yym05
Joined: 25 Mar 2007 Posts: 6 Location: South, Korea
|
It’s already connected. |
Posted: Tue Apr 03, 2007 5:40 pm |
|
|
It’s already connected.
John. Thanks.
but... As you can see the image, it was connected. _________________ Yeongmo Yang
Last edited by yym05 on Tue Apr 03, 2007 7:43 pm; edited 1 time in total |
|
|
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Tue Apr 03, 2007 5:47 pm |
|
|
OK.
Post your code and someone should be able to offer some suggestions.
John |
|
|
yym05
Joined: 25 Mar 2007 Posts: 6 Location: South, Korea
|
CODE |
Posted: Tue Apr 03, 2007 6:16 pm |
|
|
OK _________________ Yeongmo Yang
Last edited by yym05 on Tue Apr 03, 2007 7:32 pm; edited 2 times in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Apr 03, 2007 6:34 pm |
|
|
1. Post the PIC that you're using.
2. Post your compiler version. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Apr 03, 2007 9:00 pm |
|
|
The problem is in vs. 4.023 of the compiler.
In vs. 4.021, they changed the operation of the compiler, as follows:
Quote: | 4.021 The & unary operator by default no longer returns a generic (int8 *) |
But they didn't change all the example and driver files to reflect this
change.
Here is the hi() function from the 2432.c file:
Quote: | #define hi(x) (*(&x+1)) |
With the new operation of the compiler, this statement will not fetch
the high byte of a 16-bit number.
To fix the problem, you need to modify the hi() macro to this:
Code: | #define hi(x) (*((int8 *)&x+1)) |
This casts the address pointer to be a byte pointer. That's what you need. |
|
|
yym05
Joined: 25 Mar 2007 Posts: 6 Location: South, Korea
|
Is activated. |
Posted: Wed Apr 04, 2007 12:30 am |
|
|
Thanks many. _________________ Yeongmo Yang |
|
|
|