Sidekick domain is published.
Bookmark it, right now.
Entire Forum
This board
This topic
Members
Entire Site
Home
Contact Us
Help
Search
GoogleTagged
Donations
Login
Register
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
April 29, 2024, 12:52:54 12:52
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Sonsivri
>
Electronics
>
Pic Basic Languages
(Moderator:
bbarney
) >
Array
Pages: [
1
]
« previous
next »
Print
Author
Topic: Array (Read 3138 times)
0 Members and 1 Guest are viewing this topic.
Husanto
Newbie
Offline
Posts: 10
Thank You
-Given: 0
-Receive: 1
Array
«
on:
November 27, 2007, 10:37:50 10:37 »
Hi,
i want to ask about using array in microbasic. example i have a code:
dim temp1 as byte[4]
const temp as byte[3][4] =((1,2,3,4),(5,6,7,8),(7,5,3,2))
main()
for i=0 to 3
temp1 = temp[2]
next i
end.
why the result always (1,2,3,4) not ( 7,5,3,2)
?can give information about using array two dimension to use in looping function.
Logged
robban
Senior Member
Offline
Posts: 265
Thank You
-Given: 34
-Receive: 38
Warrior
Re: Array
«
Reply #1 on:
November 28, 2007, 01:06:53 01:06 »
This is actually better solved in C, but since You do it in Basic, let's see...
Proton does a 2-dim array this way:
' Display text from two LDATA tables
' Based on their address located in a seperate table
' Use a 14-bit core device
Dim ADDRESS as Word
Dim LOOP as Word
Dim DATA_BYTE as Byte
Delayms 200 ' Wait for PICmicro to stabilise
Cls ' Clear the LCD
ADDRESS = LREAD ADDR_TABLE ' Locate the address of the first string
While 1 = 1 ' Create an infinite loop
DATA_BYTE = LREAD ADDRESS ' Read each character from the LDATA string
If DATA_BYTE = 0 Then Break ' Exit if NULL found
Print DATA_BYTE ' Display the character
Inc ADDRESS ' Next character
Wend ' Close the loop
EXIT_LOOP:
Cursor 2,1 ' Point to line 2 of the LCD
ADDRESS = LREAD ADDR_TABLE + 2 ' Locate the address of the second string
While 1 = 1 ' Create an infinite loop
DATA_BYTE = LREAD ADDRESS ' Read each character from the LDATA string
If DATA_BYTE = 0 Then Break ' Exit if NULL found
Print DATA_BYTE ' Display the character
Inc ADDRESS ' Next character
Wend ' Close the loop
EXIT_LOOP2:
Stop
ADDR_TABLE: ' Table of address's
LDATA WORD STRING1,WORD STRING2
STRING1:
LDATA "HELLO",0
STRING2:
LDATA "WORLD",0
******************************************************************************************
From here You would be able to add one more table and get the job done
Logged
Code Warrior
th_sak
Active Member
Offline
Posts: 141
Thank You
-Given: 150
-Receive: 149
Re: Array
«
Reply #2 on:
November 28, 2007, 12:51:13 12:51 »
You have only one pointer for your 2 dimension array, but you should have 2 pointers.
This should work.
dim temp1 as byte[4]
const temp as byte[3][4] =((1,2,3,4),(5,6,7,8),(7,5,3,2))
main()
for i=0 to 2 ; this is pointer for rows [3]
for j=0 to 3 ; this is pointer for columns [4]
temp1 = temp[i,j]
next j
next i
end.
Logged
robban
Senior Member
Offline
Posts: 265
Thank You
-Given: 34
-Receive: 38
Warrior
Re: Array
«
Reply #3 on:
November 28, 2007, 04:33:55 16:33 »
As I say, less is more(though I haven't tested it yet)
Logged
Code Warrior
Pages: [
1
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Electronics
-----------------------------
=> Projects
=> Pic Basic Languages
=> Pic C Languages
=> AVR, 8051 Family and ARM Area
=> RTOS
=> Artificial Intelligence (AI) & Robotics
=> Hardware and Tools
=> General Electronics
-----------------------------
Computers
-----------------------------
=> Internet Scripting Languages
=> Graphics and CAD
-----------------------------
Announcements and Rules
-----------------------------
=> Help & Rules
===> English
===> Arabic
===> French
===> Italian
===> Persian
===> Portuguese (Brazilian)
===> Spanish
===> Swedish
===> Turkish
=> Announcements
-----------------------------
Others
-----------------------------
=> General
=> Entertainment
=> Suggest Forum Content
=> Holiday and Greetings
=> Testing Forum
=> Invitation Request
Loading...