How does the code get transferred?


Closed Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,605


    Did you find this post helpful? Yes | No

    Default Re: How does the code get transferred?

    wData is assigned a value and then you GOSUB a routine called SEND.

    SEND, in turn, GOUSBs a routine called OutByte where a loop itterates thru the individual bits in wData and GOUSBs either SendOne or SendZero which puts the state of the bit on the pin aliased as Sda, which in your code is PortC.5, not PortC.3.

    /Henrik

  2. #2
    Join Date
    Mar 2011
    Location
    Los Angeles, California
    Posts
    322


    Did you find this post helpful? Yes | No

    Default Re: How does the code get transferred?

    You are right about it being PortC.5, my oops, just not seeing where it is PortC.5 and not some other Port.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,605


    Did you find this post helpful? Yes | No

    Default Re: How does the code get transferred?

    Cut'n'paste from your program, relevant parts marked with red.

    Pin aliases:
    Code:
    Clk VAR PORTC.4
     Sda VAR PORTC.5
     Csn VAR PORTC.3
    Variable assignment and call to Send routine:
    Code:
    WData = $1877: GOSUB Send
    Send routine, calls OutByte:
    Code:
    Send:
     GOSUB StartCommunication
     GOSUB OutByte
     GOSUB StopCommunication
     RETURN
    Outbyte iterates thru wData and calls either SendOne or SendZero depending on if the bit is a one or a zero:
    Code:
    OutByte: 'send a 16 bit word
     FOR Bit_Counter = 1 TO 16
     IF wData.15 = 1 THEN 'MSB first
     GOSUB SendOne
     ELSE
     GOSUB SendZero
     ENDIF
     WData = wData << 1
     NEXT Bit_Counter
     RETURN
    Sendone:
    Code:
    SendOne: 'Send a bit 0
     HIGH Sda: GOSUB WasteTime
     LOW Clk: GOSUB WasteTime
     HIGH Clk: GOSUB WasteTime
     RETURN
    Sendzero:
    Code:
     SendZero: 'sending a bit 1
     LOW Sda: GOSUB WasteTime
     LOW Clk: GOSUB WasteTime
     HIGH Clk: GOSUB WasteTime
     HIGH Sda: GOSUB WasteTime
     RETURN
    /Henrik.

Similar Threads

  1. Replies: 27
    Last Post: - 9th April 2015, 04:51
  2. Serial problem between BasicStamp code and PBP code
    By AllanZilkowsky in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 6th April 2014, 02:15
  3. Working code but my layman approach uses too much code space
    By Christopher4187 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 14th December 2012, 20:44
  4. Device programming - how data is formatted and transferred
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th February 2008, 10:21
  5. Code: Why is this code greater than 2000 words?
    By DrDreas in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 1st June 2007, 19:51

Members who have read this thread : 0

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