PDA

View Full Version : Access array in PBP and .asm



JEC
- 5th September 2008, 21:37
Hi Folks,

I'm working on a project where I'm simultaneously receiving, manipulating, and transmitting serial data. This data comes and goes in 64-byte chunks.

I'd like to set up an interrupt routine in assembly language to receive the data, and then use PBP to handle the rest of the functionality.

Serial reception will be through the chip's UART (an 18F part) and transmission will be done in software. The incoming and outgoing baud rates are wildly different, so I can't just use the TX side of the same UART.

Nor can I receive a packet, reset the UART to a different baud rate and then retransmit, as I'll miss critical incoming data.

Therefore, the transmit and receive threads need to run concurrently and independently.

Here's the question:

If I define an array in PBP like this:

DataIN VAR byte[64]

how do I access it from within the .asm routine?

I'm sure it's not difficult, but I can't quite wrap my brain around it.

I know that a single PBP variable Foo can be accessed as _Foo in assembly. But how does it work with an array?

JEC

Bruce
- 5th September 2008, 22:31
Already done for you http://www.melabs.com/resources/samples/x1/pbp/serbufAx.bas

Just change the buffer size & tweak to your specs.

JEC
- 5th September 2008, 22:46
Already done for you http://www.melabs.com/resources/samples/x1/pbp/serbufAx.bas

Just change the buffer size & tweak to your specs.

Don't know how I missed that in my searching.

Many thanks, Bruce. That looks perfect.

Darrel Taylor
- 5th September 2008, 23:28
Hi John,

One problem that you will probably have is in trying to send serial data using SEROUT(2).

Those commands are timed by software, which will be continuously interrupted by the USART RX handler, which throws off the baud rate.

A possible solution can be found here ...
http://www.picbasic.co.uk/forum/showthread.php?p=53931

It uses a Timer as the baud rate generator, which overcomes the software timing problems.

HTH,

Charles Linquis
- 6th September 2008, 00:21
Could you possibly use a PIC with two hardware UARTS? That would make things *so* much easier.

JEC
- 6th September 2008, 00:35
Could you possibly use a PIC with two hardware UARTS? That would make things *so* much easier.

Actually, that's the part I didn't mention. I'm looking at the 18F6310, which appears to be only a couple dollars. Unless I've missed something, that's the smallest of the 18Fs with two ports, and it comes in a 64-TQFP package.

It has two hardware ports and two separate interrupt generators.

However, the ability to receive data into an array in the .asm routine is still very desirable. I can do my array massaging in the main program, then dump it out the door.

Darrel's link above describes some neat tricks too.

The depth of knowledge & willingness to share on this board is always amazing. Thanks to all who have taken a moment to reply.