我用bcb寫一個rs232的發送端,每次丟出以"#"開頭的字串,可是reChar本應收到35值,但卻都收到00的值,實在想不出來錯在哪,請各位高手不吝指教.. #include "nios.h"
#include
#include
#include "excalibur.h"
#define SUCCESS 1
#define FAILURE 0 int ind = 0;
int i=0;
char command[4];
int stage = 0;
int total_comm = 0; typedef struct{
np_uart *uart;
char rxChar;
}UARTISRContext; UARTISRContext gC = {0, -1}; void emptyArray()
{
int i;
for(i=0; i<4; i )
command[i] = 0;
}
//***************************************************
int rGetChar(void)
{
int result;
if(gC.rxChar >= 0)
{
result = gC.rxChar;
gC.rxChar = -1;
}
else
result = nr_uart_rxchar(0);
return result;
}
void InterruptServiceRoutine(int context)
{
UARTISRContext *c = (UARTISRContext *)context;
int status;
int rxChar;
status = c->uart->np_uartstatus;
rxChar = c->uart->np_uartrxdata;
c->uart->np_uartstatus = 0; // clear the interrupt condition
if(status & np_uartstatus_rrdy_mask )
{
if(stage == 0)
{
nr_pio_showhex(rxChar);
nr_delay(800);
if(rxChar == 35)
{
nr_pio_showhex(169);
nr_delay(800);
stage = 1;
command[ind] = (char)rxChar;
ind =1;
}
}
else if(stage ==1)
{
command[ind] = (char)rxChar;
ind =1;
nr_pio_showhex(164);
nr_delay(800);
if(rxChar == 64)
{
nr_pio_showhex(169);
nr_delay(800);
total_comm = ind;
ind = 0; if((command[0] == 35) && (command[total_comm-1] == 64))
{
nr_delay(800);
nr_pio_showhex(160);
}
stage = 0;
}
}
}
c->rxChar = rxChar;
} void EnableUartInterrupt(void)
{
gC.uart = (np_uart *)na_uart_0;
nr_installuserisr(na_uart_0_irq,InterruptServiceRoutine,(long)&gC);
{
np_uart *uart = na_uart_0;
uart->np_uartcontrol = np_uartcontrol_irrdy_mask;
}
} int main(void)
{
int s;
EnableUartInterrupt();
emptyArray();
while((s = rGetChar()) != 27)
{
}
return 0;
}