Blogtrottr
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 發問中
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 發問中
單晶片C語言 按紐做七段顯示器加減一動作
May 2nd 2013, 14:09

/* 每壓一下按鈕開關
共陽極七段顯示器的數值加減一 */
#include
#define PB0 P3_2
#define PB1 P3_3
#define LED P2
code char tab[]={0xc0,0xf9,// 0~9 的字型碼
0xa4,0xb0,0x99,0x92,0x83,0xf8,0x80,0x98};
/* 延遲副程式 */
void delay(unsigned int time)
{ while(time>0) time--; }
/* 主程式 */
void main(void)
{ char cnt;
PB0=PB1=1;
LED=tab[cnt];// 顯示器顯示0
while(1)// 無窮迴圈
{
{
while (PB0); // 按鈕未被壓下時
delay(2000); // 消除彈跳作用
while (PB0==0); // 按鈕持續被壓下
delay(2000); // 消除彈跳作用
cnt--; //做-1動作
if (cnt
LED=tab[cnt];
}
{
while (PB1); // 按鈕未被壓下時
delay(2000); // 消除彈跳作用
while (PB1==0); // 按鈕持續被壓下
delay(2000); // 消除彈跳作用
cnt++; //做+1動作
if (cnt>9) cnt=0;
LED=tab[cnt];
}
}
}

---------------------------
想請問各位大大為什麼他只能0和9在做轉換..
如果 我想要出值設定5的話 是不是在宣告那打CNT=5就可以了呢?
如果我在按鈕按下的那邊不是使用while而是用if又要怎麼更改~~

This entry passed through the Full-Text RSS service — if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers. Five Filters recommends: Thatcher's Tyrants - The Tanks, The Guns, The Christmas Cards.

You are receiving this email because you subscribed to this feed at blogtrottr.com.

If you no longer wish to receive these emails, you can unsubscribe from this feed, or manage all your subscriptions
arrow
arrow
    全站熱搜

    ksokf 發表在 痞客邦 留言(0) 人氣()