LANC code 12F675


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Jul 2007
    Posts
    2


    Did you find this post helpful? Yes | No

    Default

    No wonder I could not find it in a PicBasic Pro search! I just dug out my v2.45 and had not even tried to compile it. Still not sure what the toggling of GPIO.0 is about.

    Quote Originally Posted by mister_e View Post
    That's PDS Proton... on a PBP forum
    SET GPIO.x will translate to GPIO.x = 1 or HIGH GPIO.x (ASM BSF)
    Clear GPIO.x, will translate GPIO.x=0 (ASM BCF)

    Rsout = DEBUG

    DelayMS = PAUSE
    DelayUs = PAUSEUS

    ALL_DIGITAL = should be something like ANSEL=0 AND CMCON = 7

    Now just translate it to PBP, build the circuit,. and you're half done

  2. #2
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by MikeDD View Post
    Still not sure what the toggling of GPIO.0 is about.
    Well... when I was writing code for my LANC control a while back, I used some blinking LED's as very basic debugging indicators - it looks like this code does the same.
    After various commands, etc, the code does some blinky LED stuff in order for the PIC to let the user know that everything is working OK. Also looks like some error status might be reported too.

    Arch
    "Data sheets? I ain't got no data sheets. I don't need no data sheets. I don't have to read any stinking data sheets!"

  3. #3
    Join Date
    Jul 2007
    Posts
    65


    Did you find this post helpful? Yes | No

    Post

    As this project may be interesting to me, I attempted to convert the proton version...

    it ended with something like that, but I haven't got time to test it yet

    (*debugin* part, schematics, and some other loops aren't quite clear for me yet....)


    '** LANC CONTROL FOR *12F683 modified, BUT NOT TESTED at all yet
    '** THIS VERSION USE A BC107 AS OPEN COLLECTOR ON THE SIGNAL INPUT
    '** AS OPPOSED TO TH 2N 2907 PNP TRANSISTOR WHICH HAD A PROBLEM THAT
    '** THE VOLTAGE IS NOT PULLED TO GROUND BUT TO AROUND 0.8V WHEN LOW
    '** THE SOFTWARE NO OUTPUT AND INVERTED DATA STREAM ALSO INVERTING
    '** THE STOP BIT AND START BIT WHICH COULD NOT BE DONE BY JUST
    '** SPECIFYING DATA INVERTED WHEN USING RSOUT

    ;** DEVICE 12F683

    ;** //Check INC file setup!!!!
    ;set in INC file => device pic12F683, intrc_osc_noclkout, wdt_off, mclr_on, protect_off ;

    ;;;Include "modedefs.bas" si jamais on utilise des routines SERIN/SEROUT

    ANSEL = %00000000 ' No Analog input, set all digital
    CMCON0 = %00000111 ' turn comparators off 07H
    TRISIO = %111010 ' inputs port1,3,4 outputs 0
    GPIO = %000000 ' outputs low << very important it seems!!
    OSCCON = %01100000 ' Internal 4MHz osc set speed
    INTCON = 0 'Do not use PBP interrupts

    define OSC 4 '4mhz clock internal

    'Output on GPIO.5
    DEFINE DEBUG_REG GPIO
    DEFINE DEBUG_BIT 5 ' GPIO.5
    DEFINE DEBUG_BAUD 9600 ' 2400 bps
    DEFINE DEBUG_MODE 0 ' 1 = inverted, 0 = true

    'Input on GPIO.4
    DEFINE DEBUGIN_REG GPIO ' Set Debugin pin port
    DEFINE DEBUGIN_BIT 4 ' Set Debugin pin bit
    'Other unspecified params are taken from DEBUG settings

    ;;DECLARE RSIN_PIN GPIO.3 >> switched for GPIO.4
    ;;DECLARE RSIN_MODE TRUE
    ;;DECLARE SERIAL_BAUD 9600
    ;;DECLARE RSIN_TIMEOUT 20000
    ;;DECLARE RSOUT_PIN GPIO.5
    ;;DECLARE RSOUT_MODE TRUE

    ;;;;;Translation to test fron Proton code, si marche pas essaye Array[]??
    FBYTE0 VAR BYTE
    FBYTE1 VAR BYTE
    FBYTE2 VAR BYTE
    FBYTE3 VAR BYTE
    FBYTE4 VAR BYTE
    FBYTE5 VAR BYTE
    FBYTE6 VAR BYTE
    FBYTE7 VAR BYTE
    COMMAND VAR BYTE
    OLD VAR BYTE
    flshLight VAR BYTE

    DO_AGAIN VAR BIT
    REC_STATUS VAR BIT
    TRIGGER VAR BIT

    GAPCOUNT VAR WORD

    LED_act VAR GPIO.2 'Activity LED

    start:
    INPUT GPIO.5
    FBYTE0=%00011000^$FF ; $FF = %11111111
    GOTO MAIN

    GAP_TIME:
    GAPCOUNT=0

    DO:
    IF GPIO.4 <>1 THEN GOTO GAP_TIME
    GAPCOUNT=GAPCOUNT+1
    IF GAPCOUNT <150 THEN GOTO DO

    COMMANDOUT:
    'OUTPUT GPIO.5 ;; Delete?
    WHILE GPIO.3=1 :WEND ;; Check Syntax.

    'RSOUT **FBYTE0**
    OUTPUT GPIO.5 ;Writing on the LANC line..
    GPIO.5 = 1 'START BIT
    PAUSEUS 94 '11100111 #E7h?????? inverted >> %00011000 = #18h would make sense
    GPIO.5 = 0 'FIRST LSB BIT
    PAUSEUS 104 'BIT1
    PAUSEUS 104 'BIT2
    PAUSEUS 104 'BIT3
    GPIO.5 = 1
    PAUSEUS 104 'BIT4
    PAUSEUS 104 'BIT5
    GPIO.5 = 0
    PAUSEUS 104 'BIT6
    PAUSEUS 104 'BIT7
    PAUSEUS 104 'BIT8
    PAUSEUS 104 'STOP BIT
    INPUT GPIO.5 ;Listening on the LANC line..

    WHILE GPIO.4=1 :WEND ; ??Waiting for Start bit??

    'RSOUT COMMAND
    OUTPUT GPIO.5 ;Writing on the LANC line..
    GPIO.5 = 1
    PAUSEUS 94 'STOP BIT

    IF COMMAND=$3A THEN ; #3Ah <=> #58d <=> %00111010 (??send inverted as %11000101)
    GPIO.5 = 0
    PAUSEUS 104 'BIT1 LSB
    GPIO.5 = 1
    PAUSEUS 104 'BIT2
    GPIO.5 = 0
    PAUSEUS 104 'BIT3
    GPIO.5 = 1
    PAUSEUS 104 'BIT4
    PAUSEUS 104 'BIT5
    PAUSEUS 104 'BIT6
    GPIO.5 = 0
    PAUSEUS 104 'BIT7
    PAUSEUS 104 'BIT8
    PAUSEUS 104 'STOP BIT
    ELSE
    'RSOUT COMMAND; $30 <=> #30h <=> #48d <=> %00110000 (??send inv as %11001111)

    GPIO.5 = 0
    PAUSEUS 104 'BIT1 LSB
    PAUSEUS 104 'BIT2
    PAUSEUS 104 'BIT3
    PAUSEUS 104 'BIT4
    GPIO.5 = 1
    PAUSEUS 104 'BIT5
    PAUSEUS 104 'BIT6
    GPIO.5 = 0
    PAUSEUS 104 'BIT7
    PAUSEUS 104 'BIT8
    PAUSEUS 104 'STOP BIT
    INPUT GPIO.5 ;Listening on the LANC line..
    ENDIF

    ;;FBYTE2=RSIN ;;replaced proton code
    ;;FBYTE3=RSIN ;;FBYTE4=RSIN ;;FBYTE5=RSIN ;;FBYTE6=RSIN

    DEBUGIN [FBYTE2]
    DEBUGIN [FBYTE3]
    DEBUGIN [FBYTE4]
    DEBUGIN [FBYTE5]
    DEBUGIN [FBYTE6]

    RETURN ;----------------------------------------------

    INTERPRET:

    FBYTE4=FBYTE4^$FF ;; just an Inverter?
    IF FBYTE4=OLD THEN GOTO DONE
    OLD=FBYTE4
    ;;; should invert all BYTE before sending!?
    ;;; DEBUG 1, "LANC:",FBYTE0,FBYTE1,FBYTE2,FBYTE3,FBYTE4,FBYTE5, FBYTE6,FBYTE7,">"
    IF FBYTE4=$02 THEN GOSUB STOP_ACTIVE
    IF FBYTE4=$01 THEN GOSUB FAULT_ACTIVE
    IF FBYTE4=$04 THEN GOSUB RECORD_ACTIVE
    IF FBYTE4=$32 THEN GOSUB FAULT_ACTIVE
    IF FBYTE4=$62 THEN GOSUB FAULT_ACTIVE

    DONE:
    RETURN ;----------------------------------------------

    STOP_ACTIVE:

    REC_STATUS=0
    GPIO.2 = 0 ' RECORDING IS ACTIVE LED

    for flshLight=1 to 5
    GPIO.0 = 1 'PULSE LED/Port
    PAUSE 500
    GPIO.0 = 0
    PAUSE 500
    next flshLight

    RETURN ;----------------------------------------------

    FAULT_ACTIVE:

    for flshLight=1 to 5
    GPIO.0 = 1 'PULSE LED/Port
    PAUSE 100
    GPIO.0 = 0
    PAUSE 100
    next flshLight

    RETURN ;----------------------------------------------

    RECORD_ACTIVE:
    REC_STATUS=1
    GPIO.0 = 1
    GPIO.2 = 1 ' RECORDING IS ACTIVE LED
    PAUSE 3000
    GPIO.0 = 0

    RETURN ;----------------------------------------------

    MONITOR:
    WHILE GPIO.1=0 'Input switch!
    TRIGGER=0
    WEND

    IF TRIGGER = 1 THEN GOTO DONEMON
    IF TRIGGER = 0 THEN GOSUB INVRECSTATUS


    DONEMON:
    RETURN ;----------------------------------------------


    INVRECSTATUS:
    REC_STATUS = REC_STATUS^1 ;;Flipflop

    RETURN ;----------------------------------------------

    LOAD_COMMAND:

    IF REC_STATUS=0 THEN COMMAND=$30'^$FF 'NEW COMMAND = STOP
    IF REC_STATUS=1 THEN COMMAND=$3A'^$FF 'NEW COMMAND = REC RETURN

    MAIN:
    GAPCOUNT=0
    FBYTE1=0
    FBYTE2=0
    FBYTE3=0
    FBYTE4=0
    FBYTE5=0
    FBYTE6=0
    FBYTE7=0
    DO_AGAIN=0
    TRIGGER=0
    gpio.0=0
    gpio.2=0
    COMMAND=$00^$FF

    RERUN:
    DO_AGAIN=0

    AGAIN3:
    GAPCOUNT=0
    GOSUB GAP_TIME
    DO_AGAIN =DO_AGAIN+1
    'Resend data at least 5 times (lanc needs at least 3 valid command to exe.)
    IF DO_AGAIN<=5 THEN GOTO AGAIN3

    GOSUB INTERPRET
    'PAUSE 1000 ' WAIT WHILE TRIGGER MIGHT STILL BE ACTIVATED
    GOSUB MONITOR

    IF TRIGGER=0 THEN GOSUB LOAD_COMMAND
    TRIGGER=1
    GOTO RERUN

    END
    Attached Files Attached Files
    Last edited by flipper_md; - 9th May 2008 at 05:46.

Similar Threads

  1. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  2. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  4. 12F675 code sample
    By marad73 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 23rd May 2006, 13:53
  5. 12F675 Code Help
    By papa-smurf in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 9th August 2004, 15: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