[請益] 請教8051

看板Programming作者 (怎樣轉移檔案?)時間18年前 (2007/06/26 07:07), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
我現在要用8051作一個倒數計數器 作動原理是先用4*4按鍵輸入數字 7段顯示器出現數字 用一個按鈕作計數動作 每按一下數字減一 當數字變零 喇叭就會叫 以下是電路圖和我寫的程式 http://img514.imageshack.us/my.php?image=60441066pk9.jpg
#include <REG51F.H> sbit P1_0=P1^0; sbit P1_1=P1^1; sbit P1_2=P1^2; sbit P1_3=P1^3; #define F 1000 //定義輸出頻率=1KHz #define T 11059000/12 //T=Fosc/12=基本的計時頻率 #define t 65536-(T/2/F) //t=半週期頻率的計時器內容 sbit P2_5=P2^5; //定義P2.5腳位 char count=0,scan=0xef; char code Table[] //七段顯示器的0~F的資料 ={ 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8, 0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e}; void dataout(void); void Delay(void); main() { P0=0xff; //設定按鍵資料=00 P1=0xff; P2=0x00; EA=1; EX0=1; IT0=1; ET0=1; //致能TIMER0計時中斷 TMOD = 0x01; //設定TIMER0為模式1 TL0 =t; //設定時間 TH0 =t >> 8; TR0=1; //開始計時 while(1) //重覆執行 { if(count>15) {scan=0xef;count=0;} P1=scan; if (P1_0==0) dataout();//檢查第A列 count++;Delay(); if (P1_1==0) dataout();//檢查第B列 count++;Delay(); if (P1_2==0) dataout();//檢查第C列 count++; Delay(); if (P1_3==0) dataout();//檢查第D列 count++;Delay(); scan=scan<<1; scan=scan|0x01; } } void EX0_int(void) interrupt 0 { count=count-1; } void T0_int(void) interrupt 1 //TIMER0中斷函數 { TL0 = t; //重新設定時間 TH0 = t >> 8; P2_5 = P2_5; //P25反相輸出 } void dataout(void) //按鍵輸出 { Delay(); //處理按鍵跳動之延遲 P0=Table[count]; //送到七段顯示器輸出*/ while((P1 | 0xf0)==0xff);//若P10~3≠1111表示未放開 Delay(); //放開按鍵後先延遲再離開副程式 } void Delay(void) //延時 { int dly=70; while(dly>0) dly--; } 想用按鈕作外部中斷 但是一直沒有成功 希望有高手可以幫我解決問題 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.169.111.20
文章代碼(AID): #16W4gRJw (Programming)
文章代碼(AID): #16W4gRJw (Programming)