1 ;Writed by LinXiwei,on 2006.06.15 2 ;完成功能:等待按键输入,然后将所读到的按键码转换成十进制,送回ZLG显示,同时将前面的显示内容左移,并使当前按键值闪烁 3 4 ;*******ZLG7289 PARAMETERS******* 5 ZLG_BIT_CNT EQU 30H ;The number of data sended ;循环次数 6 ZLG_REC_BUF EQU 31H ;The buffer of data received ;做接收缓冲,传过来什么先放在该变量中 7 ZLG_SEND_BUF EQU 32H ;The buffer of data sended ;做发送缓冲, 8 ZLG_DECIMAL EQU 33H ;The digit of decimal ;要显示的十进制的数字 9 10 ZLG_CS EQU P0.0 ;/CS of ZLG7289 ;四根引脚线:/CS,CLK,DATA,/KEY 11 ZLG_CLK EQU P0.1 ;CLK of ZLG7289 12 ZLG_DATA EQU P0.2 ;DIO of ZLG7289 13 ZLG_KEY EQU P0.3 ;/KEY of ZLG7289 ;key:告诉cpu有按键 14 ;定义的几个变量四根线将ZLG和cpu连起来 15 ;*******DELAY PARAMETERS******* 16 VAR_DELAY EQU 71H ;The variable for delay function 17 18 org 0000H 19 ljmp MAIN 20 21 org 0030H 22 MAIN: 23 setb ZLG_CS ;先关闭 24 setb ZLG_KEY ;先关闭 25 setb ZLG_DATA ;先关闭 26 call delay_50 ;给时间上电各自启动,让ZLG正常上电 27 28 mov ZLG_SEND_BUF,#10100100B ;Initialize ZLG7289,初始化zlg放到变量里 29 call zlg_send ;调用一个发送函数 30 setb ZLG_CS ;Set standby mode 31 32 MAIN_LOOP: 33 jb ZLG_KEY,$ ;Wait for keyboard,等待按键按下,不知道几号键,64个按键中的一个 34 ;如果按键按下去: 35 mov ZLG_SEND_BUF,#00010101B ;Send the command of reading keyboard 36 lcall zlg_send ;发一个读按键的指令 37 lcall zlg_receive ;Read the data of keyboard,接收 38 setb ZLG_CS ;Set standby mode 39 40 mov b,#10 41 mov a,ZLG_REC_BUF ;按键有些有两位数,把原来的数左移两位,空两个位置出来显示数字:按键编号,然后再把新的两位设成闪烁 42 div ab 43 mov ZLG_DECIMAL,a 44 45 mov ZLG_SEND_BUF,#10100001B ;Shift left 1 46 call zlg_send 47 setb ZLG_CS 48 mov ZLG_SEND_BUF,#10100001B ;Shift left 1 49 lcall zlg_send 50 setb ZLG_CS 51 52 ;***Display the decimal*** 53 mov ZLG_SEND_BUF,#10000001B ;Download data and encode in mode 0 54 lcall zlg_send 55 mov ZLG_SEND_BUF,ZLG_DECIMAL 56 lcall zlg_send 57 setb ZLG_CS 58 ;***Display the one*** 59 mov ZLG_SEND_BUF,#10000000B ;Download data and encode in mode 0 60 lcall zlg_send 61 mov ZLG_SEND_BUF,b 62 lcall zlg_send 63 setb ZLG_CS 64 65 mov ZLG_SEND_BUF,#10001000B 66 lcall zlg_send 67 mov ZLG_SEND_BUF,#11111100B 68 lcall zlg_send 69 setb ZLG_CS 70 71 ;WAIT_KEY_POP: 72 jnb ZLG_KEY,$ ;Wait the key to pop,等待按键放开 73 74 ajmp MAIN_LOOP ;再回到主程序,等待按键按下去 75 76 ;JMP $ 77 ret ;main return 78 ;***************************************************************** 79 80 ;***************************************************************** 81 ;Send a byte to MCU with higer bit first 82 zlg_send: 83 mov ZLG_BIT_CNT,#8 ;Set the number of data sended,发送:循环8次,左移 84 clr ZLG_CS ;Set set ZLG7289 ready,T1 85 call delay_50;T1 86 87 ZLG_SEND_LP: 88 ;Send a bit 89 mov a,ZLG_SEND_BUF 90 rlc a 91 mov ZLG_SEND_BUF,a 92 mov ZLG_DATA,c 93 nop ;Wait for data to ready 94 nop 95 96 setb ZLG_CLK ;T2,拉高拉低直接setb clr时间不够:74164位ns级+delay 97 lcall delay_8 ;delay一个8微秒或者8个nop,然后再处理下一位 98 clr ZLG_CLK ;T3 99 lcall delay_8 100 101 djnz ZLG_BIT_CNT,ZLG_SEND_LP ;Loop to next bit 102 103 ;clr ZLG_DATA 104 105 ret 106 ;***************************************************************** 107 ;Receive a byte to ZLG7289 with higer bit first 108 zlg_receive: 109 mov ZLG_BIT_CNT,#8 ;Set the number of data received 110 clr ZLG_CS ;Set set ZLG7289 ready,T1 111 lcall delay_50 112 113 ZLG_REC_LP: 114 ;Receive a bit 115 setb ZLG_CLK ;T6 116 lcall delay_8 117 118 mov c,ZLG_DATA 119 mov a,ZLG_REC_BUF 120 rlc a 121 mov ZLG_REC_BUF,acc 122 123 clr ZLG_CLK ;T7 124 lcall delay_8 125 126 djnz ZLG_BIT_CNT,ZLG_REC_LP ;Loop to next bit 127 128 clr ZLG_DATA 129 130 ret 131 132 ;***************************************************************** 133 ;Delay for (50+2) us 134 delay_50: 135 mov VAR_DELAY,#25 136 djnz VAR_DELAY,$ 137 ret 138 ;***************************************************************** 139 ;Delay for (8+2) us 140 delay_8: 141 mov VAR_DELAY,#4 142 djnz VAR_DELAY,$ 143 ret 144 ;***************************************************************** 145 END
标签:ZLG,ZLG7289,51,mov,SEND,单片机,zlg,lcall,BUF From: https://www.cnblogs.com/luoxiaoluo/p/16920431.html