it consist of PCF8583 assembly driver

源代码在线查看: timekey.asm

软件大小: 505 K
上传用户: ldy128520
关键词: assembly consist driver 8583
下载地址: 免注册下载 普通下载 VIP

相关代码

				;----------------------------------------------------------------------------
				;                    I N T E R R U P T     P R O G R A M M                   
				;----------------------------------------------------------------------------
				
				
				;------------------------------ Entrance ------------------------------------
				
				TimeKey:	sei			;global INT enable	
				
						push	r16		;push R16
						ldi	r16,177
						out	TCNT0,r16	;T/C0 start from 177
					
						in	r16,sreg	;push sreg
						push	r16		;push sreg
				
						push	XL		;
						push	XH		;
						push	YL		;
						push	YH		;
						push	R17		;
						push	R18		;
						push	R19		;
						push	R20		;
						push	R21		;
						push	R22		;
						push	R23		;Push Rx in STACK
				
				;------------------------------ EEPROM Write --------------------------------
				
				
				;------------------------------ MIRROR SERVICE ------------------------------
				
						lds	r16,PCF8583_FLAG	;Load 8583_FLAG from RAM
				
						tst	r16			;8583_FLAG = 0 ?
						brne	TK15			;If NOT goto TK8
				
					;---------------	READ Cycle	----------------------------
						rcall	I2CSTART		;BEGIN OF TRANSFER
						ldi	r16,0xA0		;RD Addr PLL => I2C
						rcall	I2COUT			;Exequte 
						ldi	r16,0x00		;GET REGISTER 0x00
						rcall	I2COUT			;Exequte
						rcall	I2CSTOP			;END OF TRANSFER
				
						rcall	I2CSTART		;BEGIN OF TRANSFER
						ldi	r16,0xA1		;RD Addr PLL => I2C
						rcall	I2COUT			;Exequte 
				
						ldi	ACK,15			;ACK --> Counter=15
						ldi	XL,PCF8583_A00		;XL --> First ADRESS in RAM
				M1:		rcall	I2CIN			;Read Byte=>R16 
						st	X+,R16			;Store REGISTER to RAM
						dec	ACK			;DEC ACK (Counter)
						brne M1
				
						rcall	I2CSTOP			;END OF TRANSFER
						rjmp	TK16
					
					;---------------	WRITE Cycle	----------------------------
				TK15:
				
						ldi	r16,0b00000100
						sts	PCF8583_A00,r16
						clr	r16
						sts	PCF8583_A09,r16
						sts	PCF8583_A0A,r16
						sts	PCF8583_A0D,r16
						sts	PCF8583_A0E,r16
						sts	PCF8583_A0F,r16
				
						;----- PCF8583 STOP TIME ENABLE -----
						lds	r17,PCF8583_A00	;Get STATUS REGISTER from RAM
						sbr	r17,0b10000000		;Set STOP flag
						sts	PCF8583_A00,r17	;GET STATUS REGISTER
						;------------------------------------
				
						rcall	I2CSTART		;BEGIN OF TRANSFER
						ldi	r16,0xA0		;RD Addr PLL => I2C
						rcall	I2COUT			;Exequte 
						ldi	r16,0x00		;GET STATUS REGISTER
						rcall	I2COUT			;Exequte
				
						ldi	r17,15			;R17 --> Counter=15
						ldi	XL,PCF8583_A00		;XL --> First ADRESS in RAM
				
				W1:		ld	r16,X+			;GET Digit from RAM
						rcall	I2COUT			;WRITE Byte=>R16 
						dec	R17			;DEC ACK (Counter)
						brne W1
				
						rcall	I2CSTOP			;END OF TRANSFER
				
				
						;----- PCF8583 STOP TIME DISABLE -----
						lds	r17,PCF8583_A00	;Get STATUS REGISTER from RAM
						cbr	r17,0b10000000		;Set STOP flag
						sts	PCF8583_A00,r17	;GET STATUS REGISTER
						
						rcall	I2CSTART		;BEGIN OF TRANSFER
						ldi	r16,0xA0		;RD Addr PLL => I2C
						rcall	I2COUT			;Exequte 
						ldi	r16,0x00		;GET STATUS REGISTER
						rcall	I2COUT			;Exequte
						mov	r16,r17			;GET STATUS REGISTER
						rcall	I2COUT			;Exequte
						rcall	I2CSTOP			;END OF TRANSFER
						;------------------------------------
				
						clr	r16
						sts	PCF8583_FLAG,r16	;Clear PCF8583 WRITE Flag	
				
				
				TK16:	
				;-------------------------- Procedure RCALL ---------------------------------
						
						ldi	XL,DIGIT_7SEG1		;First adress of digit in 7SEG code
						ldi	YL,DIGIT_DEC1		;First adress of digit in DEC  code
						rcall	DEC_2_7SEG			
				
						ldi	XL,DIGIT_7SEG2		;First adress of digit in 7SEG code
						ldi	YL,DIGIT_DEC2		;First adress of digit in DEC  code
						rcall	DEC_2_7SEG	
				
						tst	POINT			;Test POINT state (ON/OFF)
						brne	TK11
				
						lds	r16,DIGIT_7SEG1+2	;
						sbr	r16,0b00000100		;
						sts	DIGIT_7SEG1+2,r16	;Hardware 1/4s point simulation for CLOCK
				
						tst	ALRM			;Test ALARM state (ON/OFF)
						brne	TK10
						
						lds	r16,DIGIT_7SEG2	;
						cbr	r16,0b00000100		;
						sts	DIGIT_7SEG2,r16	;Hardware 1/4s point simulation for ALARM
						rjmp	TK11
				
				TK10:		lds	r16,DIGIT_7SEG2	;
						sbr	r16,0b00000100		;
						sts	DIGIT_7SEG2,r16	;Hardware 1/4s point simulation for ALARM
				
				TK11:	
				
				;----------------- HardWare DIGIT DISPLAY & BUTTONS Capture -----------------
				
								
						lds	r18,IND_COUNT		;Get IND_COUNT from RAM
						lds	XL,IND_ADR		;Get IND_ADR from RAM
						lds	r19,KEY_SHIFT		;Load KEY_SHIFT from RAM
						
				
					;---------------	BUTTONS Capture	----------------------
					
						in	r16,PIND		;Read BUTTONS state
						swap	r16
						andi	r16,0b00000001		;Get BUTTON Pressed/Not pressed
						
						tst	r16			;
						brne	TK12			;
						sec				;
						rjmp	TK13			;
				TK12:		clc				;
				TK13:		ror	r19			;KEY state creating
						sts	KEY_SHIFT,r19		;Store IND_COUNT to RAM
				
						cpi	r18,4			;Compare IND_COUNT & 4 (number of digits displayed)
						brne	TK14			;If NOT goto TK14
						mov	r20,r19			;
						swap	r20			;
						and	r20,r19			;
						andi	r20,0x0F		;
						mov	KEY,r20			;KEY creating (antidebezg & mask including)
				TK14:
				
					;----------------------------------------------------------------
				
					
					;---------	DIGIT ROLLING & DIG1/DIG2 SELECTION	---------------
				
						in	r16,PORTB		;GET PORTB State
						mov	r17,r16			;Duplicate R16 ==> R17
						andi	r17,0b00001111		;MASKING r17
						andi	r16,0b11110000		;MASKING r16
				
						cpi	r18,4			;Compare IND_COUNT & 4 (number of digits displayed)
						brne	TK4			;If NOT goto TK4
				
						lds	r18,IND_FLAG		;Load IND_FLAG from RAM
						tst	r18			;
						brne	TK8			;
						ldi	r18,DIGIT_7SEG1	;
						rjmp	TK9			;
				TK8:		ldi	r18,DIGIT_7SEG2	;DIGIT_7SEG1/DIGIT_7SEG2 Display selection
						
				TK9:		mov	XL,r18			;Store BEGIN of DIGITS in XL
				
						clr	r18			;Clear IND_COUNT
						clc				;CLEAR CARRY Flag
						rjmp	TK5
				TK4:		sec				;SET CARRY Flag
				TK5:		rol	r17			;ROL r17
						andi	r17,0b00001111		;MASKING r17
						or	r16,r17			;r16 + r17 ==> r16
						out	PORTB,r16		;r16 OUT to PORTB
								
				
					;----------------------------------------------------------------
				
						inc	r18			;INC IND_COUNT
						ld	R16,X+			;Load data to R16 from adress X 
						sts	IND_COUNT,r18		;STORE IND_COUNT to RAM
						sts	IND_ADR,XL		;STORE	IND_ADR to RAM
					
					;------------------	DIGIT OUT THRUE 74LS164	---------------
				
						ldi	r17,8
				TK1:		rol	r16			;ROL DIGIT_7SEG thrue CARRY
						brcc	TK2			;If C=0 goto TK2
						sbi	PORTD,IND_DATA		;DATA "1" for 74LS164
						rjmp	TK3
				TK2:		cbi	PORTD,IND_DATA		;DATA "0" for 74LS164
				TK3:		sbi 	PORTD,IND_CLOCK	;
						cbi 	PORTD,IND_CLOCK	;CLOCK for 74LS164
						dec	r17
						brne	TK1
				
					;------------------	IND_FLAG GENERATION	----------------------
				
						lds	r17,IND_FLAG		;Load IND_FLAG from RAM
						inc	CNT1			;INC CNT1
						cpi	CNT1,40			;Compare CNT1 & 40 DEC
						brne	TK6
						clr	r17			;Set IND_FLAG ==> 0x00
				TK6:		cpi	CNT1,80			;Compare CNT1 & 80 DEC
						brne	TK7
						ser	r17			;Set IND_FLAG ==> 0xFF
						clr	CNT1			;Clear CNT1
				
				TK7:		sts	IND_FLAG,r17		;Store 	IND_FLAG to RAM	
				
					;----------------------------------------------------------------
				
				
				
				;---------------- DELAY 025s ---------------------------------------------
				
						tst	DEL25
						breq	EXIT
						dec	DEL25
						rjmp	EXIT
						
				;-------------------------------------------------------------------------
				
				
				;------------------------------ EXIT ---------------------------------------
					
				EXIT:		pop	r23		;
						pop	r22		;
						pop	r21		;
						pop	r20		;
						pop	R19		;
						pop	R18		;
						pop	R17		;
						pop	YH		;
						pop	YL		;
						pop	XH		;
						pop	XL		;
						pop	r16		;Pop Rx from STACK
				
						out	sreg,r16	;Pop sreg
						pop	r16		;pop R16
				
						RETI			

相关资源