Menu

i need help with read and write function in c#

2019-06-07
2019-10-17
<< < 1 2 (Page 2 of 2)
  • Mourad hosni

    Mourad hosni - 2019-10-15

    it's c code the program is picc knon as ccs
    output_high/low do? = example port B0 go high 1 go low 0

    got it working i receive from eeprom exact 64 byte.
    i changed the function output expander wih this

    define DataPin output_bit

    define ShiftClockPin output_bit

    define LatchPin output_bit

    void ShiftOut(int8 data)
    {
    ShiftClockPin(PIN_B1, 0); //default clock low
    DataPin(PIN_B2, 0); //default data low
    LatchPin(PIN_B0, 0); //default latch low
    unsigned char bitcount = 0; //init bit counter
    for(bitcount = 0; bitcount < 8; bitcount++) //send 8 bits
    {
    DataPin(PIN_B2, 0); //assume MSB = 0
    if(data & 0b10000000) //if MSB = 1
    {
    DataPin(PIN_B2, 1); //send 1
    }
    ShiftClockPin(PIN_B1, 1); //strobe clock
    ShiftClockPin(PIN_B1, 0);
    data = data << 1; //left shift data bits
    }
    LatchPin(PIN_B0, 1); //strobe latch
    LatchPin(PIN_B0, 0);
    }

     
  • Mourad hosni

    Mourad hosni - 2019-10-15

    im 50year age :)
    now i need function to receive all eeprom content, like your function in ccs:

    case SPI_READ:              //SPI read (nbytes) if n=0 reads SSPBF
                TXins(SPI_READ);
                if(RXptr+1<number_of_bytes_read){
                    i=receive_buffer[++RXptr];              //save nbytes
                    TXins(i);
    

    if !defined(SW_SPI) //hardware peripheral

                    if(!i) TXins(SSPBUF);                   //if n=0 reads SSPBF
                    else{
                        TRISBbits.TRISB0=1;     //D input
                        for(;i;i--){                        //bytes requested
                            PIR1bits.SSPIF=0;
                            i2=SSPBUF;                      //workaround for rev3 errata
                            for(SSPBUF=0;!PIR1bits.SSPIF;);     //read
                            for(i2=PR2>>1;i2;i2--);         //workaround for rev3 errata
                            TXins(SSPBUF);                          //write to queue
                        }
                    }
    

    else //software mode

                    if(!i) TXins(0);                    //if n=0 reads 0
                    else{
                        TRISBbits.TRISB0=1;     //D input
                        for(;i;i--){                        //bytes requested
                            TXins(SW_IO_SPI(0));            //write to queue
                        }
                    }
    

    endif

                }
                else{
                    TXins(RX_ERR);
                    receive_buffer[RXptr+1]=FLUSH;
                }
                break;
            case SPI_WRITE:             //SPI write (nbytes)
                TXins(SPI_WRITE);
                i=receive_buffer[++RXptr];
                if(RXptr+i<number_of_bytes_read){
                    TXins(i);
                    TRISCbits.TRISC7=0;     //D output
                    for(;i;i--){                        //bytes requested
    

    if !defined(SW_SPI) //hardware peripheral

                        PIR1bits.SSPIF=0;
                        i2=SSPBUF;                      //workaround for rev3 errata
                        for(SSPBUF=receive_buffer[++RXptr];!PIR1bits.SSPIF;);       //write
                        for(i2=PR2>>1;i2;i2--);         //workaround for rev3 errata
    

    else //software mode

                        SW_IO_SPI(receive_buffer[++RXptr]);
    

    endif

                    }
                }
                else{
                    TXins(RX_ERR);
                    receive_buffer[RXptr+1]=FLUSH;
                }
                break;
            case EXT_PORT:              //EXT_PORT, controls expansion lines on PORTB,A,C
                TXins(EXT_PORT);
                if(RXptr+2<number_of_bytes_read){
                    LATB=receive_buffer[++RXptr];
                    i=receive_buffer[++RXptr];
                    LATC=(LATC&0x3F)|(i&0xC0);  //00111111
                    LATA=(LATA&0xC7)|(i&0x38);  //11000111
                }
                else{
                    TXins(RX_ERR);
                    receive_buffer[RXptr+1]=FLUSH;
                }
                break;
    
                thx
    
     
  • Alberto Maccioni

    Ok, so you are already modifying the firmware; it was not clear at all.
    The first step is to understand what new instructions you want to implement.
    I assume you need to send a configuration to the shift registers: that's one.
    Then in order to transfer data from the memory you can use the READ_B.
    Now you have to shift to the control software and write the correct sequence of instructions.
    For example:
    -set the shift register configuration a certain amount of times (I am not familiar with the memory, it may be that you just need to set the address).
    -read B port via READ_B.
    Repeat for every address.

     
<< < 1 2 (Page 2 of 2)

Anonymous
Anonymous

Add attachments
Cancel