![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
I'm still really new with C18 but here goes. I would like to define a table for a IR remote transmitter in C18 The table would contain IR KHz modulation, mark, space, mark, space,... ,0 (end) mark and space are the IR on and off times in ms 0 = end of this data stream Also I would like to know how to address multiple tables, can they be varying in length? Lastly can I insert formula for some of the data and let the C18 compiler sort out the answer? | |
| |
| | #2 |
|
Look up arrays in your C book. Look at structs too. A C guru will give you better answers than me though.
__________________ ========================= Futz's Microcontrollers & Robotics ========================= | |
| |
| | #3 |
|
Bill - could what i've pasted below be an example of what you are asking? (Sorry - i'm a novice at this thing and don't know how to post code so it looks purdy) David // Define the structure of one table entry typedef struct { unsigned char mark; unsigned char space; // Add more stuff if you need it - bits, arrays or anything you want } BILLSIRRemoteTableStructure; // Define a Variable & initialize it that uses this structure BILLSIRRemoteTableStructure iBillsTable[] = { // Initialize table with values {1,20}, {2,40}, {3,50}, {0,0} // Mark End of data }; void DoSomething(int mark, int space); main() { int counter; // Scans through table and does something with each value // Not such a good example because it would also // do something with the last value for(counter=0;counter<sizeof(iBillsTable)/sizeof(BILLSIRRemoteTableStructure);++counter) DoSomething(iBillsTable[counter].mark,iBillsTable[counter].space); // Scans through table until sees a 0x00 for mark & space for(counter=0;iBillsTable[counter].mark!=0 && iBillsTable[counter].space!=0;++counter) DoSomething(iBillsTable[counter].mark,iBillsTable[counter].space); } void DoSomething(int xmark, int xspace) { return; } | |
| |
| | #4 |
|
Thanks, I'm an assembler guy trying to learn C. That gives me the framework I need.
| |
| |
| | #5 | |
| Quote:
Like this: Code: rom char *alpha1 = {
0x3e,0x51,0x49,0x45,0x3e, //0
0x00,0x42,0x7f,0x40,0x00, //1
0x72,0x49,0x49,0x49,0x46, //2
0x22,0x49,0x49,0x49,0x36, //3
0x0f,0x08,0x08,0x7f,0x08, //4
0x2f,0x49,0x49,0x49,0x31, //5
0x3e,0x49,0x49,0x49,0x32, //6
0x41,0x21,0x11,0x09,0x07, //7
0x36,0x49,0x49,0x49,0x36, //8
0x26,0x49,0x49,0x49,0x3e}; //9
__________________ ========================= Futz's Microcontrollers & Robotics ========================= | ||
| |
| | #6 |
|
Thank you Futz. Can you show me how you access a char in that const rom array please?
| |
| |
| | #7 |
|
Seems the answer is on page 53 http://www.kevin.org/frc/C18_2.4_getting_started.pdf | |
| |
| | #8 |
|
Thanks Bill... That example from your DS51295E document doesn't seem to be in my DS51295F document... I guess I didn't realize there was that big a difference in document revisions...
| |
| |
| | #9 |
|
Hmm, is the F the newest? I found that one searching for C18 arrays.
| |
| |
| | #10 |
|
I couldn't work out how you would use that example either and the above pdf doesn't seem to answer the problem. The pdf suggests it should be, Code: rom char alpha1[] = {
0x3e,0x51,0x49,0x45,0x3e, //0
0x00,0x42,0x7f,0x40,0x00, //1
0x72,0x49,0x49,0x49,0x46, //2
0x22,0x49,0x49,0x49,0x36, //3
0x0f,0x08,0x08,0x7f,0x08, //4
0x2f,0x49,0x49,0x49,0x31, //5
0x3e,0x49,0x49,0x49,0x32, //6
0x41,0x21,0x11,0x09,0x07, //7
0x36,0x49,0x49,0x49,0x36, //8
0x26,0x49,0x49,0x49,0x3e}; //9
Mike. | |
| |
| | #11 |
|
Is this not how it's done? Why the "return roots[val];" Code: #include <p18f452.h> /* for 'PRODL' declaration and 'ACCESS' macro */
/*
* Locate the read-only table in program memory at address 0x1000.
* 'romdata' is used for data, and 'code' is used for instructions.
*/
#pragma romdata ROOT_TABLE = 0x1000
#define TABLE_SIZE 100
const rom unsigned char roots[TABLE_SIZE] =
{ 0, 1, 1, 1, 2, 2, 2, 2, 2, 3,
3, 3, 3, 3, 3, 3, 4, 4, 4, 4,
4, 4, 4, 4, 4, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
9, 9, 9, 9, 9, 9, 9, 9, 9, 9 };
/*
* Data in access ram does not require banking.
* When compiled with -Oa, these pragmas and the near qualifier may
* be removed.
*/
#pragma udata access MY_ACS_DATA
near unsigned char root, square;
#pragma udata /* continue allocating static data in non-access ram */
/*
* Returns the truncated root of the value.
*/
unsigned char get_root (int val)
{
return roots[val];
}
void main (void)
{
static int val;
for (val = 0; val < TABLE_SIZE; val++)
{
/* 'square' holds the greatest perfect square less than or
* equal to 'val' */
square = get_root (val);
}
}
| |
| |
| | #12 | |
| Quote:
It works anyway. Here's a couple lines of the working code:Code: for(stripe=0;stripe<5;stripe++) //letter stripe loop
{
data_write(alpha1[index]); //write letters
index++; //increment stripe pointer
__________________ ========================= Futz's Microcontrollers & Robotics ========================= | ||
| |
| | #13 | |
| Quote:
Edit, Futz, are you saying it worked with the rom char *alpha1 = { definition. If so, was alpha1 defined beforehand? Mike. | ||
| |
| | #14 | |
|
Ah, here it is. From the BoostC manual: Quote:
__________________ ========================= Futz's Microcontrollers & Robotics ========================= | ||
| |
| | #15 |
|
Sorry, I was still on C18. I must get around to playing with boostC. Mike. | |
| |
|
| Tags |
| c18, data, define, table |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| usart with pic | neelam29 | Micro Controllers | 19 | 18th July 2009 09:39 AM |
| Motor controller | Totally blank | Electronic Projects Design/Ideas/Reviews | 9 | 16th January 2008 02:12 PM |
| 18F4550 - PORTD inputs are shaky, even with internal pull up enabled | toodles | Micro Controllers | 0 | 29th April 2007 03:05 AM |
| help me to describe this code | indie | Micro Controllers | 0 | 18th June 2004 02:11 PM |
| An error in pic16f84a, why? | Zener_Diode | Micro Controllers | 6 | 11th April 2004 03:55 AM |