zmliu
Member level 5
wsd v6.7
Hi,Guys,
I have trouble in debugging some kind of simple code for RS232 comm between Hyperterminal on PC and ADuC843 MCU.THe code is listed as below.I am using Keil uVision2 software to compile it and load HEX with WSD V6.7. The problem is:
send() function only works once, main() function can not continue next cycle.Please give some comments and suggestions on this code.Thanks a lot.
//-----------------------------------------------//
// Check RS232 interface to PC via Hyperterminal //
//-----------------------------------------------//
#include <ADuC843.h>
#include <stdio.h>
#define buf_size 10 // data bytes
unsigned char idata buf[buf_size]={ 'A','D','u','C', '8', '4', '3',' '};
sbit P2_4=P2^4;
void init(void)
{
PLLCON = 0x03; // core frequency at 2.09MHz
T3CON = 0x83;
T3FD = 0x2D; // configure UART for 9600 baud rate
SCON = 0x52;
P2_4=1; // buzzer off
}
void receive(unsigned char *d)
{
int k;
for(k=0;k<buf_size;k++)
{
while(RI==0);RI=0;
d[k]=SBUF;
}
printf(" \nOK\n ");
}
void send(unsigned char *d)
{
int i;
for(i=0;i<buf_size;i++){
SBUF=d;
while(TI==0);TI=0;
}
// printf(" \nOK\n ");
SBUF=0x21; // send "!" character
while(TI==0);TI=0;
}
void main(void)
{
int a;
init();
while(1)
{
printf("\nEnter 1 letter command W/R?\n");
while(RI==0);RI=0;
a=SBUF;
if(a=='W'){
printf(" \nOK\n ");
receive(buf);
}
else if(a=='R'){
printf(" \nOK\n ");
send(buf);
}
else{
printf("\nWrong command,please retry!\n");
}
}
}
Hi,Guys,
I have trouble in debugging some kind of simple code for RS232 comm between Hyperterminal on PC and ADuC843 MCU.THe code is listed as below.I am using Keil uVision2 software to compile it and load HEX with WSD V6.7. The problem is:
send() function only works once, main() function can not continue next cycle.Please give some comments and suggestions on this code.Thanks a lot.
//-----------------------------------------------//
// Check RS232 interface to PC via Hyperterminal //
//-----------------------------------------------//
#include <ADuC843.h>
#include <stdio.h>
#define buf_size 10 // data bytes
unsigned char idata buf[buf_size]={ 'A','D','u','C', '8', '4', '3',' '};
sbit P2_4=P2^4;
void init(void)
{
PLLCON = 0x03; // core frequency at 2.09MHz
T3CON = 0x83;
T3FD = 0x2D; // configure UART for 9600 baud rate
SCON = 0x52;
P2_4=1; // buzzer off
}
void receive(unsigned char *d)
{
int k;
for(k=0;k<buf_size;k++)
{
while(RI==0);RI=0;
d[k]=SBUF;
}
printf(" \nOK\n ");
}
void send(unsigned char *d)
{
int i;
for(i=0;i<buf_size;i++){
SBUF=d;
while(TI==0);TI=0;
}
// printf(" \nOK\n ");
SBUF=0x21; // send "!" character
while(TI==0);TI=0;
}
void main(void)
{
int a;
init();
while(1)
{
printf("\nEnter 1 letter command W/R?\n");
while(RI==0);RI=0;
a=SBUF;
if(a=='W'){
printf(" \nOK\n ");
receive(buf);
}
else if(a=='R'){
printf(" \nOK\n ");
send(buf);
}
else{
printf("\nWrong command,please retry!\n");
}
}
}