ORG 0000H LJMP main org 000bh ljmp time0 org 001bh ljmp time1 ORG 0013H lJMP INTPT1 ORG 0020H switch bit p1.0 mute bit p1.1 p_warning bit p1.2 p_relax bit p1.3 p_guard bit p1.4 provision_1 bit p1.5 provision_2 bit p1.6 provision_3 bit p1.7 ON_LINE BIT p2.0 dtmf_ce bit p2.1 seg_dat bit p2.2 seg_clk bit p2.3 dtmf_clk bit p2.4 dtmf_dat bit p2.5 p_record bit p2.6 p_play bit p2.7 p_int0 bit p3.2 p_int1 bit p3.3 p_localwarning bit p3.4 p_beep bit p3.5 SDA bit P3.6 SCL bit P3.7 leavehand bit 12h right bit 11h relax_flag bit 10H LED7 bit 0EH LED6 bit 0DH LED5 bit 0CH LED4 bit 0BH ;play LED3 bit 0AH ;warning LED2 bit 09H ;preset LED1 bit 08H ;guard ACK BIT 07H ;Ó¦´ð±ê־λ±äÁ¿ a_flag bit 00h time_out1 bit 01h firstflag1 bit 02h time_out bit 03h valid1 bit 04h keyflag bit 05h valid bit 06h BITBUF EQU 21H addresspoint equ 31h ;ÒÑ´æµç»°¸öÊý position equ 53h ;IICÖе绰µÄλÖà max equ 05h ;ÄÜ×î¶à´æµÄ¸öÊý ;????????????????????????? length_pw equ 04h ;ÃÜÂ볤¶È 4 times_pw equ 03h ;×î¶àÊäÈë´ÎÊý 3 count2 equ 60h ;5a~5d ΪÃÜÂ뻺´æ count1 equ 61h main: cpl p3.6 ;Çå ¿´ÃŹ· CLR EA MOV TMOD,#11H mov ip,#08h mov scon,#10h ;·½Ê½0 setb ex1 ;Éè·À mov th0,#3ch ;100ms mov tl0,#0b0h mov th1,#3ch ;100ms mov tl1,#0b0h clr IT1 SETB ET0 setb et1 mov p0,#0ffh mov p1,#0ffh mov p2,#7eh mov p3,#0efh MOV A,#00H MOV B,A MOV R0,#20H CLR_RAM: MOV @R0,A INC R0 CJNE R0,#80H,CLR_RAM setb firstflag1 mov sp,#65h mov position,#40h mov addresspoint,#01h ;µç»°¸öÊý MOV 3AH,#00H ;µç»°±íÖ¸Õë MOV 37H,#01H mov 54h,#0ffh mov 55h,#10h mov 56h,#10h mov 57h,#10h mov 58h,#10h mov 59h,#00h JB switch,RD_VALID000 ;ÌøÏß MOV 30H,#16 LCALL delay5ms JB switch,RD_VALID000 MOV 30H,#16 LCALL delay5ms JB switch,RD_VALID000 lcall clrEEPR0M RD_VALID000: lcall rd_valid ;////// ¶ÁÈ¡valid \\ ;============================ ¹ØÏÔʾ ============================== MAIN1: jb p_relax,relax1 mov a,#10h lcall disp_seg MOV 21H,#0FFH CLR LED1 MOV A,21H mov sbuf,a jnb ti,$ clr ti mov 30h,#4 lcall delay5ms relax1: cpl p3.6 ;Çå¿´ÃŹ· SETB EA MOV 37H,#01h nop nop nop nop lcall save_valid jNB p_relax,NEXT111 ;³··À MOV 30H,#10 LCALL delay5ms JNB p_relax,NEXT111 MOV 30H,#10 LCALL delay5ms JNB p_relax,NEXT111 lcall handfree clr ex1 setb relax_flag MOV 21H,#0FFH mov a,21H mov sbuf,a jnb ti,$ clr ti NEXT111: jNB p_guard,NEXT110 ;Éè·À MOV 30H,#10 LCALL delay5ms JNB p_guard,NEXT110 MOV 30H,#10 LCALL delay5ms JNB p_guard,NEXT110 cpl p3.6 ;Çå¿´ÃŹ· lcall beep MOV 21H,#0FFH CLR LED1 MOV A,21H mov sbuf,a jnb ti,$ clr ti setb ex1 clr relax_flag NEXT110: jNB p_warning,NEXT1 ;ÏìÁå¯ MOV 30H,#10 LCALL delay5ms JNB p_warning,NEXT1 MOV 30H,#10 LCALL delay5ms JNB p_warning,NEXT1 SETB ie1 ;½øÈëÖжÏ1;----------------------------- nop nop ;===================================================================================== NEXT1: JB switch,store_no ;ÌøÏß MOV 30H,#16 LCALL delay5ms JB switch,store_no MOV 30H,#16 LCALL delay5ms JB switch,store_no lcall clrEEPR0M store_no: lcall findkey jnb keyflag,main2 ;======================================================= jnb valid,enter0 jnb valid1,next4 ;ÊÜÏÞÓû§ enter0: mov a,54h ; ¼üÖµ±£´æÓÚ54H cjne a,#0ah,enter jnb time_out1,enter1 clr valid1 lcall beeplong nop nop nop lcall beeplong main2: clr time_out1 ljmp main1 ;Í˳öÃÜÂï״̬ enter1: lcall getpw nop nop ljmp main1 enter: CJNE A,#0CH,next2 ;store jnb firstflag1,modify Lcall STORE nop nop ljmp main1 modify: lcall L91 setb ea nop nop LJMP MAIN1 NEXT2: CJNE A,#0BH,NEXT3 ;RECOR LCALL RECORD nop nop LJMP MAIN1 NEXT3: CJNE A,#0eH,NEXT4 ;DELETE LCALL delete nop nop LJMP MAIN1 NEXT4: CJNE A,#0DH,NEXT5 ;SCAN_UP LCALL scan_up mov a,#10h lcall disp_seg MOV 21H,#0FFH CLR LED1 MOV A,21H mov sbuf,a jnb ti,$ clr ti nop nop LJMP MAIN1 NEXT5: CJNE A,#0FH,next6 ;PLAY setb ea LCALL PLAY nop nop LJMP MAIN1 next6: JNB valid,main2 jb valid1,main2 lcall testpw LJMP MAIN1 ;------------------------------------------------- getpw: clr right mov count1,#00 mov position,#5ah mov 58h,#0fh mov 57h,#10h mov 56h,#10h mov 55h,#10h mov 54h,#0ffh mov 59h,#00h lcall beep ;???????????????????? p92: setb ea clr time_out mov 7eh,#0 mov 7fh,#0 setb tr0 p92_1: lcall disp ;ÏÔʾ lcall findkey jb keyflag,p61 jb time_out,p92_3 ljmp p92_1 p92_3: clr time_out ljmp getpw_end p61: clr tr0 clr c mov a,54h subb a,#0ah jnc p_101 mov a,position cjne a,#5eh,save_buffle0 ljmp getpw save_buffle0: mov r0,position ;¼üÖµÊÇ09aÖ®¼ä mov @r0,54h inc position inc count1 mov a,count1 cjne a,#length_pw,p92 setb right ljmp p92 p_101: mov a,54h clr c subb a,#0ah jz p_a mov 54h,#0ffh ljmp p92 p_a: mov a,count1 cjne a,#0,P_again ljmp getpw_end P_again: mov position,#5ah mov count1,#0 inc count2 jb right,p_3 mov a,count2 clr c subb a,#times_pw jz getpw_end ljmp getpw p_3: clr right setb valid ;ÓÐÃÜÂë setb valid1 ;Õý´¦ÓÚÃÜÂë״̬ ;setb invalid ;Í˳ö±êÖ¾ lcall beep lcall beep lcall beep mov r6,#00 ;½«»º´æÖеÄÊý´æÈ ;r6Öдæ·ÅÒ³ÃæÊ×µØÖ· wt_iic0: mov r0,position mov a,@r0 mov 36h,a wt_iic00: mov a,36h clr ea lcall IWRNBYTE lcall IRDNBYTE clr c subb a,36h ;±£´ær0 jnz wt_iic00 inc r6 inc position mov a,position cjne a,#5eh,wt_iic0 mov position,#5ah cmp: mov r0,position mov a,@r0 clr c subb a,#0 jnz getpw_end inc position mov a,position cjne a,#5eh,cmp clr valid getpw_end: mov count2,#00 mov a,#10h lcall disp_seg ;mov 30h,#100 ;lcall delay5ms ret ;======================= ÃÜÂëÑéÖ¤ ============================ testpw: clr ea mov r6,#00 ;½«»º´æÖеÄÊý´æÈ ;r6Öдæ·ÅÒ³ÃæÊ×µØÖ· mov 36h,#24h re_rd: lcall IRDNBYTE mov 3ch,a clr c subb a,#0ah jnc re_rd mov a,3ch mov r0,36h mov @r0,a inc 36h inc r6 cjne r6,#04,re_rd reapt: clr right mov count1,#00 mov position,#5ah mov 58h,#12h mov 57h,#10h mov 56h,#10h mov 55h,#10h mov 59h,#00h mov 54h,#0ffh tp92: setb ea clr time_out mov 7eh,#0 mov 7fh,#0 setb tr0 tp92_1: lcall disp ;ÏÔʾ lcall findkey jb keyflag,tp61 jb time_out,tp92_3 ljmp tp92_1 tp92_3: clr time_out ljmp testpw_end tp61: clr tr0 clr c mov a,54h subb a,#0ah jnc tp_101 mov a,position cjne a,#5eh,save_buffle01 ljmp reapt save_buffle01: mov r0,position ;¼üÖµÊÇ09aÖ®¼ä mov @r0,54h inc position inc count1 mov a,count1 cjne a,#length_pw,tp92 setb right totp92: ljmp tp92 tp_101: mov a,54h clr c subb a,#0ah jz test_a mov 54h,#0ffh ljmp tp92 test_a: mov a,count1 cjne a,#0,test_again ljmp testpw_end test_again: mov position,#5ah mov count1,#0 inc count2 jb right,tp_3 mov a,count2 cjne a,#times_pw,times_no ljmp testpw_end times_no: ljmp reapt tp_3: clr right mov r0,#24h cmpagain: mov 29h,@r0 mov a,r0 add a,#36h mov r0,a mov a,@r0 cjne a,29h,tryagain mov a,r0 clr c subb a,#36h mov r0,a inc r0 cjne r0,#28h,cmpagain setb valid1 lcall beep lcall beep lcall beep lcall beep ljmp testpw_end tryagain: clr valid1 mov a,count2 cjne a,#times_pw,times_no testpw_end: mov count2,#00 lcall beep ;mov 54h,#0ffh ;mov 55h,#10h ;mov 56h,#10h ;mov 57h,#10h ;mov 58h,#10h mov a,#10h lcall disp_seg ;mov 30h,#100 ;lcall delay5ms ret ;============================== rd_valid: mov r6,#05 lcall IRDNBYTE cjne a,#0,valid_1 clr valid ajmp rd_valid_out valid_1: cjne a,#0ffh,rd_valid setb valid rd_valid_out: ret ;===============================±£´ævalid ÓÚeeprom=================== save_valid: jb valid,iic05_1 mov a,#0 mov 3ch,a ljmp save_valid1 iic05_1: mov a,#0ffh mov 3ch,a save_valid1: mov a,3ch mov r6,#05 lcall IWRNBYTE lcall IRDNBYTE cjne a,3ch,save_valid1 ret ;------------------------ÇåEEPROM---------------------------------- clrEEPR0M: mov r6,#00 clr ea clr_iic: mov a,#00 lcall IWRNBYTE lcall IRDNBYTE cjne a,#00,clr_iic ;±£´ær0 inc r6 cjne r6,#06,clr_iic ;ÊÇ#ºÅ¼üÂð;ÇåÃÜÂë clr valid mov 37h,#1 clr_phone: mov a,37h mov b,#18 mul ab mov R6,a clr_iic1: mov a,#0AH lcall IWRNBYTE lcall IRDNBYTE cjne a,#0Ah,clr_iic1 ;±£´ær0 INC 37H MOV A,37H dec a cjne a,#MAX,clr_phone ;ÊÇ#ºÅ¼üÂð;ÇåÃÜÂë lcall beeplong setb ea RET ;==================¼Òô========================== RECORD: LCALL BEEP mov 7fh,#00h mov 7eh,#00h setb tr0 CLR p_record CLR p_play RECORD1: lcall findkey jb 03h,record_end mov a,54h cjne a,#0ffh,record_end ljmp RECORD1 record_end: setb firstflag1 clr tr0 SETB p_record ret play: LCALL BEEP MOV 21H,#0FFH CLR LED4 MOV A,21H mov sbuf,a jnb ti,$ clr ti clr es mov 7fh,#00h mov 7eh,#00h setb tr0 clr mute ;·ÅÒô setb p_play SETB p_record play1: setb ex1 lcall findkey jb 03h,play_end mov a,54h cjne a,#0ffh,play_end ljmp play1 play_end: clr p_play clr tr0 setb mute mov 30h,#30 lcall delay5ms setb firstflag1 setb ex1 lcall beep jnb relax_flag,play_end1 clr ex1 play_end1: ret ;===================== ½øÈë´æ´¢×´Ì¬ ======================== ;===================== ½øÈë´æ´¢×´Ì¬ ======================== STORE: MOV 21H,#0FFH CLR LED2 ;Ô¤ÖÃµÆ MOV A,21H mov sbuf,a jnb ti,$ clr ti ;mov 30h,#1 ;lcall delay5ms L90: mov addresspoint,#1 setb firstflag1 L91: cpl p3.6 ;Çå¿´ÃŹ· lcall beep setb a_flag mov position,#40h mov 40h,#0ah mov 58h,addresspoint mov 57h,#10h mov 56h,#10h mov 55h,#10h mov 54h,#0ffh mov 59h,#00h L92: setb ea clr time_out setb tr0 L92_1: lcall disp ;ÏÔʾ lcall findkey jb keyflag,L61 jb time_out,L92_3 ljmp L92_1 L92_3: clr time_out ljmp store_end L61: clr tr0 clr c mov a,54h subb a,#0ah jnc store_101 ;¼üÖµÊÇ0~aÖ®¼ä ljmp store_1 store_101: mov a,54h cjne a,#0ah,L62 jnb a_flag,store_3 ljmp store_end store_3: mov r0,position ;½« # ´æÈ뻺´æ mov @r0,#0ah mov position,#40h ;½«»º´æÖеÄÊý´æÈëIIC mov a,addresspoint mov b,#18 mul ab mov r6,a ;r6Öдæ·ÅÒ³ÃæÊ×µØÖ· wt_iic1: mov r0,position mov a,@r0 mov 36h,a wt_iic: mov a,36h clr ea lcall IWRNBYTE mov a,#98h lcall IRDNBYTE clr c subb a,36h ;±£´ær0 jnz wt_iic mov a,36h cjne a,#0ah,goon_wt clr a_flag ;Í˳ö±êÖ¾ setb ea mov a,addresspoint cjne a,#max,addresspoint_inc ljmp L90 addresspoint_inc: inc addresspoint setb firstflag1 ljmp L91 goon_wt: inc r6 inc position ljmp wt_iic1 L62: cjne a,#0dh,L63 ;ÉÏ·­ lcall scan_up nop nop nop nop Ljmp L91 L63: cjne a,#0eh,L64 ;ɾ³ý lcall delete nop Ljmp L91 L64: cjne a,#0ch,L65 ;ÐÞ¸Ä mov 58h,#10H mov 57h,#10h mov 56h,#10h mov 55h,#10h mov 59h,#00h mov 54h,#0ffh nop setb firstflag1 Ljmp L91 L65: mov 54h,#0ffh ljmp L92 ;===============½øÈë´æ´¢ºÅÂë״̬7==5==5========================== store_1: clr a_flag mov a,position cjne a,#52h,save_buffle ljmp L91 save_buffle: mov r0,position mov @r0,54h inc position ljmp L92 ; ==================== ¹ØÏÔʾ ======================== store_end: setb ea lcall beeplong setb firstflag1 mov 54h,#0ffh mov 55h,#10h mov 56h,#10h mov 57h,#10h mov 58h,#10h mov 59h,#00h mov a,#10h lcall disp_seg ;mov 30h,#100 ;lcall delay5ms ret ;===================================== ÉÏ·­ =========================== scan_up: mov a,addresspoint cjne a,#max,scan_cycle mov addresspoint,#1 ljmp cycle scan_cycle: inc addresspoint cycle: clr firstflag1 mov a,addresspoint ;Ñ­»·ÏÔʾ mov b,#18 mul ab mov 3Ah,a mov 58h,addresspoint mov 57h,#10h mov 56h,#10h mov 55h,#10h mov 54h,#0ffh mov 59h,#00h againi000: mov 2fh,#40 disp_goon: lcall disp lcall findkey jb keyflag,cycle_end djnz 2fh,disp_goon re_rdiic: setb ea cpl p3.6 MOV r6,3AH INC 3AH clr ea lcall IRDNBYTE mov 54h,a ;±£´æ a ÀïÃæÎª¼üÖµ cjne a,#0ah,againi000 ;ÊÇ#ºÅ¼üÂð ljmp scan_end2 cycle_end: mov a,54h cjne a,#0dh,cycle_out ;scan ljmp scan_up cycle_out: cjne a,#0ah,recify ljmp scan_end2 recify: cjne a,#0ch,delt ;modify ljmp L91 delt: cjne a,#0eh,re_rdiic ;delete lcall delete scan_end2: lcall beep ;ÐÞ¸ÄÍê³É clr ea MOV 21H,#0FFH mov 54h,#0ffh mov 55h,#10h mov 56h,#10h mov 57h,#10h mov 58h,#10h mov 59h,#00h setb ea ret ;===================================== ɾ³ý =========================== delete: lcall beep mov 58h,addresspoint mov 57h,#10h mov 56h,#10h mov 55h,#11h ; mov 59h,#00h mov 54h,#0ffh mov 2fh,#20 disp_del1: lcall disp djnz 2fh,disp_del1 mov 30h,#50 lcall delay5ms mov 2fh,#20 disp_del2: lcall disp djnz 2fh,disp_del2 mov 2fh,#20 disp_del3: lcall disp djnz 2fh,disp_del3 mov a,addresspoint mov b,#18 mul ab mov r6,a clr ea wtiic_a: mov a,#0ah lcall IWRNBYTE mov a,#98h lcall IRDNBYTE clr c subb a,#0ah jz addresspoint_11 ajmp wtiic_a addresspoint_11: mov a,addresspoint cjne a,#max,addp_inc addp_1: mov addresspoint,#1 ljmp delete_out addp_inc: inc addresspoint delete_out: setb firstflag1 MOV 21H,#0FFH mov 54h,#0ffh mov 55h,#10h mov 56h,#10h mov 57h,#10h mov 58h,#10h mov 59h,#00h ;setb es setb ea mov a,#10h lcall disp_seg RET ;===================================¶¨Ê±Æ÷0ÖжϳÌÐò============================== time0: push 00h push acc push psw CLR C MOV A,7fh ADD A,#01H MOV 7fh,A MOV A,7eh ADDC A,#00H MOV 7eh,A MOV R0,7fh CJNE R0,#00H,OVER000 MOV R0,7eh CJNE R0,#01H,OVER000 setb time_out mov 7eh,#00h mov 7fh,#00h mov th0,#3ch mov tl0,#0b0h clr tr0 ljmp tout OVER000: mov th0,#3ch mov tl0,#0b0h clr time_out setb tr0 tout: pop psw pop acc pop 00h ;±£´ær0 cpl p3.6 ;Çå¿´ÃŹ reti ;===================================¶¨Ê±Æ÷0ÖжϳÌÐò============================== time1: push 00h push acc push psw CLR C MOV A,7dh ADD A,#01H MOV 7dh,A MOV R0,7dh CJNE R0,#09H,OVER222 SETB time_out1 mov 7dh,#00h mov th1,#3ch mov tl1,#0b0h clr tr1 ljmp tout1 OVER222: mov th1,#3ch mov tl1,#0b0h clr time_out1 setb tr1 tout1: pop psw pop acc pop 00h ;±£´ær0 reti ;===============================int1 ÖжÏ=========================================== INTPT1: cpl p3.6 ;Çå¿´ÃŹ· lcall beep setb es MOV 21H,#0FFH CLR LED3 MOV A,21H mov sbuf,a jnb ti,$ clr ti clr es clr ea SETB mute SETB ON_LINE MOV 30H,#40 LCALL delay10ms MOV 2dH,#00H mov 39h,#64h agains: mov 30h,#01h lcall delay10ms jb p_int0,nexti inc 2dh nexti: cpl p3.6 ;Çå¿´ÃŹ· djnz 39h,agains mov a,2dh subb a,#90 jnc next nop nop ljmp localwarning ;·ÇµÍµãÆÀ²¦ºÅÒò NOP next: ;========================================================= mov a,37h mov b,#18 mul ab mov 3Ah,a mov 30h,#60 lcall delay10ms clr ea MOV r6,3AH INC 3AH lcall IRDNBYTE setb ea cjne a,#0ah,again1 mov a,37h cjne a,#max,dailnext ljmp int1out dailnext: inc 37h ljmp INTPT1 again: INC 3AH MOV r6,3AH clr ea lcall IRDNBYTE setb ea cpl p3.6 ;Çå¿´ÃŹ· cjne a,#0ah,again1 ;ÊÇ#ºÅ¼üÂð ljmp again_out ;========================¿ªÊ¼²¦ºÅ========================== again1: clr dtmf_ce lcall out_dtmf mov 30h,#30 lcall delay10ms setb dtmf_ce mov 30h,#30 lcall delay10ms cpl p3.6 ;Çå¿´ÃŹ· LJMP again ;=========ÓïÒô¼à²â====================================================== again_out: mov 38h,#00h mov 39h,#064h mov 35h,#00h int00: mov 34h,#00h againi0: mov 30h,#0ah lcall delay10ms jnb P3.2,adcount inc 35h ljmp out adcount: inc 34h mov 35h,#00h cpl p3.6 ;Çå¿´ÃŹ· djnz 39h,againi0 ljmp handfree1 ;------------------------------ out: mov a,34h subb a,#0eh jnc oncemore mov a,34h subb a,#4 jnc ackvoice cpl p3.6 ;Çå¿´ÃŹ· mov a,34h subb a,#4 jnc oncemore mov a,34h subb a,#2 jc onceagain inc 38h mov a,38h CLR C subb a,#02h ;03h jz gohandfree ;¼ì²âµ½Ã¦Òô onceagain: mov a,35h clr c subb a,#45 jnc gohandfree oncemore: JNB p_relax,rept0 MOV 30H,#16H LCALL delay10ms JNB p_relax,rept0 MOV 30H,#16H LCALL delay10ms JNB p_relax,rept0 setb relax_flag lcall handfree ljmp int1out rept0: cpl p3.6 ;Çå¿´ÃŹ· ljmp int00 gohandfree: ljmp handfree1 ;=============================================================================================================== ackvoice: lcall beep MOV 2dH,#00H mov 2eh,#00H mov 39h,#0a0h againss: mov 30h,#0ah lcall delay10ms jnb P3.2,nextii inc 2dh ;¼ì²â¸ßµçƽ mov 2eh,#00h mov a,2dh clr c subb a,#45 jnc playmusic ljmp oncemore1 nextii: ;¼ì²âµÍµçƽ mov 2dh,#00h inc 2eh mov a,2eh clr c subb a,#3 ;3d 2d jc oncemore1 mov 30h,#15 ;100d 250d ; 15d lcall delay10ms jb P3.2,handfree1 ;¼ì²âµ½Ã¦Òô mov 2eh,#00h oncemore1: JNB p_relax,rept1 MOV 30H,#16H LCALL delay10ms JNB p_relax,rept1 MOV 30H,#16H LCALL delay10ms JNB p_relax,rept1 setb relax_flag lcall handfree ljmp int1out rept1: cpl p3.6 ;Çå¿´ÃŹ· djnz 39h,againss ljmp handfree1 playmusic: nop clr mute setb p_play SETB p_record mov r2,#00h mov r0,#64h busyloop1: mov r1,#0ah busyloop: mov 30h,#1 lcall delay10ms jb P3.2,oncemore3 inc r2 mov a,r2 clr c subb a,#20 ;30d jc oncemore2 mov 30h,#25 ;06d lcall delay10ms jb P3.2,handfree1 oncemore3: mov r2,#00h oncemore2: JNB p_relax,rept2 MOV 30H,#16H LCALL delay10ms JNB p_relax,rept2 MOV 30H,#16H LCALL delay10ms JNB p_relax,rept2 setb relax_flag lcall handfree ljmp int1out rept2: cpl p3.6 ;Çå¿´ÃŹ· djnz r1,busyloop djnz r0,busyloop1 handfree1: clr p_play lcall handfree ;37hÖдæ·Åµç»°¸öÊý mov a,37h cjne a,#max,int1next ljmp int1out int1next: cpl p3.6 ;Çå¿´ÃŹ· inc 37h ljmp INTPT1 localwarning: setb P3.4 mov 39h,#60 localw1: mov r4,#0ah localw: mov 30h,#0ah lcall delay10ms cpl p3.6 ;Çå¿´ÃŹ· JNB p_relax,repeat0 MOV 30H,#16 LCALL delay10ms JNB p_relax,repeat0 MOV 30H,#16 LCALL delay10ms JNB p_relax,repeat0 setb relax_flag lcall handfree ljmp int1out repeat0: djnz r4,localw cpl p3.6 ;Çå¿´ÃŹ· djnz 39h,localw1 int1out: setb p1.1 clr P3.4 SETB EX1 setb et0 cpl sda RETI handfree: lcall beeplong clr on_line MOV A,#0FFH mov sbuf,a jnb ti,$ clr ti mov 30h,#50 lcall delay10ms cpl p3.6 ;Çå¿´ÃŹ· ret ;==================================ÏÔʾ×Ó³ÌÐò=============================== disp: push acc push psw push 00h cpl p3.6 mov a,54h cjne a,#0ffh,mout1 ;if keyflag=1 ljmp mout mout1: cjne a,#0ah,mout2 mov 54h,#10h mout2: inc 59h mov r0,59h cjne r0,#1,disp2 mov 58h,57h mov 55h,54h ljmp mout disp2: cjne r0,#2,disp3 mov 56h,55h mov 55h,54h ljmp mout disp3: cjne r0,#3,disp4 mov 57h,56h mov 56h,55h mov 55h,54h ljmp mout disp4: mov 58h,57h mov 57h,56h mov 56h,55h mov 55h,54h mout: lcall display mov 54h,#0ffh pop 00h pop psw pop acc ret ;55,56,57,58 // °´Ï¼ü59H++ °´ÏÂ#ʱÇåÁã 54HΪ¼üÖµ display: mov a,58h lcall disp_seg MOV 21H,#7FH CLR LED2 MOV A,21H mov sbuf,a mov 30h,#1 ;1 5 lcall delay1ms clr ti mov a,57h lcall disp_seg MOV 21H,#0fFH clr LED7 CLR LED2 MOV A,21H mov sbuf,a mov 30h,#1 ;1 5 lcall delay1ms clr ti mov a,56h lcall disp_seg MOV 21H,#0FFH CLR LED6 CLR LED2 MOV A,21H mov sbuf,a mov 30h,#1 ;1 5 lcall delay1ms clr ti mov a,55h lcall disp_seg MOV 21H,#0FFH CLR LED5 CLR LED2 MOV A,21H mov sbuf,a mov 30h,#1 ;1 5 lcall delay1ms clr ti ;¹ØÏÔʾ mov a,#10h lcall disp_seg mov 30h,#2 lcall delay5ms ret ;===================================================================== disp_seg: push acc push 00h push psw mov dptr,#tab_led movc a,@a+dptr mov r0,#8 rep8: rlc a ;????????????????? mov seg_dat,c nop nop clr seg_clk setb seg_clk djnz r0,rep8 pop psw pop 00h pop acc ret tab_led: db 0c0h,0f9h,0a4h,0b0h,99h,92h,82h,0f8h ; 0 1 2 3 4 5 6 7 db 80h,90h,81h,0f7h,0f7h,0f7h,0f7h,0f7h ; 8 9 #/a b c d e f db 0ffh,0a1h,8ch ; 10 11 12 ;================================= IWRNBYTE: mov R5,A nop LCALL START ;Æð¶¯×ÜÏß MOV A,#0A0H LCALL WRBYTE ;·¢ËÍÆ÷¼þ´ÓµØÖ· LCALL CACK JNB ACK,RETWRN ;ÎÞÓ¦´ðÔòÍ˳ö MOV A,r6 ;Ö¸¶¨×ÓµØÖ· LCALL WRBYTE LCALL CACK MOV A,r5 LCALL WRBYTE ;¿ªÊ¼Ð´ÈëÊý¾Ý LCALL CACK JNB ACK,IWRNBYTE RETWRN: LCALL STOP RET IRDNBYTE: nop LCALL START MOV A,#0A0H LCALL WRBYTE ;·¢ËÍÆ÷¼þ´ÓµØÖ· LCALL CACK JNB ACK,RETRDN MOV A,r6 ;Ö¸¶¨×ÓµØÖ· LCALL WRBYTE LCALL CACK LCALL START ;ÖØÐÂÆð¶¯×ÜÏß MOV A,#0a0h INC A ;×¼±¸½øÐжÁ²Ù×÷ LCALL WRBYTE LCALL CACK JNB ACK,IRDNBYTE LCALL RDBYTE ;¶Á²Ù×÷¿ªÊ¼ LCALL MNACK ;×îºóÒ»×Ö½Ú·¢·ÇÓ¦´ðλ RETRDN: LCALL STOP ;²¢½áÊø×ÜÏß RET ;Æô¶¯I2C×ÜÏß×Ó³ÌÐò START: SETB SDA NOP SETB SCL ;ÆðʼÌõ¼þ½¨Á¢Ê±¼ä´óÓÚ4.7us NOP NOP NOP NOP NOP CLR SDA NOP ;ÆðʼÌõ¼þËø¶¨Ê±´óÓÚ4us NOP NOP NOP NOP CLR SCL ;ǯס×ÜÏߣ¬×¼±¸·¢Êý¾Ý NOP RET ;½áÊø×ÜÏß×Ó³ÌÐò STOP: CLR SDA NOP SETB SCL ;·¢ËͽáÊøÌõ¼þµÄʱÖÓÐźŠNOP ;½áÊø×ÜÏßʱ¼ä´óÓÚ4us NOP NOP NOP NOP SETB SDA ;½áÊø×ÜÏß NOP ;±£Ö¤Ò»¸öÖÕÖ¹ÐÅºÅºÍÆðʼÐźŵĿÕÏÐʱ¼ä´óÓÚ4.7us NOP NOP NOP RET ;·¢ËÍÓ¦´ðÐźÅ×Ó³ÌÐò MACK: CLR SDA ;½«SDAÖÃ0 NOP NOP SETB SCL NOP ;±£³ÖÊý¾Ýʱ¼ä£¬¼´SCLΪ¸ßʱ¼ä´óÓÚ4.7us NOP NOP NOP NOP CLR SCL NOP NOP RET ;·¢ËÍ·ÇÓ¦´ðÐźŠMNACK: SETB SDA ;½«SDAÖÃ1 NOP NOP SETB SCL NOP NOP ;±£³ÖÊý¾Ýʱ¼ä£¬¼´SCLΪ¸ßʱ¼ä´óÓÚ4.7us NOP NOP NOP CLR SCL NOP NOP RET ;¼ì²éÓ¦´ðλ×Ó³ÌÐò ;·µ»ØÖµ£¬ACK=1ʱ±íʾÓÐÓ¦´ð CACK: SETB SDA NOP NOP SETB SCL CLR ACK NOP NOP MOV C,SDA JC CEND SETB ACK ;ÅжÏÓ¦´ðλ CEND: NOP CLR SCL NOP RET ;·¢ËÍ×Ö½Ú×Ó³ÌÐò ;×Ö½ÚÊý¾Ý·ÅÈëACC ;ÿ·¢ËÍÒ»×Ö½ÚÒªµ÷ÓÃÒ»´ÎCACK×Ó³ÌÐò£¬È¡Ó¦´ðλ WRBYTE: MOV R0,#08H WLP: RLC A ;È¡Êý¾Ýλ JC WR1 SJMP WR00 ;ÅжÏÊý¾Ýλ WLP1: DJNZ R0,WLP NOP RET WR1: SETB SDA ;·¢ËÍ1 NOP SETB SCL NOP NOP NOP NOP NOP CLR SCL SJMP WLP1 WR00: CLR SDA ;·¢ËÍ0 NOP SETB SCL NOP NOP NOP NOP NOP CLR SCL SJMP WLP1 ;¶ÁÈ¡×Ö½Ú×Ó³ÌÐò ;¶Á³öµÄÖµÔÚACC ;ÿȡһ×Ö½ÚÒª·¢ËÍÒ»¸öÓ¦´ð/·ÇÓ¦´ðÐźŠRDBYTE: MOV R0,#08H RLP: SETB SDA NOP SETB SCL ;ʱÖÓÏßΪ¸ß£¬½ÓÊÕÊý¾Ýλ NOP NOP MOV C,SDA ;¶ÁÈ¡Êý¾Ýλ MOV A,R2 CLR SCL ;½«SCLÀ­µÍ£¬Ê±¼ä´óÓÚ4.7us RLC A ;½øÐÐÊý¾ÝλµÄ´¦Àí MOV R2,A NOP NOP NOP DJNZ R0,RLP ;δ¹»8룬ÔÙÀ´Ò»´Î RET ;================²¦ºÅ================ out_dtmf: mov dptr,#dialtable movc a,@a+dptr mov r0,#5 rep5: rrc a mov dtmf_dat,c clr dtmf_clk setb dtmf_clk djnz r0,rep5 ret dialtable: db 0ah,01h,02h,03h,04h,05h,06h,07h,08h,09h,0ch ; 0 1 2 3 4 5 6 7 8 9 #/a ;============================================== delay10ms: MOV R3,#30H delay2: mov R7,#32H delay1: DJNZ R7,delay1 DJNZ R3,delay2 DJNZ 30H,delay10ms RET delay5ms: push 01h push 02h delay5: MOV R2,#50 delay21: mov R1,#25 delay11: DJNZ R1,delay11 DJNZ R2,delay21 DJNZ 30H,delay5 pop 02h pop 01h RET delay1ms: push 01h push 02h delay6: MOV R2,#20 delay3: mov R1,#25 delay4: DJNZ R1,delay4 DJNZ R2,delay3 DJNZ 30H,delay6 pop 02h pop 01h RET ;========================================================== beep: clr P3.5 mov 30h,#10 lcall delay5ms setb P3.5 mov 30h,#20 lcall delay5ms ret beeplong: clr P3.5 mov 30h,#50 lcall delay5ms setb P3.5 ret ;============================================== findkey: cpl p3.6 mov p0,#0ffh MOV 54H,#0FFH clr keyflag ;ÎÞ¼ü°´ÏÂΪ 0 £» Óмü°´ÏÂÇå 1 mov P0,#0f0h mov a,P0 cjne a,#0f0h,check ljmp findkey_out check: mov 30h,#4 lcall delay5ms nop nop nop nop mov a,P0 cjne a,#0f0h,keydown ljmp findkey_out keydown: mov p0,#0f0h ;ÐÐÀ²µÍ ÁÐÀ²¸ß mov a,P0 ;Ö÷ÒªÏë±£´æp0µÄ µÍËÄλ jb p0.4,findkey_0 setb keyflag mov dptr,#tab_0 ljmp findkey_end findkey_0: jb p0.5,findkey_1 setb keyflag mov dptr,#tab_1 ljmp findkey_end findkey_1: jb p0.6,findkey_2 setb keyflag mov dptr,#tab_2 ljmp findkey_end findkey_2: jb p0.7,findkey_out setb keyflag mov dptr,#tab_3 findkey_end: mov p0,#0fh mov a,p0 cpl a anl a,#0fh movc a,@a+dptr ;µÃµ½¼üÖµ mov 54h,a ;²¦ºÅºó ¼üÖµ±£´æÔÚ54h setb ea clr time_out1 mov 7dh,#00 setb tr1 findkey_wait: mov p0,#0f0h nop mov a,p0 jnb time_out1,out2003 jb leavehand,out2003 lcall beep setb leavehand out2003: cjne a,#0f0h,findkey_wait findkey_out: mov a,54h clr tr1 clr leavehand ret tab_0: db 00h,01h,04h,00h,07h,00h,00h,00h,00h tab_1: db 00h,02h,05h,00h,08h,00h,00h,00h,0bh tab_2: db 00h,03h,06h,00h,09h,00h,00h,00h,0fh tab_3: db 00h,0ch,0dh,00h,0eh,00h,00h,00h,0ah org 0f00h nop nop nop nop nop nop nop nop nop nop ljmp main end