How does the code get transferred?


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2011
    Location
    Los Angeles, California
    Posts
    322

    Question How does the code get transferred?

    Hi All,
    I do not understand a variable labeled as Wdata and some how it gets transferred out of the PIC to the device being controlled. I can understand if you are using a command such as Hserout but how does Wdata know to appear on PortC.3?

    Thanks, Ed

    Code:
    '************************************************* ***************
    '* Name : UNTITLED.BAS *
    '* Author : [select VIEW...EDITOR OPTIONS] *
    '* Notice : Copyright (c) 2017 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 6/4/2017 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************
    'OSDCSX.bas version 2.0
    'Incruser with STV5730A and PIC 16F628 - 4 MHz
    'Source for PICBasic PRO
    'Risto Kõiva 2001, F1FCO & F6CSX, March 2003
    'Turns on F1UBZ insert (part RS232 / MAX232 useless) or demo board STV5730
    'Page mode, color bars
    'Cyclic change of background color
    '23cm or 70cm band display according to pin 18 status (RA1)


    '** HARDWARE DEFINITION **
    Define OSC 20

    CMCON = 7 'put the 18F2520 in digital mode on PORT C
    ADCON1 = $0F

    Clk VAR PORTC.4
    Sda VAR PORTC.5
    Csn VAR PORTC.3
    Mute VAR PORTB.7 '0 if sync valid, 1 if no sync
    mode VAR PORTB.3 'pin # 9, 0 = Page mode, 1 = Mixed mode
    On_off VAR PORTA.2 'Stop the incruser: pin # 1, 0 = off, 1 = on
    Band VAR PORTA.1 'incrustation 23 cm if 0 or 70 cm if 1

    INPUT Mode
    INPUT Mute
    INPUT On_off
    INPUT Band

    OUTPUT Clk
    OUTPUT Sda
    OUTPUT Csn

    '** DEFINITION OF VARIABLES **

    ICount VAR BYTE
    Bit_Counter VAR BYTE
    WData VAR WORD
    C VAR WORD
    B1 VAR BYTE
    B2 VAR BIT
    B3 VAR BIT
    B4 VAR BIT

    W1 VAR BYTE
    W2 VAR BYTE

    '** START OF PROGRAM **

    GOSUB Init 'initialization
    GOSUB Mode_mixed 'Mixed mode by default
    GOSUB Display_mixed
    b1 = 1
    b2 = 1
    b3 = 1
    c = 0
    Looped:

    B1 = On_off
    IF b1 = 0 THEN Incrust_off 'monitors the On_off button
    B4 = Band
    IF b4 = 0 THEN
    W1= $02
    W2= $03
    ELSE
    W1= $07
    W2= $00
    ENDIF

    B3 = MODE 'reads MODE
    IF b3 = b2 THEN Jump 'does not change anything

    IF b3 = 1 THEN 'If MODE = 1: Mixed Mode, Picture Overlay
    c = 0
    GOSUB Mode_mixed
    GOSUB Display_mixed
    B2 = b3
    ELSE
    GOSUB Mode_page 'Mode Page: Mire
    FOR c = 0 TO 6
    WData = $00CD: GOSUB Send '(tip at address 13)
    WData = $1000 + ($201 * c): GOSUB Send 'background color change
    GOSUB Display_page
    PAUSE 2000
    NEXT c
    B3 = Mode 'reads mode
    B2 = ~ b3 'b2 is not equal to b3, we do not jump and we start again
    ENDIF

    PAUSE 500
    GOTO Looped

    Jump:
    PAUSE 200
    GOTO Looped


    END

    disable debug
    '------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ---------
    'No overlay. We go into mixed mode and we delete the screen
    Incrust_off:

    GOSUB Mode_mixed
    PAUSE 100
    b1 = 1
    B3 = Mode 'reads mode
    B2 = ~ b3 'b2 is not equal to b3, we do not jump
    GOTO Looped

    '------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ---------
    'No Overlay
    Delete_Screen:

    c = 0

    WData = 0: GOSUB Send 'tip top left of screen (0,0)
    c = 1
    FOR c = 1 TO 308 'on clears the screen with spaces (0B)
    WData = $1700 + $0B: GOSUB Send '$1700: background disabled, white character not blinking
    NEXT c
    RETURN
    '------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ---------
    'display in overlay mode
    Display_mixed:

    WData = 0: GOSUB Send 'do not omit this line: position 0,0
    WData = $1780 + $6E: GOSUB Send 'flashing parable
    WData = $170B: GOSUB Send 'space
    WData = $1700 + $11: GOSUB Send 'F
    WData = $1700 + $06: GOSUB Send '6
    WData = $1700 + $0E: GOSUB Send 'C
    WData = $1700 + $1E: GOSUB Send 'S
    WData = $1700 + $23: GOSUB Send 'X

    WData = $170B: GOSUB Send 'space
    WData = $170B: GOSUB Send 'space
    WData = $170B: GOSUB Send 'space

    WData = $1700 + $18: GOSUB Send 'M
    WData = $1700 + $0C: GOSUB Send 'A
    WData = $1700 + $1D: GOSUB Send 'R
    WData = $1700 + $1E: GOSUB Send 'S
    WData = $1700 + $10: GOSUB Send 'E
    WData = $1700 + $14: GOSUB Send 'I
    WData = $1700 + $17: GOSUB Send 'L
    WData = $1700 + $17: GOSUB Send 'L
    WData = $1700 + $10: GOSUB Send 'E

    WData = $170B: GOSUB Send 'space
    WData = $170B: GOSUB Send 'space
    WData = $170B: GOSUB Send 'space

    WData = $1700 + $15: GOSUB Send 'J
    WData = $1700 + $19: GOSUB Send 'N
    WData = $1700 + $02: GOSUB Send '2
    WData = $1700 + $03: GOSUB Send '3
    WData = $1700 + $1D: GOSUB Send 'R
    WData = $1700 + $13: GOSUB Send 'H

    PAUSE 1000
    RETURN
    '------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ---------
    'display in page mode
    Display_page:

    'First line in Max Zoom

    WData = 0: GOSUB Send 'do not omit this line: position 0,0 Line 0
    WData = $1F0B: GOSUB Send 'space
    WData = $1F00 + $11: GOSUB Send 'F with blue background
    WData = $1F00 + $06: GOSUB Send '6
    WData = $1F00 + $0E: GOSUB Send 'C
    WData = $1F00 + $1E: GOSUB Send 'S
    WData = $1F00 + $23: GOSUB Send 'X


    WData = $100: GOSUB Send 'line 1
    WData = $170B: GOSUB Send 'space
    WData = $170B: GOSUB Send 'space
    WData = $1700 + $1A: GOSUB Send 'O with black background
    WData = $1700 + $39: GOSUB Send 'p
    WData = $1700 + $26: GOSUB Send ':
    WData = $1700 + $15: GOSUB Send 'J
    WData = $1700 + $1A: GOSUB Send 'O
    WData = $1700 + $10: GOSUB Send 'E
    WData = $1700 + $17: GOSUB Send 'L
    WData = $170B: GOSUB Send 'space
    WData = $170B: GOSUB Send 'space
    WData = $170B: GOSUB Send 'space
    WData = $170B: GOSUB Send 'space

    WData = $1700 + $1C: GOSUB Send 'Q
    WData = $1700 + $1F: GOSUB Send 'T
    WData = $1700 + $13: GOSUB Send 'H
    WData = $1700 + $26: GOSUB Send ':
    WData = $1700 + $18: GOSUB Send 'M
    WData = $1700 + $0C: GOSUB Send 'A
    WData = $1700 + $1D: GOSUB Send 'R
    WData = $1700 + $1E: GOSUB Send 'S
    WData = $1700 + $10: GOSUB Send 'E
    WData = $1700 + $14: GOSUB Send 'I
    WData = $1700 + $17: GOSUB Send 'L
    WData = $1700 + $17: GOSUB Send 'L
    WData = $1700 + $10: GOSUB Send 'E

    WData = $200: GOSUB Send 'line 2
    WData = $1700 + $1E: GOSUB Send 'S
    WData = $1700 + $1A: GOSUB Send 'O
    WData = $1700 + $19: GOSUB Send 'N
    WData = $1700 + $26: GOSUB Send ':
    WData = $1700 + $01: GOSUB Send '1
    WData = $1700 + $04: GOSUB Send '4
    WData = $1700 + $05: GOSUB Send '5
    WData = $1700 + $27: GOSUB Send '.
    WData = $1700 + $02: GOSUB Send '2
    WData = $1700 + $02: GOSUB Send '2
    WData = $1700 + $05: GOSUB Send '5
    WData = $1700 + $18: GOSUB Send 'M
    WData = $1700 + $13: GOSUB Send 'H
    WData = $1700 + $43: GOSUB Send 'z
    WData = $170B: GOSUB Send 'space
    WData = $1700 + $38: GOSUB Send 'o
    WData = $1700 + $3E: GOSUB Send 'u
    WData = $170B: GOSUB Send 'space
    WData = $1700 + $01: GOSUB Send '1
    WData = $1700 + $04: GOSUB Send '4
    WData = $1700 + $05: GOSUB Send '5
    WData = $1700 + $27: GOSUB Send '.
    WData = $1700 + $04: GOSUB Send '4
    WData = $1700 + $00: GOSUB Send '0
    WData = $1700 + $00: GOSUB Send '0
    WData = $1700 + $18: GOSUB Send 'M
    WData = $1700 + $13: GOSUB Send 'H
    WData = $1700 + $43: GOSUB Send 'z


    'Color bars, 4 lines

    FOR iCount = $0 TO $3
    WData = $300 + $100 * iCount: GOSUB Send 'to the beginning of line 3


    WData = $170B: GOSUB Send 'space
    WData = $170B: GOSUB Send 'space

    WData = $1877: GOSUB Send 'black
    WData = $1877: GOSUB Send
    WData = $1877: GOSUB Send

    WData = $1977: GOSUB Send
    WData = $1977: GOSUB Send
    WData = $1977: GOSUB Send

    WData = $1A77: GOSUB Send
    WData = $1A77: GOSUB Send
    WData = $1A77: GOSUB Send

    WData = $1B77: GOSUB Send
    WData = $1B77: GOSUB Send
    WData = $1B77: GOSUB Send

    WData = $1C77: GOSUB Send
    WData = $1C77: GOSUB Send
    WData = $1C77: GOSUB Send

    WData = $1D77: GOSUB Send
    WData = $1D77: GOSUB Send
    WData = $1D77: GOSUB Send

    WData = $1E77: GOSUB Send
    WData = $1E77: GOSUB Send
    WData = $1E77: GOSUB Send

    WData = $1F77: GOSUB Send
    WData = $1F77: GOSUB Send
    WData = $1F77: GOSUB Send 'white
    NEXT iCount


    WData = $700: GOSUB Send
    FOR iCount = $1 TO $8
    WData = $170B: GOSUB Send 'space
    NEXT iCount
    WData = $1700 + $5F: GOSUB Send '*
    WData = $1700 + $5F: GOSUB Send '*
    WData = $1700 + $5F: GOSUB Send '*
    WData = $170B: GOSUB Send 'space
    WData = $1780 + W1: GOSUB Send '2 or 7
    WData = $1780 + W2: GOSUB Send '3 or 0
    WData = $1780 + $2C: GOSUB Send 'c
    WData = $1780 + $36: GOSUB Send 'm
    WData = $170B: GOSUB Send 'space
    WData = $1700 + $5F: GOSUB Send '*
    WData = $1700 + $5F: GOSUB Send '*
    WData = $1700 + $5F: GOSUB Send '*


    PAUSE 1000

    RETURN
    '------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ---------
    WasteTime: 'timer 2 clock cycles
    ASM
    nop
    nop
    ENDASM
    RETURN
    '------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ---------
    StartCommunication: 'Start of transmission Fig 2 page 12 manual STV5730A
    HIGH Clk: GOSUB WasteTime 'Clock to 1
    LOW Csn: GOSUB WasteTime 'Chip select to 0
    LOW Clk: GOSUB WasteTime 'Clock at 0
    RETURN
    '------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ---------
    StopCommunication: 'end of transmission
    HIGH Clk: GOSUB WasteTime 'Clock to 1
    HIGH Csn: GOSUB WasteTime 'Chip select to 1
    RETURN
    '------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ---------
    SendOne: 'Send a bit 0
    HIGH Sda: GOSUB WasteTime
    LOW Clk: GOSUB WasteTime
    HIGH Clk: GOSUB WasteTime
    RETURN
    '------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ---------
    SendZero: 'sending a bit 1
    LOW Sda: GOSUB WasteTime
    LOW Clk: GOSUB WasteTime
    HIGH Clk: GOSUB WasteTime
    HIGH Sda: GOSUB WasteTime
    RETURN
    '------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ---------
    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
    '------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ---------
    Send:
    GOSUB StartCommunication
    GOSUB OutByte
    GOSUB StopCommunication
    RETURN
    '------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ---------'** INITIALIZATION (see page 12 of the DATA SHEET STV5730)


    Init:


    HIGH Clk: HIGH Sda: HIGH Csn
    WData = $3000: GOSUB Send 'Init STV5730
    WData = $3000: GOSUB Send
    WData = $00DB: GOSUB Send
    WData = $1000: GOSUB Send
    RETURN
    '------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ---------
    'PAGE MODE INITIALIZATION
    Mode_page:

    WData = $00CC: GOSUB Send 'Registry initialization (tip at address 12)
    WData = $150F: GOSUB Send 'Zoom
    WData = $1201: GOSUB Send 'Color
    WData = $1FC5: GOSUB Send 'Control
    WData = $15A1: GOSUB Send 'Position (horizontal 33, Vertical 22)
    WData = $193E: GOSUB Send 'Fashion

    WData = $00C0: GOSUB Send 'Set row attributes (tip to first line address)
    WData = $10C4: GOSUB Send '(vertical position = 4, characters with border, characters displayed, horizontal position = 0)
    WData = $10C4: GOSUB Send '(vertical position = 4, characters with border, characters displayed, horizontal position = 0)
    WData = $10C4: GOSUB Send '(vertical position = 4, characters with border, characters displayed, horizontal position = 0)
    WData = $10C8: GOSUB Send
    FOR iCount = 0 TO 2
    WData = $10C0: GOSUB Send '(vertical position = 0, characters with border, characters displayed, horizontal position = 0)
    NEXT iCount 'Same for the next 10 lines
    WData = $10C8

    GOSUB Delete_Screen
    RETURN

    '------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ---------
    Mode_mixed: 'INITIALIZATION IN JOINT MODE

    WData = $00CC: GOSUB Send 'Registry initialization (tip at address 12)
    WData = $1000: GOSUB Send 'Zoom (1pixel / dot - 1 pixel / line)
    WData = $1204: GOSUB Send 'Color (red background, line, character background)
    WData = $1FD4: GOSUB Send 'Control (mixed mode, character background controlled by BE, display on, color character by character attribute
    '0.5s flashing, duty cycle 0.5, STV sync, PAL, external luminance level, normal full page mode
    WData = $15A1: GOSUB Send 'Position (horizontal 33, Vertical 22)
    WData = $183E: GOSUB Send 'Mode (disconnected BAR, synch pulse detection, internal mute, 32-line mute time, re-inserted sync, 6dB video gain
    'Color coder in use, video out2 = video in, video out2 low impedance, normal mode, no delay compensation,
    'M sync with vertical sync

    WData = $00C0: GOSUB Send 'Set row attributes (tip to first line address)
    FOR iCount = 0 TO 10
    WData = $10C4: GOSUB Send '(vertical position = 4, characters with border, characters displayed, horizontal position = 0)
    NEXT iCount 'Same for the following lines
    GOSUB Delete_screen
    RETURN

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    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

  3. #3
    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.

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    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, 05: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, 03: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, 21: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, 11: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, 20:51

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