Hello
Thanks for your interest. Sure, I will explain.
I made the h/w connection with Tx/Rx cross over with DB9 pins. I am trying to program through Keil C compiler. I dwnld the hex file of the following prgm into my chip but it doesn't give me any data back to hyperterminal
#include <reg51.h>
#include <stdio.h>
#define XTAL 11059200 // CPU Oscillator Frequency
#define baudrate 9600 // 9600 bps communication baudrate
#define OLEN 8 // size of serial transmission buffer
unsigned char ostart; // transmission buffer start index
unsigned char oend; // transmission buffer end index
char idata outbuf[OLEN]; // storage for transmission buffer
#define ILEN 8 // size of serial receiving buffer
unsigned char istart; // receiving buffer start index
unsigned char iend; // receiving buffer end index
char idata inbuf[ILEN]; // storage for receiving buffer
bit sendfull; // flag: marks transmit buffer full
bit sendactive; // flag: marks transmitter active
/*
* Serial Interrupt Service Routine
*/
static void com_isr (void) interrupt 4 using 1 {
char c;
/*----- Received data interrupt. ----------------------------------------*/
if (RI) {
c = SBUF; // read character
RI = 0; // clear interrupt request flag
if (istart + ILEN != iend) {
inbuf[iend++ & (ILEN-1)] = c; // but character into buffer
}
}
/*------ Transmitted data interrupt. ------------------------------------*/
if (TI != 0) {
TI = 0; // clear interrupt request flag
if (ostart != oend) { // if characters in buffer and
SBUF = outbuf[ostart++ & (OLEN-1)]; // transmit character
sendfull = 0; // clear 'sendfull' flag
}
else { // if all characters transmitted
sendactive = 0; // clear 'sendactive'
}
}
}
/*
* Function to initialize the serial port and the UART baudrate.
*/
void com_initialize (void) {
istart = 0; // empty transmit buffers
iend = 0;
ostart = 0; // empty transmit buffers
oend = 0;
sendactive = 0; // transmitter is not active
sendfull = 0; // clear 'sendfull' flag
// Configure timer 1 as a baud rate generator
PCON |= 0x80; // 0x80=SMOD: set serial baudrate doubler
TMOD |= 0x20; // put timer 1 into MODE 2
TH1 = (unsigned char) (256 - (XTAL / (16L * 12L * baudrate)));
TR1 = 1; // start timer 1
SCON = 0x50; // serial port MODE 1, enable serial receiver
ES = 1; // enable serial interrupts
}
/*
* putbuf: write a character to SBUF or transmission buffer
*/
void putbuf (char c) {
if (!sendfull) { // transmit only if buffer not full
if (!sendactive) { // if transmitter not active:
sendactive = 1; // transfer first character direct
TXD = 1;
WR = 1;
SBUF = c; // to SBUF to start transmission
}
else {
ES = 0; // disable serial interrupts during buffer update
outbuf[oend++ & (OLEN-1)] = c; // put char to transmission buffer
if (((oend ^ ostart) & (OLEN-1)) == 0) {
sendfull = 1;
} // set flag if buffer is full
ES = 1; // enable serial interrupts again
}
}
}
/*
* Replacement routine for the standard library putchar routine.
* The printf function uses putchar to output a character.
*/
char putchar (char c) {
if (c == '\n') { // expand new line character:
while (sendfull); // wait until there is space in buffer
putbuf (0x0D); // send CR before LF for <new line>
}
while (sendfull); // wait until there is space in buffer
putbuf (c); // place character into buffer
return (c);
}
/*
* Replacement routine for the standard library _getkey routine.
* The getchar and gets functions uses _getkey to read a character.
*/
char _getkey (void) {
char c;
RXD = 1;
RD = 1;
while (iend == istart) {
; // wait until there are characters
}
ES = 0; // disable serial interrupts during buffer update
c = inbuf[istart++ & (ILEN-1)];
ES = 1; // enable serial interrupts again
return (c);
}
/*
* Main C function that start the interrupt-driven serial I/O.
*/
void main (void) {
EA = 1; /* enable global interrupts */
com_initialize (); /* initialize interrupt driven serial I/O */
while (1) {
char c;
c = getchar ();
printf ("\nYou typed the character %c.\n", c);
}
------------------------------------------------------------------------
My chip doesn't have a ROm in it. Is it why it is not working or you can suggest me other solution of it?
BR
bloke203