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 CCS Technical Support

Help optimizing code for LED scrolling sign
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
williefeb_19



Joined: 21 Apr 2008
Posts: 18

View user's profile Send private message

PostPosted: Fri Apr 25, 2008 10:44 am     Reply with quote

i am just doing this project so i can learn C so there isnt anything im doing that is truly needed. Changing the text isnt that important to me id rather see if i can get a longer message.


Quote:
I was thinking of alternative approach where you store the text in ROM, this would allow for larger texts even on the PIC16 but I see you want to be able to change the text. That complicates things a bit...
Do you want the modified text to be remembered when power is removed?


I have found example code to read and write to ROM. how would i delcare the string so it would be in rom and not in the ram.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Apr 25, 2008 2:48 pm     Reply with quote

You can place data in ROM by adding the 'const' keyword before the declaration.

I never use PIC16 processors because they have many limitations and the same price as an PIC18. In the old days there used to be an maximum of 256 bytes for an array in the PIC16, I don't know how this is now but that might be another text size limitation. You can work around this by creating multiple texts, each not longer than 256 bytes.

Here is a program for you to test. It compiles but I haven't checked the output it generates. I introduced a small RAM buffer that has the same size as the characters in your display, this makes it possible to manipulate the data, like shifting.

The test program shows two methods for displaying data:
1) Calling PutDisplay with the new character to add to the display.
2) Using printf. CCS has introduced a nice extension to C where you can add your own output function to printf.

Code:
#include <16F690.h>
#fuses HS, PUT
#use delay(clock=20000000)

#include <string.h>
/*
Pins used on MAX6954APL for SPI communications

MAX_DO PIN_C7
MAX_CLK PIN_B6
MAX_DI PIN_B4
MAX_SEL PIN_C6
*/

#define SPI_MODE_0  (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1  (SPI_L_TO_H)
#define SPI_MODE_2  (SPI_H_TO_L)
#define SPI_MODE_3  (SPI_H_TO_L | SPI_XMIT_L_TO_H)

#define MAX_SEL         PIN_C6
#define DISPLAY_SIZE    8         // Number of characters in display
#define MAX_MSG_LENGTH  50        //maximum message length

#define DIGIT(x)        (0x20+x)  //macro

// Identifier 'const' places the array in ROM instead of RAM.
const char message[] = "Hello world!          ";

char DispBuff[DISPLAY_SIZE];

void SendDisplay(int adr, int chars) //Function to write to displays
{
   output_low(MAX_SEL);
   spi_write(adr);
   spi_write(chars);
   output_high(MAX_SEL);
}

// Send Displaybuffer to display
void UpdateDisplay()
{
  int8 i;

  for(i=0; i<DISPLAY_SIZE; i++)
  {
    SendDisplay(DIGIT(i), DispBuff[i]);
  }
}

// Clear the display
void ClearDisplay()
{
  memset(DispBuff, ' ', sizeof(DispBuff));
  UpdateDisplay();


// Add a single new character to the display and
// shift other characters one position to the left.
void PutDisplay(char NewChar)
{
  int8 i;
 
  // Shift 1 character to left
  for (i=0; i<(DISPLAY_SIZE-1); i++)
  {
    DispBuff[i] = DispBuff[i+1];
  }
 
  // Add New character to buffer
  DispBuff[DISPLAY_SIZE-1] = NewChar;
 
  UpdateDisplay();
}

void main()
{
  int i;

  //Setup SPI FOR serial communication to MAX6954APL
  setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_16);

  //Set Global Intensity to 76
  SendDisplay(0x02, 0x13);
  //Set Configuration REGISTER
  SendDisplay(0x04, 0x13);
 
  while(1)
  {
    // Method 1: using the constant message from ROM.
    ClearDisplay();
    for(i=0; i < sizeof(Message); i++)
    {
      PutDisplay( Message[i] );
      delay_ms(200);
    }


    // Method 2: using printf
    for (i=10; i>0; i--)
    {
      ClearDisplay();
      printf(PutDisplay, "Count %d", i);
      delay_ms(500);
    }
  }
williefeb_19



Joined: 21 Apr 2008
Posts: 18

View user's profile Send private message

PostPosted: Fri Apr 25, 2008 5:07 pm     Reply with quote

ckielstra,

I tried the code you have posted, it works and doesn’t use as much resources as previous code. I'll try to figure out exactly how it's working a little bit later today.

thanks agian
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Apr 25, 2008 10:15 pm     Reply with quote

As a learning exercise you could try to extend the above code to allow control codes inside the text. For example in the CCS supplied LCD driver functions (LCD.c) you can send a '\f' inside the string to clear the screen. You could do the same and introduce codes for:
- Clearing the screen.
- Change the direction of scrolling.
- Change the speed of scrolling.
- Wait a few seconds.
- Blink.
- Other fun effects.
williefeb_19



Joined: 21 Apr 2008
Posts: 18

View user's profile Send private message

PostPosted: Sat Apr 26, 2008 9:41 pm     Reply with quote

Ok, I will give some of those a try. It maybe a while sense my schedule is kind of getting full.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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