Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

About RS232 communication between Hyperterminal and ADuC843

Status
Not open for further replies.

zmliu

Member level 5
Joined
Mar 21, 2004
Messages
89
Helped
8
Reputation
16
Reaction score
4
Trophy points
1,288
Activity points
620
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");
}

}
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top