数码管显示数字12345678

#include<reg52.h>
#include<intrins.h>
sbit DIG_DATA=P0^2;
sbit DIG_SHCP=P0^4;
sbit DIG_STCP=P2^3;
code unsigned char Segment[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
code unsigned char Select[]={0xff,0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
void DigOutput(unsigned char SelectByte,unsigned char SegmentByte)
{
    unsigned char i;
    DIG_SHCP=0;
    DIG_STCP=0;
    for(i=0;i<8;i++)
    {
       if(SegmentByte&0x80)
       {
         DIG_DATA=1;
         }
         else
         {
             DIG_DATA=0;
             }
       _nop_();
       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_();
}
void main(void)
{
    while(1)
    {
         DigOutput(Select[8],Segment[1]);
         DigOutput(Select[7],Segment[2]);
         DigOutput(Select[6],Segment[3]);
         DigOutput(Select[5],Segment[4]);
         DigOutput(Select[4],Segment[5]);
         DigOutput(Select[3],Segment[6]);
         DigOutput(Select[2],Segment[7]);
         DigOutput(Select[1],Segment[8]);
    }
}        

 

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