PDA

View Full Version : 16F877 and 4094 please help



dovegroup
- 17th October 2009, 11:29
Hello friends
I have manufactured this circuit with 16F877
3 switches of entry that them portray the situation of entry in the 4094
This code work good .my problem is always sees the last entry
that I can see the all entries simultaneously be portrayed in the 4094






INCLUDE "modedefs.bas"
DEFINE SHIFT_PAUSEUS 100



TRISB = %00000111

alarm var word
'************************************************* ***************
symbol clock=portc.4
symbol data_pin=portc.2
symbol strb=PORTc.3
'************************************************* ***************
alarm=0

start:

IF PORTB.0=0 THEN
alarm=%10000000
ENDIF
IF PORTB.1=0 THEN
alarm=01000000
ENDIF
IF PORTB.2=0 THEN
alarm=%00100000
ENDIF
gosub print
goto start

print:

ShiftOut data_pin,clock,0,[alarm]
strb = 1 : PAUSEUS 100 : STRB = 0
return

end

mehmetOzdemir
- 17th October 2009, 14:04
i didnt understand what you mean ;

i think this will help you if i understood right.




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:

IF PORTB.0=0 THEN
alarm=%10000000
flag.0 = 1
ELSE
flag.0 = 0
ENDIF

IF PORTB.1=0 THEN
alarm=01000000
flag.1 = 1
ELSE
flag.1 = 0
ENDIF

IF PORTB.2=0 THEN
alarm=%00100000
flag.2 = 1
ELSE
flag.2 = 0
ENDIF

IF flag = 0 THEN alarm = 0



gosub print
goto start

print:

ShiftOut data_pin,clock,0,[alarm]
strb = 1 : PAUSEUS 100 : STRB = 0
return

end

Jerson
- 17th October 2009, 14:05
INCLUDE "modedefs.bas"
DEFINE SHIFT_PAUSEUS 100



TRISB = %00000111

alarm var byte
'************************************************* ***************
symbol clock=portc.4
symbol data_pin=portc.2
symbol strb=PORTc.3
'************************************************* ***************
alarm=0

start:

IF PORTB.0=0 THEN
alarm = alarm + $80 ' add the bit
ELSE
alarm = alarm & $7F ' remove the bit
ENDIF

IF PORTB.1=0 THEN
alarm=alarm + $40
ELSE
alarm = alarm & $BF ' remove the bit
ENDIF

IF PORTB.2=0 THEN
alarm=alarm+$20
ELSE
alarm = alarm & $DF ' remove the bit
ENDIF
gosub print
goto start

print:

ShiftOut data_pin,clock,0,[alarm]
strb = 1 : PAUSEUS 100 : STRB = 0
return

end

dovegroup
- 18th October 2009, 07:01
Sorry for my English is not good
I want he permanently remains turned on corresponding led (TOGGLE led)
For each button that is activated

aratti
- 18th October 2009, 08:11
This will leave your last action ON.



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 Flag = 1 Then gosub print
goto start

print:

ShiftOut data_pin,clock,0,[alarm]
strb = 1 : PAUSEUS 100 : STRB = 0
Flag = 0
return

end


Al.

dovegroup
- 18th October 2009, 21:19
Thank you very much for the answers
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

Macgman2000
- 18th October 2009, 23:09
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.

aratti
- 19th October 2009, 07:37
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):




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:


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.


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.

dovegroup
- 19th October 2009, 16:45
Yes it works irreproachably
Thank you very much friend aratti
Thank you very much all friends for the answers

aratti
- 19th October 2009, 17:16
Glad to hear that! You are welcome.

Al.

Anatoli
- 19th May 2014, 11:03
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

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

7346

dovegroup
- 20th May 2014, 10:55
Hi Anatoli

I am not guru in picbasic I will try to help you, with those who I know
It tryed these changes


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

Anatoli
- 20th May 2014, 13:00
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

AvionicsMaster1
- 20th May 2014, 13:34
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.

Anatoli
- 20th May 2014, 15:10
Friends Dovegroup and AvionicsMaster1

Connecting a logic analyzer in line CLOCK and DATA
I discovered that the DATA that are directed to the IC-4094 are only 8bit, would not be supposed were 16bit
8bit for the first IC and 8bit for the second IC

See the snapshot from the analyzer

7347

dovegroup
- 20th May 2014, 15:42
Very rightly Aнатолий
8bit for the first 4094 and 8bit for the second 4094
I do not know to answer you how it will become this, I suppose that thus

ShiftOut data_pin,clock,1,[alarm_1,alarm_2]

Anatoli
- 20th May 2014, 15:58
I will try with this
Thank you .Я благодарю товарища

Anatoli
- 20th May 2014, 18:00
Товарища dovegroup

Even if you are not guru in the picbasic as you report in initial your post
Your help was very big, so that I complete my work

See the changes that I made

Alarma = (0 + C0) * 1
Alarme = (0 + B0) * 1

ShiftOut data_pin,clock,1,[Alarma,Alarme]

Thank you very much
Aнатолий (Anatoli)


7348

dovegroup
- 21st May 2014, 13:22
Anatoli good the knowledge guru my friend, but when doesn't exist appetite in order to you help ?
I am cheerful that I even helped little So that you will complete your work

привет товарищ Анатолий
алексей или иным dovegroup