Kildekode Kamera

Startside ] Linkside ] Planlagte prosjekter ] Flyfoto side ] Trådløs video ] Elektronikk ]  [ Post ]

;Mustek eSmart Mini controller
;Version: 1.0 July 19 2002
;Status ; Tested and OK
;Jon-Magne Johansen,
;               PIC 16F84
;           _________________
;          I RA2         RA1 I
;          I RA3         RA0 I
;          I RA4/T  OSC1/CLI I
;          I MCLR   OSC2/CLO I
;          I VSS         VDD I
;      RX  I RBO/INT     RB7 I LED
; PowerLED I RB1         RB6 I Shutter
;          I RB2         RB5 I Mode
;          I RB3         RB4 I On_Off
;           -----------------
;Inputs: PowerLED, RC-signal -> RB0, RB1
;Outputs: On_Off, Mode, Shutter, LED -> RB4,RB5,RB6,RB7
;Fuses: Osc=HS, WDT=Off, PWRTE=Off

include "P16F84.INC"

RX        equ 0    ;Input from RX
PowerLED  equ 1    ;Input from PowerLED
On_Off    equ 4    ;On/Off switch, active high
Mode      equ 5    ;Mode Button, active high
Shutter   equ 6    ;Shuter button
LED       equ 7    ;Message LED

Bdelay    equ 0x40 ;Time buttons must be depressed on camera
Width     equ 0CH  ;Pulse width
d1        equ 0DH  ;Delay counter 1
d2        equ 0EH  ;Delay counter 2

         MOVLW 0x0F      ;Data direction 0-3=input
         BSF STATUS, RP0 ;Select bank 1
         MOVWF TRISB     ;Set data direction
         BCF STATUS, RP0 ;Back to page 0

         call Delay      ;Flash LED 0,3 seconds

Begin   BTFSC PORTB,PowerLED ;Is powerLED on?
        GOTO Hi              ;Yes, check RX
        BSF PORTB,On_Off     ;No, set powerbutton
        movlw Bdelay         ;Waste time, button must be depressed a
        call Delay2          ;while to be recognized as a command
        BCF PORTB,On_Off     ;Release powerbutton

        BSF PORTB,Mode       ;Set Mode-button
        movlw Bdelay
        call Delay2
        BCF PORTB, Mode      ;Release modebutton, we now
                             ;have selected Mode 1

Hi     btfsc PORTB,RX        ;Is RX line Hi
       goto Hi               ;Yes

Lo     btfss PORTB,RX        ;RX line is lo wait to go Hi
       goto Lo               ;RX line lo

;At this point, we have a valid RC-signal, and camera is ready

       CALL Measure          ;Measure pulse width

PulseOK btfsc Width,7        ;Check bit7 of with, if set, pulse is
                             ;longer than 128,-> TX button is on
       goto Snap             ;Yes, TX button is on
       goto Begin            ;No - start over
Snap   BSF PORTB,Shutter     ;Yes, set shutter button
       movlw Bdelay
       call Delay2
       BCF PORTB,Shutter     ;Release shutter
       call Delay            ;Wait 0,3 seconds
       GOTO Begin            ;Start over

;* This routine measures the width of positive going pulses *
;* and returns with a value >0 for pulses up to 2.55mS or a *
;* value of 0 if it is the sync pulse. *

Measure clrf Width
Repeat nop                   ;Five NOP's to pad
       nop                   ;out routine to give
       nop                   ;a total loop time of
       nop                   ;10uS
       btfss PORTB,RX        ;is RX lo
       goto Done             ;Yes go to Done
       incfsz Width,f        ;Inc width count
       goto Repeat           ;loop for another 10uS
Done   retlw 0               ;return from routine

;* This routine gives a 0,3 sec delay *
Delay  bsf PORTB,LED         ;Turn on message LED
Delay1 movlw 0x5F
Delay2 movwf d1
       movlw 0xEB
       movwf d2
       decfsz d1, f
       goto $+2
       decfsz d2, f
       goto Delay_0
       bcf PORTB,LED         ;Turn off message LED
       retlw 0