 |
 |
View previous topic :: View next topic |
Author |
Message |
sonrie69
Joined: 05 May 2013 Posts: 3
|
sync to output array values |
Posted: Sun May 05, 2013 3:25 pm |
|
|
hi.
I am having some problems.
I have 8 arrays of 1s and 0s. I am trying to use output_d(); to output one at a time the array's values, in the way that is shown in the picture.
http://www.freeimagehosting.net/cqo2k
So far I have this code:
Code: |
int1 array0[16],array1[16],array2[16],array3[16],array4[16],array5[16],array6[16],array7[16];
output_bit(PIN_D0,array0[count]);
output_bit(PIN_D1,array1[count]);
output_bit(PIN_D2,array2[count]);
output_bit(PIN_D3,array3[count]);
output_bit(PIN_D4,array4[count]);
output_bit(PIN_D5,array5[count]);
output_bit(PIN_D6,array6[count]);
output_bit(PIN_D7,array7[count]);
|
But when i use the oscilloscope in Proteus i see that the output are shifted 260 us.
I am trying to find a function to convert the arrays values into a new variable to output them like a binary 0bXXXXXXXX.
I hope you can understand my little english.
thanks. |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun May 05, 2013 4:50 pm |
|
|
Change it to use arrays of int8, instead of int1. Then send the byte from
the array to the port. All the bits will appear on the PortD pins at the
same time, with no delay between bits.
Code: |
int8 array0[2];
output_d(array0[0]); // Output the first byte of array0 to PortD
|
|
|
 |
sonrie69
Joined: 05 May 2013 Posts: 3
|
|
Posted: Sun May 05, 2013 5:03 pm |
|
|
thanks for your answer.
if a use an int8 array, how i can change only one bit from that array,
int8 array0[2]={0b00000000,0b11111111}
how can i change to array0[1]=0b00000001 with that sentence.. because i change bit values with a matrix. |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
 |
sonrie69
Joined: 05 May 2013 Posts: 3
|
|
Posted: Mon May 06, 2013 1:02 pm |
|
|
I tried using union but the output of the port isn't right...
This is the code i am using now:
Code: |
#include "C:\Users\QxxxQ\Desktop\seq\programas pic\array2\main.h"
#include <stdio.h>
#BYTE TRISA = 0x85
#BYTE PORTA = 0x05
#BYTE TRISB = 0x86
#BYTE PORTB = 0x06
int8 i;
int8 read0,read1,read2,read3;
typedef union {
struct{
int8 b;
};
struct{
int1 bits[8];
};
}ports[4];
ports port;
void main()
{
bit_set(TRISA,0);
bit_set(TRISA,1);
bit_set(TRISA,2);
bit_set(TRISA,3);
bit_clear(TRISB,0);
bit_clear(TRISB,1);
bit_clear(TRISB,2);
bit_clear(TRISB,3);
port[0].bits[0]=1;
port[0].bits[1]=1;
port[0].bits[2]=1;
port[0].bits[3]=1;
port[0].bits[4]=1;
port[0].bits[5]=1;
port[0].bits[6]=1;
port[0].bits[7]=1;
port[1].bits[0]=1;
port[1].bits[1]=0;
port[1].bits[2]=0;
port[1].bits[3]=0;
port[1].bits[4]=0;
port[1].bits[5]=0;
port[1].bits[6]=0;
port[1].bits[7]=0;
port[2].bits[0]=1;
port[2].bits[1]=0;
port[2].bits[2]=0;
port[2].bits[3]=0;
port[2].bits[4]=0;
port[2].bits[5]=0;
port[2].bits[6]=0;
port[2].bits[7]=0;
port[3].bits[0]=0;
port[3].bits[1]=0;
port[3].bits[2]=0;
port[3].bits[3]=0;
port[3].bits[4]=0;
port[3].bits[5]=0;
port[3].bits[6]=0;
port[3].bits[7]=0;
read0=port[0].b;
read1=port[1].b;
read2=port[2].b;
read3=port[3].b;
while(1){
for(i=0;i<4;i++){
output_toggle(PIN_B4);
switch (i){
case 0:
output_d(read0);
break;
case 1:
output_d(read1);
break;
case 2:
output_d(read2);
break;
case 3:
output_d(read3);
break;
}
delay_ms(5);
}
}
} |
|
|
 |
|
|
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
|