• 51单片机实现计数器,没记3个脉冲,字符8在数码管上左右移一位


    #include <reg51.h>
    #define uint unsigned int 
    #define uchar unsigned char
    sfr P0M0 = 0x94;
    sfr P0M1 = 0x93;
    sfr P2M0 = 0x96;
    sfr P2M1 = 0x95;
    uint count,i,j;
    uchar code leddata[] = {
                    0xC0,  //"0"
                    0xF9,  //"1"
                    0xA4,  //"2"
                    0xB0,  //"3"
                    0x99,  //"4"
                    0x92,  //"5"
                    0x82,  //"6"
                    0xF8,  //"7"
                    0x80,  //"8"
                    0x90,  //"9"
                    0x88,  //"A"
                    0x83,  //"B"
                    0xC6,  //"C"
                    0xA1,  //"D"
                    0x86,  //"E"
                    0x8E,  //"F"
                    0x89,  //"H"
                    0xC7,  //"L"
                    0xC8,  //"n"
                    0xC1,  //"u"
                    0x8C,  //"P"
                    0xA3,  //"o"
                    0xBF,  //"-"
                    0xFF,  
                    0xFF 
    };
    uchar code weidata[] = {
        0x01,0x02,0x04,0x08,
        0x10,0x20,0x40,0x80,
        0x01,0x02,0x04,0x08,
        0x10,0x20,0x40,0x80,
    };
    void delay(uint ms){
        uint i,j;
        for(i = 0;i < ms;i++)
            for(j = 0;j < 1210;j++);
    }
    void timer_init(){
            TMOD = 0x60;
            TH1 = 0xfb;
            TL1 = 0xfb;
            EA = 1;
            ET1 = 1;
            TR1 = 1;
    }
    void timer_init1() interrupt 3{
        count++;
        if(count == 8){
           count = 0;
        }
    }
    void display(){
        P0 = leddata[8];
        P2 = ~weidata[count];
     }
    void main(){
        P0M0 = 0x00;
        P0M1 = 0x00;
        P2M0 = 0x00;
        P2M1 = 0x00;
        timer_init();
        while(1){
            display();
        }
    }
    //计数器同级脉冲00H-FFH
    #include <reg51.h>
    #define uint unsigned int 
    #define uchar unsigned char
    sfr P0M0 = 0x94;
    sfr P0M1 = 0x93;
    sfr P2M0 = 0x96;
    sfr P2M1 = 0x95;
    uint m,i,j;
    uchar code leddata[] = {
                    0xC0,  //"0"
                    0xF9,  //"1"
                    0xA4,  //"2"
                    0xB0,  //"3"
                    0x99,  //"4"
                    0x92,  //"5"
                    0x82,  //"6"
                    0xF8,  //"7"
                    0x80,  //"8"
                    0x90,  //"9"
                    0x88,  //"A"
                    0x83,  //"B"
                    0xC6,  //"C"
                    0xA1,  //"D"
                    0x86,  //"E"
                    0x8E,  //"F"
                    0x89,  //"H"
                    0xC7,  //"L"
                    0xC8,  //"n"
                    0xC1,  //"u"
                    0x8C,  //"P"
                    0xA3,  //"o"
                    0xBF,  //"-"
                    0xFF,  
    };
    uchar code weidata[] = {
        0x01,0x02,0x04,0x08,
        0x10,0x20,0x40,0x80
    };
    void delay(uint ms){
        uint i,j;
        for(i = 0;i < ms;i++)
            for(j = 0;j < 121;j++);
    }
    void timer_init(){
            TMOD = 0x60;
            TH1 = 255;
            TL1 = 255;
            EA = 1;
            ET1 = 1;
            TR1 = 1;
    }
    void timer_init1() interrupt 3{
        i++;
        m++;
        if(m == 255){
            i = 0;
            j = 0;
            m = 0;
        }
        if(i == 16){
           i = 0;
           j++;
           if(j == 16){
                    j = 0;
           }
        }
    }
    void display(){
        P0 = leddata[16];
        P2 = ~weidata[2];
        delay(3);
    
        P0 = leddata[i];
        P2 = ~weidata[1];
        delay(3);
    
        P0 = leddata[j];
        P2 = ~weidata[0];
        delay(3);
     }
    void main(){
        P0M0 = 0x00;
        P0M1 = 0x00;
        P2M0 = 0x00;
        P2M1 = 0x00;
        timer_init();
        while(1){
            display();
        }
    }
  • 相关阅读:
    Python并行编程(十三):进程池和mpi4py模块
    Python 列表集合 字典推导式、生成器表达式
    Python 迭代对象、迭代器
    Python 参数,嵌套函数 的变量 使用
    Python 编码进阶
    Python 深浅Copy
    Python 代码块、缓存机制
    Python 列表,字典 相关方法
    初识 python 字符串 相关函数
    初识编码格式
  • 原文地址:https://www.cnblogs.com/weimin1314/p/8260588.html
Copyright © 2020-2023  润新知