This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Prob in getchar

i am using the nrf24E1 board, i transmit the data through serial port and display on PC through hyperterminal, now i want that i have to give some data to the board through serial port and watch the display on PC so please check my code and inform how can send data to board from PC.

#include <Nordic\reg24e1.h>
#include <stdio.h>

static volatile unsigned char idata rxbuf[32]; // Uart recieve buffer
static volatile unsigned char rxrp; // Uart receive buffer read pointer
static volatile unsigned char rxwp; // Uart receive buffer write pointer
static volatile unsigned char rxn; // Number of characters left in receive buffer
static volatile unsigned char idata txbuf[32]; // Uart transmit buffer
static volatile unsigned char txrp; // Uart transmit buffer read pointer
static volatile unsigned char txwp; // Uart transmit buffer write pointer
static volatile unsigned char txn; // Number of characters left to send

void DELAY_LOOP_Wait(const unsigned int );
const char hex_tab [] ="0123456789ABCDEF";
void Init(void)
{
TH1 = 243; // 19200@16MHz (when T1M=1 and SMOD=1)
CKCON |= 0x10; // T1M=1 (/4 timer clock)
PCON = 0x80; // SMOD=1 (double baud rate)
SCON = 0x50; // Serial mode1, enable receiver
TMOD = 0x20; // Timer1 8bit auto reload
TR1 = 1; // Start timer1
P0_DIR |= 0x02; // P0.1 (RxD) is an input
P0_ALT |= 0x06; // Select alternate functions on pins P0.1 and P0.2

EA =1;
}
void Serial (void) interrupt 4 using 2
{
if (RI)
{
RI = 0; // Clear receive interrupt bit
rxbuf[rxwp] = SBUF; // Store received character in receive buffer
rxwp = (rxwp + 1) & 0x1f; // Advance write pointer
rxn++; // Increment number of characters in buffer
}
if (TI)
{
TI = 0; // Clear transmit interrupt bit
txn--; // Decrement number of characters to send
if (txn > 0) // More characters in transmit buffer?
{
SBUF = txbuf[txrp]; // Yes, store next character in uart buffer
txrp = (txrp + 1) & 0x1f; // Advance read pointer
}
}
}

void PutChar(char c)
{
while(txn > 31) // Wait while transmit buffer is full
;
if (txn == 0) // If all previous characters are sent...
{
SBUF = c; // ...write character directly to the uart...
txn = 1;
} else
{
txbuf[txwp] = c; // ...else write it to the transmit buffer
txwp = (txwp + 1) & 0x1f; // Advance write pointer
ES = 0; // Disable serial interrupt while...
txn++; // ...incrementinfg numnber of characters to send
ES = 1; // Enable serial interrupt
}
}

unsigned char GetChar(void)
{
char _getkey();
unsigned char c;

//PutChar ('a');

while(rxn == 0) // Wait until there is at least one character in the buffer
;
c = rxbuf[rxrp]; // Read next character from buffer
rxrp = (rxrp + 1) & 0x1f; // Advance buffer read pointer
ES = 0; // Disable serial interrupt while...
rxn--; // ...decrementing number of characters in buffer
ES = 1; // Enable serial interrupt
return c;
}


/*void PutChar(char c)
{
while(!TI)
;
TI = 0;
SBUF = c;
}*/

void PutString(const char *s)
{
while(*s != 0)
PutChar(*s++);
}




/*void DELAY_LOOP_Wait(const unsigned int DELAY)
{
unsigned int x, y;
for (x=0; x<=DELAY; x++)
{
for (y=0; y<= 12; y++);
}
}*/

int main(void)
{
Init();
{
while(1){
//DELAY_LOOP_Wait(10);
switch (GetChar()){
case 'a':

PutString("MY Own Board !\n");
break;}
}
}
for(;;)
;
return 0;

// ;
}

0