這里給大家介紹一個群里面朋友的單片機鍵盤程序,詳細內容請見下面:
org 0030h
ljmp main
main:
mov p1,#0ffh
mov p3,#0ffh
mov p0,#80h
mov p2,#0ffh
k0: setb p0.7
mov a,p3
ANL a,#11000000b
cjne a,#00000000b,k1
ljmp kk0 ;跳轉去執行RMA236的程序
k1: cjne a,#01000000b,k2
ljmp kk1 ;跳轉去執行RMA463、464、490、491的程序
k2: cjne a,#10000000b,k3
ljmp kk2 ;跳轉去執行RMA570的程序
k3: cjne a,#11000000b,k0
ljmp kk3 ;跳轉去執行RMA227、236成品程序
;鍵盤程序的4個按鍵
kk0: jnb p0.7,pp1 ;跳轉去執行RMA236的程序
ljmp kk0
pp1: mov p0,#06h ;按按鍵 1 2 3 4 5 6 #鍵
clr p2.0
clr p1.0
lcall delay
setb p2.0
setb p1.0
lcall delay
mov p0,#5bh
clr p2.1
clr p1.1
lcall delay
setb p2.1
setb p1.1
lcall delay
mov p0,#4fh
clr p2.2
clr p1.2
lcall delay
setb p2.2
setb p1.2
lcall delay
mov p0,#66h
clr p2.3
clr p1.3
lcall delay
setb p2.3
setb p1.3
lcall delay
mov p0,#6dh
clr p2.4
clr p1.4
lcall delay
setb p2.4
setb p1.4
lcall delay
mov p0,#7dh
clr p2.5
clr p1.5
lcall delay
setb p2.5
setb p1.5
lcall delay
mov p0,#76h
clr p2.6
clr p3.3
lcall delay
setb p2.6
setb p3.3
ppx1: mov P0,#06h
clr p2.0
lcall delay1
setb p2.0
mov p0,#5bh
clr p2.1
lcall delay1
setb p2.1
mov p0,#4fh
clr p2.2
lcall delay1
setb p2.2
mov p0,#66h
clr p2.3
lcall delay1
setb p2.3
mov p0,#6dh
clr p2.4
lcall delay1
setb p2.4
mov p0,#7dh
clr p2.5
lcall delay1
setb p2.5
mov p0,#76h
clr p2.6
lcall delay1
setb p2.6
jnb p0.7,pp2
ljmp ppx1
pp2: mov p0,#07h ;按按鍵7 4 * 1 2 3 4 5 6 # 鍵
clr p2.0
clr p1.6
lcall delay
setb p2.0
setb p1.6
lcall delay
mov p0,#66h
clr p2.1
clr p1.3
lcall delay
setb p2.1
setb p1.3
lcall delay
mov p0,#36h
clr p2.2
clr p3.1
lcall delay
setb p2.2
setb p3.1
lcall delay
mov p0,#06h
clr p2.3
clr p1.0
lcall delay
setb p2.3
setb p1.0
lcall delay
mov p0,#5bh
clr p2.4
clr p1.1
lcall delay
setb p2.4
setb p1.1
lcall delay
mov p0,#4fh
clr p2.5
clr p1.2
lcall delay
setb p2.5
setb p1.2
lcall delay
mov p0,#66h
clr p2.6
clr p1.3
lcall delay
setb p2.6
setb p1.3
lcall delay
mov p0,#6dh
clr p2.7
clr p1.4
lcall delay
setb p2.7
setb p1.4
lcall delay
mov p0,#7dh
clr p3.5
clr p1.5
lcall delay
setb p3.5
setb p1.5
lcall delay
mov p0,#76h
clr p3.4
clr p3.3
lcall delay
setb p3.4
setb p3.3
ppx2: mov p0,#07h
clr p2.0
lcall delay1
setb p2.0
mov p0,#66h
clr p2.1
lcall delay1
setb p2.1
mov p0,#36h
clr p2.2
lcall delay1
setb p2.2
mov p0,#06h
clr p2.3
lcall delay1
setb p2.3
mov p0,#5bh
clr p2.4
lcall delay1
setb p2.4
mov p0,#4fh
clr p2.5
lcall delay1
setb p2.5
mov p0,#66h
clr p2.6
lcall delay1
setb p2.6
mov p0,#6dh
clr p2.7
lcall delay1
setb p2.7
mov p0,#7dh
clr p3.5
lcall delay1
setb p3.5
mov p0,#76h
clr p3.4
lcall delay1
setb p3.4
jnb p0.7,pp3
ljmp ppx2
pp3: mov p0,#5bh ;按按鍵 2 * 7 8 9 0 0 0 # 鍵
clr p2.0
clr p1.1
lcall delay
setb p2.0
setb p1.1
lcall delay
mov p0,#36h
clr p2.1
clr p3.1
lcall delay
setb p2.1
setb p3.1
lcall delay
mov p0,#07h
clr p2.2
clr p1.6
lcall delay
setb p2.2
setb p1.6
lcall delay
mov p0,#7fh
clr p2.3
clr p1.7
lcall delay
setb p2.3
setb p1.7
lcall delay
mov p0,#6fh
clr p2.4
clr p3.0
lcall delay
setb p2.4
setb p3.0
lcall delay
mov p0,#3fh
clr p2.5
clr p3.2
lcall delay
setb p2.5
setb p3.2
lcall delay
mov p0,#3fh
clr p2.6
clr p3.2
lcall delay
setb p2.6
setb p3.2
lcall delay
mov p0,#3fh
clr p2.7
clr p3.2
lcall delay
setb p2.7
setb p3.2
lcall delay
mov p0,#76h
clr p3.5
clr p3.3
lcall delay
setb p3.5
setb p3.3
ppx3: mov p0,#5bh
clr p2.0
lcall delay1
setb p2.0
mov p0,#36h
clr p2.1
lcall delay1
setb p2.1
mov p0,#07h
clr p2.2
lcall delay1
setb p2.2
mov p0,#7fh
clr p2.3
lcall delay1
setb p2.3
mov p0,#6fh
clr p2.4
lcall delay1
setb p2.4
mov p0,#3fh
clr p2.5
lcall delay1
setb p2.5
mov p0,#3fh
clr p2.6
lcall delay1
setb p2.6
mov p0,#3fh
clr p2.7
lcall delay1
setb p2.7
mov p0,#76h
clr p3.5
lcall delay1
setb p3.5
jnb p0.7,pp4
ljmp ppx3
pp4: mov p0,#07h ;按按鍵 7 8 9 0 0 0 # 鍵
clr p2.0
clr p1.6
lcall delay
setb p2.0
setb p1.6
lcall delay
mov p0,#7fh
clr p2.1
clr p1.7
lcall delay
setb p2.1
setb p1.7
lcall delay
mov p0,#6fh
clr p2.2
clr p3.0
lcall delay
setb p2.2
setb p3.0
lcall delay
mov p0,#3fh
clr p2.3
clr p3.2
lcall delay
setb p2.3
setb p3.2
lcall delay
mov p0,#3fh
clr p2.4
clr p3.2
lcall delay
setb p2.4
setb p3.2
lcall delay
mov p0,#3fh
clr p2.5
clr p3.2
lcall delay
setb p2.5
setb p3.2
lcall delay
mov p0,#76h
clr p2.6
clr p3.3
lcall delay
setb p2.6
setb p3.3
ppx4: mov p0,#07h
clr p2.0
lcall delay1
setb p2.0
mov p0,#7fh
clr p2.1
lcall delay1
setb p2.1
mov p0,#6fh
clr p2.2
lcall delay1
setb p2.2
mov p0,#3fh
clr p2.3
lcall delay1
setb p2.3
mov p0,#3fh
clr p2.4
lcall delay1
setb p2.4
mov p0,#3fh
clr p2.5
lcall delay1
setb p2.5
mov p0,#76h
clr p2.6
lcall delay1
setb p2.6
jnb p0.7,pp5
ljmp ppx4
pp5: mov p0,#07h ;按按鍵 7 8 9 0 0 0 # 鍵
clr p2.0
clr p1.6
lcall delay
setb p2.0
setb p1.6
lcall delay
mov p0,#7fh
clr p2.1
clr p1.7
lcall delay
setb p2.1
setb p1.7
lcall delay
mov p0,#6fh
clr p2.2
clr p3.0
lcall delay
setb p2.2
setb p3.0
lcall delay
mov p0,#3fh
clr p2.3
clr p3.2
lcall delay
setb p2.3
setb p3.2
lcall delay
mov p0,#3fh
clr p2.
51單片機 16:56:48
jb p0.7 k
改為
jb p0.7 k
是跳過判斷后的程序
風兒 16:57:32
jb p0.7 k
改為
jb p0.7 k
有什么區別嗎
風兒 16:57:47
是jnb
51單片機 16:59:07
jb
51單片機 16:59:14
我的
51單片機 17:00:31
這是你完整的單片機鍵盤程序,還是一部分
Raul(66686874) 17:00:34
JB 1時跳轉 JNB 0跳轉
風兒 17:01:00
一部分,還有的現實不出來
風兒 17:01:35
郁悶的是它就怎么不動作
風兒 17:01:56
JB 1時跳轉 JNB 0跳轉
我知道啊,我的硬件是0跳轉
51單片機 17:02:21
是按鍵去抖動
風兒 17:02:38
我在早也沒有加抖動
51單片機 17:03:26
你的原來沒有改的,且 成功運行的發過來
風兒 17:04:47
我就在這原程序上修改了,沒有了
其實也沒什么,現在就增加了比較這一塊
k0: setb p0.7
mov a,p3
ANL a,#11000000b
cjne a,#00000000b,k1
ljmp kk0 ;跳轉去執行RMA236的程序
k1: cjne a,#01000000b,k2
ljmp kk1 ;跳轉去執行RMA463、464、490、491的程序
k2: cjne a,#10000000b,k3
ljmp kk2 ;跳轉去執行RMA570的程序
k3: cjne a,#11000000b,k0
ljmp kk3 ;跳轉去執行RMA227、236成品程序
風兒 17:05:06
還有相應的程序增加了
風兒 17:07:29
我就是找不到原因現在怎么就不動作
51單片機 17:08:01
你家了你的程序后就改變了原來對數值保護,
還有在按鍵選擇多種操作時并不像你想的那么簡單
風兒 17:08:34
那你的意思是錯誤在哪里呢
51單片機 17:08:51
你能不能還原成原來的程序,還有p3
干什么的
51單片機 17:09:41
你要改變別人的程序,一定要是別人的程序變成自己的程序再改
風兒 17:10:05
p3是后面P0.6 P0.7跟我要的狀態比較
風兒 17:10:21
是我自己的程序
51單片機 17:11:27
那你系統說明你是要實現的動作
51單片機 17:12:03
按鍵程序對應這程序掃描
風兒 17:12:05
對啊
地方盛霖 17:12:11
各位大俠:基于單片機人機對話接口 是什么意思??
51單片機 17:12:27
按鍵和顯示,
風兒 17:13:12
是啊
地方盛霖 17:13:25
哦,這樣啊
地方盛霖 17:13:49
那我要做設計:該怎么入手啊 ?
51單片機 17:14:23
是否想過 當你按下時單片機鍵盤程序已經掃描很多次了
51單片機 17:14:49
總體框架圖要想好
地方盛霖 17:14:57
按鍵和顯示 什么呢?
風兒 17:15:10
沒有啊,我沒按按鍵的話還在等待我按下啊(一直在掃描)
地方盛霖 17:15:26
哦,總體。。。?
地方盛霖 17:16:20
要簡單一點 總體怎么?
51單片機 17:17:08
pp2: mov p0,#07h ;按按鍵7 4 * 1 2 3 4 5 6 # 鍵
clr p2.0
這是等待
地方盛霖 17:17:21
51單片機 大哥,我該怎么弄?
地方盛霖 17:17:50
好象我也要用啊
51單片機 17:18:17
風兒 17:18:28
這個不是啊,這個是顯示啊
51單片機 17:18:31
像這樣
51單片機 17:18:54
你的等你按鍵
51單片機 17:18:58
程序呢
地方盛霖 17:19:15
恩,我看看
風兒 17:19:20
kk0: jnb p0.7,pp1 ;跳轉去執行RMA236的程序
ljmp kk0
風兒 17:19:36
有四個這樣的程序啊
風兒 17:19:54
還有kk1 kk2 kk3
51單片機 17:20:37
我知道了
風兒 17:21:02
恩,我比較有四種狀態的嘛
51單片機 17:21:06
你 應該把判斷加入循環
51單片機 17:21:19
這樣a
風兒 17:21:20
我是在循環的啊
51單片機 17:22:03
kk0
51單片機 17:22:12
k0
風兒 17:22:22
對啊,我以前就是一種狀態
現在就是我多三種狀態,用P3.6 P3.7來判斷比較的
51單片機 17:22:52
你在把kk0改為k0
51單片機 17:22:59
運行以下
風兒 17:23:21
沒有啊,我的K0和 KK0是不同用處的
李秋章(215637873) 17:23:54
他提示什么錯誤?
風兒 17:24:07
沒有錯誤,就是按下按鍵不動作
風兒 17:24:16
燒錄OK
地方盛霖 17:24:18
51單片機 大哥,象這樣的總體圖能實現什么功能 啊,能幫我再構思下嗎,?
拜謝了
李秋章(215637873) 17:24:48
沒有用過這個單片機,呵呵
風兒 17:24:50
我現在有點事要出去下,幫我想想
有時間回來繼續討論哈
地方盛霖 17:25:48
還有上圖是不是有些復雜啊,還要離合器呢? 都不知道是什么東西
地方盛霖 17:26:36
51單片機 大哥 還在嗎?
51單片機 17:26:40
那是我的一個設計圖,我是讓你知道一下什么=是設計圖
51單片機 17:26:55
總體結構圖
地方盛霖 17:28:08
哦,設計總體圖
這個知道了,謝了啊
那么帶鍵盤和顯示 再簡單些 能實現什么功能啊?
51單片機 17:28:42
單片機右邊是單片機人機對話接口,左邊是執行部分
地方盛霖 17:29:37
右邊是單片機人機對話接口?
51單片機 17:30:03
反了
模 塊 名:恒流源PWM控制
//主要滿足: 1、PWM信號的輸出。
// 2、A/D采樣的轉換。
// 3、八段碼的顯示。
// 4、串口的通信。
// 5、人機對話及鍵盤調節。
// 6、數據的存儲。
// 7、PID調節。
//通信協議:波特率:128000bps。大于F0的為指令操作,小于F1為設定值操作。// 通信格式為16進制。接收到的數據為采樣電流。發送一個設定值會 // 返回同一個設定值。發送一個指令會返回同一個指令+00+指令。
地方盛霖 17:30:31
餓,我還以為我理解那么差呢
51單片機 17:31:01
恩
51單片機 17:31:04
不錯
地方盛霖 17:32:30
您看僅有這幾部分行不:
// 2、A/D采樣的轉換。
// 3、八段碼的顯示。
// 4、串口的通信。
// 5、人機對話及鍵盤調節。
51單片機 17:32:50
干什么
地方盛霖 17:33:56
en ,加一個輸入信號,通過鍵盤,然后讓它顯示