標(biāo)題: 大神們幫我解釋一下這篇單片機程序,不知道對不對 [打印本頁]

作者: wsda2    時間: 2019-1-29 17:36
標(biāo)題: 大神們幫我解釋一下這篇單片機程序,不知道對不對
#include<reg52.h>
#define uchar unsigned char
#define uint  unsigned int
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8};
void delay(void)   
{
    unsigned char a,b;
    for(b=102;b>0;b--)
        for(a=3;a>0;a--);
}
void main (void)
{
    uint i;
        while(1)
        {
            P2=table;
    }
}



作者: jinsheng7533967    時間: 2019-1-30 01:18
你那樣是不行的,要這樣改
#include<reg52.h>
#define uchar unsigned char
#define uint  unsigned int
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8};
void delay(void)
{
        unsigned char a,b;
        for(b=102;b>0;b--)
                for(a=30;a>0;a--);//a=3改為了a=30為了看的見
}

void main (void)
{
        uint i;
       
        while(1)
        {
                for(i=8;i>0;i--)
                {
                        P2=table[i];
                        delay();
                }
        }
}






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