Hjälp med if
Hjälp med if
Hur får jag if att funka? Jag vill att en switchen på port RA0 ska få leden på port RB0 att blinka. Jag kör mikrobasic och får inte det att funka. antingen så blinkar leden hela tiden eller så funkar inget. Hade även varit kul om någon vill förklara hur der funkar om man vill att led 1 ska blinka 10ggr sedan ska led 2 blinka 10ggr med if forlmel
Jag har vellemans experiment kort med dioder motstånd och allt annat på ett och samma ställe. sw1-sw4 är kopplade till RA0-RA3 och dioderna till RB0 - RB5 med motstånd och allt. jag vet inte skillnaden mellan pull-up och vanliga motstånd men det bör vara rätt. Detta är en av alla koder jag testat
if RA0. = 1 then
goto test 1
end if
Detta är i kort som jag har förstått att det ska vara
if RA0. = 1 then
goto test 1
end if
Detta är i kort som jag har förstått att det ska vara
-
- Inlägg: 700
- Blev medlem: 23 augusti 2003, 20:42:38
Här e hela min kod
main:
cmcon = 7 ' Stäng av komparator
TrisA = 255 ' PortA är input
TrisB = 0 ' PortB är Output
loop:
If PortA.0 = 1 Then ' Ifall PortA.0 är hög.
goto test
End If
If PortA.1 = 1 Then
goto test1
else
goto loop
End If
goto loop
test:
PortB = %100000
delay_ms (100)
PortB = %110000
delay_ms (100)
PortB = %111000
delay_ms (100)
PortB = %011100
delay_ms (100)
PortB = %001110
delay_ms (100)
PortB = %000111
delay_ms (100)
PortB = %000011
delay_ms (100)
PortB = %000001
delay_ms (100)
PortB = %000011
delay_ms (100)
PortB = %000111
delay_ms (100)
PortB = %001110
delay_ms (100)
PortB = %011100
delay_ms (100)
PortB = %111000
delay_ms (100)
PortB = %110000
delay_ms (100)
PortB = %100000
delay_ms (100)
PortB = %000000
delay_ms (100)
goto loop
test1:
PortB = %001100
delay_ms (200)
PortB = %010010
delay_ms (200)
PortB = %100001
delay_ms (200)
PortB = %110011
delay_ms (200)
PortB = %111111
delay_ms (200)
PortB = %011110
delay_ms (200)
PortB = %001100
delay_ms (200)
PortB = %000000
goto loop
end.
cmcon = 7 ' Stäng av komparator
TrisA = 255 ' PortA är input
TrisB = 0 ' PortB är Output
loop:
If PortA.0 = 1 Then ' Ifall PortA.0 är hög.
goto test
End If
If PortA.1 = 1 Then
goto test1
else
goto loop
End If
goto loop
test:
PortB = %100000
delay_ms (100)
PortB = %110000
delay_ms (100)
PortB = %111000
delay_ms (100)
PortB = %011100
delay_ms (100)
PortB = %001110
delay_ms (100)
PortB = %000111
delay_ms (100)
PortB = %000011
delay_ms (100)
PortB = %000001
delay_ms (100)
PortB = %000011
delay_ms (100)
PortB = %000111
delay_ms (100)
PortB = %001110
delay_ms (100)
PortB = %011100
delay_ms (100)
PortB = %111000
delay_ms (100)
PortB = %110000
delay_ms (100)
PortB = %100000
delay_ms (100)
PortB = %000000
delay_ms (100)
goto loop
test1:
PortB = %001100
delay_ms (200)
PortB = %010010
delay_ms (200)
PortB = %100001
delay_ms (200)
PortB = %110011
delay_ms (200)
PortB = %111111
delay_ms (200)
PortB = %011110
delay_ms (200)
PortB = %001100
delay_ms (200)
PortB = %000000
goto loop
end.
-
- Inlägg: 700
- Blev medlem: 23 augusti 2003, 20:42:38