This code only has shiftout....the leds are on your shiftin receive side...right?
What you need to do is save your previous LED status. Currently every time you receive data from a button press it resets the other LED's so only 1 LED will be on.
This code only has shiftout....the leds are on your shiftin receive side...right?
What you need to do is save your previous LED status. Currently every time you receive data from a button press it resets the other LED's so only 1 LED will be on.
To have also two or three leds on at the same time you have to add more code (in red):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
Very likely you will need also a reset, in this case add the following code: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
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.
Al.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
Last edited by aratti; - 19th October 2009 at 09:30.
All progress began with an idea
Yes it works irreproachably
Thank you very much friend aratti
Thank you very much all friends for the answers
Glad to hear that! You are welcome.
Al.
All progress began with an idea
Hi,
I am inexperienced still in picbasic but I try
Reading her user guide, and studying examples of code
I noticed in this post the code from aratti, It is exactly what I need (thank you very much aratti)
I used him as a basis, and I made changes so that him I adapt in my work
Here I would want your help, so that I use also port C from the 16F876, so that I increase the inputs (push button) circuit in 16
Thank you in advance
regards
Here it is the code and the circuit, that works perfect
Code:DEFINE OSC 10 DEFINE SHIFT_PAUSEUS 100 TRISA = %00000000 TRISB = %11111111 TRISC = %00000000 ADCON1 = 7 '************************************ alarm var BYTE Flag var BYTE bleg var word B0 var word '************************************ Symbol data_pin=PORTA.0 Symbol clock=PORTA.1 Symbol strb=PORTA.2 Symbol oe=PORTA.3 '************************************ alarm=0 Flag = 0 B0 = 0 bleg= 900 portC = %00000000 '************************************ start: oe= 0:pause bleg B0 = PortB & %11111111 Alarm = (0 + B0) * 1 If Alarm <> Flag then gosub Print oe= 1:pause bleg goto start '************************************ Print: ShiftOut data_pin,clock,1,[alarm] strb = 1 : PAUSEUS 100 : STRB = 0 Flag = Alarm return end![]()
Hi Anatoli
I am not guru in picbasic I will try to help you, with those who I know
It tryed these changes
Code:DEFINE OSC 10 DEFINE SHIFT_PAUSEUS 100 TRISA = %00000000 TRISB = %11111111 TRISC = %11111111 alarm var word Flag var BYTE bleg var word B0 var word C0 var word '************************************ Symbol data_pin=PORTA.0 Symbol clock=PORTA.1 Symbol strb=PORTA.2 Symbol oe=PORTA.3 '************************************ alarm=0 Flag = 0 B0 = 0 C0 = 0 bleg= 500 portC = %00000000 ADCON1 = 7 '************************************ start: oe= 0:pause bleg B0 = PortB & %11111111 C0 = PortC & %11111111 Alarm = (0 + C0) * 1 & Alarm = (0 + B0) If Alarm <> Flag then gosub Print oe= 1:pause bleg goto start '************************************ Print: ShiftOut data_pin,clock,1,[alarm\8] strb = 1 : PAUSEUS 100 : STRB = 0 Flag = Alarm return end
Hi dovegroup
I thank you for your help, him I tryed
the second IC-4094 works rightly, but the first IC-4094 does not works any output
It looks like you're using Proteus and simulating the project. If so, and maybe not, you've assigned D9 to two chips which I'm assuming are the 4094. Change one or the other to something else and hook something up to the lower chip. Then see what you've got.
Bookmarks