数码管显示0-65536,我是以16进制发送一个0-65536之间的任一数,当单片机收到后在数码管上动态显示出来,波特率自定,请各位大侠帮忙看看,我这程序是否有问题,我现在不能做仿真,软件有问题!
程序如下:
- sbit deepLE=P3^7;
- uchar code table[]={0xc0,0xf9,0xa4,0xb0,
- 0x99,0x92,0x82,0xf8,
- 0x80,0x98,0x88,0x83,
- 0xc6,0xa1,0x86,0x8e};
- uchar flag=0;
- uint get=0,aa=65535;
- void display(uint shu);
- void delay(uint);
- void main()
- {
- deepLE=0;
- TMOD=0x20;
- TH1=0xfd;
- TL1=0xfd;
- REN=1;
- SM0=0;
- SM1=1;
- EA=1;
- ES=1;
- TR1=1;
- while(1)
- {
- if(flag==1)
- {
- aa=SBUF;
- flag=0;
- while(!RI)
- display(aa);
- }
- else
- display(aa);
-
- }
-
- }
- void series() interrupt 4
- {
- RI=0;
- get=SBUF;
- flag=1;
- }
- void display(uint shu)
- {
- uint a,b,c,d,e;
- a=shu/10000;
- b=shu%10000/1000;
- c=shu%1000/100;
- d=shu%100/10;
- e=shu%10;
- P2=0xf7;
- P0=table[a];
- delay(5);
-
- P2=0xef;
- P0=table
复制代码
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
我用keil编译了下,用AT89C51
1、所有的uchar改为 unsigned char;
2,、所有的uint改为 unsigned int;
3,加上delay函数的编写代码;
- #include<reg51.h>
- sbit deepLE=P3^7;
- unsigned char code table[]={0xc0,0xf9,0xa4,0xb0,
- 0x99,0x92,0x82,0xf8,
- 0x80,0x98,0x88,0x83,
- 0xc6,0xa1,0x86,0x8e};
- unsigned char flag=0;
- unsigned int get=0,aa=65535;
- void display(unsigned int shu);
- delay(unsigned int x);
- void main()
- {
- deepLE=0;
- TMOD=0x20;
- TH1=0xfd;
- TL1=0xfd;
- REN=1;
- SM0=0;
- SM1=1;
- EA=1;
- ES=1;
- TR1=1;
- while(1)
- {
- if(flag==1)
- {
- aa=SBUF;
- flag=0;
- while(!RI)
- display(aa);
- }
- else
- display(aa);
-
- }
-
- }
- void series() interrupt 4
- {
- RI=0;
- get=SBUF;
- flag=1;
- }
- void display(unsigned int shu)
- {
- unsigned int a,b,c,d,e;
- a=shu/10000;
- b=shu%10000/1000;
- c=shu%1000/100;
- d=shu%100/10;
- e=shu%10;
- P2=0xf7;
- P0=table[a];
- delay(5);
-
- P2=0xef;
- P0=table;
- }
- delay(unsigned int x)
- {
- unsigned int i,j;
- for(i=x;i>0;i--)
- for(j=1100;j>0;j--);
复制代码}
一周热门 更多>