This is schematic and code...Maybe I miss something important ...
Code:
@ DEVICE pic16F628A, XT_OSC, WDT_OFF, PWRT_ON, BOD_OFF, MCLR_ON, LVP_OFF, PROTECT_ON
include "alldigital.pbp"
Define OSC 4 ' 4MHz
CMCON = 7 ' Disable on-chip comparator, PORTA in digital mode
TrisA = %00011100 ; coloane la RA2, 3, 4 ; randuri la RA1, 0 ,7
porta = %00011100
TRISB = %00000000
PORTB = %00010000
oldState VAR BYTE
newState VAR BYTE
UP CON 1
DN CON 0
loop:
PortA.1 = 0
newState = PortA & %00011100 ; this is for my hw : 11100 = 28
PortA.1 = 1
If newState <> 28 THEN
If newState <> oldState THEN
Select Case oldState
Case 12
If NewState = 20 THEN dir=up
If NewState = 24 THEn dir=dn
Case 20
If NewState = 24 THEN dir=up
If NewState = 12 THEN dir=dn
Case 24
If NewState = 12 THEN dir=up
If NewState = 20 THEN dir=dn
END SELECT
oldState = newstate
GOSUB UpOrDn
pause 15 ; time for UpOrDn
endif
ENDIF
;============
UpOrDn:
if dir=DN then
PortB.4 = 0
pauseus 3850
PortB.4 = 1
pauseus 3850
PortB.4 = 0
pauseus 660
PortB.4 = 1
endif
if dir=UP then
PortB.4 = 0
pauseus 4450
PortB.4 = 1
pauseus 4400
PortB.4 = 0
pauseus 660
PortB.4 = 1
endif
return
end
Bookmarks