標題: LED數(shù)碼管動態(tài)循環(huán)顯示0-99仿真+單片機程序+原理圖 [打印本頁]

作者: 51hei電控04262    時間: 2019-4-22 12:36
標題: LED數(shù)碼管動態(tài)循環(huán)顯示0-99仿真+單片機程序+原理圖
//兩位數(shù)碼管的加減

#include "reg52.h"
#include "intrins.h"

unsigned char code table[]={0xc0,0xf9,0xa4,0xb0,0x99,         
                                                          0x92,0x82,0xf8,0x80,0x90};                        //0~9的數(shù)組          (共陽極)

/*
定義 uint uchar
*/
typedef        unsigned int uint;
typedef unsigned char uchar;

sbit smg1 = P2^0;
sbit smg2 = P2^1;

void delay(uint z)         //延時函數(shù)(不準確)
{
        uint x,y;
        for(x=0;x<z;x++)
        for(y=0;y<110;y++);        
}

void main(void)        //主函數(shù)
{
        uchar i,j;
        while(1)
        {  
                for(i = 0;i < 99;i++)                                                  //0~99
                {         
                        for(j = 0;j < 30;j++)                                          //讓一個數(shù)字閃爍多遍
                        {
                                P0 = 0XFF;                                                          //消影
                                smg1 = 0;
                                smg2 = 1;                                                         
                                P0 = table[i%100/10];
                                delay(10);

                                   P0 = 0XFF;                                                          //消影
                                smg1 = 1;
                                smg2 = 0;
                                P0 = table[i%100%10];
                                delay(10);
                        }
                }        
        }
}

全部資料51hei下載地址:
0-99.rar (91.57 KB, 下載次數(shù): 30)





歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1