But does not function the circuit,When I have in 3 inputs 0, (ΡΒ0=0,ΡΒ1=0,ΡΒ2=0)
Do not turn on 3 led but always only 1
To have also two or three leds on at the same time you have to add more code (in red):
Code:
INCLUDE "modedefs.bas"
DEFINE SHIFT_PAUSEUS 100
TRISB = %00000111
alarm var BYTE
Flag var BYTE
'****************************************************************
symbol clock=portc.4
symbol data_pin=portc.2
symbol strb=PORTc.3
'****************************************************************
alarm=0
Flag = 0
start:
Pause 10
IF PORTB.0=0 THEN
alarm=%10000000
Flag=1
ENDIF
IF PORTB.1=0 THEN
alarm=%01000000
Flag = 1
ENDIF
IF PORTB.2=0 THEN
alarm=%00100000
Flag = 1
ENDIF
IF PORTB.0=0 and PORTB.1 =0 THEN
alarm=%11000000
Flag=1
ENDIF
IF PORTB.1=0 and PORTB.2 =0 THEN
alarm=%01100000
Flag=1
ENDIF
IF PORTB.0=0 and PORTB.2 =0 THEN
alarm=%10100000
Flag=1
ENDIF
IF PORTB.0=0 and PORTB.1 =0 AND PORTB.2 = 0 THEN
alarm=%11100000
Flag=1
ENDIF
If Flag = 1 Then gosub print
goto start
print:
ShiftOut data_pin,clock,0,[alarm]
strb = 1 : PAUSEUS 100 : STRB = 0
Flag = 0
return
end
Very likely you will need also a reset, in this case add the following code:
Code:
IF PORTB.0=1 and PORTB.1 =1 AND PORTB.2 = 1 and alarm>0 THEN
alarm=%00000000
Flag=1
ENDIF
You can also try the following code which is a lot shorter and should work as well.
Code:
INCLUDE "modedefs.bas"
DEFINE SHIFT_PAUSEUS 100
TRISB = %00000111
Alarm var BYTE
Flag var BYTE
B0 var Byte
'****************************************************************
symbol clock=portc.4
symbol data_pin=portc.2
symbol strb=PORTc.3
'****************************************************************
alarm = 0
Flag = 0
B0 = 0
start:
Pause 10
B0 = PortB & %00000111
Alarm = (7 - B0) * 32
If Alarm <> Flag then gosub Print
goto start
Print:
ShiftOut data_pin,clock,0,[alarm]
strb = 1 : PAUSEUS 100 : STRB = 0
Flag = Alarm
return
end
Al.
Bookmarks