Help using Structures in MikroBasic Pro

Beta Testing discussion on mikroBasic PRO for PIC.
Post Reply
Author
Message
theberrys
Posts: 1
Joined: 19 May 2013 03:28

Help using Structures in MikroBasic Pro

#1 Post by theberrys » 02 Jul 2014 03:46

I need to send a Word Array over the EUSART as Bytes of course. Here is my solution, but I think I should be able to do this using a structure and pointers. Could someone please help me understand this subject.

Thanks Dick

program Word_Xfer_Test
'This is my solution to Transmitting a Word Array over the EUSART to a second PIC
'It seems to me it should be Structure Pointers but I just can't figure out
'how to do it in BASIC. "C" would be a natural here using Structure Pointers and Casting Types.

'Could someone show me how to set up a Structure in BASIC to access the Bytes to transmit.

'Thanks Dick


' Declarations section

'This is really a Array of Variables on the Source PIC
'But a constant doesn't need to be initialized for this test.
const Source as word [4] = (43605, 47958, 52311, 56664)

'This is the Word rray on the Destination PIC
Dim Destination as word [4]

'Old Fortran stuff for a general pourpose Variable
dim i as byte

'This is the Byte to be transmitted on the Source PIC
'and the Received Byte on the Destination PIC
dim Uart as byte


main:
' Main program To transmit Word Bytes over the EUSART and
' store in an Word Array on the receiving end

for i = 0 to 3 'Prefill for testing not required in application
Destination = 0x0000
next i

for i = 0 to 3 'i is the size of the transmitted or received Array in Words
Uart = Source >> 8 'Get a byte to transmit
'Put the transmit through USART or Receive through USART here
Destination = Uart 'Receiver stuffs it in Array after Usart read
Destination = Destination << 8 'Receiver shifts the Byte into the high 8 bits
Uart = Source and 0x00FF 'Transmitter gets low Byte and sends it
'Put the transmit through USART or Receive through USART here
Destination = Destination or Uart 'Receiver stuffs it into the low byte of the Word Array
next i
i = 0xAA 'this just gives me a indication in the Watch Window
nop 'of when the routine is done while single stepping.
end.

Post Reply

Return to “mikroBasic PRO for PIC Beta Testing”