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

how to create,access and write in a 100-element array?

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



Joined: 16 Feb 2008
Posts: 33

View user's profile Send private message

how to create,access and write in a 100-element array?
PostPosted: Sun Mar 23, 2008 1:46 am     Reply with quote

my topic subject says it all, how do i access/write to a 100-element array?

i am using PIC16F877A, the keypad is the input and a 16x2 LCD for the display.

initially, the array is blank. the contents should be the 100 alarm events which will be entered by the user and will be stored in the array. the contents will be in hours (0-24). the interrupt has to check from time to time if any of the elements match the recent time, and if it does, it will signal an alarm (such as a blinking LED or a buzzer).

what are the things that i need to do first? is it possible for the microcontroller to scan the entire 100 element (alarms) by merely using an interrupt?


are there any suggestions?....thanks a lot....
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Sun Mar 23, 2008 3:53 am     Reply with quote

hi,
example of using an array:
Code:


#define ARRAY_LENGTH 100

char myarray[ARRAY_LENGTH];
char i;
for(i=0;i<ARRAY_LENGTH;i++)
{
printf("value %i=%i",i,myarray[i]);
}

cheers
crystal_lattice



Joined: 13 Jun 2006
Posts: 164

View user's profile Send private message

Array
PostPosted: Sun Mar 23, 2008 5:08 am     Reply with quote

Maybe use a two dimensional array
Code:

byte alarm[100][2];


then your index will be 0-99 and your two variables, hours & minutes will be eg. for index alarm 15: alarm[14][0] = hours, alarm[14][1] = minutes

This way setting your hour/min is much easier, just increment the index for each new alarm.

In your interrupt enable a flag eg.
Code:

Check_alarms = true;


And in your main code scan the array:
Code:


if(check_alarms)
   {
      for(i=0;i<=99;i++)
      {
         if (alarm[i][0]=desired_hour)
         {
            if (alarm[i][1]=desired_minute)
            {
               service alarm function
            }
         }
      }
   }

Regards
baltazar_aquino



Joined: 16 Mar 2008
Posts: 27

View user's profile Send private message

PostPosted: Sun Mar 23, 2008 5:29 am     Reply with quote

If you are thinking of saving events, your array data should be wide enough to accomodate the event itself and some time stamps. Normally an array of unsigned int will do but you have to take note of your available memory. If it is an event I would suggest writing each copy of the array in the flash area everytime it overflows. You have to set the address limit so as not to corrupt your own program. You can also set an alarm when the address limit is going to be reached soon so you can download and save them somewhere else. Auto downloading can also be implemented by a simple RS232 routine with connection to the outside world of course. Very Happy
elizabeth ann



Joined: 16 Feb 2008
Posts: 33

View user's profile Send private message

PostPosted: Sun Mar 23, 2008 9:25 pm     Reply with quote

thank you...

i will implement that code and check the results.

meanwhile, how do i write to the flash? does it entail another set of commands or something? i still have to read on that though Crying or Very sad


and i do have another question, does anyone here ever used PORT EXPANDERS? need some advice on that too..speaking of which, it is where i will connect my 100 LEDs, which will signal the alarm occurence...

i'm open to your comments, thanks.
baltazar_aquino



Joined: 16 Mar 2008
Posts: 27

View user's profile Send private message

PostPosted: Mon Mar 24, 2008 12:09 am     Reply with quote

Quote:
and i do have another question, does anyone here ever used PORT EXPANDERS?

For indications only, Port expander will be more expensive and programmatic. Why not just use simple TTL decoders . ( you have the choices of 74LS138 ( 3-8 decoder) or its bigger brother 74LS154 (4-16). The output port sinks 8mA - just enough to lit up a T1 LED. if it is not enough for your app, you can buffer the output using ULN2803A darlington drive from toshiba or simple transistor switch. Check the National Semiconductor site for the datasheets. interfacing is straightforward. It was the favorite of old time designers Wink
elizabeth ann



Joined: 16 Feb 2008
Posts: 33

View user's profile Send private message

PostPosted: Mon Mar 31, 2008 11:25 pm     Reply with quote

hey, thanks for the reply.

the thing is, we have already been provided with free samples of port expanders and have implemented the design and layout using them in our project. in fact, we already have these components in PCB. so we'd just concentrate on that. thanks for the tip anyway, appreciate it!
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