|
我希望用藍(lán)牙輸入8個(gè)數(shù)字,每輸入一個(gè)數(shù)字,動(dòng)態(tài)數(shù)碼管點(diǎn)亮一位,顯示該數(shù)字?墒菙(shù)碼管不管輸入幾都是全部點(diǎn)亮,包括小數(shù)點(diǎn)。
- #include "reg51.h"
- #include "intrins.h"
- typedef unsigned char u8;
- typedef unsigned int u16;
- #define GPIO_DIG P0
- u8 DisplayData[8]=0x00;
- u8 a;
- sbit LSA=P2^2;
- sbit LSB=P2^3;
- sbit LSC=P2^4;
- u8 code smgduan[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//共陰
- u8 tmp=0;
- void delay(u16 i)
- {
- while(i--);
- }
- init()
- {
- TMOD|=0x20;
- TL1=0xfd;
- TH1=0xE6;
- SCON=0x50;
- PCON=0x00;
- TR1=1;
- ES=1;
- EA=1; //定時(shí)器1開(kāi)始工作,產(chǎn)生波特率
- //發(fā)送標(biāo)志位置0
- TI=0; //接收標(biāo)志位置0
- RI=0;
- }
- void get(void) interrupt 4//串口中斷服務(wù)程序
- {
-
- if(RI==1)
- {
- RI=0;//軟件清除串口響應(yīng)
- a=SBUF;
- DisplayData[tmp]=smgduan[a];
- tmp++;
-
- }
-
- }
- void digdisplay()
- {
- u8 i;
- for(i=0;i<8;i++)
- {
- switch(i)
- {
- case (0):
- LSA=0;LSB=0;LSC=0;break;
- case (1):
- LSA=1;LSB=0;LSC=0;break;
- case (2):
- LSA=0;LSB=1;LSC=0;break;
- case (3):
- LSA=1;LSB=1;LSC=0;break;
- case (4):
- LSA=0;LSB=0;LSC=1;break;
- case (5):
- LSA=1;LSB=0;LSC=1;break;
- case (6):
- LSA=0;LSB=1;LSC=1;break;
- case (7):
- LSA=1;LSB=1;LSC=1;break;
- }
- GPIO_DIG=DisplayData[i];
- delay(500);
- P0=0x00;
- }
- }
- void main()
- {
- init();
- while(1)
- {
- digdisplay();
- }
-
- }
復(fù)制代碼
|
|