read in from serial port; getchar()
Hey,
I am going to apologise straight up and say im kinda new to c programming and this forum so excuse me if I miss something out.
At this stage, I am using an FPGA board to print a message to the hyperterminal using an embedded project on a microcontroller. Now what I am trying to do is read in the characters that I type in the hyperterminal and once I hit enter, they appear back on the hyperterminal screen right under where i printed below.
My guess is a have to use the getchar() approach! im just unsure how to execute it into this programm and put it in an array and pass it back to the WriteChar function I have.
For example; i type
"hello" and it print
hello under it.
this is the code I have so far with regards to sending message to hyperterminal.
Code:
void WriteChar(unsigned char Character);
void InitSerial(void);
void WriteString(char *Str);
void delay(void);
void main (void) {
char String[]="\r\nPlease Print a Character to be returned back to you...\r\n";
InitSerial();
unsigned char j;
for(j=0; j < 1; j++)
WriteString(String);
void InitSerial(void){
SLR0_PCON=0x80;
SLR0_SCON=0x40;
SLR0_SRELL=0x5d;
SLR0_SRELH=0x03;
SLR0_ADCON=0x80;
}
void WriteChar(unsigned char Character){
unsigned char variable = 0;
SLR0_SBUF = Character;
while (variable != 0x02) {
variable = SLR0_SCON & 0x02;
delay();
}
SLR0_SCON = 0x40;
}
void WriteString(char *Str){
unsigned char i;
for(i=0; Str[i]!='\0'; i++)
WriteChar(Str[i]);
}
// Delay
void delay(void){
int i;
for (i=0; i<0xFFFF; i++) __asm("nop");
}
I hope this makes sense and thanks again in advance, if you need more info, more than happy to provide.