homemade24
New Member
I'm trying to migrate some code from 16f690 to a 12f629 it will build (with warnings) but not work. I've changed the porta to gpio etc. but maybe I have miss something. I will work with the 690 maybe some one see's something I missed
thanks
"be easy on me I'm trying to learn I'm just not real bright"
thanks
"be easy on me I'm trying to learn I'm just not real bright"
Code:
;-----------------------------------------------------------------------------------------------;
; LANC Controller ;
; --------------- ;
;ORIGNAL CODE FOR 16F690 ;
; ;
; ;
; When reading and writing the LANC codes, the codes are inverted. So if we read a 1, we save ;
; a 0 etc. ;
;-----------------------------------------------------------------------------------------------;
#include "p12f629.inc" ;CHANGED FROM 16F690
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _CPD_OFF
cblock 0x20
; ******************************************
Byte ; holds the Byte we are reading on the LANC line
ReadError ; bit 0 is used to hold a 1 if there is a read error
Byte0 ; holds Byte0
Byte1 ; holds Byte1
Byte2 ; holds Byte2
Byte3 ; holds Byte3
Byte4 ; holds Byte4
Byte5 ; holds Byte5
Byte6 ; holds Byte6
Byte7 ; holds Byte7
SendByte0 ; used to hold the value that will be sent in Byte0
SendByte1 ; used to hold the value that will be sent in Byte1
Buttons ; bit 0 holds a 1 when a button has been pressed
Sender ; used when sending a command. A command need to be sent 3 - 5 times
; to the camera, so this is used as a counter
BitCount ; counter used in bit counting
Count ; counter
Temp ; tempory register
endc
org 0
goto Start ; jump to Start
;--------------------------------------;
; Subroutines are here at the top ;
;--------------------------------------;
;-----------------------------------------------------------------------------------------------;
; Read and Write LANC subs setup GPIO,0 for reading and writing ;
;-----------------------------------------------------------------------------------------------;
ReadLANC:
bsf STATUS,RP0 ; register page 1
movlw B'00001101' ;CHANGED FROM 1 *************
movwf TRISIO ; set GPIO,0 as an input CHANGED FROM TRISA*******************
bcf STATUS,RP0 ; back to Register Page 0
return
WriteLANC:
bsf STATUS,RP0 ; register page 1
movlw B'00001100' ;CHANGED FROM 0
movwf TRISIO ; set GPIO,0 as an output CHANGED FROM TRISA*************
bcf STATUS,RP0 ; back to Register Page 0
return
;-----------------------------------------------------------------------------------------------;
; RecordButton is a debouce debouce sub for the for the Record button ;
;-----------------------------------------------------------------------------------------------;
RecordButton:
movlw 0xFF ; put FFh into W
movwf Temp ; put W into Temp
RecordButton2:
btfsc GPIO,2 ; see if GPIO,2 is low CHANGED FROM RB4*************************
return ; if not return
decfsz Temp ; if so, decrement Temp
goto RecordButton2 ; jump back up for another decrement
bsf Buttons,0 ; if we counted all the way from 256 down to 0, set bit 0 of Buttons reg
RecordButton3: ; make sure the button has been released for a 256 count
movlw 0xFF ; put FFh into W
movwf Temp
RecordButton4:
btfss GPIO,2 ; make sure the button has been released CHENGED FROM RB4******************
goto RecordButton3
decfsz Temp
goto RecordButton4
movlw 0x18
movwf SendByte0
movlw 0x27 ; record THIS WORKS FOR MY CAM CHANGED FROM 3A
movwf SendByte1 ; the 2 bytes to command the camera to record
movlw 5
movwf Sender ; put 5 into the Sender reg
return
;-----------------------------------------------------------------------------------------------;
; StopButton is a debouce debouce sub for the for the Stop button ;
;-----------------------------------------------------------------------------------------------;
StopButton:
movlw 0xFF ; put FFh into W
movwf Temp ; put W into Temp
StopButton2:
btfsc GPIO,3 ; see if GPIO,3 is low CHANGED FROM RB5 ***********************
return ; if not return
decfsz Temp ; if so, decrement Temp
goto StopButton2 ; jump back up for another decrement
bsf Buttons,0 ; if we counted all the way from 256 down to 0, set bit 0 of Buttons reg
StopButton3: ; make sure the button has been released for a 256 count
movlw 0xFF ; put FFh into W
movwf Temp
StopButton4:
btfss GPIO,3 ; make sure the button has been released CHANGED FROM RB5*************
goto StopButton3
decfsz Temp
goto StopButton4
movlw 0x18
movwf SendByte0
movlw 0x29 ; stop WORK WITH MY CAM CHANGED FROM 30 *******************
movwf SendByte1 ; the 2 bytes to command the camera to stop
movlw 5
movwf Sender ; put 5 into the Sender reg
return
;-----------------------------------------------------------------------------------------------;
; The waitHalf sub delays the program by 48uS. This is used when the start bit of each byte is ;
; found so we are reading the bits in the middle, not on the transistion. Half a bit length is ;
; actually 52uS, but most lines of code take 1uS, these lines of code in the program have been ;
; worked to make sure the delay is correct. ;
;-----------------------------------------------------------------------------------------------;
WaitHalf:
movlw .14
movwf Count
nop
WaitHalfLoop:
decfsz Count
goto WaitHalfLoop
return
;-----------------------------------------------------------------------------------------------;
; ReadByte is called to read a byte on the LANC line, the byte is stored in the Byte register ;
; The bits we read are inverted before they are stored. ;
;-----------------------------------------------------------------------------------------------;
ReadByte:
clrf Byte ; clear the Byte register
btfsc GPIO,0 ; skip when the LANC line drops to 0 CHANGED FROM PORTA,0********
goto $-1
call WaitHalf ; wait for 50uS
btfsc GPIO,0 ; make sure the LANC line is still 0 CHANGED FROM PORTA,0*************
bsf ReadError,0 ; set the read error flag
; now we are in the middle of the start bit, so we wait for 104uS
; so we are in the middle of Bit0
call WaitHalf ; wait for 48uS (about half of a bit length)
call WaitHalf ; wait for 48uS (about half of a bit length)
nop
nop
nop
nop
nop
nop ; wait another 5uS
; CheckBit is looped 8 times in order to read the 8 bits of the byte
movlw .8 ; put 8 into W
movwf BitCount
CheckBit:
rrf Byte,1 ; rotate the Byte register right
bcf Byte,7 ; clear bit 7 of the Byte register incase the Carry flag has been rotated into it
btfss GPIO,0 ; is the LANC line 0 CHANGED FROM PORTA,0*************
bsf Byte,7 ; if the LANC line was 'high' clear bit 7 of the Byte register
call WaitHalf ; wait for 52uS (half of a bit length)
call WaitHalf ; wait for 52uS (half of a bit length)
decfsz BitCount ; have we read all 8 bits
goto CheckBit
return
;-----------------------------------------------------------------------------------------------;
; WriteByte is called to write a byte on the LANC line, the Byte register is written to LANC ;
;-----------------------------------------------------------------------------------------------;
WriteByte:
btfsc GPIO,0 ; skip when the LANC line drops to 0 CHANGED FROM PORTA,0************
goto $-1
call WaitHalf ; wait for 50uS
btfsc GPIO,0 ; make sure the LANC line is still 0 CHANGED FROM PORTA,0*******************
bsf ReadError,0 ; set the read error flag
; now we are in the middle of the start bit, so we wait for 104uS
; so we are in the middle of Bit0
call WaitHalf ; wait for 48uS (about half of a bit length)
call WriteLANC ; set up GPIO,0 for writing to LANC
; WriteBit is looped 8 times in order to write the 8 bits of the byte
movlw .8 ; put 8 into W
movwf BitCount
WriteBit:
btfss Byte,0 ; is bit 0 of the Byte register a 1
bsf GPIO,0 ; output a 0 CHANGED FROM PORTA,0******************************
btfsc Byte,0 ; is bit 0 of the Byte register a 0
bcf GPIO,0 ; output a 1 CHANGED FROM PORTA,0******************
rrf Byte ; rotate the Byte register to the right
call WaitHalf ; wait for 52uS (half of a bit length)
call WaitHalf ; wait for 52uS (half of a bit length)
decfsz BitCount ; have we read all 8 bits
goto WriteBit
call ReadLANC
return
;-----------------------------------------------------------------------------------------------;
; Main program starts here ;
;-----------------------------------------------------------------------------------------------;
Start:
bsf STATUS,RP0 ; register page 1
MOVLW 0X07 ;SET UP W TO TURN COMPARATOR OFF ******ADDED
MOVWF CMCON
bsf STATUS,RP0 ; register page 1
;MOVLW 0 ; TOOK OUT NO PORTC ON 12F***********
;MOVWF TRISC ;**************************
movlw b'00001100' ;CHANGED FROM B'01110000'
movwf TRISIO ; CHANGED FROM TRISB ***********
bsf STATUS,RP1 ; select Page 2,
bcf STATUS,RP0 ; by setting RP1 in Status register and clearing RP0
;clearing RP0 ; REMOVED ***Error[122] Illegal opcode (RP0)*********
;clrf ANSEL ;not need for 12f629 ************
;clrf ANSELH ;not need for 12f629 ************
bcf STATUS,RP1 ;back to registor page 0
clrf Sender ; clear the Sender register
clrf Buttons ; clear the Buttons register
;clrf PORTB ;NOT NEED FOR 12F629************
;clrf PORTC ;NOT NEED FOR 12F629************
Start2:
btfss GPIO,2 ; is the Record button being pressed CHANGED FROM PORTB,4*************
call RecordButton
btfss GPIO,3 ; is the Stop button being pressed CHAGED FROM PORTB,5*******************
call StopButton
Sync:
call ReadLANC ; set for reading
Sync2:
clrf Count ; clear the Count register
SyncLoop:
btfss GPIO,0 ; see if the LANC line is high CHANGED FROM PORTA,0************
goto Sync2
; If the Count register gets to zero, we know we are in the interframe
; gap. 256 x 5uS (the time for the loop) = 1280uS. There is only about
; 200uS between bytes on the LANC line!
decfsz Count ; decrement the Count register
goto SyncLoop
movfw Sender ; if there is a value in the Sender register
iorlw 0 ; that means that we need to write the first
btfsc STATUS,Z ; 2 bytes, not read them
goto ReadFrom0
; Write byte 0
clrf ReadError
movfw SendByte0
movwf Byte ; put SendByte 0 into Byte
call WriteByte
btfsc ReadError,0 ; did the sub return a read error?
goto Start2 ; if so, return to Start2
; Write byte 1
clrf ReadError
movfw SendByte1
movwf Byte ; put SendByte 1 into Byte
call WriteByte
btfsc ReadError,0 ; did the sub return a read error?
goto Start2 ; if so, return to Start2
decf Sender ; decrement the Sender register
goto ReadFrom2
ReadFrom0:
; Read byte 0
clrf ReadError
call ReadByte ; read the first byte on the LANC line
btfsc ReadError,0 ; did the sub return a read error?
goto Start2 ; if so, return to Start2
movfw Byte
movwf Byte0
; Read byte 1
clrf ReadError
call ReadByte ; read the first byte on the LANC line
btfsc ReadError,0 ; did the sub return a read error?
goto Start2 ; if so, return to Start2
movfw Byte
movwf Byte1
ReadFrom2:
; Read byte 2
clrf ReadError
call ReadByte ; read the first byte on the LANC line
btfsc ReadError,0 ; did the sub return a read error?
goto Start2 ; if so, return to Start2
movfw Byte
movwf Byte2
; Read byte 3
clrf ReadError
call ReadByte ; read the first byte on the LANC line
btfsc ReadError,0 ; did the sub return a read error?
goto Start2 ; if so, return to Start2
movfw Byte
movwf Byte3
; Read byte 4
clrf ReadError
call ReadByte ; read the first byte on the LANC line
btfsc ReadError,0 ; did the sub return a read error?
goto Start2 ; if so, return to Start2
movfw Byte
movwf Byte4
; Read byte 5
clrf ReadError
call ReadByte ; read the first byte on the LANC line
btfsc ReadError,0 ; did the sub return a read error?
goto Start2 ; if so, return to Start2
movfw Byte
movwf Byte5
; Read byte 6
clrf ReadError
call ReadByte ; read the first byte on the LANC line
btfsc ReadError,0 ; did the sub return a read error?
goto Start2 ; if so, return to Start2
movfw Byte
movwf Byte6
; Read byte 7
clrf ReadError
call ReadByte ; read the first byte on the LANC line
btfsc ReadError,0 ; did the sub return a read error?
goto Start2 ; if so, return to Start2
movfw Byte
movwf Byte7
;REMOVED FROM PROGRAM FOR NOW
;CHECK TO SEE OF CAMERA IS RECORDING
;movfw byte4 ;put byte4 into w
;xorlw 0x04 ;xor with 04 (recording)
;btfss STATUS,Z ;if it's the same , put the recording light on
;bsf portb,7
;btfss STATUS,Z
;bcf portb,7
;movfw byte4 ;portc used to monitor
;movwf PORTC
goto Start2
end
Warning[205] C:\LANC\CHEAP690\LANC690.ASM 30 : Found directive in column 1. (cblock)
Warning[205] C:\LANC\CHEAP690\LANC690.ASM 59 : Found directive in column 1. (ENDC)
Message[302] C:\LANC\CHEAP690\LANC690.ASM 76 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] C:\LANC\CHEAP690\LANC690.ASM 83 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[305] C:\LANC\CHEAP690\LANC690.ASM 99 : Using default destination of 1 (file).
Message[305] C:\LANC\CHEAP690\LANC690.ASM 111 : Using default destination of 1 (file).
Message[305] C:\LANC\CHEAP690\LANC690.ASM 135 : Using default destination of 1 (file).
Message[305] C:\LANC\CHEAP690\LANC690.ASM 147 : Using default destination of 1 (file).
Message[305] C:\LANC\CHEAP690\LANC690.ASM 173 : Using default destination of 1 (file).
Message[305] C:\LANC\CHEAP690\LANC690.ASM 220 : Using default destination of 1 (file).
Message[305] C:\LANC\CHEAP690\LANC690.ASM 257 : Using default destination of 1 (file).
Message[305] C:\LANC\CHEAP690\LANC690.ASM 262 : Using default destination of 1 (file).
Message[302] C:\LANC\CHEAP690\LANC690.ASM 280 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] C:\LANC\CHEAP690\LANC690.ASM 283 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] C:\LANC\CHEAP690\LANC690.ASM 288 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] C:\LANC\CHEAP690\LANC690.ASM 289 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[305] C:\LANC\CHEAP690\LANC690.ASM 323 : Using default destination of 1 (file).
Message[305] C:\LANC\CHEAP690\LANC690.ASM 352 : Using default destination of 1 (file).
Warning[205] C:\LANC\CHEAP690\LANC690.ASM 443 : Found directive in column 1. (end)