Ïîèñê ïî ñàéòó: |
|
Ïî áàçå: |
|
Ãëàâíàÿ ñòðàíèöà > Îáçîðû ïî ôèðìàì > Dallas > Ïðèìåíåíèå |
|
|||||||||
Ïðèìåð ïðîãðàììû íà ÿçûêå Àñåìáëåð; ÏÐÎÃÐÀÌÌÀ DS1307.ASM ; ; ÝÒÀ ÏÐÎÃÐÀÌÌÀ ÎÒÂÅ×ÀÅÒ ÍÀ ÊÎÌÀÍÄÛ ÏÐÈÍßÒÛÅ ÏÎ ÏÎÑËÅÄÎÂÀÒÅËÜÍÎÌÓ ; ÏÎÐÒÓ ÄËß ÓÑÒÀÍÎÂÊÈ ÄÀÒÛ/ÂÐÅÌÅÍÈ ÒÀÊ ÆÅ ÊÀÊ ÄÀÍÍÛÅ RAM  DS1307, ; Ñ ÈÑÏÎËÜÇÎÂÀÍÈÅÌ DS5000  ÊÀ×ÅÑÒÂÅ ÊÎÍÒÐÎËËÅÐÀ ; CR EQU 0DH LF EQU 0AH MCON EQU 0C6H PCON EQU 087H TA EQU 0C7H SCL BIT P1.0 SDA BIT P1.1 TRIG BIT P1.2 DS1307W EQU 0D0H DS1307R EQU 0D1H FLAGS DATA 20H LASTREAD BIT FLAGS.0 _12_24 BIT FLAGS.1 PM_AM BIT FLAGS.2 OSC BIT FLAGS.3 SQW BIT FLAGS.4 ACK BIT FLAGS.5 BUS_FAULT BIT FLAGS.6 _2W_BUSY BIT FLAGS.7 BITCOUNT DATA 21H BYTECOUNT DATA 22H BYTE DATA 23H CSEG AT 0 AJMP START ; CSEG AT 30H ;************************************************************** ; ;*** ÇÄÅÑÜ ÏÐÎÈÑÕÎÄÈÒ ÑÁÐÎÑ ÄËß ÇÀÏÓÑÊÀ ÏÐÎÃÐÀÌÌÛ**** ; ;************************************************************** START: MOV TA,#0AAH ; ÂÐÅÌÅÍÍÎÉ MOV TA,#55H ; ÄÎÑÒÓÏ. MOV PCON,#0 ; ÑÁÐÎÑ ÑËÅÄßÙÅÃÎ ÒÀÉÌÅÐÀ. MOV MCON,#0F8H ; ÂÛÊËÞ×ÅÍÈÅ CE2 ÄËß ; ÄÎÑÒÓÏÀ Ê ÏÀÌßÒÈ. MOV SP,#70H ; ÏÎÇÈÖÈß ÑÒÅÊÀ ÏÐÅÂÛØÀÅÒ ; ÁÓÔÅÐ. MOV IE,#0 MOV TMOD,#20H ; ÈÍÈÖÈÀËÈÇÈÐÎÂÀÍÈÅ MOV TH1,#0FAH ; ÏÎÑËÅÄÎÂÀÒÅËÜÍÎÃÎ ÏÎÐÒÀ MOV TL1,#0FAH ; ÄËß ÑÊÎÐÑÒÈ 9600 ORL PCON,#80H ; ÁÎÄ. MOV SCON,#52H MOV TCON,#40H ;MOV R0,#0 ;MOV R1,#0 ;DJNZ R0,$ ;DJNZ R1,$–2 SETB SDA ; ÎÁÅÑÏÅ×ÈÂÀÅÒ ÂÛÑÎÊÎÅ ÑÎÑÒÎßÍÈÅ SDA LCALL SCL_HIGH ; ÎÁÅÑÏÅ×ÈÂÀÅÒ ÂÛÑÎÊÎÅ ÑÎÑÒÎßÍÈÅ SCL CLR ACK ; ÑÁÐÀÑÛÂÀÍÈÅ ÔËÀÃΠÑÎÑÒÎßÍÈß CLR BUS_FAULT CLR _2W_BUSY ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ; ÝÒÎ ÖÈÊË «ÂÅÄÓÙÅÃλ ÊÎÍÒÐÎËËÅÐÀ ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– MASTER_CONTROLLER: MOV BYTECOUNT,#10H FORM_FEED: MOV A,#LF ; Î×ÈÑÒÊÀ ÝÊÐÀÍÀ ÄËß ÃËÀÂÍÎÃÎ ; ÌÅÍÞ LCALL WRITE_DATA DJNZ BYTECOUNT,FORM_FEED MOV DPTR, #TEXT0 ; ÏÎÌÅÑÒÈÒÜ ÎÑÍÎÂÍÎÅ ÌÅÍÞ ; ÍÀ ÝÊÐÀÍ LCALL WRITE_TEXT MOV DPTR, #TEXT3 LCALL WRITE_TEXT LCALL READ_DATA CLR ACC.5 ; ÏÅÐÅÂÅÑÒÈ ACC  ÂÅÐÕÍÈÉ ; ÐÅÃÈÑÒÐ CJNE A,#’A’,NOTA ; ÂÛÇÂÀÒÜ ÔÓÍÊÖÈÞ ÓÑÒÀÍÎÂÊÈ ; ×ÀÑΠLCALL SET_CLOCKM JMP MASTER_CONTROLLER ; ÂÅÐÍÓÒÑß Â ÃËÀÂÍÎÅ ÌÅÍÞ NOTA: CJNE A,#’B’,NOTB ; ÂÛÇÂÀÒÜ ÔÓÍÊÖÈÞ SET RAM ; È LCALL SET_RAM ; ÂÛÇÂÀÒÜ ÔÓÍÊÖÈÞ READ RAM LCALL READ_RAM JMP MASTER_CONTROLLER ; ÂÅÐÍÓÒÑß Â ÃËÀÂÍÎÅ ÌÅÍÞ NOTB: CJNE A,#’C’,NOTC ; ÂÛÇÂÀÒÜ ÔÓÍÊÖÈÞ READ CLOCK LCALL READ_CLOCK JMP MASTER_CONTROLLER ; ÂÅÐÍÓÒÑß Â ÃËÀÂÍÎÅ ÌÅÍÞ NOTC: CJNE A,#’D’,NOTD ; ÂÛÇÂÀÒÜ ÔÓÍÊÖÈÞ READ RAM LCALL READ_RAM JMP MASTER_CONTROLLER ; ÂÅÐÍÓÒÑß Â ÃËÀÂÍÎÅ ÌÅÍÞ NOTD: CJNE A,#’E’,NOTE ; ÂÛÇÂÀÒÜ ÓÏÐÀÂËÅÍÈÅ OSC CLR OSC ; ÑÁÐÎÑ ÔËÀÃÀ OSC – ÂÊË. LCALL OSC_CONTROL JMP MASTER_CONTROLLER ; ÂÅÐÍÓÒÑß Â ÃËÀÂÍÎÅ ÌÅÍÞ NOTE: CJNE A,#’F’,NOTF ; ÂÛÇÂÀÒÜ ÔÓÍÊÖÈÞ ÓÏÐÀÂËÅÍÈß OSC SETB OSC ; ÓÑÒÀÍÎÂÈÒÜ ÔËÀà OSC – ÂÛÊË. LCALL OSC_CONTROL JMP MASTER_CONTROLLER ; ÂÅÐÍÓÒÑß Â ÃËÀÂÍÎÅ ÌÅÍÞ NOTF: CJNE A,#’G’,NOTG ; ÂÛÇÂÀÒÜ ÓÏÐÀÂËÅÍÈÅ SWQ CLR SQW ; ÑÁÐÎÑ ÔËÀÃÀ SQW – ÂÊË. LCALL SQW_CONTROL_1HZ JMP MASTER_CONTROLLER ; ÂÅÐÍÓÒÑß Â ÃËÀÂÍÎÅ ÌÅÍÞ NOTG: CJNE A,#’G’,NOTH ; ÂÛÇÂÀÒÜ ÔÓÍÊÖÈÞ ÓÏÐÀÂËÅÍÈß SWQ CLR SQW ; ÑÁÐÎÑ ÔËÀÃÀ SQW – ÂÊË. LCALL SQW_CONTROL_1HZ JMP MASTER_CONTROLLER ; ÂÅÐÍÓÒÑß Â ÃËÀÂÍÎÅ ÌÅÍÞ NOTH: CJNE A,#’H’,NOTI ; ÂÛÇÂÀÒÜ ÔÓÍÊÖÈÞ ÓÏÐÀÂËÅÍÈß SWQ CLR SQW ; ÑÁÐÎÑ ÔËÀÃÀ SQW – ÂÊË. LCALL SQW_CONTROL_4KHZ JMP MASTER_CONTROLLER ; ÂÅÐÍÓÒÑß Â ÃËÀÂÍÎÅ ÌÅÍÞ NOTI: CJNE A,#’I’,NOTJ ; ÂÛÇÂÀÒÜ ÔÓÍÊÖÈÞ ÓÏÐÀÂËÅÍÈß SWQ CLR SQW ; ÑÁÐÎÑ ÔËÀÃÀ SQW – ÂÊË. LCALL SQW_CONTROL_8KHZ JMP MASTER_CONTROLLER ; ÂÅÐÍÓÒÑß Â ÃËÀÂÍÎÅ ÌÅÍÞ NOTJ: CJNE A,#’J’,NOTK ; ÂÛÇÂÀÒÜ ÔÓÍÊÖÈÞ ÓÏÐÀÂËÅÍÈß SWQ CLR SQW ; ÑÁÐÎÑ ÔËÀÃÀ SQW – ÂÊË. LCALL SQW_CONTROL_32KHZ JMP MASTER_CONTROLLER ; ÂÅÐÍÓÒÑß Â ÃËÀÂÍÎÅ ÌÅÍÞ NOTK: CJNE A,#’K’,NOTL ; ÂÛÇÂÀÒÜ ÔÓÍÊÖÈÞ ÓÏÐÀÂËÅÍÈß SWQ SETB SQW ; ÓÑÒÀÍÎÂÈÒÜ ÔËÀà SQW – ÂÛÊË. LCALL SQW_CONTROL_1HZ JMP MASTER_CONTROLLER NOTL: CJNE A,#’L’,NOTM LCALL SET_RAM_UNQ LCALL READ_RAM NOTM: JMP MASTER_CONTROLLER ; ÂÅÐÍÓÒÑß Â ÃËÀÂÍÎÅ ÌÅÍÞ ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ; ; ÝÒÀ ÏÎÄÏÐÎÃÐÀÌÌÀ ÏÎÑÛËÀÅÒ ÑÎÑÒÎßÍÈÅ START ; ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– SEND_START: SETB _2W_BUSY ; ÏÎÊÀÇÛÂÀÅÒ, ×ÒÎ ÂÛÏÎËÍßÅÒÑß ; ÄÂÓÕÏÐÎÂÎÄÍÀß ÎÏÅÐÀÖÈß CLR ACK ; ÑÁÐÀÑÛÂÀÅÒ ÔËÀÃÈ ÑÎÑÒÎßÍÈß CLR BUS_FAULT JNB SCL,FAULT ; ÏÐÎÂÅÐßÅÒ ØÈÍÓ JNB SDA,FAULT ; ÍÀ×ÀËÎ ÑÎÑÒÎßÍÈß START SETB SDA LCALL SCL_HIGH ; SDA CLR SDA ; LCALL DELAY ; SCL ^START CLR SCL RET FAULT: SETB BUS_FAULT ; ÓÑÒÀÍÀÂËÈÂÅÒ ÑÎÑÒÎßÍÈÅ ÎØÈÁÊÈ RET ; È ÂÛÕÎÄÈÒ ÈÇ ÏÎÄÏÐÎÃÐÀÌÌÛ ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ; ; ÝÒÀ ÏÎÄÏÐÎÃÐÀÌÌÀ ÏÎÑÛËÀÅÒ ÑÎÑÒÎßÍÈÅ STOP ; ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– SEND_STOP: CLR SDA ; SDA LCALL SCL_HIGH SETB SDA ; SCL ^STOP CLR _2W_BUSY RET ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ; ; ÝÒÀ ÏÎÄÏÐÎÃÐÀÌÌÀ ÏÎÑÛËÀÅÒ ÎÄÈÍ ÁÀÉÒ Â DS1307 ; ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– SEND_BYTE: MOV BITCOUNT,#08H ; ÓÑÒÀÍÀÂËÈÂÀÅÒ ÑרÒ×ÈÊ ÍÀ 8 ÁÈÒΠSB_LOOP: JNB ACC.7,NOTONE ; ÏÐÎÂÅÐßÅÒ ÐÀÂÅÍ ËÈ ÁÈÒ 7 ACC 1 SETB SDA ; ÓÑÒÀÍÀÂËÈÂÀÅÒ SDA  ÂÛÑÎÊÎÅ ÑÎÑÒÎßÍÈÅ JMP ONE NOTONE: CLR SDA ; ÑÁÐÀÑÛÂÀÅÒ SDA (0) ONE: LCALL SCL_HIGH ; ÏÅÐÅÕÎÄ ÍÀ SCL ÈÇ ÍÈÇÊÎÃÎ Â ÂÛÑÎÊÎÅ RL A ; ÑÄÂÈà ÂËÅÂÎ ACC ÍÀ 1 ÁÈÒ CLR SCL ; ÏÅÐÅÕÎÄ ÍÀ SCL ÈÇ ÂÛÑÎÊÎÃÎ Â ÍÈÇÊÎÅ DJNZ BITCOUNT,SB_LOOP ; ÖÈÊË ÄËß 8 ÁÈÒ SETB SDA ; ÓÑÒÀÍÀÂËÈÂÀÅÒ ÍÀ SDA ÂÛÑÎÊÎÅ ÑÎÑÒ. ; ÄËß ÈÌÏÓËÜÑÀ ÏÎÄÒÂÅÐÆÄÅÍÈß ÏÐȨÌÀ LCALL SCL_HIGH ; ÏÅÐÅÕÎÄ ÍÀ SCL ÈÇ ÍÈÇÊÎÃÎ Â ÂÛÑÎÊÎÅ CLR ACK ; ÑÁÐÎÑ ÔËÀÃÀ ÏÎÒÂÅÐÆÄÅÍÈß ÏÐȨÌÀ JNB SDA,SB_EX ; ÏÐÎÂÅÐÊÀ ÍÀ ÏÎÒÂÅÐÆ. ÈËÈ ÍÅÏÎÄÒÂÅÐÆ. SETB ACK ; ÓÑÒÀÍÎÂÊÀ ÔËÀÃÀ ÏÎÄÒÂÅÐÆÄÅÍÈß ÄËß ; ÍÅÏÎÄÒÂÅÐÆÄÅÍÈß SB_EX: LCALL DELAY ; ÇÀÄÅÐÆÊÀ ÎÏÅÐÀÖÈÈ CLR SCL ; ÏÅÐÅÕÎÄ ÍÀ SCL ; ÈÇ ÂÛÑÎÊÎÃÎ Â ÍÈÇÊÎÅ LCALL DELAY ; ÇÀÄÅÐÆÊÀ ÎÏÅÐÀÖÈÈ RET ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ; ; ÝÒÀ ÏÎÄÏÐÎÃÐÀÌÌÀ ×ÈÒÀÅÒ ÎÄÈÍ ÁÀÉÒ ÈÇ DS1307 ; ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– READ_BYTE: MOV BITCOUNT,#008H ; ÓÑÒÀÍÀÂËÈÂÀÅÒ ÑרÒ×ÈÊ ÍÀ 8 ÁÈÒ ; ÄÀÍÍÛÕ MOV A,#00H SETB SDA ; ÏÅÐÅÂÎÄÈÒ SDA  ÂÛÑÎÊÎÅ ÄËß ; ÎÑÂÎÁÆÄÅÍÈß ËÈÍÈÈ READ_BITS: LCALL SCL_HIGH ; ÏÅÐÅÕÎÄ SCL ÈÇ ÂÛÑÎÊÎÃÎ Â ÍÈÇÊÎÅ MOV C,SDA ; ÏÐÅÍÅÑÒÈ ÁÈÒ ÄÀÍÍÛÕ Â ÁÈÒ ; ÏÅÐÅÍÎÑÀ \ RLC A ; ÑÄÂÈÍÓÒÜ ÜÈÒ ÏÅÐÅÍÎÑÀ  ACC.0 CLR SCL ; ÏÅÐÅÕÎÄ SCL ÈÇ ÍÈÇÊÎÃÎ Â ÂÛÑÎÊÎÅ DJNZ BITCOUNT,READ_BITS ; ÖÈÊË ÄËß 8 ÁÈÒ JB LASTREAD,ACKN ; ÏÐÎÂÅÐÈÒÜ ÏÐÎ×ÈÒÀÍ ; ÏÎÑËÅÄÍÈÉ ÁÀÉÒ ? CLR SDA ; ÅÑËÈ Ñ×ÈÒÀÍ ÍÅ ÏÎÑËÅÄÍÈÉ, ; ÒÎ ÁÈÒ ÏÎÒÂÅÐÆÄÅÍÈß ACKN: LCALL SCL_HIGH ; ÈÌÏÓËÜÑ SCL ÄËß ÏÅÐÅÕÎÄÀ ; ÁÈÒÀ ÏÎÄÒÂÅÐÆÄÅÍÈß CLR SCL ; ÈËÈ ÍÅ ÏÎÄÒÂÅÐÆÄÅÍÈß RET ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ; ; ; ÝÒÀ ÏÎÄÏÐÎÃÐÀÌÌÀ ÏÅÐÅÂÎÄÈÒ ËÈÍÈÞ SCL  ÂÛÑÎÊÎÅ ÑÎÑÒÎßÍÈÅ ; ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– SCL_HIGH: SETB SCL ; ÓÑÒÀÍÎÂÊÀ SCL  ÂÛÑÎÊÎÅ JNB SCL,$ ; ÖÈÊË ÏÎÊÀ SCL  ÂÛÑÎÊÎÌ ÑÎÑÒÎßÍÈÈ RET ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ; ; ; ÝÒÀ ÏÎÄÏÐÎÃÐÀÌÌÀ ÄÅËÀÅÒ ÇÀÄÅÐÆÊÓ ÍÀ ØÈÍÅ ; ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– DELAY: NOP ; ÇÀÄÅÐÆÊÀ RET ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ; ; ÏÎÄÏÐÎÃÐÀÌÌÀ ÇÀÄÅÐÆÊÈ Â 4 ÖÈÊËÀ ; ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– DELAY_4: NOP ; ÇÀÄÅÐÆÊÀ NOP NOP NOP RET ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ; ; ÝÒÀ ÏÎÄÏÐÎÃÐÀÌÌÀ ÓÑÒÀÍÀÂËÈÂÀÅÒ ×ÀÑÛ ( ÐÓ×ÍÓÞ) ; ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– SET_CLOCKM: MOV R1,#2EH ; ÓÑÒÀÍÀÂ. R1  ÑÂÅÐÕÎÏÅÐÀÖÈÎÍÍÎÌ ÎÇÓ ; ÄËß ÄÀÒÛ\ÂÅÐÌÅÍÈ MOV DPTR, #YEAR ; ÏÎËÓ×ÈÒÜ ÄÀÒÓ\ÂÐÅÌß ; ÎÒ ÏÎËÜÇÎÂÀÒÅËß. LCALL WRITE_TEXT ; ÇÀÏÈÑÜ ÄÀÒÛ\ÂÐÅÌÅÍÈ ;  ÑÂÅÐÕÎÏÅÐÀÒÈÂÍÓÞ LCALL READ_BCD ; ÏÀÌßÒÜ MOV @R1,A DEC R1 MOV DPTR, #MONTH LCALL WRITE_TEXT LCALL READ_BCD MOV @R1,A DEC R1 MOV DPTR, #DAY LCALL WRITE_TEXT LCALL READ_BCD MOV @R1,A DEC R1 MOV DPTR, #DAYW LCALL WRITE_TEXT LCALL READ_BCD ANL A, #7 MOV @R1,A DEC R1 MOV DPTR, #HOUR LCALL WRITE_TEXT LCALL READ_BCD MOV @R1,A DEC R1 MOV DPTR, #MINUTE LCALL WRITE_TEXT LCALL READ_BCD MOV @R1,A DEC R1 MOV DPTR, #SECOND LCALL WRITE_TEXT LCALL READ_BCD MOV @R1,A MOV R1,#28H ; ÓÊÀÇÀÒÅËÜ ÍÀ ÄÀÍÍÛÅ ; ×ÀÑΠ ÑÂÅÐÕÎÏÅÐÀÒÈÂÍÎÅ ÎÇÓ LCALL SEND_START ; ÓÑÒÀÍÀÂËÈÂÀÅÒ ÑÎÑÒÎßÍÈÅ START MOV A,#DS1307W ; ÓÑÒÀÍÀÂËÈÂÀÅ ÊÎÌÀÍÄÓ ÇÀÏÈÑÈ DS1307 LCALL SEND_BYTE MOV A,#00H ; ÓÑÒÀÍÎÂÈÒÜ ÓÊÀÇÀÒÅËÜ ÄÀÍÍÛÕ ; ÍÀ ÐÅÃÈÑÒÐ 00H LCALL SEND_BYTE ; DS1307 SEND_LOOP: MOV A,@R1 ; ÄÂÈÃÀÅÒ ÏÅÐÂÛÉ ÁÀÉÒ ÄÀÍÍÛÕ ;  ACC LCALL SEND_BYTE INC R1 CJNE R1,#2FH,SEND_LOOP ; ÖÈÊË ÏÎÊÀ ÄÀÍÍÛÅ ÏÎÑÛËÀÞÒÑß ;  DS1307 LCALL SEND_STOP ; ÓÑÒÀÍÀÂËÈÂÀÅÒ ÑÎÑÒÎßÍÈÅ STOP RET ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ; ; ÝÒÀ ÏÎÄÏÐÎÃÐÀÌÌÀ ÓÑÒÀÍÀÂËÈÂÀÅÒ RAM ÏÎËÜÇÎÂÀÒÅËß DS1307 ;  ‘BYTE’ ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– SET_RAM: MOV R1,#08H ; ÓÊÀÇÀÒÅËÜ ÍÀ ; DS1307 RAM ÏÎËÜÇÎÂÀÒÅËß MOV DPTR, #TEXT5 ; ÑÎÎÁÙÅÍÈÅ ÄËß ÂÂÎÄÀ ÁÀÉÒÀ ÄÀÍÍÛÕ LCALL WRITE_TEXT ; LCALL READ_BCD ; ×ÒÅÍÈÅ ÁÀÉÒÀ Ñ ÊËÀÂÈÀÒÓÐÛ MOV BYTE,A ; È ÑÎÕÐÀÍÅÍÈÅ Â ’BYTE’ LCALL SEND_START ; ÓÑÒÀÍÀÂËÈÂÀÅÒ ÑÎÑÒÎßÍÈÅ START MOV A,#DS1307W ; ÇÀÃÐÓÆÀÅÒ ÊÎÌÀÍÄÓ ÇÀÏÈÑÈ DS1307 LCALL SEND_BYTE ; ÏÎÑÛËÀÅÒ ÊÎÌÀÍÄÓ ÇÀÏÈÈ MOV A,#08H ; ÓÑÒÀÍÀÂËÈÂÀÅÒ DS1307 ÓÊÀÇÀÒÅËÜ ÄÀÍÍÛÕ ÍÀ ; ÍÀ×ÀËÎ LCALL SEND_BYTE ; RAM ÏÎËÜÇÎÂÀÒÅËß – 08H SEND_LOOP2: MOV A,BYTE ; ÇÀÏÈÑÜ ÁÀÉÒÀ ÂÎ ÂÍÓÒÐÅÍÍÅÅ ; ÏÐÎÑÒÐÀÍÑÒÂÎ RAM, LCALL SEND_BYTE ; ÊÎÒÎÐÎÅ ÍÀÕÎÄÈÒÑß Ñ 08H ÏÎ 37H INC R1 CJNE R1,#040H,SEND_LOOP2 ; ÖÈÊË ÏÎÊÀ RAM ÍÅ ÇÀÏÎËÍÈÒÑß CALL SEND_STOP ; ÓÑÒÀÍÀÂËÈÂÀÅÒ ÑÎÑÒÎßÍÈÅ STOP RET ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ; ; ÝÒÀ ÏÎÄÏÐÎÃÐÀÌÌÀ ÓÑÒÀÍÀÂËÈÂÀÅÒ RAM ÏÎËÜÇÎÂÀÒÅËß DS1307 ÓÍÈÊÀËÜÍÛÌ ÎÁÐÀÇÎÌ ; ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– SET_RAM_UNQ: MOV R1,#08H ; ÓÊÀÇÀÒÅËÜ ÍÀ ÍÀ×ÀËÎ ; ÏÎËÜÇÎÂÀÒÅËÜÑÊÎÉ RAM DS1307 LCALL SEND_START ; ÓÑÒÀÍÎÂÊÀ ÑÎÑÒÎßÍÈß START MOV A,#DS1307W ; ÇÀÃÐÓÇÊÀ ÊÎÌÀÍÄÛ ÇÀÏÈÑÈ DS1307 LCALL SEND_BYTE ; ÏÎÑËÀÒÜ ÊÎÌÀÍÄÓ ÇÀÏÈÑÈ MOV A,#08H ; ÓÑÒÀÍÎÂÈÒÜ ÓÊÀÇÀÒÅËÜ ÄÀÍÍÛÕ DS1307 ÍÀ ; ÍÀ×ÀËÎ LCALL SEND_BYTE ; RAM ÏÎËÜÇÎÂÀÒÅËß – 08H SEND_LOOP3: LCALL SEND_BYTE ; ÊÎÒÎÐÎÅ ÍÀÕÎÄÈÒÑß Ñ 08H ÏÎ 37H INC R1 INC A CJNE R1,#040H,SEND_LOOP3 ; ÖÈÊË ÏÎÊÀ RAM ÍÅ ÇÀÏÎËÍÈÒÑß LCALL SEND_STOP ; ÏÎÑÛËÊÀ ÑÎÑÒÎßÍÈß STOP RET ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ; ; ÝÀ ÏÎÄÏÐÎÃÐÀÌÌÀ ×ÈÒÀÅÒ RAM DS1307 È ÇÀÏÈÑÛÂÀÅÒ Å¨  ÑÂÅÐÕÎÏÅÐÀÒÈÂÍÓÞ ÏÀÌßÒÜ ; ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– READ_RAM: MOV DPTR,#TEXT4 ; ÏÎÑËÀÒÜ ÑÎÎÁÙÅÍÈÅ Î ÍÀÆÀÒÈÈ ÊËÀÂÈØÈ LCALL WRITE_TEXT MOV R1,#30H ; ÍÀ×ÀËÎ ÐÅÃÈÑÒÐΠRAM  ; ÑÂÅÐÕÎÏÅÐÀÒÈÂÍÎÉ ÏÀÌßÒÈ MOV BYTECOUNT,#00H ; ÑרÒ×ÈÊ ÍÀ 56 ÁÀÉÒ RAM CLR LASTREAD ; ÔËÀà ÏÐÎÂÅÐÊÈ ÏÎÑËÅÄÍÅÃÎ ÏÐÎ×ÈÒÀÍÍÎÃÎ ÁÀÉÒÀ LCALL SEND_START ; ÏÎÑËÀÒÜ ÑÎÑÒÎßÍÈÅ START MOV A,#DS1307W ; ÏÎÑËÀÒÜ ÊÎÌÀÍÄÓ ÇÀÏÈÑÈ DS1307 LCALL SEND_BYTE MOV A,#08H ; ÓÑÒÀÍÎÂÈÒÜ ÓÊÀÇÀÒÅËÜ ÍÀ ÐÅÃÈÑÒÐ 08H ; DS1307 LCALL SEND_BYTE LCALL SEND_STOP ; ÓÑÒÀÍÎÂÈÒÜ ÑÎÑÒÎßÍÈÅ STOP LCALL SEND_START ; ÓÑÒÀÍÎÂÈÒÜ ÑÎÑÒÎßÍÈÅ START MOV A,#DS1307R ; ÏÎÑËÀÒÜ ÊÎÌÀÍÄÓ ×ÒÅÍÈß DS1307 LCALL SEND_BYTE READ_LOOP2: MOV A,BYTECOUNT ; ÏÐÎÂÅÐßÒÜ ×ÒÅÍÈÅ ÏÎÑËÅÄÍÅÃÎ ; ÁÀÉÒÀ CJNE A,#37H,NOT_LAST2 SETB LASTREAD ; ÅÑËÈ Ñ×ÈÒÀÍ ÏÎÑËÅÄÍÈÉ ÓÑÒÀÍÎÂÈÒÜ ; ÔËÀà LASTREAD NOT_LAST2: LCALL READ_BYTE ; ×ÒÅÍÈÅ ÁÀÉÒÀ ÄÀÍÍÛÕ MOV @R1,A ; ÏÅÐÅÌÅÑÒÈÜ ÄÀÍÍÛÅ Â ÑÂÅÐÕÎÏÅÐÀÒÈÂÍÓÞ ; ÏÀÌßÒÜ INC R1 ; ÓÂÅËÈ×ÈÒÜ ÇÍÀ×ÅÍÈÅ ÓÊÀÇÀÒÅËß ÍÀ 1 INC BYTECOUNT MOV A,BYTECOUNT CJNE A,#38H,READ_LOOP2 ; ÖÈÊË ÄËß ÂÍÓÒÐÅÍÍÅÉ RAM DS1307 LCALL SEND_STOP ; ÏÎÑËÀÒÜ ÑÎÑÒÎßÍÈÅ STOP LCALL DISP_RAM ; ÎÒÎÁÐÀÇÈÒÜ ÄÀÍÍÛÅ Â ; ÑÂÅÐÕÎÏÅÐÀÒÈÍÎÉ ÏÀÌßÒÈ JNB RI,$ ; ÆÄÀÒÜ ÏÎÊÀ ÍÅ ÍÀÆÀÒÀ ÊËÀÂÈØÀ CLR RI RET ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ; ; ÝÒÀ ÏÎÄÏÐÎÃÐÀÌÌÀ ÎÒÎÁÐÀÆÀÅÒ ÄÀÍÍÛÅ RAM  ÑÂÅÐÕÎÏÅÐÅÀÒÈÂÍÎÉ ÏÀÌßÒÈ ; ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– DISP_RAM: MOV R1,#30H ;ÍÀ×ÀËÎ RAM  ÑÂÅÐÕÎÏÅÐÀÒÈÂÍÎÉ ;ÏÀÌßÒÈ MOV BITCOUNT,#00H MOV DPTR,#TEXT6 ;ÎÒÎÁÐÀÆÀÒÜ ÂÅÐÕ ÒÀÁËÈÖÛ LCALL WRITE_TEXT DISP_ADDR: LCALL DISP_LOC ; ÎÒÎÁÐÀÆÀÅÒ ÇÍÀ×ÅÍÈÅ ÒÅÊÓÙÅÃÎ ; ÏÎËÎÆÅÍÈß Â RAM DIS_LOOP: MOV A,@R1 ; ÎÒÎÁÀÆÀÅÒ ÄÀÍÍÛÅ RAM ÑÎÕÐÀͨÍÍÛÅ ;  ÑÂÅÐÕÎÏÅÐÀÒÈÂÍÎÉ ÏÀÌßÒÈ LCALL WRITE_BCD ; ÏÐÅÎÁÐÀÇÎÂÀÍÈÅ Â ÔÎÐÌÀÒ BCD È ; ÎÒÎÁÐÀÆÅÍÈÅ INC R1 INC BITCOUNT MOV A,#20H ; ÏÐÎÑÒÐÀÍÑÒÂÎ ÌÅÆÄÓ ÁÀÉÒÀÌÈ ÄÀÍÍÛÕ LCALL WRITE_DATA MOV A,BITCOUNT CJNE A,#08H,DIS_LOOP ; ÏÅÐÅÕÎÄ ÑÒÐÎÊÈ ÏÎÑËÅ 8 ÁÀÉÒΠ; ÄÀÍÍÛÕ MOV BITCOUNT,#00H MOV DPTR,#TEXT3 ; ’CR,LF’ LCALL WRITE_TEXT CJNE R1,#68H,DISP_ADDR ; ÎÒÎÁÐÀÆÀÅÒ ÄÀÍÍÛÅ ÄËß 56 ÁÀÉÒΠ; RAM RET ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ; ; ; ÝÒÀ ÏÎÄÏÐÎÃÐÀÌÀ ÇÀÏÈÑÛÂÀÅÒ ÏÎËÎÆÅÍÈÅ ÄÀÍÍÛÕ Â RAM ; ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– DISP_LOC: MOV A,R1 ; ÎÒÎÁÐÀÆÅÍÈÅ HEX ÇÍÀ×ÅÍÈß ; ÄËß ÄÀÍÍÛÕ ADD A, #–28H ;  ÏÐÎÑÒÐÀÍÑÒÂÅ DS1307 RAM LCALL WRITE_BCD ; ÏÐÅÎÁÐÀÇÎÂÀÍÈÅ ÀÄÐÅÑÀ ÑÂÅÐÕÎÏÅÐÀÒÈÂÍÎÉ MOV A,#20H ; ÏÀÌßÒÈ Â ÀÄÐÅÑ DS1307 RAM LCALL WRITE_DATA MOV A,#20H LCALL WRITE_DATA MOV A,#20H LCALL WRITE_DATA RET ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ; ; ÝÒÀ ÏÎÄÏÐÎÃÐÀÌÌÀ ×ÈÒÀÅÒ ÏÎÊÀÇÀÍÈß ×ÀÑÎÂ È ÇÀÏÈÑÛÂÀÅÒ ÈÕ Â ; ÑÂÅÐÕÎÏÅÐÀÒÈÂÍÓÞ ÏÀÌßÒÜ ; ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– READ_CLOCK: MOV DPTR,#TEXT4 ; ÑÎÎÁÙÅÍÈÅ Î ÍÀÆÀÒÈÈ ÊËÀÂÈØÈ LCALL WRITE_TEXT READ_AGAIN: MOV R1,#28H ; ÍÀ×ÀËÎ ÐÅÃÈÑÒÐÀ ×ÀÑΠ ; ÑÂÅÐÕÎÏÅÐÀÒÈÂÍÓÞ RAM MOV BYTECOUNT,#00H ; ÑרÒ×ÈÊ ÄÎ 8 ÁÀÉÒΠÄËß ; ×ÀÑΠCLR LASTREAD ; ÏÐÎÂÅÐÊÀ ×ÒÅÍÈß ÔËÀÃÀ ÏÎÑËÅÄÍÅÃÎ ÁÀÉÒÀ LCALL SEND_START ; ÏÎÑÛËÊÀ ÑÎÑÒÎßÍÈß START MOV A,#DS1307W ; ÓÑÒÀÍÎÂÈÒÜ ÓÊÀÇÀÒÅËÜ ÍÀ ÐÅÃÈÑÒÐÅ 00H ; DS1307 LCALL SEND_BYTE MOV A,#00H LCALL SEND_BYTE LCALL SEND_STOP ; ÏÎÑÛËÊÀ ÑÎÑÒÎßÍÈß STOP LCALL SEND_START ; ÏÎÑÛËÊÀ ÑÎÑÒÎßÍÈß START MOV A,#DS1307R ; ÏÎÑÛËÊÀ ÊÎÌÀÍÄÛ ×ÒÅÍÈß DS1307 LCALL SEND_BYTE READ_LOOP: MOV A,BYTECOUNT ; ÏÐÎÂÅÐÊÀ ×ÒÅÍÈß ÏÎÑËÅÄÍÅÃÎ ; ÁÀÉÒÀ CJNE A,#07H,NOT_LAST SETB LASTREAD ; ÓÑÒÀÍÎÂÈÒÜ ÔËÀà ×ÒÅÍÈß ÏÎÑËÅÄÍÅÃÎ ÁÀÉÒÀ NOT_LAST: LCALL READ_BYTE ; ÏÐÎ×ÈÒÀÒÜ ÁÀÉÒ ÄÀÍÍÛÕ MOV @R1,A ; ÏÎÌÅÑÒÈÒÜ ÄÀÍÍÛÅ Â ÑÂÅÐÕÎÏÅÐÀÒÈÂÍÓÞ ; ÏÀÌßÒÜ MOV A,BYTECOUNT ; ÏÐÎÂÅÐÊÀ ×ÒÅÍÈß ; ÐÅÃÈÑÒÐÀ ÑÅÊÓÍÄ CJNE A,#00H,NOT_FIRST CLR OSC ; Î×ÈÑÒÊÀ ÔËÀÃÀ OSC MOV A,@R1 ; ÑÎÄÅÐÆÈÌÎÅ ÐÅÃÈÑÒÐÀ ÑÅÊÓÍÄ Â ACC JNB ACC.7,NO_OSC ; ÏÅÐÅÕÎÄ ÅÑËÈ ÁÈÒ 7 = 0 SETB OSC ; ÓÑÒÀÍÎÈÒÜ ÔËÀà OSC ÁÈÒ 7 = 1 CLR ACC.7 ; Î×ÈÑÒÈÒÜ ÁÈÒ 7 ÄËß ÎÒÎÁÐÀÆÅÍÈß MOV @R1,A ; ÂÅÐÍÓÒÜ ÄÀÍÍÛÅ Â ÑÂÅÐÕÎÏÅÐÀÒÈÂÍÓÞ ÏÀÌßÒÜ NO_OSC: NOT_FIRST: INC R1 ; ÓÂÅËÈ×ÈÒÜ ÑÎÄÅÐÆÈÌÎÅ ÑרÒ×ÈÊÀ ÍÀ 1 INC BYTECOUNT MOV A,BYTECOUNT CJNE A,#08H,READ_LOOP ; ÖÈÊË ÄËß ÂÍÓÒÐÅÍÍÈÕ ÐÅÃÈÑÒÐΠ; ×ÀÑΠLCALL SEND_STOP ; ÏÎÑËÀÒÜ ÑÎÑÒÎßÍÈ STOP LCALL DISP_CLOCK ; ÎÒÎÁÐÀÇÈÒÜ ÄÀÒÓ/ÂÐÅÌß ÈÇ ; ÑÂÅÐÕÎÏÅÐÀÒÈÂÍÎÉ ÏÀÌßÒÈ JNB RI,READ_AGAIN ; ×ÈÒÀÒÜ È ÎÒÎÁÐÀÆÀÒÜ ÏÎÊÀ ; ÍÅ ÍÀÆÀÒÀ ÊËÀÂÈØÀ CLR RI RET ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ; ; ÝÒÀ ÏÎÄÏÐÎÃÐÀÌÌÀ ÎÒÎÁÐÀÆÀÅÒ ÄÀÒÓ È ÂÐÅÌß ÕÐÀÍßÙÈÅÑß Â ; ÑÂÅÐÕÎÏÅÐÅÀÒÈÂÍÎÉ ÏÀÌßÒÈ ; ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– DISP_CLOCK: MOV DPTR,#TEXT1 ; ÄÀÒÀ: LCALL WRITE_TEXT MOV R1,#2DH ; ÌÅÑßÖ MOV A,@R1 LCALL WRITE_BCD MOV A,#’/’ LCALL WRITE_DATA MOV R1,#2CH ; ÄÀÒÀ MOV A,@R1 LCALL WRITE_BCD MOV A,#’/’ LCALL WRITE_DATA MOV R1,#2EH ; YEAR MOV A,@R1 LCALL WRITE_BCD MOV A,#09H ; ÒÀÁÓËßÖÈß LCALL WRITE_DATA MOV DPTR,#TEXT2 ; ÂÐÅÌß: LCALL WRITE_TEXT MOV R1,#2AH ; ×ÀÑÛ MOV A,@R1 LCALL WRITE_BCD MOV A,#3AH ; ÄÂÎÅÒÎ×ÈÅ LCALL WRITE_DATA MOV R1,#29H ; ÌÈÍÓÒÛ MOV A,@R1 LCALL WRITE_BCD MOV A,#3AH ; ÄÂÎÅÒÎ×ÈÅ LCALL WRITE_DATA MOV R1,#28H ; ÑÅÊÓÍÄÛ MOV A,@R1 LCALL WRITE_BCD RET ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ; ; ÝÒÀ ÏÎÄÏÐÎÃÐÀÌÌÀ ÓÑÒÀÍÀÂËÈÂÀÅÒ ÎÑÖÈËßÒÎÐ ÑÎÃËÀÑÍÎ ÁÈÒÓ OSC ; ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– OSC_CONTROL: LCALL SEND_START ; ÓÑÒÀÍÎÂÊÀ ÑÎÑÒÎßÍÈß START MOV A,#DS1307W ; ÓÑÒÀÍÎÂÈÒÜ ÓÊÀÇÀÒÅËÜ ÍÀ ÐÅÃÈÑÒÐ 00H ; DS1307 LCALL SEND_BYTE MOV A,#00H LCALL SEND_BYTE SETB LASTREAD ; ÓÑÒÀÍÎÂÈÒÜ ×ÒÅÍÈÅ ÏÎÑËÅÄÍÅÃÎ ÁÀÉÒÀ ; ÍÀ ÎÄÈÍÎ×ÍÎÅ ×ÒÅÍÈÅ LCALL SEND_STOP ; ÏÎÑËÀÒÜ ÑÎÑÒÎßÍÈÅ STOP LCALL SEND_START ; ÏÎÑËÀÒÜ ÑÎÑÒÎßÍÈÅ START MOV A,#DS1307R ; ÏÎÑËÀÒÜ ÊÎÌÀÍÄÓ ×ÒÅÍÈß ÄËß DS1307 LCALL SEND_BYTE LCALL READ_BYTE ; ×ÈÒÀÒÜ ÐÅÃÈÑÒÐ ÑÅÊÓÍÄ CLR ACC.7 ; ÂÊËÞ×ÈÒÜ OSC JNB OSC,OSC_SET SETB ACC.7 ; ÂÛÊËÞ×ÈÒÜ OSC ÅÑËÈ ÁÈÒ OSC ; ÓÑÒÀÍÎÂËÅÍ Â OSC_SET: ; ÐÅÃÈÑÒÐÅ ÑÅÊÓÍÄ PUSH ACC ; ÑÎÕÐÀÍÈÒÜ ÄÀÍÍÛÅ ÑÅÊÓÍÄ Â ÑÒÅÊÅ LCALL SEND_STOP ; ÏÎÑËÀÒÜ ÑÎÑÒÎßÍÈÅ STOP LCALL SEND_START ; ÏÎÑËÀÒÜ ÑÎÑÒÎßÍÈÅ START MOV A,#DS1307W ; ÓÑÒÀÍÎÂÈÒÜ ÓÊÀÇÀÒÅËÜ ÍÀ ÐÅÃÈÑÒÐ 00H ; DS1307 LCALL SEND_BYTE MOV A,#00H LCALL SEND_BYTE POP ACC ; ÏÎÑËÀÒÜ ÑÎÄÅÐÆÈÌÎÅ ÐÅÃÈÑÒÐÀ ÑÅÊÓÍÄ ; ÄËß ÓÏÐÀÂËÅÍÈß LCALL SEND_BYTE ; OSC DS1307 LCALL SEND_STOP RET ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ; ; ÝÒÀ ÏÎÄÏÐÎÃÐÀÌÌÀ ÓÑÒÀÍÀÂËÈÂÀÅÒ ÂÛÕÎÄ SQW ÍÀ 1Ãö ; ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– SQW_CONTROL_1HZ: LCALL SEND_START ; ÏÎÑËÀÒÜ ÑÎÑÒÎßÍÈÅ START MOV A,#DS1307W ; ÓÑÒÀÍÎÂÈÒÜ ÓÊÀÇÀÒÅËÜ ÍÀ ÐÅÃÈÑÒÐ 07H ; DS1307 LCALL SEND_BYTE MOV A,#07H LCALL SEND_BYTE MOV A,#90H ; SQW/OUT ÍÀ 1HZ JNB SQW,SQW_SET ; ÏÅÐÅÕÎÄ ÅÑËÈ ÁÈÒ SQW = 1 MOV A,#80H ; ÂÛÊËÞ×ÈÒÜ SQW/OUT SQW_SET: LCALL SEND_BYTE LCALL SEND_STOP RET ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ; ; ÝÒÀ ÏÎÄÏÐÎÃÐÀÌÌÀ ÓÑÒÀÍÀÂËÈÂÀÅÒ ÂÛÕÎÄ SQW ÍÀ 4êÃö ; ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– SQW_CONTROL_4KHZ: LCALL SEND_START ; ÏÎÑËÀÒÜ ÑÎÑÒÎßÍÈÅ START MOV A,#DS1307W ; ÓÑÒÀÍÎÂÈÒÜ ÓÊÀÇÀÒÅËÜ ÍÀ ÐÅÃÈÑÒÐ 07H ; DS1307 LCALL SEND_BYTE MOV A,#07H LCALL SEND_BYTE MOV A,#91H ; SQW/OUT ÍÀ 1Ãö JNB SQW,SQW_SET1 ; ÏÅÐÅÕÎÄ ÅÑËÈ ÁÈÒ SQW = 1 MOV A,#80H ; ÂÛÊËÞ×ÈÒÜ SQW/OUT SQW_SET1: LCALL SEND_BYTE LCALL SEND_STOP RET ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ; ; ÝÒÀ ÏÎÄÏÐÎÃÐÀÌÌÀ ÓÑÒÀÍÀÂËÈÂÀÅÒ ÂÛÕÎÄ SQW ÍÀ 8êÃö ; ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– SQW_CONTROL_8KHZ: LCALL SEND_START ; ÏÎÑËÀÒÜ ÑÎÑÒÎßÍÈÅ START MOV A,#DS1307W ; ÓÑÒÀÍÎÂÈÒÜ ÓÊÀÇÀÒÅËÜ ÍÀ ÐÅÃÈÑÒÐ 07H ; DS1307 LCALL SEND_BYTE MOV A,#07H LCALL SEND_BYTE MOV A,#92H ; SQW/OUT ÍÀ 1Ãö JNB SQW,SQW_SET2 ; ÏÅÐÅÕÎÄ ÅÑËÈ ÁÈÒ SQW = 1 MOV A,#80H ; ÂÛÊËÞ×ÈÒÜ SQW/OUT SQW_SET2: LCALL SEND_BYTE LCALL SEND_STOP RET ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ; ; ÝÒÀ ÏÎÄÏÐÎÃÐÀÌÌÀ ÓÑÒÀÍÀÂËÈÂÀÒ ÂÛÕÎÄ SQW ÍÀ 32êÃö ; ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– SQW_CONTROL_32KHZ: LCALL SEND_START ; ÏÎÑËÀÒÜ ÑÎÑÒÎßÍÈÅ START MOV A,#DS1307W ; ÓÑÒÀÍÎÂÈÒÜ ÓÊÀÇÀÒÅËÜ ÍÀ ÐÅÃÈÑÒÐ 07H ; DS1307 LCALL SEND_BYTE MOV A,#07H LCALL SEND_BYTE MOV A,#93H ; SQW/OUT ÍÀ 1Ãö JNB SQW,SQW_SET3 ; ÏÅÐÅÕÎÄ ÅÑËÈ ÁÈÒ SQW = 1 MOV A,#80H ; ÂÛÊËÞ×ÈÒÜ SQW/OUT SQW_SET3: LCALL SEND_BYTE LCALL SEND_STOP RET ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ; ; ÝÒÀ ÏÎÄÏÐÎÃÐÀÌÌÀ ÍÀÁËÞÄÀÅÒ ÇÀ ÒÐÈÃÃÅÐÍÛÌ ÁÈÒÎÌ ; ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– TRIGGER: CLR TRIG SETB TRIG LCALL DELAY_4 CLR TRIG RET ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ; ; ÝÒÀ ÏÎÄÏÐÎÃÐÀÌÌÀ Ñ×ÈÒÛÂÀÅÒ ÄÀÍÍÛÅ Ñ ÝÊÐÀÍÀ È ÏÐÅÎÁÐÀÇÓÅÒ ÈÕ Â BCD ÔÎÐÌÓ ; ; ÄÀÍÍÛÅ ÄÎËÆÍÛ ÁÛÒÜ ØÅÑÒÍÀÄÖÀÒÅÐÈ×ÍÛÌÈ: 1,2,3...9,A,B,C,D,E,F ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– READ_BCD: MOV R0,#0 ; ÑÁÐÎÑ R0 BCD_LOOP: LCALL READ_DATA ; ÏÐÎ×ÈÒÀÒÜ ÁÀÉÒ Ñ ÊËÀÂÈÀÒÓÐÛ LCALL WRITE_DATA ; ÇÀÏÈÑÜ ÁÀÉÒÀ ÎÁÐÀÒÍÎ ÍÀ ÝÊÐÀÍ CJNE A, #0DH, BCD ; ÏÐÎÂÅÐÊÀ CR MOV A,R0 ; ÏÅÐÅÌÅÑÒÈÒÜ R0  ACC È ÂÛÉÒÈ RET ; ÈÇ ÏÎÄÏÐÎÃÐÀÌÌÛ BCD: ADD A,#–30H ; ÍÀ×ÀËÎ ÏÐÅÎÁÐÀÇÎÂÀÍÈß Â ; ÄÅÉÑÒÂÈÒÅËÜÍÎÅ ÇÍÀ×ÅÍÈÅ JNB ACC.4,DIGIT ; ÏÅÐÅÕÎÄ ÅÑËÈ ÍÅ A–F ADD A,#–07H ; ÅÑËÈ A–F ÒÎ ÂÛ×ÈÒÀÒÜ 7 DIGIT: ANL A,#0FH ; ÎÁÅÑÏÅ×ÈÒÜ Î×ÈÑÒÊÓ ÁÈÒΠ4–7 ANL 0,#0FH ; XCH A,R0 ; ÏÎÌÅÍßÒÜ ÌÅÑÒÀÌÈ R0 È ACC SWAP A ; ÎÁÌÅÍ ÏÎËÓÁÀÉÒΠACC ORL A,R0 ; ÂÑÒÀÂÈÒÜ ÁÈÒÛ 0–3 R0  ACC MOV R0,A ; ÏÎÌÅÑÒÈÒÜ ACC  R0 SJMP BCD_LOOP ; ÖÈÊË ÏÎÊÀ ÂÑÒÐÅ×ÀÅÒÑß CR ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ; ; ÝÒÀ ÏÎÄÏÐÎÃÐÀÌÌÀ ÇÀÏÈÑÛÂÀÅÒ ÁÀÉÒ ÍÀ ÝÊÐÀÍ ; ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– WRITE_BCD: PUSH ACC ; ÇÀÏÈÑÀÒÜ ACC  ÑÒÅÊ SWAP A ; ÏÎÌÅÍßÒÜ ÏÎËÓÁÀÉÒÛ ACC ÌÅÑÒÀÌÈ ANL A,#0FH ; Î×ÈÑÒÈÒÜ ÁÈÒÛ 4–7 ADD A,#07H ; ÄÎÁÀÂÈÒÜ 7  ACC ÄËß ÏÐÅÎÁÐÀÇÎÂÀÍÈß ;  ASCII HEX JNB ACC.4, LESSNINE ; ÏÐÎÂÅÐÊÀ ÅÑËÈ ÌÅÍÜØÅ 9 ; 0–8 CJNE A,#10H,NOTNINE ; ÏÅÐÅÕÎÄ ÅÑËÈ ÁÎËÜØÅ 9 ; A–F LESSNINE: ADD A,#–07H ; ÏÐÈÁÀÂÈÒÜ 7 ÄËß 0–9 NOTNINE: ADD A,#30H ; ÏÐÈÁÀÂÈÒÜ 30 ÄËß ÏÐÅÎÁÐÀÇÎÂÀÍÈß ; ÝÊÂÈÂÀËÅÍÒ Â ASCII LCALL WRITE_DATA ; ÇÀÏÈÑÜ ÁÀÉÒÀ ÍÀ ÝÊÐÀÍ POP ACC ; ÂÛÇΠACC ÈÇ ÑÒÅÊÀ ANL A,#0FH ; ÒÎ ÆÅ ÑÀÌÎÅ ÄËß ÂÒÎÐÎÉ ; ÏÎËÎÂÈÍÛ ÁÀÉÒÀ ADD A,#07H JNB ACC.4,NINE2 CJNE A,#10H,NOTNINE2 NINE2: ADD A,#–07H NOTNINE2: ADD A,#30H LCALL WRITE_DATA RET ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– READ_DATA: JNB RI,READ_DATA ; ÖÈÊË ÏÎÊÀ ÁÈÒ RI=0 CLR RI MOV A,SBUF ; ÏÎËÓ×ÈÒÜ ÁÀÉÒ ÄÀÍÍÛÕ ; ÈÇ ÏÎÑËÅÄÎÂÀÒÅËÜÍÎÃÎ ÁÓÔÅÐÀ RET ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– WRITE_DATA: JNB TI,WRITE_DATA ; ÖÈÊË ÏÎÊÀ ÁÈÒ TI=0 CLR TI MOV SBUF,A ; ÏÎËÓ×ÈÒÜ ÁÀÉÒÄÀÍÍÛÕ ; ÈÇ ÏÎÑËÅÄÎÂÀÒÅËÜÍÎÃÎ ÁÓÔÅÐÀ RET ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– WRITE_TEXT: PUSH ACC ; ÑÎÕÐÀÍÈÒÜ ÁÀÉÒ ACC  ÑÒÅÊÅ WT1: CLR A ; Î×ÈÑÒÊÀ ACC MOVC A,@A+DPTR ; ÏÎÌÅÑÒÈÒÜ ÏÅÐÂÛÉ ÁÀÉÒ ÑÒÐÎÊÈ ;  ACC INC DPTR ; ÍÀÐÀÑÒÈÒÜ ÍÀ 1 ÓÊÀÇÀÒÅËÜ ÄÀÍÍÛÕ CJNE A,#0,WT2 ; ÏÐÎÂÅÐÊÀ ÍÀ ÊÎÍÅÖ ; ÑÒÐÎÊÈ – 0 POP ACC ; ÂÎÑÑÒÀÍÎÂÈÒÜ ACC RET ; ÂÅÐÍÓÒÑß ÊÎÃÄÀ ÑÒÐÎÊÀ ÏÎÑËÀÍÀ WT2: LCALL WRITE_DATA ; ÏÎÑËÀÒÜ ÁÀÉÒ ÑÒÐÎÊÈ ÏÎ ; ÏÎÑËÅÄÎÂÀÒÅËÜÍÎÌÓ ÏÎÐÒÓ SJMP WT1 ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– ; ; ÒÅÊÑÒÎÂÛÅ ÑÒÐÎÊÈ, ÈÑÏÎËÜÇÓÅÌÛÅ ÄËßÏÎËÜÇÎÂÀÒÅËÜÑÊÎÃÎ ÈÍÒÅÐÔÅÉÑÀ ÏÎ ; ÏÎÑËÅÄÎÂÀÒÅËÜÍÎÌÓ ÏÎÐÒÓ ; ;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– YEAR: DB CR,LF,’YEAR (0 – 99) : ’,0 MONTH: DB CR,LF,’MONTH (1 – 12) : ’,0 DAY: DB CR,LF,’DAY OF MONTH : ’,0 DAYW: DB CR,LF,’DAY OF WEEK : ’,0 HOUR: DB CR,LF,’HOUR (0 – 23) : ’,0 MINUTE: DB CR,LF,’MINUTE (0 – 59) : ’,0 SECOND: DB CR,LF,’SECOND (0 – 59) : ’,0 TRIER: DB CR,LF,’PRESS ANY KEY TO SET THIS TIME ’,CR,LF,0 TEXT0: DB CR,LF,’******* DALLAS SEMICONDUCTOR ******* ’ DB CR,LF,’ DS1307 TEST PROGRAM ’,CR,LF DB CR,LF,’PLEASE CHOOSE AN OPTION TO CONTINUE ’ DB CR,LF,’–––––––––––––––––––––––––––––––––––– ’ DB CR,LF,’A. SET TIME(MANUAL) B. SET RAM ’ DB CR,LF,’C. READ DATE/TIME D. READ RAM ’ DB CR,LF,’E. OSC ON F. OSC OFF ’ DB CR,LF DB CR,LF,’G. SQW/OUT ON–1HZ H. SQW/OUT ON–4KHZ’ DB CR,LF,’I. SQW/OUT ON–8KHZ J. SQW/OUT ON–32KHZ’ DB CR,LF DB CR,LF,’K. SQW/OUT OFF’ DB CR,LF,’L. WRITE RAM UNIQUE PATTERN ’ DB CR,LF,’ESC. TO QUIT ’,0 TEXT1: DB CR,’DATE: ’,0 TEXT2: DB ’TIME: ’,0 TEXT3: DB CR,LF,0 TEXT4: DB CR,LF,’PRESS ANY KEY TO RETURN’ DB C R,LF,0 TEXT5: DB CR,LF,’ENTER THE BYTE VALUE WHICH WILL FILL THE RAM’ DB CR,LF,0 TEXT6: DB CR,LF,’RAM RAM’ DB CR,LF,’ADDR DATA’ DB CR,LF,’–––––––––––––––––––––––––––––’ DB CR,LF,0 ;****************************************** ;**** ÊÎÍÅÖ ÏÐÎÃÐÀÌÌÛ ***************** ;****************************************** END Ãëàâíàÿ - Ìèêðîñõåìû - DOC - ÆÊÈ - Èñòî÷íèêè ïèòàíèÿ - Ýëåêòðîìåõàíèêà - Èíòåðôåéñû - Ïðîãðàììû - Ïðèìåíåíèÿ - Ñòàòüè |
|
Âïåðâûå? | Ðåêëàìà íà ñàéòå | Î ïðîåêòå | Êàðòà ïîðòàëà òåë. ðåäàêöèè: +7 (995) 900 6254. e-mail:info@eust.ru ©1998-2023 Ðûíîê Ìèêðîýëåêòðîíèêè |
|