besoin de l'aide pour interfacer l'eeprpm m95160
Répondre à la discussion
Affichage des résultats 1 à 3 sur 3

besoin de l'aide pour interfacer l'eeprpm m95160



  1. #1
    LABTOOL48

    besoin de l'aide pour interfacer l'eeprpm m95160


    ------

    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;
    }

    -----
    Fichiers attachés Fichiers attachés

  2. #2
    LABTOOL48

    Re : besoin de l'aide pour interfacer l'eeprpm m95160

    bonjour

    j'ai trouver ce fichier en assembleur et c'est la meme chose avec la 95160 et j'ai modifier mes fonctions mais toujour rien


    ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~
    ;
    ; Software License Agreement
    ;
    ; The software supplied herewith by Microchip Technology Incorporated
    ; (the "Company") for its PICmicro® Microcontroller is intended and
    ; supplied to you, the Company’s customer, for use solely and
    ; exclusively on Microchip PICmicro Microcontroller products.
    ;
    ; The software is owned by the Company and/or its supplier, and is
    ; protected under applicable copyright laws. All rights are reserved.
    ; Any use in violation of the foregoing restrictions may subject the
    ; user to criminal sanctions under applicable laws, as well as to
    ; civil liability for the breach of the terms and conditions of this
    ; license.
    ;
    ; THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,
    ; WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
    ; TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
    ; PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
    ; IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
    ; CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
    ;
    ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~
    ;
    ; Filename: PIC16F877 SPI.asm
    ; Date: December 7, 2004
    ; File Version: 1.0
    ; Assembled using: MPLAB IDE 6.50.00.0
    ;
    ; Author: Martin Kvasnicka
    ; Company: Microchip Technology, Inc.
    ;
    ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~
    ;
    ; Files required: p16f877.inc
    ;
    ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~
    ;
    ; Purpose:
    ;
    ; Besides serving as an update to AN647, the firmware for this app note is
    ; being written so it can be used as a basis for any of the SPI devices
    ; Microchip currently makes from 4K to 256K.
    ;
    ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~
    ;
    ; Program Description:
    ;
    ; This program goes through the basics of SPI communication using the
    ; MSSP module for the PIC16F877. AN909 should be referenced for further
    ; explaination as far as what to watch out for and proper programming
    ; techniques for the SPI protocol. The program has examples of WRITE ENABLE,
    ; WRITE, READ, READ STATUS, and WRITE DISABLE commmands. There are also
    ; Scope plots of all these commands in the Application Note itself.
    ; The program write enables the device, writes one byte, polls the WIP
    ; bit, reads the data written, write disables the device and keeps running
    ; this sequence continuously.
    ;
    ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~
    LIST P=16F877
    ; Port C pin descriptions
    ; SCK bit = 3
    ; SDI bit = 4
    ; SDO bit = 5
    ; CS bit = 7
    ;
    ; 10MHz crystal is being used, thus each instruction cycle = 1600nS
    ;
    ;*******************RAM register definitions******************* ***
    w equ 1
    f equ 0
    rxdata equ 20h
    txdata equ 21h
    addr equ 22h
    loops equ 23h
    outbyte equ 24h
    temp1 equ 25h
    temp2 equ 26h
    ;*******************Bit definitions******************* ************
    CS equ 7
    ;*******************Include file************************** ********
    include "p16f877.inc" ; this is the include file for a PIC16F877
    errorlevel -302 ; suppress message 302 from list file
    LIST
    ; P16C877.INC Standard Header File, Ver. 1.00 Microchip Technology, Inc.
    LIST
    ;***************************** ****************************** ******
    org 0x000 ; set the reset vector
    goto start ; go to the beginning of main
    ;!!!!!!!!!!!!!!!!!!!!!!Begin Main Program!!!!!!!!!!!!!!!!!!!!!!! !!
    start
    bcf STATUS,RP0 ; set to bank 0
    clrf PORTC ; initialize portc to 0
    bsf STATUS,RP0 ; set to bank 1
    movlw 0x10 ; all bits are outputs except SDI
    movwf TRISC ; move the value to TRIS portc
    bcf STATUS,RP0 ; set to bank0
    bsf PORTC,CS ; make the chip select is high
    clrf PIE1 ; disable peripheral interrupts
    clrf INTCON ; disables all interrupts
    bcf STATUS,RP0 ; set to bank 0
    clrf SSPCON ; clear SSP control register
    movlw 0x31 ; set up spi port, SPI master,
    movwf SSPCON ; clk/16, ckp=1 (mode 1,1)
    bsf STATUS,RP0 ; set to bank 1
    clrf SSPSTAT ; clear SSP status register
    movlw 0x80 ; set up spi port, SPI master,
    movwf SSPSTAT ; cke = 0 (mode 1,1)
    bcf STATUS,RP0 ; set to bank 0
    movlw 0x55 ; put starting address 55 in
    movwf addr ; addr for later use
    ;Send the write enable sequence (WREN)
    bcf PORTC,CS ; clear the chip select (active)
    movlw 0x06 ; load WREN sequence
    movwf outbyte ; store in RAM location outbyte
    call output ; call the SPI output routine
    bsf PORTC,CS ; set the chip select line
    ;Send the write status register sequence (WRSR)
    bcf PORTC,CS ; clear the chip select line
    movlw 0x01 ; clear all status register
    movwf outbyte ; store in RAM location outbyte
    call output ; call the SPI output routine
    movlw 0x00 ; load up zero to send
    movwf outbyte ; store in RAM location outbyte
    call output ; call the SPI output routine
    bsf PORTC,CS ; set the chip select line
    ;Wait the required 5mS for the write cycle timer Twc
    call delay ; call the delay subroutine
    ;Send the write enable sequence (WREN)
    bcf PORTC,CS ; clear the chip select (active)
    movlw 0x06 ; load WREN sequence
    movwf outbyte ; store in RAM location outbyte
    call output ; call the SPI output routine
    bsf PORTC,CS ; set the chip select line
    ;Send the read status register sequence (RDSR)
    bcf PORTC,CS ; clear the chip select line
    movlw 0x05 ; load RDSR sequence
    movwf outbyte ; store in RAM location outbyte
    call output ; call the SPI output routine
    call output ; read the data in status reg.
    bsf PORTC,CS ; set the chip select line
    ;Send the write sequence (WRITE)
    bcf PORTC,CS ; clear the chip select line
    movlw 0x02 ; load WRITE sequence
    movwf outbyte ; store in RAM location outbyte
    call output ; call the SPI output routine
    ;****Comment out for use with 25xx010, 25xx020 or 25xx040********
    movlw 0x00 ; load high address byte
    movwf outbyte ; store in RAM location outbyte
    call output ; call the SPI output routine
    ;***************************** ****************************** *****
    movf addr,W ; move the address into w
    movwf outbyte ; store in RAM location outbyte
    call output ; call the SPI output routine
    movlw 0xAA ; load data AA into w
    movwf outbyte ; store in RAM location outbyte
    call output ; call the SPI output routine
    bsf PORTC,CS ; set the chip select line
    ;Perform data polling (RDSR bit 0)
    bcf PORTC,CS ; clear the chip select line
    movlw 0x05 ; load RDSR sequence
    movwf outbyte ; store in RAM location outbyte
    call output ; call the SPI output routine
    movlw 0x10 ; give the spi device time to;
    movwf loops ; set the WIP bit in the;
    wait
    decfsz loops,f ; status register before coming;
    goto wait ; back and doing data polling;
    polling
    bcf PORTC,CS ; clear the chip select line
    call output ; read the data in status reg.
    call output ; read the data in status reg.
    bsf PORTC,CS ; set the chip select line
    btfsc rxdata,0 ; test the WIP bit in status reg.
    goto polling ; WIP set, loop until WIP clear
    bsf PORTC,CS ; set the chip select line
    ;Send read sequence (READ), read address 0x55
    bcf PORTC,CS ; clear the chip select line
    movlw 0x03 ; load READ sequence
    movwf outbyte ; store in RAM location outbyte
    call output ; call the SPI output routine
    ;****Comment out for use with 25xx010, 25xx020 or 25xx040********
    movlw 0x00 ; load high address byte
    movwf outbyte ; store in RAM location outbyte
    call output ; call the SPI output routine
    ;***************************** ****************************** *****
    movf addr,W ; move the address into w
    movwf outbyte ; store in RAM location outbyte
    call output ; call the SPI output routine
    call output ; call output to read 1 byte
    bsf PORTC,CS ; set the chip select line
    ;Send the write enable sequence (WREN)
    bcf PORTC,CS ; clear the chip select (active)
    movlw 0x06 ; load WREN sequence
    movwf outbyte ; store in RAM location outbyte
    call output ; call the SPI output routine
    bsf PORTC,CS ; set the chip select line
    ;Send the read status register sequence (RDSR)
    bcf PORTC,CS ; clear the chip select line
    movlw 0x05 ; load RDSR sequence
    movwf outbyte ; store in RAM location outbyte
    call output ; call the SPI output routine
    call output ; read the data in status reg.
    bsf PORTC,CS ; set the chip select line
    ;Send the write disable sequence (WRDI)
    bcf PORTC,CS ; clear the chip select (active)
    movlw 0x04 ; load WRDI sequence
    movwf outbyte ; store in RAM location outbyte
    call output ; call the SPI output routine
    bsf PORTC,CS ; set the chip select line
    ;Send the read status register sequence (RDSR)
    bcf PORTC,CS ; clear the chip select line
    movlw 0x05 ; load RDSR sequence
    movwf outbyte ; store in RAM location outbyte
    call output ; call the SPI output routine
    call output ; read the data in status reg.
    ;*******Go back to main routine*********************** **********
    goto start
    ;*******************SPI output subroutine******************** ***
    output
    movf outbyte,W ; move outbyte into w
    movwf SSPBUF ; place data in send buffer
    loop1
    bsf STATUS,RP0 ; set to bank 1
    btfss SSPSTAT,BF ; has data been received?
    goto loop1 ; loop if not received yet
    bcf STATUS,RP0 ; set to bank 0
    movf SSPBUF,W ; empty the receive buffer
    movwf rxdata ; put received byte into rxdata
    retlw 0 ; return from subroutine
    ; 250 x 400nS x 50 = 5mS (plus overhead)
    delay
    movlw 0x32 ; move 50 decimal into w
    movwf temp1 ; move 50 decimal into temp1
    dec1
    movlw 0xFA ; move 250 decimal into w
    movwf temp2 ; move 250 decimal into temp2
    dec2
    decfsz temp2,1 ; decrement temp2, skip if zero
    goto dec2 ; goto decrement 2 if not zero
    decfsz temp1,1 ; decrement temp1, skip if zero
    goto dec1 ; goto decrement 1 if not zero
    retlw 0 ; return both locations = 0

    END
    j'ai corrigé cet expression pour le test de l'indicateur BF
    unsigned char Spi_out(unsigned char Spi_byte)
    {
    SSPBUF = Spi_byte;
    do{}
    while(BF == 1);
    return SSPBUF;
    }
    et j'ai utiliser le meme parametre d'initialisation
    void init_25xxx(void)
    {
    PORTC = 0;SSPSTAT = 0;SSPCON = 0;INTCON = 0;PIE1 = 0;PIE2 = 0;
    TRISC = 0x10; //0b00010000; //SCK.RC3=0 /SDI.RC4=1 /SDO.RC5=0
    SSPSTAT = 0x80; //0b10000000; //SMP.B7=1 //CKE.B6=0 //BF.B0=0
    SSPCON = 0x31; //0b00110001; //SSPEN.B5=1 /CKP.B4=1 /SSPM.BX=0001
    CS = 1;
    }
    Fichiers attachés Fichiers attachés
    Dernière modification par LABTOOL48 ; 26/05/2010 à 14h22.

  3. #3
    LABTOOL48

    Re : besoin de l'aide pour interfacer l'eeprpm m95160

    et voici mon programme principal
    /****************************** ********************
    *
    ****************************** *********************/
    void main()
    {
    __delay_ms(5);
    init_25xxx();
    Send_command(WREN_CMD);
    CS = 0;
    Spi_out(WRSR_CMD);
    Spi_out(0x00);
    CS = 1;
    __delay_ms(5);
    Send_command(WREN);
    CS = 0;
    Spi_out(RDSR_CMD);
    Spi_out(RDSR_CMD);
    CS = 1;
    Write_25xxx(0x0004, 0x55);
    Write_25xxx(0x0010,Read_25xxx( 0x0004));
    while(1){}
    }

Discussions similaires

  1. Réponses: 1
    Dernier message: 09/04/2009, 09h24
  2. Besoin d'aide pour OCAML A l'aide !
    Par invitedfb06e4d dans le forum Logiciel - Software - Open Source
    Réponses: 1
    Dernier message: 25/03/2009, 20h58
  3. A l'aide, j'ai besoin d'un petit conseil pour un transistor ?
    Par invite51d5feb2 dans le forum Électronique
    Réponses: 1
    Dernier message: 17/07/2008, 22h46
  4. Réponses: 0
    Dernier message: 15/02/2007, 09h03
  5. Réponses: 11
    Dernier message: 21/12/2006, 22h49
Dans la rubrique Tech de Futura, découvrez nos comparatifs produits sur l'informatique et les technologies : imprimantes laser couleur, casques audio, chaises gamer...