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

[Answered] Out of Rom Pic16F628A

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



Joined: 11 Mar 2012
Posts: 45
Location: Egypt

View user's profile Send private message

[Answered] Out of Rom Pic16F628A
PostPosted: Sun Mar 11, 2012 3:28 pm     Reply with quote

I am making a digital clock using LEDs powered by shift registers instead of a 7 segment display. Anyway, when compiling the code, I get the following error:

Code:
***Error 71 "test.c" Line 351(0,1) Out of ROM, A segment or the program is too large  num
Seg 00004-007FF, 07DC left, need 0F8F
Seg 00000-00003, 0000 left, need 0F8F



And here is my code so far:

Code:


#include <16f628a.h>
#use delay (crystal=32768)


void num(int rnum, char out, char clk) {
   
//start clear shift register   
   output_high(clk);
   output_low(clk);
   output_high(clk);
   output_low(clk);
   output_high(clk);
   output_low(clk);
   output_high(clk);
   output_low(clk);
   output_high(clk);
   output_low(clk);
   output_high(clk);
   output_low(clk);
   output_high(clk);
   output_low(clk);
   output_high(clk);
   output_low(clk);
//end clear shift register
   
   switch(rnum) {
      case 0:
         output_high(out);
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
         output_low(out);
         output_high(clk);
         output_low(clk);
         output_high(out);
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
         output_low(out);
         output_high(clk);
         output_low(clk);
         output_low(out);
      break;
      case 1:
         output_low(out);
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
         output_high(out);
         output_high(clk);
         output_low(clk);
         output_low(out);
         output_high(clk);
         output_low(clk);
         output_high(out);
         output_high(clk);
         output_low(clk);
         output_low(out);
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
         break;
      case 2:
         output_high(out);//7
         output_high(clk);
         output_low(clk);
         output_low(out);//6
         output_high(clk);
         output_low(clk);
         output_high(out);//5
         output_high(clk);
         output_low(clk);
         output_high(clk);//4
         output_low(clk);
         output_high(clk);//3
         output_low(clk);
         output_low(out);//2
         output_high(clk);
         output_low(clk);
         output_high(out);
         output_high(clk);
         output_low(clk);
         output_low(out);
         output_high(clk);
         output_low(clk);
      break;
      case 3:
         output_high(out);//7
         output_high(clk);
         output_low(clk);
         output_high(clk);//6
         output_low(clk);
         output_high(clk);//5
         output_low(clk);
         output_low(out);//4
         output_high(clk);
         output_low(clk);
         output_high(out);//3
         output_high(clk);
         output_low(clk);
         output_low(out);//2
         output_high(clk);
         output_low(clk);
         output_high(out);//1
         output_high(clk);
         output_low(clk);
         output_low(out);
         output_high(clk);
         output_low(clk);
      break;
      case 4:
         output_high(out);//7
         output_high(clk);
         output_low(clk);
         output_high(out);//6
         output_high(clk);
         output_low(clk);
         output_low(out);//5
         output_high(clk);
         output_low(clk);
         output_low(out);//4
         output_high(clk);
         output_low(clk);
         output_high(out);//3
         output_high(clk);
         output_low(clk);
         output_high(out);//2
         output_high(clk);
         output_low(clk);
         output_low(out);//1
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
      break;
      case 5:
         output_low(out);//7
         output_high(clk);
         output_low(clk);
         output_high(out);//6
         output_high(clk);
         output_low(clk);
         output_high(out);//5
         output_high(clk);
         output_low(clk);
         output_low(out);//4
         output_high(clk);
         output_low(clk);
         output_high(out);//3
         output_high(clk);
         output_low(clk);
         output_high(out);//2
         output_high(clk);
         output_low(clk);
         output_high(out);//1
         output_high(clk);
         output_low(clk);
         output_low(out);//reset
         output_high(clk);
         output_low(clk);
      break;
      case 6:
         output_low(out);//7
         output_high(clk);
         output_low(clk);
         output_high(out);//6
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
         output_low(out);//reset
         output_high(clk);
         output_low(clk);
      break;
      case 7:
         output_high(out);//7
         output_high(clk);
         output_low(clk);
         output_high(clk);//6
         output_low(clk);
         output_low(out);//5
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
         output_high(out);//1
         output_high(clk);
         output_low(clk);
         output_low(out);//reset
         output_high(clk);
         output_low(clk);
      break;
      case 8:
         output_high(out);//7
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
         output_low(out);//reset
         output_high(clk);
         output_low(clk);
      break;
      case 9:
         output_high(out);//7
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
         output_low(out);//4
         output_high(clk);
         output_low(clk);
         output_high(out);//3
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
         output_low(out);//reset
         output_high(clk);
         output_low(clk);
      break;
      case 10:
         output_high(out);
         output_high(clk);//7
         output_low(clk);
         output_high(clk);//6
         output_low(clk);
         output_high(clk);//5
         output_low(clk);
         output_high(clk);//4
         output_low(clk);
         output_low(out);//3 l
         output_high(clk);//3
         output_low(clk);
         output_high(out);//2 h
         output_high(clk);//2
         output_low(clk);
         output_high(clk);//1
         output_low(clk);
         output_high(clk);
         output_low(clk);
         output_low(out);
      break;
      case 11:
         output_low(out);
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
         output_high(clk);
         output_low(clk);
         output_high(out);
         output_high(clk);
         output_low(clk);
         output_low(out);
         output_high(clk);
         output_low(clk);
         output_high(out);
         output_high(clk);
         output_low(clk);
         output_low(out);
         output_high(clk);
         output_low(clk);
         output_high(out);
         output_high(clk);
         output_low(clk);
         output_low(out);
         break;
      case 12:
         output_high(out);//7
         output_high(clk);
         output_low(clk);
         output_low(out);//6
         output_high(clk);
         output_low(clk);
         output_high(out);//5
         output_high(clk);
         output_low(clk);
         output_high(clk);//4
         output_low(clk);
         output_high(clk);//3
         output_low(clk);
         output_low(out);//2
         output_high(clk);
         output_low(clk);
         output_high(out);
         output_high(clk);
         output_low(clk);
         output_high(out);
         output_high(clk);
         output_low(clk);
         output_low(out);
      break;
   }
}

//==============================


void main() {
   int i;
   while(true) {
     
      for(i=1;i<10;++i) {
         num(i, pin_a1, pin_a0);
         delay_ms(2000);
      }
      i=0;
   }
}


can somebody please help me with this problem regarding that I'm a newbie to this subject?

Thanks in advance.


Last edited by seifpic on Sun Mar 11, 2012 5:45 pm; edited 2 times in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 11, 2012 3:31 pm     Reply with quote

Get a book on the C language or just Google for this:
Quote:

C tutorial for loops


And one more tip: Don't use floating point in a small PIC.
seifpic



Joined: 11 Mar 2012
Posts: 45
Location: Egypt

View user's profile Send private message

PostPosted: Sun Mar 11, 2012 3:34 pm     Reply with quote

PCM programmer wrote:
Get a book on the C language or just Google for this:
Quote:

C tutorial for loops


And one more tip: Don't use floating point in a small PIC.


Ok, I know I did the loop in the main function in a hideous way but my question was about the Out of ROM error. I also forgot to mention I'm new to this subject so I didn't understand your tip.
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Sun Mar 11, 2012 3:39 pm     Reply with quote

A search of the forum would find the answer.
Key point is that the PIC memory, is organised as a number of small pages, and each subroutine has to fit into a page.
You have 99% of your code in one enormous 'lump', which can't be split up.
Most of the sequences of high/low clocks, could be made into a single routine, and then called, rather than being repeated again and again in the code.....

Best Wishes
seifpic



Joined: 11 Mar 2012
Posts: 45
Location: Egypt

View user's profile Send private message

PostPosted: Sun Mar 11, 2012 3:43 pm     Reply with quote

Ttelmah wrote:
A search of the forum would find the answer.
Key point is that the PIC memory, is organised as a number of small pages, and each subroutine has to fit into a page.
You have 99% of your code in one enormous 'lump', which can't be split up.
Most of the sequences of high/low clocks, could be made into a single routine, and then called, rather than being repeated again and again in the code.....

Best Wishes


Your reply gave me an idea, the numbers' segments could be stored as an array of bits which is called in a function that has the routine. Could that work?
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Mon Mar 12, 2012 3:00 am     Reply with quote

Even simpler an array of bytes.
For instance (hypothetical only):
Code:

const int8 patterns[] = {0b00101011,0b11001100,.....};

void send_pattern(int8 pattern_number) {
    int8 count, temp,mask=1;
    temp=patterns[pattern_number]; //Get the selected pattern to send
    for (count=0;count<8;count++) {
       output_high(clk);
       output_low(clk);
    }
    //much smaller than doing this eight times.....
    for (count=0;count<8;count++) {
       output_bit(out,temp&mask); //output bit
       output_high(clk);
       mask<<=1; //rotate mask
       output_low(clk);
    }
    //Then send 'patterns[pattern_number]'
}

This sends the bits LSb first - alternatively start with mask=128, and shift it right to send the bits MSb first.

Hopefully you get the idea.

Your cases would then disappear, and just become a single call to send_pattern, with rnum being the pattern to send.
Code many times smaller...

Best Wishes
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