|
|
View previous topic :: View next topic |
Author |
Message |
doguhanpala
Joined: 05 Oct 2016 Posts: 120
|
output_a() pin select |
Posted: Wed Nov 23, 2016 6:51 am |
|
|
Hello everyone,
I try to make a 5x5 led matrix and make some figures with it like letters, smiley faces etc. I use 18f2550.
I can do it with output_a() command like this.
Code: | int number=0b00001001;
output_a(number); |
But i don't want to use all the pins at the A port because i will use some of the pins for other purposes like pwm.
So i tried this
Code: | int number=0b001001;
output_a(number); |
to leave pin7 and pin8 alone. I think it worked. I measured the voltage and it was about 1.5v.
In my code i tried to create a pwm signal, from pin 12 and 13. I looked at the signal with oscilloscope and saw the pwm is generated succesfully.
My question is, is there a way to leave a specific pin alone in output_a() command ? For example i need 14 pin. But i want to use the pin 12 and 13 for pwm, and use the 2 pins i need from b port. So is there way to leave them out of the command output_a() ? Like selecting pins which i can use?
Can i say to the pic, hey i need port a but don't touch pin7 ?
Sorry for bad english and thanks for the help. |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1354
|
|
Posted: Wed Nov 23, 2016 7:49 am |
|
|
Your method will not leave pin 7 and 8 alone. It will put 0's in them.
You can do:
Code: |
if(bit_test(number,5)){output_high(PIN_A5);}else{output_low(PIN_A5);}
if(bit_test(number,4)){output_high(PIN_A5);}else{output_low(PIN_A4);}
if(bit_test(number,3)){output_high(PIN_A5);}else{output_low(PIN_A3);}
if(bit_test(number,2)){output_high(PIN_A5);}else{output_low(PIN_A2);}
if(bit_test(number,1)){output_high(PIN_A5);}else{output_low(PIN_A1);}
if(bit_test(number,0)){output_high(PIN_A5);}else{output_low(PIN_A0);}
|
I don't have the compiler up to compile check that, but hopefully the idea is clear.
EDIT:
or probably better
Code: |
output_bit(PIN_A5,bit_test(number,5));
output_bit(PIN_A4,bit_test(number,4));
output_bit(PIN_A3,bit_test(number,3));
output_bit(PIN_A2,bit_test(number,2));
output_bit(PIN_A1,bit_test(number,1));
output_bit(PIN_A0,bit_test(number,0));
|
|
|
|
doguhanpala
Joined: 05 Oct 2016 Posts: 120
|
|
Posted: Thu Nov 24, 2016 4:08 am |
|
|
jeremiah wrote: | Your method will not leave pin 7 and 8 alone. It will put 0's in them.
You can do:
Code: |
if(bit_test(number,5)){output_high(PIN_A5);}else{output_low(PIN_A5);}
if(bit_test(number,4)){output_high(PIN_A5);}else{output_low(PIN_A4);}
if(bit_test(number,3)){output_high(PIN_A5);}else{output_low(PIN_A3);}
if(bit_test(number,2)){output_high(PIN_A5);}else{output_low(PIN_A2);}
if(bit_test(number,1)){output_high(PIN_A5);}else{output_low(PIN_A1);}
if(bit_test(number,0)){output_high(PIN_A5);}else{output_low(PIN_A0);}
|
I don't have the compiler up to compile check that, but hopefully the idea is clear.
EDIT:
or probably better
Code: |
output_bit(PIN_A5,bit_test(number,5));
output_bit(PIN_A4,bit_test(number,4));
output_bit(PIN_A3,bit_test(number,3));
output_bit(PIN_A2,bit_test(number,2));
output_bit(PIN_A1,bit_test(number,1));
output_bit(PIN_A0,bit_test(number,0));
|
|
Thank you for the warning! I tried to output_high() on pin7 and saw that it becomes zero after the output_a() command. When i saw pwm on pin 13 i thought it leaves them alone. It doesn't, as you said to me.
I understood your method and logic. I will try to use output_high() and manage each led with this command. Thank you again!
Best Wishes
Doğuhan |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Thu Nov 24, 2016 5:19 am |
|
|
If you set the port for 'fast_io', then you can cheat and use the byte wide I/O.
Code: |
//in the setup at the top of the code
#use fast_io(A)
//Now PORTA TRIS is under _[u]your[/u]_ control completely.
//assuming all the bits are used as outputs.
set_tris_a(0b00000000); //all eight pins output
//Then for the bit wide I/O
output_high(PIN_A7);
output_high(PIN_A6);
//to put a byte out on the low 6 bits only:
output_a((input_a() & 0xC0) | (number & 0x3F));
|
With fast_io selected this will work even if one or two of the top two bits are inputs (with the TRIS set suitably).
It reads the value currently in the port register, takes the top 2 bits of this, and then combines this with the bottom 6 bits from 'number' and writes this back. |
|
|
doguhanpala
Joined: 05 Oct 2016 Posts: 120
|
|
Posted: Thu Nov 24, 2016 5:58 am |
|
|
Thank you so much Ttelmah,
I will go with the first solution for now (because i want to be able use port a and port b at the same time) but i really liked cheating logic. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|