Saturday, February 6, 2010

Electronics- MC based Serial Data Transfer to PC


Hi frnds,
Given below is the source code in C for the serial data transfer to PC using Micro-Controller (MC) using RS 232-C.

SOURCE CODE:

#include

/* special function register declarations */
/* for the intended 8051 derivative */

#include /* prototype declarations for I/O functions */
sbit MES1 = P2^0;
sbit MES2 = P2^1;
sbit MES3 = P2^2;
sbit MES4 = P2^3;
sbit MES5 = P2^4;
sbit MES6 = P2^5;
sbit MES7 = P2^6;
sbit MES8 = P2^7;
int i;
void time1ms();
void delay(int n);
/****************/
/* main program */
/****************/
void main (void) { /* execution starts here after stack init */
SCON = 0x52; /* SCON: mode 1, 8-bit UART, enable rcvr */
TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */
TH1 = 0xfd; /* TH1: reload value for 9600 baud@11.0592mhz */
TR1 = 1; /* TR1: timer 1 run */
TI = 1; /* TI: set TI to send first char of UART */


while (1) {
P2=0xFF;
if (MES1 == 0)
{
printf ("Welcome to EFY \n ");
printf ("Microcontroller Based Serial Data transfer To PC \n ");
printf ("by T.Shankar & S.Thangamani \n ");
printf ("Data transmission successful\n\n ");
delay(1000);
}
if (MES2 == 0)
{
printf ("T.Shankar & S.Thangamani\n ");
printf ("Old door N0. 8, Power House Road, Madurai\n ");
printf ("Contact.- 91-9443474124, 91-9944082936\n ");
printf ("shankartbe@yahoo.co.in, parvatyele@yahoo.co.in\n ");
printf ("Data transmission successful \n\n ");
delay(1000);
}
if (MES3 == 0)
{
printf ("Welcome to EFY \n ");
printf ("EFY Enterprises Pvt. Ltd.\n ");
printf ("D87/1, Phase-I\n ");
printf ("Okhla Industrial Area, New Delhi-110020\n ");
printf ("Data transmission successful \n\n ");
delay(1000);
}
if (MES4 == 0)
{
printf ("Tested By Sunil Kumar\n ");
printf ("Publised in EFY Magazine, Feb.-2010\n\n ");
delay(1000);
}
if (MES5 == 0)
{
printf ("Welcome to EFY \n ");
printf ("Message-5\n\n ");
delay(1000);
}
if (MES6 == 0)
{
printf ("Welcome to EFY \n ");
printf ("Message-6\n\n ");
delay(1000);
}
if (MES7 == 0)
{
printf ("Welcome to EFY \n ");
printf ("Message-7\n\n ");
delay(1000);
}
if (MES8 == 0)
{
printf ("Welcome to EFY \n ");
printf ("Message-8\n\n ");
delay(1000);
}
}
}

void time1ms() /* 1 ms delay */
{
int i;
for(i=0;i<50;i++); // the value shown in this line, 50 was calibrated for 1ms
// you may change it!
}

void delay(int n) /* do nothing n*1ms */
{
int i;
for(i=0;i time1ms();

}


NOTE: We can Change the messages printed in the "printf" statement and put our own messages. We need to connect serial cable to our PC and run Hyperterminal Software. Choose the COM port properties and then execute in the kit u can see the message! :)

SOURCE: ELECTRONICS FOR YOU Magazine FEB. 2010

No comments:

Post a Comment