PDA

View Full Version : Using 4 input to control 10 output



cibotsan
- 3rd November 2004, 04:07
Dear all.

first off all i would like to apologise my bad english.
Iam been working a robot project control via serial com PC using 4 channel RF( thanks to melaine that give source code on this forum). Transmitter section, iam using PIC 16F626 and to control 4 (led) output RA.0 to RA.3 that i connected to Transmitter module (4 ch).
On Reciever section, Reciever module is connected to PIC16F877 RB.0 to RB.3.
10 Output(led) is connected to RA.0 to RC.2
The problem is how to control the 10 LED individually using only 4 input?
i hope that this imformation can inderstand my project situation
regards

cibotsan

mister_e
- 3rd November 2004, 05:43
The result will be based on this table



state of inputs state of outputs
============== ================
0000 0000000001
0001 0000000010
0010 0000000100
0011 0000001000
0100 0000010000
0101 0000100000
etc

simple code here...

ADCON1=7 ;disable ADC


TRISB=$FF
TRISA=0
TRISC=0


InputBCD VAR PORTB
Out1_8 VAR PORTA ;first 5 LEDs
Out9_10 VAR PORTC ;last 5 LEDs
GetInput VAR BYTE
BCDToDEC VAR BYTE

Out1_5=0
Out6_10=0

start:
Getinput=InputBCD

Select case Getinput
Case is<=5
Out6_10=0
BCDToDEC=dcd Getinput
Out1_5= BCDToDEC
Case is>=6
Out1_5=0
BCDToDEC=dcd (GetInput-6)
Out6_10= BCDToDEC
End Select
goto start


it's suppose to work. Try and post reply on this. There's several different way to do this

cibotsan
- 4th November 2004, 15:07
Thanks steve .
any how i try it but ist wont work.for you imformation.when i run it all output is on all while input = 0.When i set any input = 1 , the only ouput Rc0 =0 below is my code .

ADCON1=7 ;disable ADC


TRISB=$FF
TRISA=0
TRISC=0


InputBCD VAR PORTB
Out1_5 VAR PORTA.0 ;first 5 LEDs
Out2_5 VAR PORTA.1 ;first 5 LEDs
Out3_5 VAR PORTA.2 ;first 5 LEDs
Out4_5 VAR PORTA.3 ;first 5 LEDs
Out5_5 VAR PORTA.4 ;first 5 LEDs
Out6_10 VAR PORTC.0 ;last 5 LEDs
Out7_10 VAR PORTC.1 ;last 5 LEDs
Out8_10 VAR PORTC.2 ;last 5 LEDs
Out9_10 VAR PORTC.3 ;last 5 LEDs
Out10_10 VAR PORTC.4 ;last 5 LEDs

GetInput VAR BYTE
BCDToDEC VAR BYTE

Out1_5=0
Out6_10=0

start:
Getinput=InputBCD

Select case Getinput
Case is<=5
Out6_10=0
BCDToDEC=dcd Getinput
Out1_5= BCDToDEC
Case is>=6
Out1_5=0
BCDToDEC=dcd (GetInput-6)
Out6_10= BCDToDEC
End Select
goto start

mister_e
- 4th November 2004, 15:48
"Thanks steve .
any how i try it but ist wont work.for you imformation.when i run it all output is on all while input = 0.When i set any input = 1 , the only ouput Rc0 =0 below is my code ."


can you provide the output table from transmitter you have and receiver you want?

maybe

transmitter:
1111 = receiver out1
1110 = receiver out2
1101 = receiver out3
1100 = receiver out4
1011 = receiver out5
.....

let us know

cibotsan
- 4th November 2004, 16:16
thanks again steve
okey whats i need is like this

state of inputs state of outputs
============== ================
0000 all output =0
0001 out1 =1 out3=1
0010 out2 = 1 out 4 =1
0100 out1=1 out4=1
1000 out2=1 out3=1
0011 out5=1
0110 out6=1
1100 out7=1
0111 out8=1
1110 out9=1
1111 out10=1

its is possible to change from out put to a label? because i will use to control a different output devices for example RC servo, DC motor ,relay etc?

mister_e
- 4th November 2004, 16:40
"its is possible to change from out put to a label? because i will use to control a different output devices for example RC servo, DC motor ,relay etc?"

sure....



ADCON1=7 ;disable ADC


TRISB=$FF
TRISA=0
TRISC=0


Out1 VAR PORTA.0
Out2 VAR PORTA.1
Out3 VAR PORTA.2
Out4 VAR PORTA.3
Out5 VAR PORTA.4
Out6 VAR PORTC.0
Out7 VAR PORTC.1
Out8 VAR PORTC.2
Out9 VAR PORTC.3
Out10 VAR PORTC.4
Rinput VAR PORTB

GetInput VAR BYTE
Gosub ResetOutputPort
start:

GetInput=Rinput & $0F ;will mask the MSB bits of PORTB

select case Getinput
Case 0
Gosub ResetOutputPort
Case 1
Out1=1
Out3=1
Case 2
Out2=1
Out4=1
Case 3
Out5=1
Case 4
Out1=1
Out4=1
Case 6
Out6=1
Case 7
Out8=1
Case 8
Out2=1
Out3=1
Case 12
Out7=1
Case 14
Out9=1
Case 15
Out10=1
End Select
goto start


ResetOutputPort:
PORTA=0
PORTC=0
return



now it's really suppose to match with your specific need.

NEXT!!!

cibotsan
- 5th November 2004, 03:23
Yes!!! its working, thanks again steve you safe my robot life.can i buy you a drink?If i have further problem i will online again.

mister_e
- 5th November 2004, 12:08
hi cibotsan,
Great to know that everything work for you !!!

>can i buy you a drink?

hehe nothing exepensive.... 50 year age PORTO will do the job :)

best regards