Unfiortunately its about 5 pages long, but here is the full listing of void serialout(void) where I am having the problem.
Digitalout WR(p15);
.
.
.
/*************** Serial bus routine for control relays and digital I/O ***************/
/* this routine takes the 8 bit relay data and the 8 bit control data and joins them */
/* and writes 16 bits out on the serial bus */
void serialout(void) {
int unsigned serialdata=0;/* the 16 bits of serial data to go out to the analog board - first flush it so its clean */
int unsigned m=1; /* this is the bit position counter */
int shift_out_bit=0; /* this is the bit that will be sent out */
int SCOUNT=0; /* loop counter */
int control=0; /*control is temporary storage of the lower 8 bits of the serial bitstream */
/* put the hpmute, mute and recloop1 bits into the relay part of the output bitstream */
inputrelay=(inputrelay|hpmutebit|mutebit|recloop1bit); /* these are bits set in other routines */
//printf("1 %d %d\n\r",relay,inputrelay); /* just for debugging */
/* relay now has the input selection and the status of the mute and recloop1 relays */
/* next shift the relay data into the top 8 MSB's */
serialdata=(inputrelay<<8);
//printf("2 serialdata=%u\n\r",serialdata);
/* top 8 MSB's now have the relay data including mute, hpmute and recloop1 and the bottom 8 LSB's are filled with 0's */
/* now add the bottom 8 control bits below */
control=(control|bright|trigger|power|loopgain); /* last bit position is unused in the control word */
// printf("3 control=%d\n\r",control);
serialdata=(serialdata|control); /* join them - we now have all the data to send to the analog board */
RD=LOW; /* ASTROBE - it must be LOW on the analog board intitially */
WR=HIGH; /* DATA */
RS=HIGH; /* ACLK - so the clock line on the analog board is now LOW*/
SBUSON=HIGH; /* turn the SBUS on */
wait_ms(0.5);
do {
shift_out_bit = (serialdata&m); /* ADATA = the LSB (k=1) */
//printf("4 serialdata = %u\n\r",serialdata);
//printf("5 shiftoutbit = %u\n\r",shift_out_bit);
if (shift_out_bit==1) {
WR=HIGH;
} else if (shift_out_bit==0) {
WR=LOW;
}
//WR=shift_out_bit;
printf("wr = %d\n\r",WR);
wait_ms(1);
RS=LOW; /* clock goes high on main board - data latches */
wait_ms(1);
RS=HIGH; /* clock goes low */
SCOUNT=SCOUNT+1; /* increment the bit counter */
m=(m<<1); /* shift bit mask up one position towards the MSB */
} while (SCOUNT<16);
wait_ms(1);
RD=HIGH; /* Strobe the data into the A6821*/
wait_ms(1);
RD=LOW; /* Strobe now goes LOW again on the main board */
wait_ms(1);
SBUSON=LOW; /* remember to enable the outputs after intial set-up */
wait_ms(1);
}
I am trying to bit bang an output port linr this
Digitalout WR(p15) /* declare port here and cal l it 'WR' */
code . . . .
code. . . . .
do {
shift_out_bit = (serialdata&m); /* m is a bit position mask */
if (shift_out_bit==1) {
WR=HIGH; /* I am hoping to set the p15 HIGH with this statement */
} else if (shift_out_bit==0) {
WR=LOW; /* or set it LOW here */
}
printf("wr = %d\n\r",WR); /* instead, when I print it out here, I get 28456 instead of either 1 or 0 */
wait_ms(1);
RS=LOW; /* clock goes high on main board - data latches */
wait_ms(1);
RS=HIGH; /* clock goes low */
SCOUNT=SCOUNT+1; /* increment the bit counter */
m=(m<<1); /* shift bit mask up one position towards the MSB */
} while (SCOUNT<16);
and, nothing happens on p15 - it just initially spews out a tean of bits and after that never changes. My bit bang serial bus is stuck.