#include <reg51.h>
void uart_init(void);
void sendchar(unsigned char);
unsigned char receivechar(void);
void delay();
void sendstring(char*);
void main()
{
unsigned char ch;
char* str={"Type any character here.. "};
uart_init();
sendstring(str);
sendchar('\r');
sendstring("It will be incremented by one..");
sendchar('\r');
sendchar('\r');
while(1)
{
ch=receivechar();
sendchar(ch+1);
}
}
void uart_init(void)
{
TMOD=0x20;
TH1=0xFD;
SCON=0x50;
TR1=1;
}
void sendchar(unsigned char ch)
{
SBUF=ch;
while(TI==0);
TI=0;
}
unsigned char receivechar(void)
{
while(RI==0);
RI=0;
return(SBUF);
}
void delay()
{
int i,j;
for(i=0;i<100;i++)
for(j=0;j<1000;j++);
}
void sendstring(char* str)
{
int i;
for(i=0;str[i]!=0;i++)
sendchar(str[i]);
}
Comments
Post a Comment