bonjour
mon compilateur est hi-tech pic10/12/16 pro et j'utilise le PIC16F877A j'ai ecrire ce code pour interfacer l'eeprom 95160 mais ce code ne marche pas si vous m'aider a l'occaliser le probleme ?
merci d'avance
/****************************** ****************************** ******************
* *
****************************** ****************************** *******************/
#include <htc.h>
#define _XTAL_FREQ 4000000
#include <_25xxx.h>
/****************************** ****************************** ******************/
__CONFIG (XT & WDTDIS & PWRTEN & BORDIS & WRTEN & LVPDIS & DUNPROT & DEBUGDIS);
/****************************** ****************************** ******************
* *
****************************** ****************************** *******************/
unsigned char buffe;
void main()
{
__delay_ms(5);
init_25xxx();
Send_command(WREN_CMD);
Write_25xxx(0x0004, 0x55);
Write_25xxx(0x0010,Read_25xxx( 0x0004));
while(1){}
}/****************************** ****************************** ******************
*
*
*
*
*
*
*
****************************** ****************************** *******************/
#define WREN_CMD 0b00000110
#define WRDI_CMD 0b00000100
#define WRITE_CMD 0b00000010
#define READ_CMD 0b00000011
#define WRDS_CMD 0b00000100
#define RDSR_CMD 0b00000101
#define CS RC7
/****************************** ****************************** ******************
* déclaration fonctions
****************************** ****************************** *******************/
void init_25xxx(void);
void Write_25xxx(unsigned int,unsigned char);
unsigned char Read_25xxx(unsigned int);
void Send_command(unsigned char x);
unsigned char Spi_out(unsigned char);
/****************************** ****************************** ******************
* déclaration variables
****************************** ****************************** *******************/
unsigned int adresse;
unsigned char HIbyte;
unsigned char LObyte;
unsigned char Mem_data;
unsigned char dummy;
/****************************** ****************************** ******************
* initial spi port
****************************** ****************************** *******************/
void init_25xxx(void)
{
PORTC = 0;
SSPSTAT = 0;
SSPCON = 0;
TRISC = 0b00010000;
SSPSTAT = 0b10000000;
SSPCON = 0b00110001;
}
/****************************** ****************************** ******************
* Write eeprom
****************************** ****************************** *******************/
void Write_25xxx(unsigned int adresse, unsigned char Mem_data)
{
LObyte = adresse;
HIbyte = (unsigned char)(adresse >> 8);
CS = 0;
dummy = Spi_out(WRITE_CMD);
dummy = Spi_out(HIbyte);
dummy = Spi_out(LObyte);
dummy = Spi_out(Mem_data);
CS = 1;
}
/****************************** ****************************** ******************
* Read eeprom
****************************** ****************************** *******************/
unsigned char Read_25xxx(unsigned int adresse)
{
LObyte = adresse;
HIbyte = (unsigned char)(adresse >> 8);
CS = 0;
dummy = Spi_out(READ_CMD);
dummy = Spi_out(HIbyte);
dummy = Spi_out(LObyte);
CS = 1;
return SSPBUF;
}
/****************************** ****************************** ******************
* Send command
****************************** ****************************** *******************/
void Send_command(unsigned char Command)
{
CS = 0;
dummy = Spi_out(Command);
CS = 1;
}
/****************************** ****************************** ******************
* Spi_output
****************************** ****************************** *******************/
unsigned char Spi_out(unsigned char Spi_byte)
{
SSPBUF = Spi_byte;
do{}
while(!BF);
return SSPBUF;
}
-----