View previous topic :: View next topic |
Author |
Message |
elizabeth ann
Joined: 16 Feb 2008 Posts: 33
|
how to create,access and write in a 100-element array? |
Posted: Sun Mar 23, 2008 1:46 am |
|
|
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
|
|
Posted: Sun Mar 23, 2008 3:53 am |
|
|
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
|
Array |
Posted: Sun Mar 23, 2008 5:08 am |
|
|
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
|
|
Posted: Sun Mar 23, 2008 5:29 am |
|
|
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. |
|
|
elizabeth ann
Joined: 16 Feb 2008 Posts: 33
|
|
Posted: Sun Mar 23, 2008 9:25 pm |
|
|
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
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
|
|
Posted: Mon Mar 24, 2008 12:09 am |
|
|
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 |
|
|
elizabeth ann
Joined: 16 Feb 2008 Posts: 33
|
|
Posted: Mon Mar 31, 2008 11:25 pm |
|
|
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! |
|
|
|