Salve a tutti. Ho intenzione di costruire un programmatore per scrivere solo alcuni valori su una eprom 24lc02. Ho preso questo schema e l'ho modoficato per il pic16f876 che ha l'I2c incorporato mettendo le due resistenze di pullup da 10k su SDA e SCL.
Poi ho cercato di programmare il pic usando il programma mikroC pro: ho selezionato come device in basso a sinistra il pic16f876 e come mcu clock 4Mhz in quanto il quarzo sui piedini del''oscillatore del pic è da 4Mhz.
Poi ho caricato il file di esempio:
void main(){
ANCON0 = 0; // Configure PORTB pins as digital
ANCON1 = 0; // Configure PORTC pins as digital
ANCON2 = 0;
TRISB = 0; // Configure PORTB as output
LATB = 0; // Clear PORTB
I2C1_Init(100000); // initialize I2C communication
I2C2_Init(100000);
Delay_ms(500);
// TRISD5_bit = 0;
while(1){
I2C1_Start(); // issue I2C start signal
I2C1_Wr(0xA2); // send byte via I2C (device address + W)
I2C1_Wr(2); // send byte (address of EEPROM location)
I2C1_Wr(0xAA); // send data (data to be written)
I2C1_Stop(); // issue I2C stop signal
Delay_100ms();
I2C1_Start(); // issue I2C start signal
I2C1_Wr(0xA2); // send byte via I2C (device address + W)
I2C1_Wr(2); // send byte (data address)
I2C1_Repeated_Start(); // issue I2C signal repeated start
I2C1_Wr(0xA3); // send byte (device address + R)
LATB = I2C1_Rd(0u); // Read the data (NO acknowledge)
I2C1_Stop(); // issue I2C stop signal
Delay_ms(1000);
I2C2_Start(); // issue I2C start signal
I2C2_Wr(0xA2); // send byte via I2C (device address + W)
I2C2_Wr(2); // send byte (address of EEPROM location)
I2C2_Wr(0x55); // send data (data to be written)
I2C2_Stop(); // issue I2C stop signal
Delay_100ms();
I2C2_Start(); // issue I2C start signal
I2C2_Wr(0xA2); // send byte via I2C (device address + W)
I2C2_Wr(2); // send byte (data address)
I2C2_Repeated_Start(); // issue I2C signal repeated start
I2C2_Wr(0xA3); // send byte (device address + R)
LATB = I2C2_Rd(0u); // Read the data (NO acknowledge)
I2C2_Stop(); // issue I2C stop signal
Delay_ms(1000);
}
Ho cliccato sul''icona program e dalla finestra che si apre ho salvato l'hex che ho messo nel pic tramite icprog. Ma non funziona. Ho provato anche a sostituire gli indirizzi 0xA2 e 0xA3 con 0xA0 e 0xA1 perchè ho tutti i pin della eprom collegati a massa, ma non va non scrive niente.
Mi potete aiutare per favore? Quali sono i punti che sbaglio?
Grazie come sempre del vostro supporto.
Pier
circ.jpg (Dimensione: 36.9 KB / Download: 13)
Poi ho cercato di programmare il pic usando il programma mikroC pro: ho selezionato come device in basso a sinistra il pic16f876 e come mcu clock 4Mhz in quanto il quarzo sui piedini del''oscillatore del pic è da 4Mhz.
Poi ho caricato il file di esempio:
void main(){
ANCON0 = 0; // Configure PORTB pins as digital
ANCON1 = 0; // Configure PORTC pins as digital
ANCON2 = 0;
TRISB = 0; // Configure PORTB as output
LATB = 0; // Clear PORTB
I2C1_Init(100000); // initialize I2C communication
I2C2_Init(100000);
Delay_ms(500);
// TRISD5_bit = 0;
while(1){
I2C1_Start(); // issue I2C start signal
I2C1_Wr(0xA2); // send byte via I2C (device address + W)
I2C1_Wr(2); // send byte (address of EEPROM location)
I2C1_Wr(0xAA); // send data (data to be written)
I2C1_Stop(); // issue I2C stop signal
Delay_100ms();
I2C1_Start(); // issue I2C start signal
I2C1_Wr(0xA2); // send byte via I2C (device address + W)
I2C1_Wr(2); // send byte (data address)
I2C1_Repeated_Start(); // issue I2C signal repeated start
I2C1_Wr(0xA3); // send byte (device address + R)
LATB = I2C1_Rd(0u); // Read the data (NO acknowledge)
I2C1_Stop(); // issue I2C stop signal
Delay_ms(1000);
I2C2_Start(); // issue I2C start signal
I2C2_Wr(0xA2); // send byte via I2C (device address + W)
I2C2_Wr(2); // send byte (address of EEPROM location)
I2C2_Wr(0x55); // send data (data to be written)
I2C2_Stop(); // issue I2C stop signal
Delay_100ms();
I2C2_Start(); // issue I2C start signal
I2C2_Wr(0xA2); // send byte via I2C (device address + W)
I2C2_Wr(2); // send byte (data address)
I2C2_Repeated_Start(); // issue I2C signal repeated start
I2C2_Wr(0xA3); // send byte (device address + R)
LATB = I2C2_Rd(0u); // Read the data (NO acknowledge)
I2C2_Stop(); // issue I2C stop signal
Delay_ms(1000);
}
Ho cliccato sul''icona program e dalla finestra che si apre ho salvato l'hex che ho messo nel pic tramite icprog. Ma non funziona. Ho provato anche a sostituire gli indirizzi 0xA2 e 0xA3 con 0xA0 e 0xA1 perchè ho tutti i pin della eprom collegati a massa, ma non va non scrive niente.
Mi potete aiutare per favore? Quali sono i punti che sbaglio?
Grazie come sempre del vostro supporto.
Pier
