C51单片机从串口接收数据多个字节的数据的C语言程序,谢谢
3个回答
展开全部
#include<reg52.h>
unsigned char code table[] ={" "};
unsigned char code table1[]={" : "};
sbit rs=P1^2;
sbit lcden=P1^0;
unsigned char flag,m;
void delay(int xms)
{
int i,j;
for(i=xms;i>0;i--) //i=xms即延时约xms毫秒
for(j=110;j>0;j--);
}
void write_com(unsigned char com)
{//写液晶命令函数
rs=0;
lcden=0;
P2=com;
delay(3);
lcden=1;
delay(3);
lcden=0;
}
void write_date(unsigned char date)
{//写液晶数据函数
rs=1;
lcden=0;
P2=date;
delay(3);
lcden=1;
delay(3);
lcden=0;
}
void init()
{//初始化函数
unsigned char num;
lcden=0;
rs=0;
write_com(0x38);//1602液晶初始化
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(num=0;num<15;num++)//写入液晶固定部分显示
{
write_date(table[num]);
delay(3);
}
write_com(0x80+0x40);
for(num=0;num<5;num++)
{
write_date(table1[num]);
delay(3);
}
}
void write_dianya(unsigned char add,unsigned char date)
{//1602液晶刷新时分秒函数4为时,7为分,10为秒
unsigned char bai,shi,ge;
bai=date/100;
shi=date%100/10;
ge=date%10;
write_com(0x80+0x40+add);
write_date(0x30+bai);
write_date(0x30+shi);
write_date(0x30+ge);
}
void main ()
{
init();
TMOD=0x20; //设置定时器1工作方式2
TH1=0xfd;
TL1=0xfd;
TR1=1;
REN=1; //设置串行口工作方式
SM0=0;
SM1=1;
EA=1; //中断设置
ES=1;
while(1)
{
if(flag==1)
{
ES=0;
SBUF=m;
while(!TI);
TI=0;
ES=1;
}
}
}
void ser() interrupt 4
{
RI=0;
m=SBUF;
write_dianya(5,m);
flag=1;
}
unsigned char code table[] ={" "};
unsigned char code table1[]={" : "};
sbit rs=P1^2;
sbit lcden=P1^0;
unsigned char flag,m;
void delay(int xms)
{
int i,j;
for(i=xms;i>0;i--) //i=xms即延时约xms毫秒
for(j=110;j>0;j--);
}
void write_com(unsigned char com)
{//写液晶命令函数
rs=0;
lcden=0;
P2=com;
delay(3);
lcden=1;
delay(3);
lcden=0;
}
void write_date(unsigned char date)
{//写液晶数据函数
rs=1;
lcden=0;
P2=date;
delay(3);
lcden=1;
delay(3);
lcden=0;
}
void init()
{//初始化函数
unsigned char num;
lcden=0;
rs=0;
write_com(0x38);//1602液晶初始化
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(num=0;num<15;num++)//写入液晶固定部分显示
{
write_date(table[num]);
delay(3);
}
write_com(0x80+0x40);
for(num=0;num<5;num++)
{
write_date(table1[num]);
delay(3);
}
}
void write_dianya(unsigned char add,unsigned char date)
{//1602液晶刷新时分秒函数4为时,7为分,10为秒
unsigned char bai,shi,ge;
bai=date/100;
shi=date%100/10;
ge=date%10;
write_com(0x80+0x40+add);
write_date(0x30+bai);
write_date(0x30+shi);
write_date(0x30+ge);
}
void main ()
{
init();
TMOD=0x20; //设置定时器1工作方式2
TH1=0xfd;
TL1=0xfd;
TR1=1;
REN=1; //设置串行口工作方式
SM0=0;
SM1=1;
EA=1; //中断设置
ES=1;
while(1)
{
if(flag==1)
{
ES=0;
SBUF=m;
while(!TI);
TI=0;
ES=1;
}
}
}
void ser() interrupt 4
{
RI=0;
m=SBUF;
write_dianya(5,m);
flag=1;
}
展开全部
#include<reg52.h>
unsigned
char
code
table[]
={"
"};
unsigned
char
code
table1[]={"
:
"};
sbit
rs=P1^2;
sbit
lcden=P1^0;
unsigned
char
flag,m;
void
delay(int
xms)
{
int
i,j;
for(i=xms;i>0;i--)
//i=xms即延时约xms毫秒
for(j=110;j>0;j--);
}
void
write_com(unsigned
char
com)
{//写液晶命令函数
rs=0;
lcden=0;
P2=com;
delay(3);
lcden=1;
delay(3);
lcden=0;
}
void
write_date(unsigned
char
date)
{//写液晶数据函数
rs=1;
lcden=0;
P2=date;
delay(3);
lcden=1;
delay(3);
lcden=0;
}
void
init()
{//初始化函数
unsigned
char
num;
lcden=0;
rs=0;
write_com(0x38);//1602液晶初始化
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(num=0;num<15;num++)//写入液晶固定部分显示
{
write_date(table[num]);
delay(3);
}
write_com(0x80+0x40);
for(num=0;num<5;num++)
{
write_date(table1[num]);
delay(3);
}
}
void
write_dianya(unsigned
char
add,unsigned
char
date)
{//1602液晶刷新时分秒函数4为时,7为分,10为秒
unsigned
char
bai,shi,ge;
bai=date/100;
shi=date%100/10;
ge=date%10;
write_com(0x80+0x40+add);
write_date(0x30+bai);
write_date(0x30+shi);
write_date(0x30+ge);
}
void
main
()
{
init();
TMOD=0x20;
//设置定时器1工作方式2
TH1=0xfd;
TL1=0xfd;
TR1=1;
REN=1;
//设置串行口工作方式
SM0=0;
SM1=1;
EA=1;
//中断设置
ES=1;
while(1)
{
if(flag==1)
{
ES=0;
SBUF=m;
while(!TI);
TI=0;
ES=1;
}
}
}
void
ser()
interrupt
4
{
RI=0;
m=SBUF;
write_dianya(5,m);
flag=1;
}
unsigned
char
code
table[]
={"
"};
unsigned
char
code
table1[]={"
:
"};
sbit
rs=P1^2;
sbit
lcden=P1^0;
unsigned
char
flag,m;
void
delay(int
xms)
{
int
i,j;
for(i=xms;i>0;i--)
//i=xms即延时约xms毫秒
for(j=110;j>0;j--);
}
void
write_com(unsigned
char
com)
{//写液晶命令函数
rs=0;
lcden=0;
P2=com;
delay(3);
lcden=1;
delay(3);
lcden=0;
}
void
write_date(unsigned
char
date)
{//写液晶数据函数
rs=1;
lcden=0;
P2=date;
delay(3);
lcden=1;
delay(3);
lcden=0;
}
void
init()
{//初始化函数
unsigned
char
num;
lcden=0;
rs=0;
write_com(0x38);//1602液晶初始化
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(num=0;num<15;num++)//写入液晶固定部分显示
{
write_date(table[num]);
delay(3);
}
write_com(0x80+0x40);
for(num=0;num<5;num++)
{
write_date(table1[num]);
delay(3);
}
}
void
write_dianya(unsigned
char
add,unsigned
char
date)
{//1602液晶刷新时分秒函数4为时,7为分,10为秒
unsigned
char
bai,shi,ge;
bai=date/100;
shi=date%100/10;
ge=date%10;
write_com(0x80+0x40+add);
write_date(0x30+bai);
write_date(0x30+shi);
write_date(0x30+ge);
}
void
main
()
{
init();
TMOD=0x20;
//设置定时器1工作方式2
TH1=0xfd;
TL1=0xfd;
TR1=1;
REN=1;
//设置串行口工作方式
SM0=0;
SM1=1;
EA=1;
//中断设置
ES=1;
while(1)
{
if(flag==1)
{
ES=0;
SBUF=m;
while(!TI);
TI=0;
ES=1;
}
}
}
void
ser()
interrupt
4
{
RI=0;
m=SBUF;
write_dianya(5,m);
flag=1;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
只是一个接收功能吗?
追问
恩,接受多个字符的功能,大侠有吗,给一个吧,谢谢了,murennan@163.com
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询