数码管显示数字1

#include<reg52.h>
#include<intrins.h>
sbit DIG_DATA=P0^2;
sbit DIG_SHCP=P0^4;
sbit DIG_STCP=P2^3;
void main(void)
{
  unsigned char i,SegmentByte,SelectByte;
  SegmentByte=0xf9;
  SelectByte=0x01;
  DIG_SHCP=0;
  DIG_STCP=0;
  for(i=0;i<8;i++)
  {
     if(SegmentByte&0x80)
     {
       DIG_DATA=1;
       }
       else
       {
           DIG_DATA=0;
           }
    DIG_SHCP=1;
    _nop_();
    DIG_SHCP=0;
    _nop_();
    SegmentByte<<=1;
  }
  for(i=0;i<8;i++)
  {
     if(SelectByte&0x80)
     {
       DIG_DATA=1;
       }
       else
       {
           DIG_DATA=0;
           }
    _nop_();
    DIG_SHCP=1;
    _nop_();
    DIG_SHCP=0;
    _nop_();
    SelectByte<<=1;
  }
  DIG_STCP=1;
  _nop_();
  DIG_STCP=0;
  _nop_();
  while(1)
  {
    }
}

 

posted @ 2015-03-23 17:51  zhaoyang16  阅读(598)  评论(0编辑  收藏  举报