Jump to content


Photo

Help Boost C Pointer Array Not Working!


6 replies to this topic

#1 Badejavu

Badejavu

    Regular

  • EstablishedMember
  • Pip
  • 27 posts
  • Gender:Male

Posted 04 September 2012 - 02:40 PM

Hello can anyone help with the codes below.I want to display the contents of a pointer array by loading it into another buffer array on an I2C lcd.when i do this, it does not get the contents of the font map on my logic analyser.However if i load the buffer with test (1 to 6) it works.I also tried writing the *N4 [ ] array directly to the I2C sspbuf and it works.I cannot seem to understand why( m_temp_buf[i] = N4[i]; )does not work.
Thanks


//////////////////// MY CODE ///////////////////////////////////////////////

rom char *N4 = { 0xfe, 0x2a, 0xc5, 0x00, 0xa2, 0xe7 }; // LCD font map for the number " 4 "
char m_temp_buf[6] // buffer to hold 6 bytes for the number "4"

/*char m_temp_buf[ ] = {1,2,3,4,5,6};*/ // i tested the buffer with to see this data on my logic analyser and it worked
void GetSegbytes(char); // function to get bytes from the array "N4"
void WritetoLcd(char); //I2C function to write the bytes to an LCD



void main() // main start
{

WritetoLcd(4); // write number " 4 " to Lcd
} //main ends


///////Functions//////////////////////////////////
void GetSegbytes(char num)
{
char i;
switch(num)
{
case '4':
for(i =0; i < 6; i++)
m_temp_buf[i] = N4[i]; //PROBLEM:DOES NOT LOAD VALUES IN ( *N4) ARRAY TO (m_temp_buf)
break;
}
}

void WritetoLcd(char number)
{

GetSegbytes(number);

I2C_start(); //start
for(char i1=0;i1<6;i1++) //send 6 bytes from buffer to I2C
{
sspbuf = m_temp_buf[i1]; //write 6 bytes via I2C ,IF I REPLACE (m_temp_buf[i1]) WITH (N4[i] ) IT WORKS WELL
while (!pir1.SSPIF);
pir1.SSPIF=0;
}
I2C_stop(); // stop
}

#2 Reynard

Reynard

    Maniac

  • EstablishedMember
  • PipPipPipPip
  • 659 posts
  • Gender:Male
  • Location:Scotland
  • Interests:Archery - target and field

Posted 04 September 2012 - 08:14 PM

Did you add the semicolon in your code ?

char m_temp_buf[6]; // buffer to hold 6 bytes for the number "4"

Cheers

Reynard

#3 Badejavu

Badejavu

    Regular

  • EstablishedMember
  • Pip
  • 27 posts
  • Gender:Male

Posted 04 September 2012 - 11:26 PM

Hi Reynard, yes…I did . the code compiles.
m_temp_buf[i] = N4[i];

The array elements of N4 do not load in the m_temp_buf array to be sent over I2C.This is where the problem is.I do not know if it is an issue with the compiler?

#4 Pavel

Pavel

    Super Maniac

  • Administrators
  • PipPipPipPipPip
  • 1,441 posts
  • Gender:Male
  • Location:Melbourne, Australia

Posted 05 September 2012 - 12:03 AM

The problem with the code is that it assumes that 4 is same as '4'.

Regards,
Pavel

#5 Reynard

Reynard

    Maniac

  • EstablishedMember
  • PipPipPipPip
  • 659 posts
  • Gender:Male
  • Location:Scotland
  • Interests:Archery - target and field

Posted 05 September 2012 - 08:29 AM

Doh! I didn't spot that one.

The case is expecting the ascii character '4' but the function WritetoLcd is being past the value of 4.

Cheers

Reynard

#6 Badejavu

Badejavu

    Regular

  • EstablishedMember
  • Pip
  • 27 posts
  • Gender:Male

Posted 05 September 2012 - 10:02 AM

Thanks guys...It worked! :) the case was the problem.Much appreciation.I am new to boost C and the support i am getting here is great!

#7 John S

John S

    Regular

  • EstablishedMember
  • Pip
  • 34 posts
  • Gender:Male
  • Location:UK
  • Interests:Money, Peace

Posted 06 September 2012 - 11:00 AM

!


Edited by John S, 15 June 2013 - 01:52 PM.




Reply to this topic



  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users