標(biāo)題: 為什么6位數(shù)碼管最后一位用不了? [打印本頁]

作者: 喻小見    時(shí)間: 2014-7-31 15:04
標(biāo)題: 為什么6位數(shù)碼管最后一位用不了?
#include<reg51.h>
unsigned char code LedChar[] = {                 //數(shù)碼管顯示數(shù)
        0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8,
    0x80, 0x90, 0x88, 0x83, 0xC6, 0xA1, 0x86, 0x8E               
};
unsigned char LedBuff[7] = {                                 //數(shù)碼管顯示緩沖區(qū)
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,0xFF
};
unsigned char code Table[] = {
        0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF
};
void DisPlay(unsigned long num);
void delay1ms(unsigned char n);
void LedScan();
void main()
{

        DisPlay(53467);                //數(shù)碼管顯示0   高位為0不顯示
        LedScan();
}
void DisPlay(unsigned long num)
{
    signed char i;
    unsigned char buf[6];

    for (i=0; i<6; i++)   //把長整型數(shù)轉(zhuǎn)換為6位十進(jìn)制的數(shù)組
    {
        buf = num % 10;
        num = num / 10;
    }
    for (i=5; i>=1; i--)  //從最高位起,遇到0轉(zhuǎn)換為空格,遇到非0則退出循環(huán)
    {
        if (buf == 0)
            LedBuff = 0xFF;
        else
            break;
    }
    for ( ; i>=0; i--)    //剩余低位都如實(shí)轉(zhuǎn)換為數(shù)碼管顯示字符
    {
        LedBuff = LedChar[buf];
    }
}
void LedScan()
{
        unsigned char i;
        P0 = 0xFF;
        for (i=0; i<6; i++)
        {
                P2 = Table;
                P0 = LedBuff;
                delay1ms(1);        
        }

}
void delay1ms(unsigned char n)
{
        static unsigned char i;
        while(n--)
        for(i=0;i<125;i++);
?



資料:
http://bbs.dzsc.com/showtopic-371170.html






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