zoukankan      html  css  js  c++  java
  • 51单片机实现定时器中断0-F

    #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 = 0x01;
            TH0 = 0x3c;
            TL0 = 0x0b0;
            EA = 1;
            ET0 = 1;
            TR0 = 1;
    }
    void timer_init1() interrupt 1{
            TH0 = 0x3c;
            TL0 = 0x0b0;
            count++;
            if(count == 20){
                    count = 0;
                    i++;
                    if(i == 16){
                        i = 0;
                    }
            }
    }
    void display(){
        P0 = leddata[i];
        P2 = ~weidata[i];
     }
    void main(){
        P0M0 = 0x00;
        P0M1 = 0x00;
        P2M0 = 0x00;
        P2M1 = 0x00;
        timer_init();
        while(1){
            display();
        }
    }
  • 相关阅读:
    HTML的<head>中的内容总结
    毕业设计
    win7中protel99添加元件库
    E题
    D 题
    C 题 KMP中next[]问题
    B题 Sort the Array
    A题
    CSU1350 To Add which?
    CodeForce 448C 木片填涂问题
  • 原文地址:https://www.cnblogs.com/weimin1314/p/8260573.html
Copyright © 2011-2022 走看看