单片机教学打铃控制器程序设计课程设计Word下载.docx
《单片机教学打铃控制器程序设计课程设计Word下载.docx》由会员分享,可在线阅读,更多相关《单片机教学打铃控制器程序设计课程设计Word下载.docx(33页珍藏版)》请在冰豆网上搜索。
![单片机教学打铃控制器程序设计课程设计Word下载.docx](https://file1.bdocx.com/fileroot1/2023-1/26/807a3cdc-63f3-4d83-beea-9c35179bb483/807a3cdc-63f3-4d83-beea-9c35179bb4831.gif)
micro;
F
4
电解电容
220&
F/16V
二极管
1N4007
发光二极管
Ф3MM、红光
三极管
9013
晶体
12MHz(矮封装)
集成块
7805
AT89S52
24C02
7407
IC插座
40PIN
8PIN
14PIN
数码管
2位动态、红光、共阴极(FJ5202AH)
3
继电器
5V、AC220V/5A(HRS4H-S-DC5V)
接插件
IDC10
1套
按键
国产欧姆龙轻触按键,带透明帽
8套
--------------------------------------------------------------------------------
程序:
;
**************教学打铃控制器程序*********
CPU:
AT89S52,Fosc=12MHz
++++++++++++++++++变量定义+++++++++++++++
SET_TIMEBITP1.0;
时间设定
SET_ALARMBITP1.1;
打铃设定
LEFTBITP1.2;
左移位
UPBITP1.3;
上翻/加1
DOWNBITP1.4;
下翻/减1
RIGHTBITP1.5;
右移位
ESCBITP1.6;
取消/退出
ENTERBITP1.7;
确认
KEY_BUFEQU30H;
原按键状态
KEY_STEQU31H;
键闭合标志,ON:
0FFH,OFF:
00H
SCLBITP3.3;
IIC时钟线
SDABITP3.2;
IIC数据线
FLASH_SBITP3.1;
秒闪
CONTRELBITP3.4;
控制;
1=ON
H_MEMEQU10H;
时
M_MEMEQU11H;
分
S_MEMEQU12H;
秒
CT_50MSEQU13H;
50mS计数器
NEW_TIMEEQU14H;
时间更新标志,0FFH更新
DIS_MEM1EQU15H;
显示数据存储器1
DIS_MEM2EQU16H;
显示数据存储器2
DIS_MEM3EQU17H;
显示数据存储器3
DIS_BUF1EQU20H;
显示缓冲器1(段码,左)
DIS_BUF2EQU21H;
显示缓冲器2(段码)
DIS_BUF3EQU22H;
显示缓冲器3(段码)
DIS_BUF4EQU23H;
显示缓冲器4(段码)
DIS_BUF5EQU24H;
显示缓冲器5(段码)
DIS_BUF6EQU25H;
显示缓冲器6(段码,右)
AL_NUMBEREQU26H;
打铃序号
AL_TOTAEQU27H;
打铃点总数
ALARM_STEQU28H;
打铃状态,0FFH正在打铃
TIME_OVEREQU29H;
按键返回时间计数器
TOTA_ADDREQU60H;
打铃点总数在24C02中的存储地址
ORG0000H
AJMPSTART
ORG0002BH
AJMPINT_T0;
T2中断向量
ORG0030H
START:
MOVSP,#60H
CLRCONTREL
CLRFLASH_S
MOVH_MEM,#12
MOVM_MEM,#0
MOVS_MEM,#0
MOVCT_50MS,#20
MOVNEW_TIME,#0
MOVKEY_ST,#0
MOVR4,#TOTA_ADDR;
从24C02读打铃时间点总数
MOVR0,#AL_TOTA
MOVR3,#1
ACALLRD_EEROM
MOVA,AL_TOTA;
总数大于0,小于、等于40判断
JZJMP_RD
CLRC
SUBBA,#40
JCRD_AL_LIST
MOVAL_TOTA,#0
MOVR4,#TOTA_ADDR
ACALLWR_EEROM
SJMPJMP_RD
RD_AL_LIST:
从24C02读打铃时间表
RLA
MOVR3,A
R0:
RAM地址指针,R2:
8位移位计数器
R3:
数据字节计数器
R4:
24C02存储地址
MOVR0,#80H
MOVR4,#00H
JMP_RD:
MOVTH2,#3CH;
T2工作方式、时间常数
MOVTL2,#0ABH
MOVRCAP2H,#3CH
MOVRCAP2L,#0ABH
MOVT2CON,#04H
SETBET2;
开中断
SETBEA
WAITE:
ACALLDISPLAY
ACALLKEY_CHECK
MOVA,KEY_ST
CJNEA,#00H,KEY_MAIN
MOVA,NEW_TIME
CJNEA,#0FFH,WAITE
NEW_DIS:
MOVA,H_MEM
ACALLHBCD
MOVDIS_MEM1,A
MOVA,M_MEM
MOVDIS_MEM2,A
MOVA,S_MEM
MOVDIS_MEM3,A
ACALLDIS_TIME
MOVA,ALARM_ST
JNZCHEK_OFF
JNZWAITE
ACALLCHEK_AL;
打铃检测
CHEK_OFF:
MOVA,S_MEM
SUBBA,#20
JCWAITE
MOVALARM_ST,#0
SJMPWAITE
SJMP$
********打铃控制子程序***************
CHEK_AL:
MOVA,AL_TOTA
JZCHEK_END
MOVR6,AL_TOTA
CHK_LOOP:
MOVA,@R0
CJNEA,H_MEM,NEXT_AL_1
INCR0
MOVA,@R0
CJNEA,M_MEM,NEXT_AL_2
SETBCONTREL
MOVALARM_ST,#0FFH
SJMPCHEK_END
NEXT_AL_1:
INCR0
NEXT_AL_2:
DJNZR6,CHK_LOOP
CHEK_END:
RET
********键盘处理程序段***************
KEY_MAIN:
JNBSET_TIME,TIME_SET
JNBSET_ALARM,JMP_SET_A
SJMPNEW_DIS
JMP_SET_A:
AJMPALARM_SET
========时间设置=====================
TIME_SET:
MOVTIME_OVER,#30
MOVR5,H_MEM
MOVR6,M_MEM
MOVR7,S_MEM
SET_H:
JNBFLASH_S,GATE_H
MOVDIS_MEM1,#0AAH
SJMPCLS_H
GATE_H:
MOVA,R5
MOVA,R6
MOVA,R7
CLS_H:
ACALLDIS_TIME
ACALLDISPLAY
CJNEA,#0FFH,JMP_1
DJNZTIME_OVER,JMP_1
AJMPWAITE
JMP_1:
ACALLKEY_CHECK
CJNEA,#0FFH,SET_H
JNBUP,H_UP
JNBDOWN,H_DOWN
JNBLEFT,JMP_SET_S
JNBRIGHT,SET_M
JNBESC,JMP_ESC
JNBENTER,JMP_OK
SJMPSET_H
JMP_ESC:
AJMPTIME_SET_ESC
JMP_OK:
AJMPTIME_SET_OK
JMP_SET_S:
AJMPSET_S
H_UP:
CJNER5,#23,INC_H
MOVR5,#0FFH
INC_H:
INCR5
AJMPGATE_H
H_DOWN:
CJNER5,#0,DEC_H
MOVR5,#24
DEC_H:
DECR5
===========分钟设置===============
SET_M:
JNBFLASH_S,GATE_M
MOVDIS_MEM2,#0AAH
SJMPCLS_M
GATE_M:
MOVA,R6
MOVA,R5
CLS_M:
CJNEA,#0FFH,JMP_2
DJNZTIME_OVER,JMP_2
JMP_2:
CJNEA,#0FFH,SET_M
JNBUP,M_UP
JNBDOWN,M_DOWN
JNBLEFT,JMP_SET_H
JNBRIGHT,SET_S
JNBESC,TIME_SET_ESC
JNBENTER,TIME_SET_OK
SJMPSET_M
M_UP:
CJNER6,#59,INC_M
MOVR6,#0FFH
INC_M:
INCR6
AJMPGATE_M
M_DOWN:
CJNER6,#0,DEC_M
MOVR6,#60
DEC_M:
DECR6
JMP_SET_H:
AJMPSET_H
============秒设置=================
SET_S:
JNBFLASH_S,GATE_S
MOVDIS_MEM3,#0AAH
SJMPCLS_S
GATE_S:
MOVA,R7
CLS_S:
CJNEA,#0FFH,JMP_3
DJNZTIME_OVER,JMP_3
JMP_3:
CJNEA,#0FFH,SET_S
JNBUP,S_UP
JNBDOWN,S_DOWN
JNBLEFT,JMP_SET_S_M
JNBRIGHT,JMP_S_H
SJMPSET_S
JMP_S_H:
AJMPSET_H
S_UP:
CJNER7,#59,INC_S
MOVR7,#0FFH
INC_S:
INCR7
AJMPGATE_S
S_DOWN:
CJNER7,#0,DEC_S
MOVR7,#60
DEC_S:
DECR7
JMP_SET_S_M:
AJMPSET_M
======================================
TIME_SET_ESC:
AJMPNEW_DIS;
时间设置取消/返回
TIME_SET_OK:
MOVS_MEM,R7;
时间设置确认/返回
MOVM_MEM,R6
MOVH_MEM,R5
AJMPNEW_DIS
=========打铃设置程序段===============
ALARM_SET:
MOVTIME_OVER,#20
MOVAL_NUMBER,AL_TOTA
AL_LIST:
MOVA,AL_NUMBER
JNZNUMBER_N
MOVDIS_MEM1,#0
AJMPWAITE_A
NUMBER_N:
DECA
ADDA,#80H
MOVR0,A
MOVA,AL_NUMBER
WAITE_A:
ACALLDISPLAY
CJNEA,#0FFH,JMP_4
DJNZTIME_OVER,JMP_4
JMP_4:
CJNEA,#0FFH,WAITE_A
JNBUP,NUM_UP
JNBDOWN,NUM_DOWN
JNBESC,JMP_ESC_AL
JNBENTER,JMP_OK_AL
JNBSET_ALARM,JMP_DEL_AL
JNBSET_TIME,CHANGE_AL
SJMPWAITE_A
JMP_DEL_AL:
AJMPDEL_AL
-------------------------------------
NUM_UP:
MOVA,AL_NUMBER
CJNEA,AL_TOTA,INC_NUM
MOVAL_NUMBER,#0FFH
INC_NUM:
INCAL_NUMBER
AJMPAL_LIST
NUM_DOWN:
CJNEA,#0,DEC_NUM
SJMPJ_DECNUM
DEC_NUM:
DECAL_NUMBER
J_DECNUM:
AJMPAL_LIST
==========修改打铃时间点=================
CHANGE_AL:
JZJMP_ADD_AL
MOVR6,A
MOVR7,A
------------时修改------------------
SET_AL_H:
JNBFLASH_S,GATE_AL_H
SJMPCLS_AL_H
GATE_AL_H:
CLS_AL_H:
CJNEA,#0FFH,JMP_5
DJNZTIME_OVER,JMP_5
JMP_5:
CJNEA,#0FFH,SET_AL_H
JNBUP,AL_H_UP
JNBDOWN,AL_H_DOWN
JNBLEFT,SET_AL_M
JNBRIGHT,SET_AL_M
JNBESC,JMP_AL_LIST
JNBENTER,JMP_SET_AL_OK
SJMPSET_AL_H
JMP_ESC_AL:
AJMPESC_AL
JMP_OK_AL:
AJMPOK_AL
JMP_ADD_AL:
AJMPADD_AL
JMP_SET_AL_OK:
AJMPSET_AL_OK
JMP_AL_LIST:
AL_H_UP:
CJNER6,#23,INC_H_AL
INC_H_AL:
INCR6
AJMPGATE_AL_H
AL_H_DOWN:
CJNER6,#0,DEC_H_AL
MOVR6,#24
DEC_H_AL:
DECR6
----------分修改----------------
SET_AL_M:
JNBFLASH_S,GATE_AL_M
SJMPCLS_AL_M
GATE_AL_M:
CLS_AL_M: