基于串口助手的单片机时钟程序问题
时间:10-02
整理:3721RD
点击:
下面是程序的代码,时钟能够正常在数码管上显示出来,但是有其他数码管也会有走的迹象,不过比较暗,仔细看才能看出来,第二个问题是写好的用串口助手发送没有返回,就是没接收,我不知道是程序那里出了问题,有没有高手帮忙看看,谢谢 在线急等。
#include<reg52.h>
#include<absacc.h>
#include<source.h>
uint buf1[6]={0};
uchar uart[9]="000000000";
uint uart_deal[8]={0};
uint t=0;
uint num=0,i=0,temp1,temp2,flag;
uchar tab[]="11111";
uchar code dispcode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf};
uchar miao=0;
uchar fen=0;
uchar shi=12;
uchar mstcnt=0;
sbit P1_0=P1^0;
sbit P1_1=P1^1;
sbit P1_2=P1^2;
sbit P1_5=P1^5;
void delay(uint k);
void time_pro();
void display();
void timer0_init();
void get_uart_deal();
void display()
{
P2=0xfe;
P0=dispcode[miao%10];
delay(1);
P2=0xfd;
P0=dispcode[miao/10];
delay(1);
P2=0xfb;
P0=dispcode[10];
delay(1);
P2=0xf7;
P0=dispcode[fen%10];
delay(1);
P2=0xef;
P0=dispcode[fen/10];
delay(1);
P2=0xdf;
P0=dispcode[10];
delay(1);
P2=0xbf;
P0=dispcode[shi%10];
delay(1);
P2=0x7f;
P0=dispcode[shi/10];
delay(1);
}
void delay(uint k)
{
uchar j;
while((k--)!=0)
{
for(j=0;j<125;j++);
}
}
void time_pro(void)
{
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
{
shi=0;
}
}
}
}
void zhengdian(void)
{
if((miao==0)&(fen==0))
{
P1_5=0;
delay(1000);
P1_5=1;
}
}
void main(void)
{
P1=0xff;
TMOD=0x11;
TH0=0x3c;
TL0=0xb0;
EA=1;
ET0=1;
TR0=1;
timer0_init();
while(1)
{
zhengdian();
display();
}
}
void timer0(void) interrupt 1
{
TH0=0x3c;
TL0=0xb0;
TMOD=0x11;
mstcnt++;
if(mstcnt==20)
{
miao++;
time_pro();
mstcnt=0;
}
}
void timer0_init()
{
display(); //??ê?oˉêy3?ê??ˉ
PCON |= 0x80; //SMOD=1£?2¨ì??ê?ó±?
TMOD=0x21; //éè???¨ê±?÷01¤×÷·?ê??a1£¨0000 0001£?;′??ú1¤×÷:?¨ê±?÷11¤×÷·?ê?2£¨0010 0000£?
TH0=(65535-50000)/256; //×°?¨ê±?÷3??μ,?¨ê±50msoó·¢éú?D??
TL0=(65535-50000)%256;
TH1=0xe8; //?¨ê±ê±??243|ìs
TL1=0xe8; //2¨ì??ê2400
TR0=1; //???ˉ?¨ê±?÷0
TR1=1; //???ˉ?¨ê±?÷1
ET0=1; //?a?¨ê±?÷0?D??
SM0=0; //8??UART2¨ì??ê?é±?£¨T1ò?3??ê/N£?·?ê?1
SM1=1;
PS=1; //′??ú?D????ó??è??
REN=1; //?êDí′??ú?óê?
EA=1; //?a×ü?D??
ES=1; //?a′??ú?D??
}
void get_uart_deal()
{
if(num==9)
{
ES=0;
for(i=1;i<9;i++)
{
uart_deal[i]=uart[i]-48;
}
if(uart[0]==115)
{
shi=uart_deal[1]*10+uart_deal[2];
if(shi>=24)
shi=0;
fen=uart_deal[4]*10+uart_deal[5];
if(fen>=60)
fen=0;
miao=uart_deal[7]*10+uart_deal[8];
if(miao>=60)
miao=0;
}
for(i=0;i<14;i++)
{
SBUF=tab[i];
while(!TI);
TI=0;
}
for(i=0;i<9;i++)
{
SBUF=uart[i];
while(!TI);
TI=0;
}
ES=1;
num=0;
}
}
void uart_isr() interrupt 4
{
if(RI==1)
{
RI=0;
uart[num]=SBUF;
num++;
}
}
#include<reg52.h>
#include<absacc.h>
#include<source.h>
uint buf1[6]={0};
uchar uart[9]="000000000";
uint uart_deal[8]={0};
uint t=0;
uint num=0,i=0,temp1,temp2,flag;
uchar tab[]="11111";
uchar code dispcode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf};
uchar miao=0;
uchar fen=0;
uchar shi=12;
uchar mstcnt=0;
sbit P1_0=P1^0;
sbit P1_1=P1^1;
sbit P1_2=P1^2;
sbit P1_5=P1^5;
void delay(uint k);
void time_pro();
void display();
void timer0_init();
void get_uart_deal();
void display()
{
P2=0xfe;
P0=dispcode[miao%10];
delay(1);
P2=0xfd;
P0=dispcode[miao/10];
delay(1);
P2=0xfb;
P0=dispcode[10];
delay(1);
P2=0xf7;
P0=dispcode[fen%10];
delay(1);
P2=0xef;
P0=dispcode[fen/10];
delay(1);
P2=0xdf;
P0=dispcode[10];
delay(1);
P2=0xbf;
P0=dispcode[shi%10];
delay(1);
P2=0x7f;
P0=dispcode[shi/10];
delay(1);
}
void delay(uint k)
{
uchar j;
while((k--)!=0)
{
for(j=0;j<125;j++);
}
}
void time_pro(void)
{
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
{
shi=0;
}
}
}
}
void zhengdian(void)
{
if((miao==0)&(fen==0))
{
P1_5=0;
delay(1000);
P1_5=1;
}
}
void main(void)
{
P1=0xff;
TMOD=0x11;
TH0=0x3c;
TL0=0xb0;
EA=1;
ET0=1;
TR0=1;
timer0_init();
while(1)
{
zhengdian();
display();
}
}
void timer0(void) interrupt 1
{
TH0=0x3c;
TL0=0xb0;
TMOD=0x11;
mstcnt++;
if(mstcnt==20)
{
miao++;
time_pro();
mstcnt=0;
}
}
void timer0_init()
{
display(); //??ê?oˉêy3?ê??ˉ
PCON |= 0x80; //SMOD=1£?2¨ì??ê?ó±?
TMOD=0x21; //éè???¨ê±?÷01¤×÷·?ê??a1£¨0000 0001£?;′??ú1¤×÷:?¨ê±?÷11¤×÷·?ê?2£¨0010 0000£?
TH0=(65535-50000)/256; //×°?¨ê±?÷3??μ,?¨ê±50msoó·¢éú?D??
TL0=(65535-50000)%256;
TH1=0xe8; //?¨ê±ê±??243|ìs
TL1=0xe8; //2¨ì??ê2400
TR0=1; //???ˉ?¨ê±?÷0
TR1=1; //???ˉ?¨ê±?÷1
ET0=1; //?a?¨ê±?÷0?D??
SM0=0; //8??UART2¨ì??ê?é±?£¨T1ò?3??ê/N£?·?ê?1
SM1=1;
PS=1; //′??ú?D????ó??è??
REN=1; //?êDí′??ú?óê?
EA=1; //?a×ü?D??
ES=1; //?a′??ú?D??
}
void get_uart_deal()
{
if(num==9)
{
ES=0;
for(i=1;i<9;i++)
{
uart_deal[i]=uart[i]-48;
}
if(uart[0]==115)
{
shi=uart_deal[1]*10+uart_deal[2];
if(shi>=24)
shi=0;
fen=uart_deal[4]*10+uart_deal[5];
if(fen>=60)
fen=0;
miao=uart_deal[7]*10+uart_deal[8];
if(miao>=60)
miao=0;
}
for(i=0;i<14;i++)
{
SBUF=tab[i];
while(!TI);
TI=0;
}
for(i=0;i<9;i++)
{
SBUF=uart[i];
while(!TI);
TI=0;
}
ES=1;
num=0;
}
}
void uart_isr() interrupt 4
{
if(RI==1)
{
RI=0;
uart[num]=SBUF;
num++;
}
}
没有人能看看吗? 乱码那里是注释而已
在线急等 没有人帮忙吗
延时肯能太短了把 二极管暗
