Grounded
Here is LanC using loops and no bitbanging you can send serial data to the pic in the form of hex numbers and it will try these commands on the camera.
like 5e
Code:
@ DEVICE PIC16F84,HS_OSC,WDT_OFF,PWRT_ON,PROTECT_OFF
DEFINE OSC 10
command_bit var bit
syncbit var byte
syncbyte var word
counter var byte
value var word
Bits var byte
pause 2000
Serial_data:
Serin2 portb.3,84,[value]
counter = 0
pause 20
if value =" " then goto serial_data
If value =$5C THEN gosub wakeup
serout2 portb.4,84,[value]
gosub Send_command
goto Serial_data
Send_command: 'This section converts the hex value stored in the vairable value
gosub command_byte 'to the eight bits of data and sends the correct High Low commands
gosub sync_bit 'needed to control the LanC device.
For Bits = 0 to 7
Command_bit = value.0[Bits]
if command_bit = 1 then
low portb.2
else
input portb.2
endif
pauseus 80
next
counter = counter + 1
if counter = 3 then return
goto Send_command
Sync_byte: 'Sync_byte looks for the inter_frame gap 5.4mS to 7mS at the end of every
syncbyte = 0 'frame tranmissions and just before the start of the next frame
while syncbyte < 700
pulsin portb.1, 1, syncbyte
wend
Return
Sync_bit: 'Sync_Bit looks for the start_bit of each frame this is used
syncbit = 0 'in sending the second byte of a command
while syncbit < 9
pulsin portb.1, 0, syncbit
wend
Return
Command_byte: 'tell camera that a command is to follow normal commands
gosub sync_byte
pauseus 80 'pause for camera's start bit to finish
input portb.2 'first byte to send (LSB 1ST)Hex 18 %0001,1000
pauseus 312
low portb.2
pauseus 208
input portb.2
pauseus 312
input portb.2 'Stop bits set high
Return
Wakeup:
low portb.2 'This wakes camera up for short period to accept commands
pause 500
input portb.2
pause 100
Return
Bookmarks