mk7a11p mcu的電子壺源程序 供大家參考
0.png (44.38 KB, 下載次數: 67)
下載附件
2018-7-9 02:44 上傳
單片機源程序如下:
- #include "mk7a11p.inc" ;編譯該文檔需包含"mk7a11p.inc"文件
- ;------------------------------------------------------------------
- ;芯片型號(mk7a11p)
- ;------------------------------------------------------------------
- ;配置寄存器設置說明(CONFIG)
- ;1-----------FOSC=RC ;LS,NS,HS,RC
- ;2-----------INRC=ON ;ON,OFF
- ;3-----------CPT=OFF ;ON,OFF
- ;4-----------WDTE=Disable ;Enable,Disable
- ;5-----------LV=Low Vol Reset ON ;Low Vol Reset ON,Low Vol Reset OFF
- ;6-----------RESET=...input... ;...input...,...reset...
- ;------------------------------------------------------------------
- a_buf equ 0x20 ;acc緩存器
- status_buf equ 0x21 ;status緩存器
- tm_r equ 0x22 ;1s計時
- pb_buf equ 0x23 ;端口緩存
- del_r0 equ 0x24 ;延時計數
- del_r1 equ 0x25 ;延時計數
- gs_flag equ 0x26 ;高水位標志
- cs_flag equ 0x27 ;常水位標志
- ns_flag equ 0x28 ;濃縮位標志
- fmq_flag equ 0x29 ;蜂鳴器標志位
- ct1_flag equ 0x2A ;加熱次數標志
- ct2_flag equ 0x2B ;加熱次數標志
- ct3_flag equ 0x2C ;加熱次數標志
- grcs_flag equ 0x2e ;加熱次數標志
- grcs0_flag equ 0x2e ;加熱次數標志
- ;------------------------------------------------------------------
- org 0x3fe ;mk7a11p的中斷向量地址定義
- lgoto int ;跳轉到中斷程序入口
- org 0x3ff ;mk7a11p的復位向量地址定義
- lgoto main ;跳轉到主程序入口
- ;------------------------------------------------------------------
- org 0x000
- int ;中斷入口地址
- ;保護現場
- movam a_buf
- swap status,a
- movam status_buf
- ;---------------------------------------------------------------
- btsc irqf,tm0f ;判斷是不是tmr0溢出中斷
- lgoto int_tm0 ;進入tmr0中斷服務程序
- ;---------------------------------------------------------------
- int_end
- ;中斷結束要恢復現場
- swap status_buf,a
- movam status
- swap a_buf,m ;這里不能用"mov a_buf,a"因為
- swap a_buf,a ;"mov a_buf,a"會影響status
- reti
- ;------------------------------------------------------------------
- int_tm0 ;tmr0中斷服務程序
- bc irqf,tm0f ;清除tmr0中斷標志
- ;---------------------------------------------------------------
- inc tm_r,m
- movla .1 ;4x250=1s
- xor tm_r,a
- btss status,z ;邏輯結果操作結果零標記位
- lgoto int_end
- clr tm_r
- ;---------------------------------------------------------------
- movla b'00100000'
- xor portb,m ;PA0的High Low切換
- lgoto int_end
- ;------------------------------------------------------------------
- delay
- decsz del_r0,m ;延時消抖
- lgoto delay
- movla .255
- movam del_r0
- decsz del_r1,m
- lgoto delay
- ret ;子程序返回
- main ;主程序入口地址定義
- ;PortA端口方向及狀態設定
- movla b'11110000'
- iodir porta
- clr porta
- clr pa_pdm
- ;------------------------------------------------------
- ;PortB端口方向及狀態設定pb2高水位鍵盤和綠燈控制
- movla b'11001001';六個鍵 PB0 PB3設置為輸入
- iodir portb
- clr portb
- clr pb_pod ;lou ji kai lu
- clr pb_pdm ;gong neng xuan ze
- clr pb_pup ;shang la dian zu qi
- bs pb_pup, 0
- ;bs pb_pup, 3
- ;------------------------------------------------------初始化
- movla .0
- MOVAM a_buf
- movla .0
- MOVAM status_buf
- movla .0
- MOVAM tm_r
- movla .0
- MOVAM pb_buf
- movla .0
- MOVAM gs_flag
- movla .0
- MOVAM cs_flag
- movla .0
- MOVAM ns_flag
- movla .0
- MOVAM fmq_flag
- movla .0
- MOVAM ct1_flag
- movla .0
- MOVAM ct2_flag
- movla .0
- MOVAM ct3_flag
- movla .0
- MOVAM grcs_flag
- movla .0
- MOVAM grcs0_flag
- ;bs pb_pup, 3
- ; movla b'00000001'
- ; xor portb,m ;PA0的High Low切換
- ;----------------------------------------------------------
- ;PortB端口8個IO喚醒使能
- ;movla b'11111111'
- ;movam wake_up
- ;---------------------------------------------------
- ;配置TMR0,預分頻比為1:16
- ;TMR0初始值為250
- movla b'11000011'
- select
- movla .12
- movam tmr0 ;tmr0的溢出時間是:250x16=4ms
- ;---------------------------------------------------
- ;tmr0中斷使能
-
- ;inc del_r0,m ;tmr0的溢出時間是:250x16=4ms
- movla .255
- movam del_r0
- movla .255
- movam del_r1
- ;--------------------------------------延時一段時間等待電路穩定
- lcall delay
- lcall delay
- lcall delay
- ; lcall delay
- ; lcall delay
- ;--------------------------------------——————第一次讀取按鍵;
- duqu1
- movla b'11001101' ;六個鍵 PB0 PB3設置為輸入
- iodir portb ; pb2 設 置為輸入
- mov portb,a ;讀取端口狀態
- movam pb_buf ;保存端口狀態
- COM pb_buf, m ;取反端口狀態
- lgoto qu01_flag ;延時狀態
- yqu0
- movla b'11001101' ;六個鍵 PB0 PB3設置為輸入
- iodir portb ; pb2 設 置為輸入
- mov portb,a ;二次讀取端口狀態
- AND pb_buf, m
- BTSc pb_buf,2 ;測試pb2 為5零sikp高水位測試位
- lgoto qingchu
- BTSc pb_buf,3 ;測試pb2 為5零sikp高水位測試位
- lgoto qingchu
- movam pb_buf ;一次測試pb0通過 。
- inc grcs0_flag,m
- BTSs grcs0_flag,7 ;八次測試pb0通過 。
- lgoto duqu1
- BTSs grcs0_flag,6 ;八次測試pb0通過 。
- lgoto duqu1
- BTSs grcs0_flag,5 ;八次測試pb0通過 。
- lgoto duqu1
- BTSc pb_buf,2
- lgoto sns_flag
- lgoto sgs_flag
- qu01_flag
- movla .200
- MOVAM fmq_flag
- qu011_flag
- movla b'11001001' ;六個鍵 PB0 PB3設置為輸入
- iodir portb ; pb2 設 置為輸入
- bc portb, 2 ;綠色指示燈亮
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- DECSZ fmq_flag, m
- lgoto qu011_flag
- lgoto yqu0 ;
- qingchu
- movla .0
- MOVAM grcs0_flag
- lgoto duqu1
-
- sgs_flag
- movla .1
- MOVAM gs_flag
- lgoto jiare_flag ;只可能一個鍵被按下檢測到后直接跳轉加熱
- sns_flag
- BTSc pb_buf,3 ;測試pb3 為零sikp
- lgoto scs_flag
- movla .1
- MOVAM ns_flag
- lgoto jiare_flag ;只可能一個鍵被按下檢測到后直接跳轉加熱
- scs_flag movla .1
- MOVAM cs_flag
- ;----------------------------------------------------------------電路全功率加熱
- jiare_flag
- bc portb, 4 ;紅色指示燈亮,
- movla b'10000001'
- movam irqm
- clr irqf
- ;bs portb, 5 ;打開蜂鳴器
- movla .5
- movam del_r1
- lcall delay ;蜂鳴器響一聲,
- ;lcall delay ;蜂鳴器響一聲,
- lcall delay ;蜂鳴器響一聲,
- lcall delay ;蜂鳴器響一聲,
- movla b'00000000'
- movam irqm
- clr irqf
- ;bc portb, 5 ;關閉蜂鳴器
-
- bs portb, 1 ;繼電器打開全功率加熱。
- bs portb, 0
- ; bs portb, 0 ;繼電器打開全功率加熱。
-
-
- jiare
- mov portb,a ;讀取端口狀態
- movam pb_buf ;保存端口狀態
- btss pb_buf,0 ;測試pb0
- lgoto jiare ;等待溫控器信號為零時跳出循環體
- nop
- bc portb, 4 ;紅色指示燈亮,
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- btss pb_buf,0 ;測試pb0
- lgoto jiare ;等待溫控器信號為零時跳出循環體
- nop
- nop
- nop
- nop
- lcall delay
- nop
- nop
- nop
- nop
- btss pb_buf,0 ;測試pb0
- lgoto jiare ;等待溫控器信號為零時跳出循環體
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- btss pb_buf,0 ;測試pb0
- lgoto jiare ;等待溫控器信號為零時跳出循環體
- ;------------------------------------------------------------加熱完成延時加熱;
- BTSc gs_flag,0 ;為一表示高電平沒有按鍵,跳過指令
- lgoto wcjiare1 ;高水位加熱后直接完成加熱狀態
- BTSc cs_flag,0
- lgoto csjiare_flag ;常水位加熱后延時2分鐘
- BTSc ns_flag,0
- lgoto nsjiare1_flag ;濃縮水位加熱后延時6分鐘
- csjiare_flag
- movla .121
- MOVAM fmq_flag
- csjiare1_flag
- lcall delay
- lcall delay
- lcall delay
- lcall delay
- lcall delay
- DECSZ fmq_flag, m
- LGOTO csjiare1_flag
- LGOTO wcjiare1
- nsjiare1_flag
- movla .180
- MOVAM fmq_flag
- nsjiare11_flag
- lcall delay
- lcall delay
- lcall delay
- lcall delay
- lcall delay
- DECSZ fmq_flag, m
- LGOTO nsjiare11_flag
- nsjiare2_flag
- movla .180
- MOVAM fmq_flag
- nsjiare22_flag
- lcall delay
- lcall delay
- lcall delay
- lcall delay
- lcall delay
- DECSZ fmq_flag, m
- LGOTO nsjiare22_flag
- wcjiare1
- movla b'11001001';六個鍵 PB0 PB3設置為輸入
- iodir portb ; pb2 設 置為輸出
- bs portb, 4 ;紅色指示燈滅,
- bc portb, 1 ;關閉繼電器打開全功率加熱。
- bs portb, 2 ;綠色指示燈亮
- movla .10 ;蜂鳴器響十聲,
- MOVAM fmq_flag
- sss1_flag
- movla b'10000001'
- movam irqm
- clr irqf
- lcall delay
- lcall delay
- movla b'00000000'
- movam irqm
- clr irqf
- lcall delay
- lcall delay
- DECSZ fmq_flag, m
- LGOTO sss1_flag
- bc portb, 5 ;關蜂鳴器,
- ;----------------------------------------------------------加熱延時完成關閉加熱;
- ;----------------------------------------------------------加熱完成二次讀取按鍵;
- baowen
- movla b'11001101' ;六個鍵 PB0 PB3設置為輸入
- iodir portb ; pb2 設 置為輸入
- mov portb,a ;讀取端口狀態
- movam pb_buf ;保存端口狀態
- COM pb_buf, m ;取反端口狀態
- lgoto qu1_flag ;延時狀態
- yqu
- movla b'11001101' ;六個鍵 PB0 PB3設置為輸入
- iodir portb ; pb2 設 置為輸入
- mov portb,a ;二次讀取端口狀態
- AND pb_buf, m
- BTSc pb_buf,2 ;測試pb2 為5零sikp高水位測試位
- lgoto qingchu0
- BTSc pb_buf,3 ;測試pb2 為5零sikp高水位測試位
- lgoto qingchu0
- movam pb_buf ;一次測試pb0通過 。
- inc grcs_flag,m
- BTSs grcs_flag,7 ;八次測試pb0通過 。
- lgoto baowen
- BTSc pb_buf,2
- lgoto sns1_flag
- lgoto jiare2
- qu1_flag
- movla .100
- MOVAM fmq_flag
- qu11_flag
- movla b'11001001' ;六個鍵 PB0 PB3設置為輸入
- iodir portb ; pb2 設 置為輸入
- bs portb, 2 ;綠色指示燈亮
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- DECSZ fmq_flag, m
- lgoto qu11_flag
- lgoto yqu ;
- qingchu0
- movla .0
- MOVAM grcs_flag
- lgoto baowen
- sns1_flag
- BTSc pb_buf,3 ;測試pb3 為零sikp濃縮水位測試位
- lgoto scs1_flag ;不是高水位也不是濃縮水位
- BTSc gs_flag,0 ;是濃縮水位,
- lgoto sss_flag ;高水位轉濃縮水位,轉加熱6分鐘
- BTSc cs_flag,0 ;是濃縮不是高水位
- lgoto loop3 ;常水位轉濃縮水位,加熱四分鐘
- lgoto jiare2 ;是濃縮水位,不是高水位,也不是常水位轉保溫加熱
- scs1_flag ;二次讀取為常水位。
- BTSc gs_flag,0
- lgoto loop ;高水位轉常水位 加熱兩分鐘
- lgoto jiare2 ;不是高水位轉常水位轉到保溫加熱。
- loop
- BTSc ct1_flag,0
- lgoto jiare2
- inc ct1_flag,m
- movla b'11001001' ;六個鍵 PB0 PB3設置為輸入
- iodir portb ; pb2 設 置為輸入
- bc portb, 2 ;綠色指示燈亮
- bc portb, 4 ;紅色指示燈亮,
- bs portb, 1 ;繼電器打開全功率加熱。
- movla .120
- MOVAM fmq_flag
- nsjiare44_flag ;延時
- lcall delay
- lcall delay
- lcall delay
- lcall delay
- lcall delay
- DECSZ fmq_flag, m
- LGOTO nsjiare44_flag
- lgoto wcjiare1 ;延時加熱后轉保溫加熱
- sss_flag
- BTSc ct2_flag,0
- lgoto jiare2
- BTSc ct1_flag,0
- lgoto nsjiare045_flag
- inc ct2_flag,m
- movla b'11001001' ;六個鍵 PB0 PB3設置為輸入
- iodir portb ; pb2 設 置為輸入
- bc portb, 2 ;綠色指示燈亮
- bc portb, 4 ;紅色指示燈亮,
- bs portb, 1 ;繼電器打開全功率加熱。
- movla .120
- MOVAM fmq_flag
- nsjiare45_flag ;延時
- lcall delay
- lcall delay
- lcall delay
- lcall delay
- lcall delay
- DECSZ fmq_flag, m
- LGOTO nsjiare45_flag
- nsjiare045_flag
- inc ct2_flag,m
- bc portb, 2 ;綠色指示燈滅
- bc portb, 4 ;紅色指示燈亮,
- bs portb, 1 ;繼電器打開全功率加熱。
- movla .230
- MOVAM fmq_flag
- nsjiare46_flag ;延時
- lcall delay
- lcall delay
- lcall delay
- lcall delay
- lcall delay
- DECSZ fmq_flag, m
- LGOTO nsjiare46_flag
- lgoto wcjiare1 ;延時六分鐘加熱后轉保溫加熱
- loop3
- BTSc ct3_flag,0
- lgoto jiare2
- inc ct3_flag,m
- movla b'11001001' ;六個鍵 PB0 PB3設置為輸入
- iodir portb ; pb2 設 置為輸入
- bc portb, 2 ;綠色指示燈亮
- bc portb, 4 ;紅色指示燈亮,
- bs portb, 1 ;繼電器打開全功率加熱。
- movla .240
- MOVAM fmq_flag
- nsjiare47_flag ;延時
- lcall delay
- lcall delay
- lcall delay
- lcall delay
- lcall delay
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
14 6A12_dzkwh.rar
(15.45 KB, 下載次數: 6)
2018-7-8 22:13 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|