transferring word array to another pic


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    garret's Avatar
    garret Guest

    Cool transferring word array to another pic

    hi all, I think this one is truly nuts and bolts. 16f877a to 16f877a using pbp. I would like someone to suggest the simplest code to transfer a 12 element word array from one pic to the other using serout/ serin.
    -break the elements into high and low bytes?
    -loop the serout so that transmit is one element at a time?

    how about serout porte.0,t9600,'the whole bloody word array'

    any pre-existing snippets of code would be really nice to read. And i do thank everyone in advance...Garret

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Take a look at...

    http://www.picbasic.co.uk/forum/showthread.php?t=544

    Then for simplicity (based on a 12 element word array) try...

    Code:
    	For CounterA=0 to 23
    		Serout porte.0,t9600,MyWordArray.Lowbyte(CounterA)
    		Next CounterA
    Personally I wouldn't ever do that... preferring always to send my Serial Data as ASCII alphanumerics preceeded with a Lead-in and Qualifier and similarly properly Terminated... but good Serial Comms practice is an endless story...

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Code:
    MyArray   var word[12]
    Loop      var byte
    
    start:
         for loop=0 to 11
             serout PORTE.0,T9600,[MyArray[Loop]]
         next
    same for receiver... i guess.

    I also agree with the Melanie's suggestion. Well if it's working, it's working
    Last edited by mister_e; - 5th April 2005 at 18:50.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    garret's Avatar
    garret Guest


    Did you find this post helpful? Yes | No

    Default welcome replies

    wow melanie, how nice it is to see a photo of you after all this time. You look rather excellent. A good photographer and a good subject always tends to impress others....
    I find the syntax you came up with to be very hard to fix in my mind. You are stepping through the array on lowbytes of half words...Mind you if it works...! My brain would never come up with such syntax....
    Do you think that serin in the same manner will work?

    For CounterA=0 to 23
    Serin porte.0,t9600,MyWordArray.Lowbyte(CounterA)
    Next CounterA

    could it possibly transfer the array keeping the right elements in order.

    Could you throw me a single line of how you would code your serout with all the accoutrements that you spoke of.

    Mister E...thanxs...i am in montreal as well.....

  5. #5
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Thanks for the compliment... I'm told I look better in real-life than in the photo...

    Code:
    	CommsPort var PortE.0
    
    	SEROUT CommsPort,t9600,[REP $00\16,13,10,"Z-"]
    	CheckDigit=0
    	For CounterA=0 to 8
    		CheckDigit=CheckDigit ^ MyWordArray.Lowbyte(CounterA)
    		SEROUT CommsPort,t9600,[HEX2 MywordArray.Lowbyte(CounterA)]
    		Next CounterA
    	SEROUT CommsPort,t9600,[HEX2 CheckDigit,13,10]
    Quickly thrown together...

    The first SEROUT flushes any trash out of the receiving buffer (if there is one) and provides a unique qualifier to lock up on which is unlike any possible Data combination... If you're transmitting by wireless, that Lead-In also wakes up the Data-Slicer.

    The For-Next Loop transmits your Data Array and doubles in creating a CheckDigit...

    The last SEROUT transmits the CheckDigit (so the receiver can verify a good Data packet has been received) and terminates the packet with a Return/Line-Feed combination (again forcing any remaining Data out of the Receivers buffers if Hardware USARTS are being employed).

    The bonus here is that you can "break-in" to the transmission and make a connection say to Hyperterminal and "see" the transmitted packet and check each Byte manually if you need to do any Debugging. You don't see the Lead-In, and each packet of Data is on a unique Line on the display on it's own, prefixed with a 'Z-'.

    The receiver captures the string of Hex (you don't need to bother capturing the CR/LF - 13/10 - at the end), verifies good Data against the Transmitted CheckDigit and reconstructs the Word Array from the Hex. Simple and Safe.

  6. #6
    garret's Avatar
    garret Guest


    Did you find this post helpful? Yes | No

    Default brilliant and beautifull

    ahhhh!

    Your solution as well... You've given me a chunk to work on.
    I have an interrupt on the receiving pic producing the raster for a led matrix display. I'm 20mhz running tmr0 at prescaler of 256...so....i beleive the raster (interrupt) is running at 1220 hz.

    It looks like your solution should allow the interrupts to continue even through the core of your code. Do you think i should expect any loss of serout-serin timing in the array...

  7. #7
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default I know... modest too...

    If you're playing with interrupts or have any other timing critical functions on the receiver then lose the Serial Comms. Pipe the async into your USART pin and poll the Receive Register Flag when you have free time. Sitting in a SERIN loop waiting for Data is the equivallent of watching paint dry.

    If you need to generate a background Pulse for whatever purpose, you could always get that from your PICs Harware PWM Port (if it has one). If the PIC is refreshing or multiplexing an LED array, then the byte-by-byte Hardware receive method is the best way to go, otherwise there will be a momentary flicker on the display as the data is received.

  8. #8
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Wink

    Your picture is hot enough...

    Melanie>>I'm told I look better in real-life than in the photo...<<

    If that is so....I am moving to your country...:}

    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

Similar Threads

  1. Serial VB 2005 pic 16f877a problems
    By Snap in forum mel PIC BASIC Pro
    Replies: 28
    Last Post: - 8th July 2013, 00:52
  2. RF Modules
    By tonyfelloni in forum mel PIC BASIC Pro
    Replies: 44
    Last Post: - 26th June 2010, 17:42
  3. Minimizing code space
    By Tobias in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th May 2009, 07:25
  4. SEROUT WORD variable problem
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th April 2009, 11:20
  5. pic to pic ir link versus wired link : help please anyone
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 30th May 2008, 21:01

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts