美文网首页16级单片机实践经验分享每天一点单片机知识单片机学习
【C51单片机期末复习整理系列】[四]八段数码管的选择与显示

【C51单片机期末复习整理系列】[四]八段数码管的选择与显示

作者: Topus | 来源:发表于2018-10-31 00:17 被阅读2次

    分两个版本,实现的功能类似

    注意:要想八个八段数码管都显示内容则必须将延时降低并且方式是来回快速刷新

    #include <reg52.h>
    sbit ce = P1^3;
    sbit le1 = P1^4;
    sbit le2 = P1^5;
    char code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
    char code select[] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
    void delay( unsigned int xms){
    
    unsigned char i,j;
    
    for(i=xms;i>0;i--)
    
    for(j=300;j>0;j--);
    }
    
    void main(){
        unsigned char display_number = 0;
        unsigned char select_number = 0;
      ce = 0;
        le1 = 0;
        le2 = 0;
        while(1){
    
            le1 = 1; 
            P0 = ~table[display_number];
            le1 = 0;
                
            le2 = 1;
            P0 =  select[select_number];
            le2 = 0;
                
            delay(6);
            
            ++display_number;
            display_number %= 8;
            ++select_number;
            select_number %= 8;
            
        }
            
    }
    
    #include <reg52.h>
    sbit ce = P1^3;
    sbit le1 = P1^4;
    sbit le2 = P1^5;
    char code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
    char code select[] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
    
    void delay( unsigned int xms){
    
    unsigned char i,j;
    
    for(i=xms;i>0;i--)
    
    for(j=300;j>0;j--);
        
    }
    
    void main(){
        unsigned char display_number = 0;
        unsigned char select_number = 0;
      ce = 0;
        le1 = 0;
        le2 = 0;
        while(1){
    
            
            le2 = 1;
            P0 =  select[select_number];
            le2 = 0;
            
            delay(2000);
            
            le1 = 1; 
            P0 = ~table[display_number];
            le1 = 0;
            
            
                
            
                delay(2000);
            
            
            ++display_number;
            display_number %= 10;
            
            
        }
            
    }
    

    相关文章

      网友评论

        本文标题:【C51单片机期末复习整理系列】[四]八段数码管的选择与显示

        本文链接:https://www.haomeiwen.com/subject/yxcotqtx.html