Hi BBarney
This is my basic get you going proton code, there are alot of improvements that can be made, the procedure is:
LED + connected to portb.1
LED - connected to portb.0 through 330ohm resistor
You will find that the led will flas fast in normal light, and slow in dark, my codes have some timing issues and are by no means perfect but they should give you the bulding blocks
<code>
device = 18f452
xtal = 20
dim timer as word
start:
output portb.0 'make pin output
output portb.1 'make pin output
high portb.1 'make led + high
low portb.0 'make led - low led lights up
delayms 20 ' small delay
low portb.1 'make led + low
high portb.0 'make led - low reverse bias led
timer = 0 'clear timer
input portb.0 make led - an input
loop:
if portb.0 <> 0 then timer = timer + 1 : goto loop 'if led - is not at logic low then increment timer and loop until it is logic low
serout porte.1 , 84, [dec timer,13,10,0] ' sent the result to serial lcd
goto start
stop
end
</code>
This is the same in ASM except im using porta.7 & 6 for led
<code>
LIST p=16f628a
#include <p16f628a.inc>
ORG 0000h
START
MOVLW 7
MOVWF CMCON
BSF STATUS, RP0
CLRF TRISB
BCF STATUS, RP0
MAIN
BSF STATUS, RP0
MOVLW b'00000000'
MOVWF TRISA
BCF STATUS, RP0
BSF PORTA, 7
BCF PORTA, 6
CALL DELAY
BCF PORTA, 7
BSF PORTA, 6
MOVLW 0
MOVWF TMR0
BSF STATUS, RP0
MOVLW b'01000000'
MOVWF TRISA
BCF STATUS, RP0
LOOP
INCF TMR0, 1
BTFSC PORTA, 6
GOTO LOOP
MOVF TMR0, 0
MOVWF PORTB
GOTO MAIN
DELAY
MOVLW 0FFh
MOVWF TMR1L
MOVLW 0Ah
MOVWF TMR1H
DELAY_INNER
DECFSZ TMR1L, 1
GOTO DELAY_INNER
MOVLW 0FFh
MOVWF TMR1L
DECFSZ TMR1H, 1
GOTO DELAY_INNER
RETURN
END
</code>
Bookmarks