|
各位好,程序見(jiàn)下面,我想實(shí)現(xiàn)的功能是兩個(gè)按鈕對(duì)應(yīng)兩個(gè)共陽(yáng)數(shù)碼管,上電后兩個(gè)數(shù)碼管顯示零,按第一個(gè)按鈕第一個(gè)數(shù)碼管顯示一,第二個(gè)數(shù)碼管不變,按到5,數(shù)碼管就顯示5。但現(xiàn)在的問(wèn)題是我不論按哪個(gè)按鈕,兩個(gè)數(shù)碼管一起顯示同樣的數(shù),不能分別控制,請(qǐng)各位高手幫忙指點(diǎn)一下程序要怎樣修改,謝謝
#include <reg51.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit KK1 = P3^2;//按鍵輸入;
sbit KK2 = P3^3;//按鍵輸入;
uchar code table[11] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90, 0xff};
/**************************************************************
* 名稱 : Delay_1ms()
* 功能 : 延時(shí)子程序,延時(shí)時(shí)間為 1ms * x
* 輸入 : x (延時(shí)一毫秒的個(gè)數(shù))
* 輸出 : 無(wú)
***************************************************************/
void Delay_1ms(uint x)
{
uchar i, j;
for(i = 0; i < x; i++) for(j = 0; j <= 148; j++);
}
/**************************************************************
* 名稱 : Display(uchar k)
* 功能 : 將參數(shù)分成十位、個(gè)位分別顯示
* 輸入 : k
* 輸出 : 無(wú)
***************************************************************/
void Display(uchar k)
{
P2 = 0; //先消隱
P2 = 0x02; Delay_1ms(5); //顯示5ms
P2 = 0;
P0 = table[k % 10]; //顯示個(gè)位
P2 = 0x01; Delay_1ms(5);
P1 = table[k % 10]; //顯示個(gè)位
}
/**************************************************************
* 名稱 : Main()
* 功能 : 主函數(shù)
***************************************************************/
void Main(void)
{
uchar Value = 0; //數(shù)值
while(1) {
P3 = 0xff;
if(!KK1) {//KK1按下
Display(Value);//延時(shí)消抖
// Delay_1ms(20);
if(!KK1) {//KK1依然按下
while(!KK1);//等KK1釋放
Value++;
if (Value > 5) Value = 5;//顯示最大值0-10
}
}
if(!KK2) {//KK1按下
Display(Value);//延時(shí)消抖
// Delay_1ms(20);
if(!KK2) {//KK1依然按下
while(!KK2);//等KK1釋放
Value++;
if (Value > 5) Value = 5;//顯示最大值0-10
}
}
Display(Value); //顯示值
}
}
|
|