1.包括流水灯,时钟,计时器,简易的用4x4键盘控制的计算器
2.四个按键选择功能,直接对应那种一般开发板配套的红外遥控器的1234键(试过是可以的)当然仿真中不包括红外,红外选项是多余的
仿真中不包括红外
3.计时器,上键运行,下键清零,右键暂停,右键长按切换时钟
4.时钟的右键切换调整,长按到计时器,调整位会闪烁
5计算器用4x4按键控制
6.代码用的汇编
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- LCD_RS EQU P2.0 ;1602控制
- LCD_RW EQU P2.1 ;......
- LCD_E EQU P2.2 ;脉冲
- LCD_D7 EQU P0.7 ;
- LCD_DATA EQU P0 ;1602数据口
- LCD_JISHU EQU 20H ;1602写数据计数
- LCD_CAIDAN EQU 21H ;1602菜单编号
- LCD_CAIDAN_YE EQU 22H ;1602页编号
- KEY_UP EQU P2.3 ;上键
- KEY_DOWN EQU P2.4 ;下键
- KEY_OK EQU P2.5 ;确认键
- KEY_EXIT EQU P2.6 ;退出键
- LCD_BEI EQU P2.7 ;1602背光
- EXIT_BIAOZHI EQU 23H.0 ;计时器,中按退出会置一标志位
- OK_BIAOZHI EQU 23H.1
- UP_BIAOZHI EQU 23H.2
- DOWN_BIAOZHI EQU 23H.3
- DINGSHI_JISHU EQU 24H ;用定时器延时计数
- LED EQU P1 ;
- ;数码管595 ;
- MINGXIANG EQU P3.3
- HC595_DATA EQU P3.4 ;数码管数据,移位输出,,,复用hc164数据口
- HC595_SLCP EQU P3.5 ;读入数据端
- HC595_SHCP EQU P3.6 ;刷新显示端,、、复用hc164的clk
- HC595_SHI EQU 25H ;时钟的时分秒
- HC595_FEN EQU 26H ;
- HC595_MIAO EQU 27H ;
- ;矩阵键盘.......
- JIANPAN1 EQU P3.0
- JIANPAN2 EQU P3.1
- HC164_DATA EQU P3.4
- HC164_CLK EQU P3.7
- JIANSHUXU EQU 28H ;矩阵键盘按下的顺序,
- JISUANQI_DATA1 EQU 29H ;
- JISUANQI_YUNSUAN EQU 2AH ;
- JISUANQI_DATA2 EQU 2BH ;
- JISUANQI_JIEGUO1 EQU 2CH ;
- JISUANQI_JIEGUO2 EQU 2DH ;
- ANJIAN_CHANGAN EQU 2FH
- OKCHANGAN_BIAOZHI EQU 23H.4 ;
- HONGWAIZ_ EQU P3.2
- HONGWAIZ_MA EQU 30H
- LEDYANSHI_JISHU EQU 31H
- ORG 0000H
- AJMP MAIN
- ORG 03H
- LJMP WAIBU0
- ORG 0BH
- LJMP T0DINGSHI
- ORG 001BH
- LJMP T1DINGSHI;定时器中断
- ORG 0030H
- MAIN:
- LCALL SHUMA_JIANCE
- LCALL SHUMA_QINGLING
- MOV HONGWAIZ_MA,#00H
- CLR LCD_BEI
- LCALL LCD_XIANSHI ;1602初始化,欢迎界面
- SETB PT0 ;把定时器t1设置为高优先级
- MOV TMOD,#11H ;T1为工作方式一
- MOV IE,#8BH ;允许T1中断,T0,外部中断0
- MOV TH1,#0D8H ;放入数据
- MOV TL1,#0F0H
- MOV TH0,#0DBH
- MOV TL0,#0F0H
- SETB TR1 ;启动T1定时器
- LOOP0:
- LCALL ANJIAN_RENYI ;按键判断
- SJMP LOOP0
- SJMP $
- WAIBU0:
- CLR EA
- PUSH 01H
- PUSH 02H
- PUSH 03H
- PUSH 04H
- PUSH ACC
- MOV A,HONGWAIZ_MA
- CJNE A,#0,WAIBU0_JIESHU
- ;MOV ANJIAN_CHANGAN,#10
- WAIBU0_LOOP8:
- MOV R3,#10
- WAIBU0_LOOP7:
- LCALL DELAY840US
- JB HONGWAIZ_,WAIBU0_JIESHU
- DJNZ R3,WAIBU0_LOOP7
- WAIBU0_LOOP13:
- ;MOV R1,ANJIAN_CHANGAN
- ;CJNE R1,#00H,WAIBU0_LOOP9
- ;WAIBU0_JIESHU_1:
- ;LJMP WAIBU0_JIESHU
- WAIBU0_LOOP9:
- JNB HONGWAIZ_,WAIBU0_LOOP13
- LCALL DELAY4MS750US
- MOV R4,#8H
- MOV R3,#4H
- WAIBU0_LOOP1:
- ;MOV R1,ANJIAN_CHANGAN
- ;CJNE R1,#00H,WAIBU0_LOOP10
- ;LJMP WAIBU0_JIESHU
- WAIBU0_LOOP10:
- JNB HONGWAIZ_,WAIBU0_LOOP1
- LCALL DELAY840US
- JB HONGWAIZ_,WAIBU0_LOOP0
- CLR ACC.0
- RLC A
- DJNZ R4,WAIBU0_LOOP1
- LJMP WAIBU0_LOOP2
- WAIBU0_LOOP0:
- SETB ACC.0
- RLC A
- WAIBU0_LOOP11:
- ;MOV R1,ANJIAN_CHANGAN
- ;CJNE R1,#00H,WAIBU0_LOOP12
- ;LJMP WAIBU0_JIESHU
- WAIBU0_LOOP12:
- JB HONGWAIZ_,WAIBU0_LOOP11
- DJNZ R4,WAIBU0_LOOP1
- WAIBU0_LOOP2:
- RRC A
- CJNE R3,#04H,WAIBU0_LOOP3
- CJNE A,#00H,WAIBU0_JIESHU
- LJMP WAIBU0_LOOP6
- WAIBU0_LOOP3:
- CJNE R3,#03H,WAIBU0_LOOP4
- CJNE A,#0FFH,WAIBU0_JIESHU
- LJMP WAIBU0_LOOP6
- WAIBU0_LOOP4:
- CJNE R3,#02H,WAIBU0_LOOP5
- MOV R2,A
- LJMP WAIBU0_LOOP6
- WAIBU0_LOOP5:
- CJNE R3,#01H,WAIBU0_LOOP6
- ADD A,R2
- CJNE A,#0FFH,WAIBU0_JIESHU
- CJNE R2,#30H,WAIBU0_HONGWAI_J2
- MOV HONGWAIZ_MA,#01H
- WAIBU0_HONGWAI_J2:
- CJNE R2,#18H,WAIBU0_HONGWAI_J3
- MOV HONGWAIZ_MA,#02H
- WAIBU0_HONGWAI_J3:
- CJNE R2,#7AH,WAIBU0_HONGWAI_J4
- MOV HONGWAIZ_MA,#03H
- WAIBU0_HONGWAI_J4:
- CJNE R2,#10H,WAIBU0_JIESHU
- MOV HONGWAIZ_MA,#04H
- LJMP WAIBU0_JIESHU
- WAIBU0_LOOP6:
- MOV R4,#08H
- DJNZ R3,WAIBU0_LOOP1
- LJMP WAIBU0_JIESHU
- WAIBU0_JIESHU:
- POP ACC
- POP 04H
- POP 03H
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
显示键盘.zip
(173.42 KB, 下载次数: 28)
|