首页 > 其他 > 详细

数码管显示数字12345678

时间:2015-03-23 19:15:05      阅读:414      评论:0      收藏:0      [点我收藏+]
#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]);
    }
}        

 

数码管显示数字12345678

原文:http://www.cnblogs.com/zhaoruiqi/p/4360564.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!