CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Not sure what to ask for

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
logical



Joined: 21 Dec 2009
Posts: 57
Location: SouthPort, UK

View user's profile Send private message Visit poster's website

Not sure what to ask for
PostPosted: Tue Dec 22, 2009 8:44 am     Reply with quote

Hi Guys/Gals

Been out of this game for years and have forgotten a lot (never was an expert to start with lol), I have created (partially) a working driver for the sh1101a OLED Screen that I see people posting about recently.

The problem I have is manually using spi_write(0x**) etc

Instead of manually having to create a new line with the above command like a thousand times for each bit, could anyone help me remember how to send a large (string is maybe the name) to it and use the command to send single hex commands via the Spi Port.

This is the code/function that bit bangs the data out and works perfectly

Code:
void write_d (char c);
{

OUTPUT_low(pin_b5);
OUTPUT_high(pin_a0);
//delay_us(1);
spi_write(c); //send the value of comm via the serial port interface
OUTPUT_HIGH(pin_b5);// Tell the chip to ignore all commands from now on
}


My main goal is also to load an image or part of one to the screen

Probably sounds like a dumb [spam] but hey, thought I would ask as I have a C reference book but am totally unsure what to search for.
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Dec 22, 2009 9:49 am     Reply with quote

I'm not sure if this is what your looking for or not,...but
there is a function of printf in CCS that allows you to use your own function, as long as it acts on only a single char. It is then called for again and again for every char in the printf.
See C:\Program Files\PICC\Examples\EX_92LCD.C
Code:
printf(lcd_putc,"\f%4lu",number);

uses lcd_putc
You could do this with write_d().
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Dec 22, 2009 9:54 am     Reply with quote

The above solution is for smaller strings.
Since its an image, it will be larger than a string of 25 or so.
Make a function that takes a pointer to the data area and the size of the
data as the arguments.

Code:
//=======================checksum============================//
int8 chksum(char *data,int8 size)
{
  int8 x;
  int8 chksum=0;
  for (x=0;x<size;x++,data++)
  {
    chksum=chksum+*data;
    //fprintf(DEBUG,".");
  }
  return(chksum);
}
logical



Joined: 21 Dec 2009
Posts: 57
Location: SouthPort, UK

View user's profile Send private message Visit poster's website

PostPosted: Tue Dec 22, 2009 10:01 am     Reply with quote

treitmey wrote:
I'm not sure if this is what your looking for or not,...but
there is a function of printf in CCS that allows you to use your own function, as long as it acts on only a single char. It is then called for again and again for every char in the printf.
See C:\Program Files\PICC\Examples\EX_92LCD.C
Code:
printf(lcd_putc,"\f%4lu",number);

uses lcd_putc
You could do this with write_d().


That is actually a very good idea, was set on the whole graphics idea but have thought of a work around thanks to your suggestion, the screen res is 128*64 graphic but will be mainly using text, that would be a good start for me.

With regards to using a longer string/pointer, I will have to read up on that on how to use, great suggestion and thanks.

Chris
Guest








PostPosted: Tue Dec 22, 2009 6:04 pm     Reply with quote

One more question if anyone can help (on printf)

Would you know if there are any limitations on the printf command or have I done something wrong.

I have added this
Code:
BYTE CONST TABLE [15]= {0x20, 0xff, 0x00, 0x00, 0x00, 0x20, 0x54, 0x54, 0x54, 0x78,0x20, 0x54, 0x54, 0x54, 0x78};


And get the data from it with this:
Code:
printf(write_d,"%s", table);


As soon as it hits one of the 0x00's it breaks, if there are none of them present then the data is sent correctly to the screen.

Thanks again and I have looked rather than being lazy just asking others.
Leef_me



Joined: 14 Mar 2006
Posts: 45

View user's profile Send private message

PostPosted: Tue Dec 22, 2009 7:40 pm     Reply with quote

Per the manual and C in general:
Arrow printf (string)
String is a constant string or an array of characters null terminated.
Using C, null is defined as 0x00

Later, you would have probably found that the bytes 0x0d and 0x0a as well as 0x80, 0x8d, 0x8a would have behaved strangely.

Instead of the printf statement, you will have to write your loop to send the bytes.

__untested code__
Code:

BYTE CONST TABLE [15]= {0x20, 0xff, 0x00, 0x00, 0x00, 0x20, 0x54, 0x54, 0x54, 0x78,0x20, 0x54, 0x54, 0x54, 0x78};

for (x=0; x<15; x++)
{
  write_d(TABLE[x]);
}



edit: corrected loop index test


Last edited by Leef_me on Tue Dec 22, 2009 8:26 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 22, 2009 8:04 pm     Reply with quote

Quote:
for (x=0; x<16; x++)

The array only has 15 elements. The interation limit should be "< 15"
to give iterations from 0 to 14.
logical



Joined: 21 Dec 2009
Posts: 57
Location: SouthPort, UK

View user's profile Send private message Visit poster's website

PostPosted: Tue Dec 22, 2009 8:16 pm     Reply with quote

@leef_me

Absolutely fantastic, I was totally missing the obvious and that loop works perfectly.
should have thought of doing it a similar way rather than messing around Thank you very very much for a prompt reply.

@PCM, duly noted and totally agree thanks :o)

Thanks guys for your help, have helped put me back on track, kind of feel an idiot for asking/overlooking the obvious but its been a long time.

Thanks again

Chris
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group