proteus仿真图
代码:
- #include<reg51.h>
- #include<intrins.h>
- typedef unsigned char uchar;
- typedef unsigned int uint;
- #define Hidden 11
- #define CmdDat 0
- sbit Clock=P3^3;
- sbit Data=P3^2;
- const uint TimeOver=800;
- uchar code DispCode[]={
- //0x28,0xee,0x32,0xa2,0xe4,
- // 0xa1,0x21,0xea,0x20,0xa0,
- // 0xff
- 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,
- 0xF8,0x80,0x90,0xff
- };
- uchar code DispBit[]={0x7f,0xfe,0xef,0xdf};
- uint DispData=0;
- uchar DispBuf[4]={0,0,0,0};
- uchar RecDatCount;
- uchar bdata RecDat;
- sbit RecDat0=RecDat^0;
- bit renovate;
- bit ReciveMark=1;
- uchar DotCnt=1;
- uchar MaskSing=0;
- bit StartOverCount;
- bit RecEnd;
- uint OverCount;
- /**********************************************
- uS延时函数
- **********************************************/
- void DelayUs2x(unsigned char t)
- {
- while(--t);
- }
- /**********************************************
- mS延时函数
- ***********************************************/
- void DelayMs(unsigned char t)
- {
-
- while(t--)
- {
- //大致延时1mS
- DelayUs2x(245);
- DelayUs2x(245);
- }
- }
- void ReciveDate() interrupt 2
- {
- ReciveMark=0;
- if(!StartOverCount)
- StartOverCount=1;
- RecDatCount++;
- RecDat=RecDat<<1;
- if(Data)
- RecDat0=1;
- else
- RecDat0=0;
- if(RecDatCount==8)
- {
- MaskSing=RecDat;
- }
- else if(RecDatCount==16)
- {
- if(MaskSing==CmdDat)
- DispData=RecDat*256;
-
- }
- else if(RecDatCount==24)
- {
- if(MaskSing==CmdDat)
- DispData+=RecDat;
-
- }
- else if(RecDatCount==32)
- {
- if(MaskSing==CmdDat)
- DispData=RecDat;
- renovate=1;
- RecDatCount=0;
- StartOverCount=0;
- OverCount=0;
- RecEnd=1;
- RecDat=0;
-
- }
- }
- void Timer0() interrupt 1
- {
- uchar temp;
- static uchar Count;
- if(StartOverCount)
- OverCount++;
- Count++;
- if(Count==4)
- Count=0;
- P3|=0XB1;
- temp=DispBit[Count];
- P3&=temp;
- temp=DispBuf[Count];
- P1=DispCode[temp];
- if(DotCnt==(4-Count))
- P1&=0XDF;
- TH0=-(600/256);
- TL0=-(600%256);
- }
- void main()
- {
- uchar temp0,temp1,temp2,temp3;
- uint temp;
- TH0=-(600/256);
- TL0=-(600%256);
- TR0=1;
- IT1=1;
- EA=1;
- ET0=1;
- EX1=1;
- PT0=0;
- PX1=1;
- renovate=1;
- P1=0;
- Clock=1;
- Data=1;
-
- //////////////////////
- DispData=9999;
- //DispData=8888;
- //DispData=654;
- for(;;)
- {
- if(renovate)
- {
- temp=DispData;
- temp%=10000;
- temp3=temp%10;
- temp/=10;
- temp2=temp%10;
- temp/=10;
- temp1=temp%10;
- temp/=10;
- temp0=temp%10;
-
- if((temp0==0)&&(DotCnt<3))
- DispBuf[0]=Hidden;
- else
- DispBuf[0]=temp0;
-
- if((temp0==0)&&(temp1==0)&&(DotCnt<2))
- DispBuf[1]=Hidden;
- else
- DispBuf[1]=temp1;
-
- if(((temp0==0)&&(temp1==0)&&(temp2==0)
- &&(DotCnt<1))||((temp3==0)&&(temp2==0)
- &&(DotCnt>2)))
- DispBuf[2]=Hidden;
- else
- DispBuf[2]=temp2;
- if((temp3==0)&&(DotCnt>1))
- DispBuf[3]=Hidden;
- else
- DispBuf[3]=temp3;
- renovate=0;
- }
- if(OverCount>=TimeOver)
- {
- RecDatCount=0;
- StartOverCount=0;
- OverCount=0;
- RecEnd=1;
- }
-
- }
- }
复制代码
proteus仿真文件及C工程
通用显示器.rar
(199.44 KB, 下载次数: 5)
|