2 byte eeprom displaying on USART

Discussion in 'Embedded Systems and Microcontrollers' started by quantumlab, Feb 5, 2009.

  1. quantumlab

    Thread Starter Member

    Dec 4, 2008
    19
    0
    The code below should display a 16 bit number on the USART as 2 seperate byte,MSB and LSB one after the other on the same recieved line, our output should look like

    10 = 256
    11 = 257
    12 = 258
    13 = 259

    instead it outputs

    Received: 0 0
    Received: 1 2
    Received: 2 3

    We know that the loop is incorrect, we think it is re-reading the same address line, can anybody help??

    Thanks

    int i;
    long j, byte_Byte1, byte_Byte2;
    unsigned short temp_res, temp_res2;
    void EEPROMWriteInt(int p_address, long p_value)
    {
    byte_Byte1 = ((p_value >> 0) & 0xFF);
    byte_Byte2 = ((p_value >> 8) & 0xFF);

    EEprom_Write(p_address , byte_Byte1);
    EEprom_Write(p_address +1 , byte_Byte2);
    }

    void main() {
    ANSEL = 0; // Configure AN pins as digital I/O
    ANSELH = 0;
    PORTB = 0; // Initial PORTB value
    TRISB = 0; // Set PORTB as output
    PORTD = 0;
    TRISD = 0;

    j = 257;
    for (i = 0; i < 3; i++)
    // Write some data to EEPROM
    /* EEprom_Write(i, j++); */ // at addresses 0..3
    EEPROMWriteINT(i,j++) ;
    Delay_ms(50);
    for (i = 0; i < 3; i++) {

    USART_Init(19200); // Initalize USART (19200 baud rate, 1 stop bit, no parity...)

    ns as digital I/O
    temp_res = PORTB; // Read 10-bit ADC from AN2 and discard 2 LS bits
    temp_res2 = PORTD ;
    Delay_ms(100);

    PORTB = EEPROM_Read(i); // Read data and display it on PORTB

    PORTD = EEPROM_Read(i+1) ;
    USART_Write(temp_res); // Send ADC reading as byte
    USART_Write(temp_res2);
    Delay_ms(500);
    }
     
  2. n9352527

    AAC Fanatic!

    Oct 14, 2005
    1,198
    4
    Hm... the first two values would always be zero. Those are the default PORTB and PORTD values.

    Where's the EEPROM reading function?
     
Loading...