PORTA RA0. Help Needed. thank

thatoneguy

Joined Feb 19, 2009
6,359
That would be compiler specific. Sadly, there isn't much for cross compiler compatibility, and a lot of translating needs to be done sometimes.

Check the manual for the commands, reading the #include files also gives you good tips sometimes.

Sorry I can't be of more help with that particular question, I don't use that compiler.
 

thatoneguy

Joined Feb 19, 2009
6,359
I happen to have C18, I just don't use it.

Here's the info for the syntax:

LATDbits.LATD7

The LATDbits struct is also defined in p18f45k20.h and
gives access to the individual bits in the LATD SFR. (There is
also a TRISDbits struct for accessing bits of TRISD, and a
LATD variable defined to access the entire byte-wide register.)
The LATD (latch) register is used to set the output state of the
RD7-RD0 pins. A bit value of ‘1’ sets an output pin to a high
state. Bits for pins defined in the TRIS register as inputs do not
have an effect. Setting LATDbits.LATD7 = 1 will output a
high level on RD7, turning on LED 7 on the demo board.
 

Thread Starter

Ralf

Joined Mar 16, 2009
31
Bro.. thank.. i get it.. now i doing the part that need array finding some good website to teach me array format..

or if anyone know can roughly teach here?? thank alot.. everyone!!

PS: i have checked the chip for p18f45k20 and my p18f24k20. they work about the same and the command too.. :)
 

thatoneguy

Joined Feb 19, 2009
6,359
Arrays start at index zero, the TABLE[] array for the LEDS is an array to define which segments light for a digit.

P.S. Apologies for PORTB/LATB, I've been doing a lot in 16F recently and forgot about the latches.
 

Thread Starter

Ralf

Joined Mar 16, 2009
31
hmm.. i still quiet blur. any clear example?? because i been searching and i found those example not that clear for me to understand..
 

thatoneguy

Joined Feb 19, 2009
6,359
Here is a simple example I made for arrays, hope it makes sense...

The "This may take some time" line and cycle waster is a joke.

Written in GNU gcc, built on a few different platforms, results below.

This won't work on a PIC, as printf isn't defined, but the array works will.

they can be of type char or int, struct, or any other variable.

Rich (BB code):
 1: #include [SIZE=+1]<stdio[SIZE=+1].[/SIZE]h[SIZE=+1]>[/SIZE]
 2: int main[SIZE=+1]([/SIZE]void[SIZE=+1])[/SIZE]
 3: [SIZE=+1]{[/SIZE]
 4:     // Declare variables
 5:     int myintarray[SIZE=+1][[/SIZE]9[SIZE=+1]][/SIZE][SIZE=+1];[/SIZE]          // Array to fill with numbers
 6:     unsigned int i[SIZE=+1];[/SIZE]             //index counter for array
 7:     printf[SIZE=+1]([/SIZE]"\nWelcome to the CPU Cycle waster!\n"[SIZE=+1])[/SIZE][SIZE=+1];[/SIZE]
 8:     printf[SIZE=+1]([/SIZE]"Architecture, sizeof(int) is: %d bits"[SIZE=+1],[/SIZE] sizeof[SIZE=+1]([/SIZE]int[SIZE=+1])[/SIZE][SIZE=+1]*[/SIZE]16[SIZE=+1])[/SIZE][SIZE=+1];[/SIZE]
 9: 
10:     printf[SIZE=+1]([/SIZE]"\nFillng array, this may take some time...\n"[SIZE=+1])[/SIZE][SIZE=+1];[/SIZE]
11:     // fill array with squares;
12:     for [SIZE=+1]([/SIZE]i [SIZE=+1]=[/SIZE] 0[SIZE=+1];[/SIZE] i [SIZE=+1]<[/SIZE] 6[SIZE=+1];[/SIZE] i[SIZE=+1][SIZE=+1]+[/SIZE][SIZE=+1]+[/SIZE][/SIZE][SIZE=+1])[/SIZE] [SIZE=+1]{[/SIZE]
13:         myintarray[SIZE=+1][[/SIZE]i[SIZE=+1]][/SIZE] [SIZE=+1]=[/SIZE] i [SIZE=+1]*[/SIZE] i[SIZE=+1];[/SIZE]
14:     [SIZE=+1]}[/SIZE]
15:     // print out array contents
16:     for [SIZE=+1]([/SIZE]i [SIZE=+1]=[/SIZE] 0[SIZE=+1];[/SIZE] i [SIZE=+1]<[/SIZE] 6[SIZE=+1];[/SIZE] i[SIZE=+1][SIZE=+1]+[/SIZE][SIZE=+1]+[/SIZE][/SIZE][SIZE=+1])[/SIZE] [SIZE=+1]{[/SIZE]
17:         printf[SIZE=+1]([/SIZE]"Array index %i has a value of %d\n"[SIZE=+1],[/SIZE] i[SIZE=+1],[/SIZE] myintarray[SIZE=+1][[/SIZE]i[SIZE=+1]][/SIZE][SIZE=+1])[/SIZE][SIZE=+1];[/SIZE]
18:     [SIZE=+1]}[/SIZE]
19: 
20: [SIZE=+1]}[/SIZE]                               //end main
[/SIZE]

	
	
	
	



	



	










Rich (BB code):
Here is the output:
Linux-64 (AMD)

	
	
	
	



	



	










Rich (BB code):
Welcome to the CPU Cycle waster!
Architecture, sizeof(int) is: 64 bits
Fillng array, this may take some time...
Array index 0 has a value of 0
Array index 1 has a value of 1
Array index 2 has a value of 4
Array index 3 has a value of 9
Array index 4 has a value of 16
Array index 5 has a value of 25

real    0m0.000s
user    0m0.000s
sys     0m0.000s
Rich (BB code):
Rich (BB code):
 

Thread Starter

Ralf

Joined Mar 16, 2009
31
hmm.. i somehow think i get it.. just wanted to ask.. i got a table that i need to use array to extract it. how can i do it?

let say if i get the result of:
Result---------Display
22.02 ---------0
21.63 ---------5
17.64 ---------10
14.47 ---------15
11.94 ---------20

thank a lot for helping me
 

thatoneguy

Joined Feb 19, 2009
6,359
Are the floats on the left fixed values, or would they be ranges that would return the number on the right?

If it is a range, such as an ADC result, use the case/switch statement.

If it is an array, some compilers will optimize out unused indexes, some won't. The standard is "fuzzy" for PICs.

Another option would be a 2 dimensional array, which is an array of arrays, where you would search in the matrix (array of arrays = 2D Matrix) for the value, then display the other value. This is similar to the way hashs work in perl.
 

thatoneguy

Joined Feb 19, 2009
6,359
For loops are not required for use with an array. They can have data defined with their definition, addressed with pointers, etc.

I used it in an example as a simple way to loop from 0,1,2,3,4,5 to fill in the positions, then to loop through them again to display the contents.

Strings, such as "Hello, World!" are arrays in C. They are terminated with a NULL, but can be accessed with the array operator [] to get a single character from it.

Tables are often stored in arrays, then retrieved by the index number, as in the LED Segment storage above.

The best way to think of an array is simple a table in memory with indexes, if you know the index, you can get the data, or, if you know the data, you can get the index using a C function.
 

Thread Starter

Ralf

Joined Mar 16, 2009
31
wanna to ask.. if my result come out is between the 2 array.. wad can i do about it?? let say..

array 1

array[1] = 1111
array[2] = 2222

array2
array[1] = 10
array[2] = 20

array 1 is the result i get then i go array 2 to extract my result..

i know this part abit blur.. but i wanna to ask is. if my result is between the array[1] and array[2] in array 1. wad should i do?
 

thatoneguy

Joined Feb 19, 2009
6,359
I guess I'm unsure where that would come up.

Arrays are used to store known information, such as strings, Serial data, bits for digits as in LEDs, etc.

Are you trying to compare against an array? Your example above with floating point conversion to integers would probably be best served by a function.
 
Top