;CodeVisionAVR C Compiler V1.23.8c Standard
;(C) Copyright 1998-2003 HP InfoTech s.r.l.
;http://www.hpinfotech.ro
;e-mail:office@hpinfotech.ro

;Chip type           : AT90S8535
;Clock frequency     : 4,000000 MHz
;Memory model        : Small
;Optimize for        : Size
;(s)printf features  : int, width
;External SRAM size  : 0
;Data Stack size     : 128
;Promote char to int : No
;char is unsigned    : Yes
;8 bit enums         : Yes
;Automatic register allocation : On
;Use AVR Studio Terminal I/O   : No

	.DEVICE AT90S8535
	.LISTMAC
	.EQU UDRE=0x5
	.EQU RXC=0x7
	.EQU USR=0xB
	.EQU UDR=0xC
	.EQU EERE=0x0
	.EQU EEWE=0x1
	.EQU EEMWE=0x2
	.EQU SPSR=0xE
	.EQU SPDR=0xF
	.EQU EECR=0x1C
	.EQU EEDR=0x1D
	.EQU EEARL=0x1E
	.EQU EEARH=0x1F
	.EQU WDTCR=0x21
	.EQU MCUCR=0x35
	.EQU RAMPZ=0x3B
	.EQU SPL=0x3D
	.EQU SPH=0x3E
	.EQU SREG=0x3F

	.DEF R0X0=R0
	.DEF R0X1=R1
	.DEF R0X2=R2
	.DEF R0X3=R3
	.DEF R0X4=R4
	.DEF R0X5=R5
	.DEF R0X6=R6
	.DEF R0X7=R7
	.DEF R0X8=R8
	.DEF R0X9=R9
	.DEF R0XA=R10
	.DEF R0XB=R11
	.DEF R0XC=R12
	.DEF R0XD=R13
	.DEF R0XE=R14
	.DEF R0XF=R15
	.DEF R0X10=R16
	.DEF R0X11=R17
	.DEF R0X12=R18
	.DEF R0X13=R19
	.DEF R0X14=R20
	.DEF R0X15=R21
	.DEF R0X16=R22
	.DEF R0X17=R23
	.DEF R0X18=R24
	.DEF R0X19=R25
	.DEF R0X1A=R26
	.DEF R0X1B=R27
	.DEF R0X1C=R28
	.DEF R0X1D=R29
	.DEF R0X1E=R30
	.DEF R0X1F=R31

	.EQU __se_bit=0x40
	.EQU __sm_mask=0x30
	.EQU __sm_powerdown=0x20

	.MACRO __CPD1N
	CPI  R30,LOW(@0)
	LDI  R26,HIGH(@0)
	CPC  R31,R26
	LDI  R26,BYTE3(@0)
	CPC  R22,R26
	LDI  R26,BYTE4(@0)
	CPC  R23,R26
	.ENDM

	.MACRO __CPD2N
	CPI  R26,LOW(@0)
	LDI  R30,HIGH(@0)
	CPC  R27,R30
	LDI  R30,BYTE3(@0)
	CPC  R24,R30
	LDI  R30,BYTE4(@0)
	CPC  R25,R30
	.ENDM

	.MACRO __CPWRR
	CP   R@0,R@2
	CPC  R@1,R@3
	.ENDM

	.MACRO __CPWRN
	CPI  R@0,LOW(@2)
	LDI  R30,HIGH(@2)
	CPC  R@1,R30
	.ENDM

	.MACRO __ADDD1N
	SUBI R30,LOW(-@0)
	SBCI R31,HIGH(-@0)
	SBCI R22,BYTE3(-@0)
	SBCI R23,BYTE4(-@0)
	.ENDM

	.MACRO __ADDD2N
	SUBI R26,LOW(-@0)
	SBCI R27,HIGH(-@0)
	SBCI R24,BYTE3(-@0)
	SBCI R25,BYTE4(-@0)
	.ENDM

	.MACRO __SUBD1N
	SUBI R30,LOW(@0)
	SBCI R31,HIGH(@0)
	SBCI R22,BYTE3(@0)
	SBCI R23,BYTE4(@0)
	.ENDM

	.MACRO __SUBD2N
	SUBI R26,LOW(@0)
	SBCI R27,HIGH(@0)
	SBCI R24,BYTE3(@0)
	SBCI R25,BYTE4(@0)
	.ENDM

	.MACRO __ANDD1N
	ANDI R30,LOW(@0)
	ANDI R31,HIGH(@0)
	ANDI R22,BYTE3(@0)
	ANDI R23,BYTE4(@0)
	.ENDM

	.MACRO __ORD1N
	ORI  R30,LOW(@0)
	ORI  R31,HIGH(@0)
	ORI  R22,BYTE3(@0)
	ORI  R23,BYTE4(@0)
	.ENDM

	.MACRO __DELAY_USB
	LDI  R24,LOW(@0)
__DELAY_USB_LOOP:
	DEC  R24
	BRNE __DELAY_USB_LOOP
	.ENDM

	.MACRO __DELAY_USW
	LDI  R24,LOW(@0)
	LDI  R25,HIGH(@0)
__DELAY_USW_LOOP:
	SBIW R24,1
	BRNE __DELAY_USW_LOOP
	.ENDM

	.MACRO __CLRD1S
	CLR  R30
	STD  Y+@0,R30
	STD  Y+@0+1,R30
	STD  Y+@0+2,R30
	STD  Y+@0+3,R30
	.ENDM

	.MACRO __GETD1S
	LDD  R30,Y+@0
	LDD  R31,Y+@0+1
	LDD  R22,Y+@0+2
	LDD  R23,Y+@0+3
	.ENDM

	.MACRO __PUTD1S
	STD  Y+@0,R30
	STD  Y+@0+1,R31
	STD  Y+@0+2,R22
	STD  Y+@0+3,R23
	.ENDM

	.MACRO __POINTB1MN
	LDI  R30,LOW(@0+@1)
	.ENDM

	.MACRO __POINTW1MN
	LDI  R30,LOW(@0+@1)
	LDI  R31,HIGH(@0+@1)
	.ENDM

	.MACRO __POINTW1FN
	LDI  R30,LOW(2*@0+@1)
	LDI  R31,HIGH(2*@0+@1)
	.ENDM

	.MACRO __POINTB2MN
	LDI  R26,LOW(@0+@1)
	.ENDM

	.MACRO __POINTW2MN
	LDI  R26,LOW(@0+@1)
	LDI  R27,HIGH(@0+@1)
	.ENDM

	.MACRO __GETD1N
	LDI  R30,LOW(@0)
	LDI  R31,HIGH(@0)
	LDI  R22,BYTE3(@0)
	LDI  R23,BYTE4(@0)
	.ENDM

	.MACRO __GETD2N
	LDI  R26,LOW(@0)
	LDI  R27,HIGH(@0)
	LDI  R24,BYTE3(@0)
	LDI  R25,BYTE4(@0)
	.ENDM

	.MACRO __GETD2S
	LDD  R26,Y+@0
	LDD  R27,Y+@0+1
	LDD  R24,Y+@0+2
	LDD  R25,Y+@0+3
	.ENDM

	.MACRO __GETB1MN
	LDS  R30,@0+@1
	.ENDM

	.MACRO __GETW1MN
	LDS  R30,@0+@1
	LDS  R31,@0+@1+1
	.ENDM

	.MACRO __GETD1MN
	LDS  R30,@0+@1
	LDS  R31,@0+@1+1
	LDS  R22,@0+@1+2
	LDS  R23,@0+@1+3
	.ENDM

	.MACRO __GETBRMN
	LDS  R@2,@0+@1
	.ENDM

	.MACRO __GETWRMN
	LDS  R@2,@0+@1
	LDS  R@3,@0+@1+1
	.ENDM

	.MACRO __GETB2MN
	LDS  R26,@0+@1
	.ENDM

	.MACRO __GETW2MN
	LDS  R26,@0+@1
	LDS  R27,@0+@1+1
	.ENDM

	.MACRO __GETD2MN
	LDS  R26,@0+@1
	LDS  R27,@0+@1+1
	LDS  R24,@0+@1+2
	LDS  R25,@0+@1+3
	.ENDM

	.MACRO __PUTB1MN
	STS  @0+@1,R30
	.ENDM

	.MACRO __PUTW1MN
	STS  @0+@1,R30
	STS  @0+@1+1,R31
	.ENDM

	.MACRO __PUTD1MN
	STS  @0+@1,R30
	STS  @0+@1+1,R31
	STS  @0+@1+2,R22
	STS  @0+@1+3,R23
	.ENDM

	.MACRO __PUTBMRN
	STS  @0+@1,R@2
	.ENDM

	.MACRO __PUTWMRN
	STS  @0+@1,R@2
	STS  @0+@1+1,R@3
	.ENDM

	.MACRO __GETW1R
	MOV  R30,R@0
	MOV  R31,R@1
	.ENDM

	.MACRO __GETW2R
	MOV  R26,R@0
	MOV  R27,R@1
	.ENDM

	.MACRO __GETWRN
	LDI  R@0,LOW(@2)
	LDI  R@1,HIGH(@2)
	.ENDM

	.MACRO __PUTW1R
	MOV  R@0,R30
	MOV  R@1,R31
	.ENDM

	.MACRO __PUTW2R
	MOV  R@0,R26
	MOV  R@1,R27
	.ENDM

	.MACRO __ADDWRN
	SUBI R@0,LOW(-@2)
	SBCI R@1,HIGH(-@2)
	.ENDM

	.MACRO __ADDWRR
	ADD  R@0,R@2
	ADC  R@1,R@3
	.ENDM

	.MACRO __SUBWRN
	SUBI R@0,LOW(@2)
	SBCI R@1,HIGH(@2)
	.ENDM

	.MACRO __SUBWRR
	SUB  R@0,R@2
	SBC  R@1,R@3
	.ENDM

	.MACRO __ANDWRN
	ANDI R@0,LOW(@2)
	ANDI R@1,HIGH(@2)
	.ENDM

	.MACRO __ANDWRR
	AND  R@0,R@2
	AND  R@1,R@3
	.ENDM

	.MACRO __ORWRN
	ORI  R@0,LOW(@2)
	ORI  R@1,HIGH(@2)
	.ENDM

	.MACRO __ORWRR
	OR   R@0,R@2
	OR   R@1,R@3
	.ENDM

	.MACRO __EORWRR
	EOR  R@0,R@2
	EOR  R@1,R@3
	.ENDM

	.MACRO __GETWRS
	LDD  R@0,Y+@2
	LDD  R@1,Y+@2+1
	.ENDM

	.MACRO __PUTWSR
	STD  Y+@2,R@0
	STD  Y+@2+1,R@1
	.ENDM

	.MACRO __MOVEWRR
	MOV  R@0,R@2
	MOV  R@1,R@3
	.ENDM

	.MACRO __INWR
	IN   R@0,@2
	IN   R@1,@2+1
	.ENDM

	.MACRO __OUTWR
	OUT  @2+1,R@1
	OUT  @2,R@0
	.ENDM

	.MACRO __CALL1MN
	LDS  R30,@0+@1
	LDS  R31,@0+@1+1
	ICALL
	.ENDM

	.MACRO __NBST
	BST  R@0,@1
	IN   R30,SREG
	LDI  R31,0x40
	EOR  R30,R31
	OUT  SREG,R30
	.ENDM


	.MACRO __PUTB1SN
	LDD  R26,Y+@0
	LDD  R27,Y+@0+1
	SUBI R26,LOW(-@1)
	SBCI R27,HIGH(-@1)
	ST   X,R30
	.ENDM

	.MACRO __PUTW1SN
	LDD  R26,Y+@0
	LDD  R27,Y+@0+1
	SUBI R26,LOW(-@1)
	SBCI R27,HIGH(-@1)
	ST   X+,R30
	ST   X,R31
	.ENDM

	.MACRO __PUTD1SN
	LDD  R26,Y+@0
	LDD  R27,Y+@0+1
	SUBI R26,LOW(-@1)
	SBCI R27,HIGH(-@1)
	RCALL __PUTDP1
	.ENDM

	.MACRO __PUTB1SNS
	LDD  R26,Y+@0
	LDD  R27,Y+@0+1
	ADIW R26,@1
	ST   X,R30
	.ENDM

	.MACRO __PUTW1SNS
	LDD  R26,Y+@0
	LDD  R27,Y+@0+1
	ADIW R26,@1
	ST   X+,R30
	ST   X,R31
	.ENDM

	.MACRO __PUTD1SNS
	LDD  R26,Y+@0
	LDD  R27,Y+@0+1
	ADIW R26,@1
	RCALL __PUTDP1
	.ENDM

	.MACRO __PUTB1PMN
	LDS  R26,@0
	LDS  R27,@0+1
	SUBI R26,LOW(-@1)
	SBCI R27,HIGH(-@1)
	ST   X,R30
	.ENDM

	.MACRO __PUTW1PMN
	LDS  R26,@0
	LDS  R27,@0+1
	SUBI R26,LOW(-@1)
	SBCI R27,HIGH(-@1)
	ST   X+,R30
	ST   X,R31
	.ENDM

	.MACRO __PUTD1PMN
	LDS  R26,@0
	LDS  R27,@0+1
	SUBI R26,LOW(-@1)
	SBCI R27,HIGH(-@1)
	RCALL __PUTDP1
	.ENDM

	.MACRO __PUTB1PMNS
	LDS  R26,@0
	LDS  R27,@0+1
	ADIW R26,@1
	ST   X,R30
	.ENDM

	.MACRO __PUTW1PMNS
	LDS  R26,@0
	LDS  R27,@0+1
	ADIW R26,@1
	ST   X+,R30
	ST   X,R31
	.ENDM

	.MACRO __PUTD1PMNS
	LDS  R26,@0
	LDS  R27,@0+1
	ADIW R26,@1
	RCALL __PUTDP1
	.ENDM

	.MACRO __GETB1SX
	MOV  R30,R28
	MOV  R31,R29
	SUBI R30,LOW(-@0)
	SBCI R31,HIGH(-@0)
	LD   R30,Z
	.ENDM

	.MACRO __GETW1SX
	MOV  R30,R28
	MOV  R31,R29
	SUBI R30,LOW(-@0)
	SBCI R31,HIGH(-@0)
	LD   R0,Z+
	LD   R31,Z
	MOV  R30,R0
	.ENDM

	.MACRO __GETD1SX
	MOV  R30,R28
	MOV  R31,R29
	SUBI R30,LOW(-@0)
	SBCI R31,HIGH(-@0)
	LD   R0,Z+
	LD   R1,Z+
	LD   R22,Z+
	LD   R23,Z
	MOV  R30,R0
	MOV  R31,R1
	.ENDM

	.MACRO __GETB2SX
	MOV  R26,R28
	MOV  R27,R29
	SUBI R26,LOW(-@0)
	SBCI R27,HIGH(-@0)
	LD   R26,X
	.ENDM

	.MACRO __GETW2SX
	MOV  R26,R28
	MOV  R27,R29
	SUBI R26,LOW(-@0)
	SBCI R27,HIGH(-@0)
	LD   R0,X+
	LD   R27,X
	MOV  R26,R0
	.ENDM

	.MACRO __GETD2SX
	MOV  R26,R28
	MOV  R27,R29
	SUBI R26,LOW(-@0)
	SBCI R27,HIGH(-@0)
	LD   R0,X+
	LD   R1,X+
	LD   R24,X+
	LD   R25,X
	MOV  R26,R0
	MOV  R27,R1
	.ENDM

	.MACRO __GETBRSX
	MOV  R30,R28
	MOV  R31,R29
	SUBI R30,LOW(-@1)
	SBCI R31,HIGH(-@1)
	LD   R@0,Z
	.ENDM

	.MACRO __GETWRSX
	MOV  R30,R28
	MOV  R31,R29
	SUBI R30,LOW(-@2)
	SBCI R31,HIGH(-@2)
	LD   R@0,Z+
	LD   R@1,Z
	.ENDM

	.MACRO __LSLW8SX
	MOV  R30,R28
	MOV  R31,R29
	SUBI R30,LOW(-@0)
	SBCI R31,HIGH(-@0)
	LD   R31,Z
	CLR  R30
	.ENDM

	.MACRO __PUTB1SX
	MOV  R26,R28
	MOV  R27,R29
	SUBI R26,LOW(-@0)
	SBCI R27,HIGH(-@0)
	ST   X,R30
	.ENDM

	.MACRO __PUTW1SX
	MOV  R26,R28
	MOV  R27,R29
	SUBI R26,LOW(-@0)
	SBCI R27,HIGH(-@0)
	ST   X+,R30
	ST   X,R31
	.ENDM

	.MACRO __PUTD1SX
	MOV  R26,R28
	MOV  R27,R29
	SUBI R26,LOW(-@0)
	SBCI R27,HIGH(-@0)
	ST   X+,R30
	ST   X+,R31
	ST   X+,R22
	ST   X,R23
	.ENDM

	.MACRO __CLRW1SX
	MOV  R30,R28
	MOV  R31,R29
	SUBI R30,LOW(-@0)
	SBCI R31,HIGH(-@0)
	CLR  R0
	ST   Z+,R0
	ST   Z,R0
	.ENDM

	.MACRO __CLRD1SX
	MOV  R30,R28
	MOV  R31,R29
	SUBI R30,LOW(-@0)
	SBCI R31,HIGH(-@0)
	CLR  R0
	ST   Z+,R0
	ST   Z+,R0
	ST   Z+,R0
	ST   Z,R0
	.ENDM

	.MACRO __PUTB2SX
	MOV  R30,R28
	MOV  R31,R29
	SUBI R30,LOW(-@0)
	SBCI R31,HIGH(-@0)
	ST   Z,R26
	.ENDM

	.MACRO __PUTW2SX
	MOV  R30,R28
	MOV  R31,R29
	SUBI R30,LOW(-@0)
	SBCI R31,HIGH(-@0)
	ST   Z+,R26
	ST   Z,R27
	.ENDM

	.MACRO __PUTBSRX
	MOV  R30,R28
	MOV  R31,R29
	SUBI R30,LOW(-@0)
	SBCI R31,HIGH(-@0)
	ST   Z,R@1
	.ENDM

	.MACRO __PUTWSRX
	MOV  R30,R28
	MOV  R31,R29
	SUBI R30,LOW(-@2)
	SBCI R31,HIGH(-@2)
	ST   Z+,R@0
	ST   Z,R@1
	.ENDM

	.MACRO __PUTB1SNX
	MOV  R26,R28
	MOV  R27,R29
	SUBI R26,LOW(-@0)
	SBCI R27,HIGH(-@0)
	LD   R0,X+
	LD   R27,X
	MOV  R26,R0
	SUBI R26,LOW(-@1)
	SBCI R27,HIGH(-@1)
	ST   X,R30
	.ENDM

	.MACRO __PUTW1SNX
	MOV  R26,R28
	MOV  R27,R29
	SUBI R26,LOW(-@0)
	SBCI R27,HIGH(-@0)
	LD   R0,X+
	LD   R27,X
	MOV  R26,R0
	SUBI R26,LOW(-@1)
	SBCI R27,HIGH(-@1)
	ST   X+,R30
	ST   X,R31
	.ENDM

	.MACRO __PUTD1SNX
	MOV  R26,R28
	MOV  R27,R29
	SUBI R26,LOW(-@0)
	SBCI R27,HIGH(-@0)
	LD   R0,X+
	LD   R27,X
	MOV  R26,R0
	SUBI R26,LOW(-@1)
	SBCI R27,HIGH(-@1)
	ST   X+,R30
	ST   X+,R31
	ST   X+,R22
	ST   X,R23
	.ENDM

	.CSEG
	.ORG 0

	.INCLUDE "acces1el.vec"
	.INCLUDE "acces1el.inc"

__RESET:
	CLI
	CLR  R30
	OUT  EECR,R30
	OUT  MCUCR,R30

;DISABLE WATCHDOG
	LDI  R31,0x18
	OUT  WDTCR,R31
	LDI  R31,0x10
	OUT  WDTCR,R31

;CLEAR R2-R14
	LDI  R24,13
	LDI  R26,2
	CLR  R27
__CLEAR_REG:
	ST   X+,R30
	DEC  R24
	BRNE __CLEAR_REG

;CLEAR SRAM
	LDI  R24,LOW(0x200)
	LDI  R25,HIGH(0x200)
	LDI  R26,0x60
__CLEAR_SRAM:
	ST   X+,R30
	SBIW R24,1
	BRNE __CLEAR_SRAM

;GLOBAL VARIABLES INITIALIZATION
	LDI  R30,LOW(__GLOBAL_INI_TBL*2)
	LDI  R31,HIGH(__GLOBAL_INI_TBL*2)
__GLOBAL_INI_NEXT:
	LPM
	ADIW R30,1
	MOV  R1,R0
	LPM
	ADIW R30,1
	MOV  R22,R30
	MOV  R23,R31
	MOV  R31,R0
	MOV  R30,R1
	SBIW R30,0
	BREQ __GLOBAL_INI_END
	LPM
	ADIW R30,1
	MOV  R26,R0
	LPM
	ADIW R30,1
	MOV  R27,R0
	LPM
	ADIW R30,1
	MOV  R24,R0
	LPM
	ADIW R30,1
	MOV  R25,R0
__GLOBAL_INI_LOOP:
	LPM
	ADIW R30,1
	ST   X+,R0
	SBIW R24,1
	BRNE __GLOBAL_INI_LOOP
	MOV  R30,R22
	MOV  R31,R23
	RJMP __GLOBAL_INI_NEXT
__GLOBAL_INI_END:

;STACK POINTER INITIALIZATION
	LDI  R30,LOW(0x25F)
	OUT  SPL,R30
	LDI  R30,HIGH(0x25F)
	OUT  SPH,R30

;DATA STACK POINTER INITIALIZATION
	LDI  R28,LOW(0xE0)
	LDI  R29,HIGH(0xE0)

	RJMP _main

	.ESEG
	.ORG 0
	.DB  0 ; FIRST EEPROM LOCATION NOT USED, SEE ATMEL ERRATA SHEETS

	.DSEG
	.ORG 0xE0
;       1 /*********************************************
;       2 This program was produced by the
;       3 CodeWizardAVR V1.0.2.2d Standard
;       4 Automatic Program Generator
;       5 © Copyright 1998-2002
;       6 Pavel Haiduc, HP InfoTech s.r.l.
;       7 http://www.hpinfotech.ro
;       8 e-mail:office@hpinfotech.ro , hpinfotech@xmail.ro
;       9 
;      10 Project : PPE contrôle d'accès
;      11 Version : 2
;      12 Date    : 18/01/2003
;      13 Author  : 
;      14 Company : Lycée PE MARTIN
;      15 Comments: Lecture du code dans une mémoire I2C 24C32 ou 24C65, traitement et simulation 
;      16 de la commande du portail
;      17 Entrée : Carte en place si Fréq = 0, 
;      18 Sortie : Led0 allumée = ouverture du portail
;      19 
;      20 Chip type           : AT90S8535
;      21 Clock frequency     : 4,000000 MHz
;      22 Memory model        : Small
;      23 Internal SRAM size  : 512
;      24 External SRAM size  : 0
;      25 Data Stack size     : 128
;      26 *********************************************/
;      27 
;      28 #include <90s8535.h>
;      29 
;      30 // Librairies non générées par Wizard (à rajouter)      
;      31 #include <ssi.h>      	// contient les fonctions Lire_BP, Affiche_LCD et RegleHTR 
;      32 			// eeprom_read
;      33 #include <delay.h> 	// contient la fonction delay_ms
;      34 #include <stdio.h>      // contient la fonction sprintf
;      35 
;      36 // Etats du graphe des transitions
;      37 #define Attente	 	0
;      38 #define Traitement 	1
;      39 #define Refus 		2
;      40 #define RetraitCarte	3
;      41 #define CdePortail	4
;      42 #define Reglage_HTR	5
;      43 
;      44 // Codes des BP de la carte SSI
;      45 #define INC		0b00011111
;      46 #define DEC		0b00101111
;      47 #define OK		0b00110111
;      48 #define ECHAP		0b00111011
;      49 #define SET		0b00111101
;      50 #define ENTER		0b00111110
;      51 
;      52 // codes d'acces
;      53 #define administration	'A'    // à remplacer par vos codes
;      54 #define prof		'P'
;      55 #define eleve		'E'
;      56 
;      57 // define booléens
;      58 #define autorise 1
;      59 #define refuse 0
;      60  
;      61 // I2C Bus functions
;      62 #asm
;      63    .equ __i2c_port=0x12
   .equ __i2c_port=0x12
;      64    .equ __sda_bit=3
   .equ __sda_bit=3
;      65    .equ __scl_bit=4
   .equ __scl_bit=4
;      66 #endasm

;      67 #include <i2c.h>
;      68 
;      69 // DS1621 Thermometer/Thermostat functions
;      70 #include <ds1621.h>
;      71 
;      72 // PCF8583 Real Time Clock functions
;      73 #include <pcf8583.h>
;      74 
;      75 // Alphanumeric LCD Module functions
;      76 #asm
;      77    .equ __lcd_port=0x15
   .equ __lcd_port=0x15
;      78 #endasm

;      79 #include <lcd.h>
;      80 
;      81 // Declare your global variables here
;      82 char display_buffer_ligne0[17]; // tampon ligne 0 de l'afficheur
_display_buffer_ligne0:
	.BYTE 0x11
;      83 char display_buffer_ligne1[17]; // tampon ligne 1 de l'afficheur
_display_buffer_ligne1:
	.BYTE 0x11
;      84 char heures, minutes, secondes, secondes_1, dizieme; //stockage de l'heure
;      85 
;      86 // Prototype des fonctions
;      87 unsigned char Traiter_code(char);
;      88 
;      89 void main(void)
;      90 {

	.CSEG
_main:
;      91 // Declare your local variables here
;      92 // etat, etat_1 : position dans le graphe des transitions
;      93 // BP : état du clavier
;      94 unsigned char etat=Attente, etat_1 = Reglage_HTR, BP;
;      95 unsigned char Heure_ou_Date, Acces;
;      96 char H_J, mn_mois,code;
;      97 int sec_annee;
;      98 
;      99 
;     100 // Input/Output Ports initialization
;     101 // Port A
;     102 PORTA=0x1F;
	SBIW R28,4
;	etat -> R16
;	etat_1 -> R17
;	BP -> R18
;	Heure_ou_Date -> R19
;	Acces -> R20
;	H_J -> R21
;	mn_mois -> Y+3
;	code -> Y+2
;	sec_annee -> Y+0
	LDI  R16,0
	LDI  R17,5
	LDI  R30,LOW(31)
	OUT  0x1B,R30
;     103 DDRA=0x00;
	CLR  R30
	OUT  0x1A,R30
;     104 
;     105 // Port B
;     106 PORTB=0x00;
	OUT  0x18,R30
;     107 DDRB=0x1F;
	LDI  R30,LOW(31)
	OUT  0x17,R30
;     108 
;     109 // I2C Bus initialization
;     110 i2c_init();
	RCALL _i2c_init
;     111 
;     112 // DS1621 Thermometer/Thermostat initialization
;     113 // tlow: 50°C
;     114 // thigh: 55°C
;     115 // Tout polarity: 0
;     116 ds1621_init(0,50,55,0);
	RCALL SUBOPT_0x0
	LDI  R30,LOW(50)
	ST   -Y,R30
	LDI  R30,LOW(55)
	RCALL SUBOPT_0x1
	RCALL _ds1621_init
;     117 
;     118 // PCF8583 Real Time Clock initialization
;     119 rtc_init(0,0);
	RCALL SUBOPT_0x0
	RCALL SUBOPT_0x0
	RCALL _rtc_init
;     120 
;     121 // LCD module initialization
;     122 lcd_init(16);
	RCALL SUBOPT_0x2
	RCALL _lcd_init
;     123 
;     124 sprintf(display_buffer_ligne0,"Introduire      ");
	RCALL SUBOPT_0x3
	__POINTW1FN _58,0
	ST   -Y,R31
	ST   -Y,R30
	LDI  R24,0
	RCALL SUBOPT_0x4
;     125 sprintf(display_buffer_ligne1,"     votre carte");
	RCALL SUBOPT_0x5
	__POINTW1FN _58,17
	ST   -Y,R31
	ST   -Y,R30
	LDI  R24,0
	RCALL SUBOPT_0x4
;     126 Affiche_LCD(display_buffer_ligne0,display_buffer_ligne1); 
	RCALL SUBOPT_0x3
	RCALL SUBOPT_0x5
	RCALL _Affiche_LCD
;     127 
;     128 while (1)
_0x3B:
;     129       {// début While
;     130        BP = Lire_BP();
	RCALL _Lire_BP
	MOV  R18,R30
;     131       
;     132       switch (etat)
	RCALL SUBOPT_0x6
;     133       {// début switch
;     134        case Attente : rtc_get_time(0,&heures,&minutes,&secondes,&dizieme);
	BRNE _0x41
	RCALL SUBOPT_0x0
	LDI  R30,LOW(5)
	LDI  R31,HIGH(5)
	ST   -Y,R31
	ST   -Y,R30
	LDI  R30,LOW(6)
	LDI  R31,HIGH(6)
	ST   -Y,R31
	ST   -Y,R30
	LDI  R30,LOW(7)
	LDI  R31,HIGH(7)
	ST   -Y,R31
	ST   -Y,R30
	LDI  R30,LOW(9)
	LDI  R31,HIGH(9)
	ST   -Y,R31
	ST   -Y,R30
	RCALL _rtc_get_time
;     135        		      if ((etat_1 != etat) || (secondes_1 != secondes))
	CP   R16,R17
	BRNE _0x43
	CP   R7,R8
	BREQ _0x42
_0x43:
;     136                        { 
;     137                          sprintf(display_buffer_ligne0,"Placez la carte");
	RCALL SUBOPT_0x3
	__POINTW1FN _58,34
	ST   -Y,R31
	ST   -Y,R30
	LDI  R24,0
	RCALL SUBOPT_0x4
;     138                          sprintf(display_buffer_ligne1,"%-uh / %-umn / %-us",heures, minutes, secondes);
	RCALL SUBOPT_0x5
	__POINTW1FN _58,50
	ST   -Y,R31
	ST   -Y,R30
	MOV  R30,R5
	RCALL SUBOPT_0x7
	MOV  R30,R6
	RCALL SUBOPT_0x7
	MOV  R30,R7
	RCALL SUBOPT_0x7
	LDI  R24,12
	RCALL SUBOPT_0x8
;     139                          Affiche_LCD(display_buffer_ligne0,display_buffer_ligne1);
	RCALL SUBOPT_0x3
	RCALL SUBOPT_0x5
	RCALL _Affiche_LCD
;     140                          secondes_1 = secondes;
	MOV  R8,R7
;     141                        }
;     142                       if (!PIND.6) etat = Traitement;
_0x42:
	SBIC 0x10,6
	RJMP _0x45
	LDI  R16,LOW(1)
;     143                               else if (BP == SET) etat = Reglage_HTR;
	RJMP _0x46
_0x45:
	CPI  R18,61
	BRNE _0x47
	LDI  R16,LOW(5)
;     144                               		else	  etat = Attente;
	RJMP _0x48
_0x47:
	LDI  R16,LOW(0)
_0x48:
_0x46:
;     145                       etat_1 = Attente; 
	LDI  R17,LOW(0)
;     146        break;
	RJMP _0x40
;     147        		   
;     148        case Traitement : if (etat_1 != etat)		// à modifier en fonction du lecteur de carte
_0x41:
	CPI  R30,LOW(0x1)
	BRNE _0x49
	CP   R16,R17
	BREQ _0x4A
;     149                        { code=eeprom_read(0xAE,0x0000); // EEPROM à l'adresse @AEh
	LDI  R30,LOW(174)
	ST   -Y,R30
	CLR  R30
	CLR  R31
	ST   -Y,R31
	ST   -Y,R30
	RCALL _eeprom_read
	STD  Y+2,R30
;     150                          sprintf(display_buffer_ligne0,"Traitement");
	RCALL SUBOPT_0x3
	__POINTW1FN _58,70
	ST   -Y,R31
	ST   -Y,R30
	LDI  R24,0
	RCALL SUBOPT_0x4
;     151                          sprintf(display_buffer_ligne1,"Code = %c",code);
	RCALL SUBOPT_0x5
	__POINTW1FN _58,81
	ST   -Y,R31
	ST   -Y,R30
	LDD  R30,Y+6
	RCALL SUBOPT_0x7
	LDI  R24,4
	RCALL _sprintf
	ADIW R28,8
;     152                          Affiche_LCD(display_buffer_ligne0,display_buffer_ligne1);
	RCALL SUBOPT_0x3
	RCALL SUBOPT_0x5
	RCALL _Affiche_LCD
;     153                        } 
;     154                       delay_ms(2000);
_0x4A:
	LDI  R30,LOW(2000)
	LDI  R31,HIGH(2000)
	RCALL SUBOPT_0x9
;     155                       
;     156        		      Acces = Traiter_code(code);
	RCALL SUBOPT_0xA
	RCALL _Traiter_code
	MOV  R20,R30
;     157                       if (Acces == autorise) etat = RetraitCarte;
	CPI  R20,1
	BRNE _0x4B
	LDI  R16,LOW(3)
;     158                       	       	   	else etat = Refus;
	RJMP _0x4C
_0x4B:
	LDI  R16,LOW(2)
_0x4C:
;     159                       etat_1 = Traitement;
	LDI  R17,LOW(1)
;     160        break;
	RJMP _0x40
;     161                       
;     162        case Refus :   if (etat_1 != etat)
_0x49:
	CPI  R30,LOW(0x2)
	BRNE _0x4D
	CP   R16,R17
	BREQ _0x4E
;     163                        {
;     164                          sprintf(display_buffer_ligne0,"Refus Reprenez");
	RCALL SUBOPT_0x3
	__POINTW1FN _58,91
	ST   -Y,R31
	ST   -Y,R30
	LDI  R24,0
	RCALL SUBOPT_0x4
;     165                          sprintf(display_buffer_ligne1,"    votre carte");
	RCALL SUBOPT_0x5
	__POINTW1FN _58,106
	ST   -Y,R31
	ST   -Y,R30
	LDI  R24,0
	RCALL SUBOPT_0x4
;     166                          Affiche_LCD(display_buffer_ligne0,display_buffer_ligne1);
	RCALL SUBOPT_0x3
	RCALL SUBOPT_0x5
	RCALL _Affiche_LCD
;     167                          PORTD.5 = 1;
	SBI  0x12,5
;     168                        }
;     169                       delay_ms(5000);  // 5 secondes pour retirer la carte
_0x4E:
	RCALL SUBOPT_0xB
;     170                       if (PIND.6) {
	SBIS 0x10,6
	RJMP _0x4F
;     171                                     etat = Attente;
	LDI  R16,LOW(0)
;     172                                     PORTD.5 = 0;
	CBI  0x12,5
;     173                                    }
;     174                                 else etat = Refus;
	RJMP _0x50
_0x4F:
	LDI  R16,LOW(2)
_0x50:
;     175                       etat_1 = Refus;
	LDI  R17,LOW(2)
;     176        break;
	RJMP _0x40
;     177                       		             
;     178        case RetraitCarte :  if (etat_1 != etat)
_0x4D:
	CPI  R30,LOW(0x3)
	BRNE _0x51
	CP   R16,R17
	BREQ _0x52
;     179                        {
;     180                          sprintf(display_buffer_ligne0,"Accepte Reprenez");
	RCALL SUBOPT_0x3
	__POINTW1FN _58,122
	ST   -Y,R31
	ST   -Y,R30
	LDI  R24,0
	RCALL SUBOPT_0x4
;     181                          sprintf(display_buffer_ligne1,"     votre carte");
	RCALL SUBOPT_0x5
	__POINTW1FN _58,139
	ST   -Y,R31
	ST   -Y,R30
	LDI  R24,0
	RCALL SUBOPT_0x4
;     182                          Affiche_LCD(display_buffer_ligne0,display_buffer_ligne1);
	RCALL SUBOPT_0x3
	RCALL SUBOPT_0x5
	RCALL _Affiche_LCD
;     183                        }
;     184                       delay_ms(5000); 
_0x52:
	RCALL SUBOPT_0xB
;     185                       if (PIND.6) etat = CdePortail;
	SBIS 0x10,6
	RJMP _0x53
	LDI  R16,LOW(4)
;     186                                 else etat = Refus; 
	RJMP _0x54
_0x53:
	LDI  R16,LOW(2)
_0x54:
;     187                       etat_1 = RetraitCarte;
	LDI  R17,LOW(3)
;     188        break;
	RJMP _0x40
;     189                       
;     190        case CdePortail :     if (etat_1 != etat)
_0x51:
	CPI  R30,LOW(0x4)
	BRNE _0x55
	CP   R16,R17
	BREQ _0x56
;     191                        {    
;     192        			sprintf(display_buffer_ligne0,"Ouverture       ");
	RCALL SUBOPT_0x3
	__POINTW1FN _58,156
	ST   -Y,R31
	ST   -Y,R30
	LDI  R24,0
	RCALL SUBOPT_0x4
;     193        			sprintf(display_buffer_ligne1,"      du portail");
	RCALL SUBOPT_0x5
	__POINTW1FN _58,173
	ST   -Y,R31
	ST   -Y,R30
	LDI  R24,0
	RCALL SUBOPT_0x4
;     194                         Affiche_LCD(display_buffer_ligne0,display_buffer_ligne1);
	RCALL SUBOPT_0x3
	RCALL SUBOPT_0x5
	RCALL _Affiche_LCD
;     195           	       }
;     196                       // SP CdePortail
;     197                       PORTB.0 = 1;
_0x56:
	SBI  0x18,0
;     198                       delay_ms(5000);
	RCALL SUBOPT_0xB
;     199                       PORTB.0 = 0;
	CBI  0x18,0
;     200                       etat = Attente; etat_1 = CdePortail;
	LDI  R16,LOW(0)
	LDI  R17,LOW(4)
;     201        break;
	RJMP _0x40
;     202        
;     203        case Reglage_HTR : if (etat_1 != etat)
_0x55:
	CPI  R30,LOW(0x5)
	BRNE _0x5F
	CP   R16,R17
	BREQ _0x58
;     204                         {
;     205         	         sprintf(display_buffer_ligne0,"Mode reglage    ");
	RCALL SUBOPT_0x3
	__POINTW1FN _58,190
	ST   -Y,R31
	ST   -Y,R30
	LDI  R24,0
	RCALL SUBOPT_0x4
;     206         	         sprintf(display_buffer_ligne1,"Ok->H Echp->Date");
	RCALL SUBOPT_0x5
	__POINTW1FN _58,207
	ST   -Y,R31
	ST   -Y,R30
	LDI  R24,0
	RCALL SUBOPT_0x4
;     207         	         Affiche_LCD(display_buffer_ligne0,display_buffer_ligne1);
	RCALL SUBOPT_0x3
	RCALL SUBOPT_0x5
	RCALL _Affiche_LCD
;     208         		}               
;     209         	       switch(BP)
_0x58:
	MOV  R30,R18
;     210         		{
;     211         		  case OK   : Heure_ou_Date = 0;
	CPI  R30,LOW(0x37)
	BRNE _0x5C
	LDI  R19,LOW(0)
;     212         		  	      H_J = 12;
	LDI  R21,LOW(12)
;     213         		  	      mn_mois = 30;
	LDI  R30,LOW(30)
	STD  Y+3,R30
;     214         		  	      sec_annee = 0;
	CLR  R30
	STD  Y+0,R30
	STD  Y+0+1,R30
;     215         		  	      regle_HTR(Heure_ou_Date, H_J, mn_mois, sec_annee);
	RCALL SUBOPT_0xC
;     216         		 	      etat = Attente;
	LDI  R16,LOW(0)
;     217         		  break;
	RJMP _0x5B
;     218         		 
;     219         		  case ECHAP : Heure_ou_Date = 1;
_0x5C:
	CPI  R30,LOW(0x3B)
	BRNE _0x5E
	LDI  R19,LOW(1)
;     220         		  	       H_J = 15;
	LDI  R21,LOW(15)
;     221         		  	       mn_mois = 6;
	LDI  R30,LOW(6)
	STD  Y+3,R30
;     222         		  	       sec_annee = 2002;
	LDI  R30,LOW(2002)
	LDI  R31,HIGH(2002)
	ST   Y,R30
	STD  Y+1,R31
;     223         		  	       regle_HTR(Heure_ou_Date, H_J, mn_mois, sec_annee);
	RCALL SUBOPT_0xC
;     224         		  	       etat = Attente;
	LDI  R16,LOW(0)
;     225         		  break;
	RJMP _0x5B
;     226         		 
;     227         		  default:     etat = Reglage_HTR;
_0x5E:
	LDI  R16,LOW(5)
;     228         		 } 
_0x5B:
;     229         		 
;     230         	       etat_1 = Reglage_HTR;
	LDI  R17,LOW(5)
;     231         break; 
	RJMP _0x40
;     232         
;     233        default: etat = Attente;  
_0x5F:
	LDI  R16,LOW(0)
;     234        
;     235        } // fin switch
_0x40:
;     236       }; // fin while
	RJMP _0x3B
;     237 } // fin prog       
	ADIW R28,4
_0x60:
	RJMP _0x60
;     238 
;     239 unsigned char Traiter_code(char code) // à remplacer par votre solution
;     240 {
_Traiter_code:
;     241  unsigned char Acces=0;
;     242  
;     243  switch(code)
	ST   -Y,R16
;	code -> Y+1
;	Acces -> R16
	LDI  R16,0
	LDD  R30,Y+1
;     244   {
;     245    case administration : Acces = 1; break;
	CPI  R30,LOW(0x41)
	BRNE _0x65
	LDI  R16,LOW(1)
	RJMP _0x64
;     246    case prof : Acces = 0; break;
_0x65:
	CPI  R30,LOW(0x50)
	BRNE _0x66
	LDI  R16,LOW(0)
	RJMP _0x64
;     247    case eleve : Acces = 0; break; 
_0x66:
	CPI  R30,LOW(0x45)
	BRNE _0x68
	LDI  R16,LOW(0)
	RJMP _0x64
;     248    default : Acces = 0;
_0x68:
	LDI  R16,LOW(0)
;     249   }
_0x64:
;     250   return (Acces);
	MOV  R30,R16
	LDD  R16,Y+0
	ADIW R28,2
	RET
;     251 }
;     252  
_Lire_BP:

	.DSEG

	.CSEG
	RCALL __SAVELOCR2
	IN   R17,25
	ANDI R17,LOW(63)
	MOV  R30,R10
	CPI  R30,LOW(0x1)
	BRNE _0x6D
	CPI  R17,63
	BRNE _0x6E
	MOV  R16,R17
	RCALL SUBOPT_0xD
	IN   R17,25
	ANDI R17,LOW(63)
	CP   R17,R16
	BRNE _0x6F
	CLR  R10
	LDI  R30,LOW(255)
	RJMP _0x183
_0x6F:
	CLR  R30
	RJMP _0x183
	RJMP _0x71
_0x6E:
	CLR  R30
	RJMP _0x183
_0x71:
	RJMP _0x6C
_0x6D:
	CPI  R30,0
	BRNE _0x6C
	CPI  R17,63
	BREQ _0x73
	MOV  R16,R17
	RCALL SUBOPT_0xD
	IN   R17,25
	ANDI R17,LOW(63)
	CP   R17,R16
	BRNE _0x74
	LDI  R30,LOW(1)
	MOV  R10,R30
	MOV  R30,R17
	RJMP _0x183
_0x74:
	LDI  R30,LOW(255)
	RJMP _0x183
	RJMP _0x76
_0x73:
	LDI  R30,LOW(255)
_0x76:
_0x6C:
_0x183:
	RCALL __LOADLOCR2P
	RET
_Affiche_LCD:
	RCALL _lcd_clear
	RCALL SUBOPT_0xE
	RCALL _lcd_puts
	RCALL SUBOPT_0x0
	RCALL SUBOPT_0xF
	RCALL _lcd_gotoxy
	LD   R30,Y
	LDD  R31,Y+1
	ST   -Y,R31
	ST   -Y,R30
	RCALL _lcd_puts
	ADIW R28,4
	RET
_regle_HTR:
	SBIW R28,36
	RCALL __SAVELOCR5
	LDI  R17,LOW(0)
_0x79:
	RCALL _Lire_BP
	MOV  R16,R30
	MOV  R30,R17
	CPI  R30,LOW(0x3)
	BRNE _0x7F
	LDD  R26,Y+45
	CPI  R26,LOW(0x1)
	BRNE _0x80
	RCALL SUBOPT_0x10
	ST   -Y,R31
	ST   -Y,R30
	RCALL _rtc_set_date
	RJMP _0x81
_0x80:
	RCALL SUBOPT_0x10
	RCALL SUBOPT_0x1
	RCALL _rtc_set_time
_0x81:
	CLR  R30
	CLR  R31
	RJMP _0x182
_0x7F:
	CPI  R30,0
	BREQ PC+2
	RJMP _0x82
	RCALL SUBOPT_0x11
	BRNE _0x83
	LDD  R26,Y+44
	CPI  R26,LOW(0x18)
	BRNE _0x84
	RCALL SUBOPT_0x12
_0x84:
	LDD  R26,Y+44
	CPI  R26,LOW(0xFF)
	BRNE _0x85
	LDI  R30,LOW(23)
	STD  Y+44,R30
_0x85:
	RCALL SUBOPT_0x13
	BRNE _0x87
	CP   R17,R18
	BREQ _0x86
_0x87:
	RCALL SUBOPT_0x14
	__POINTW1FN _120,0
	ST   -Y,R31
	ST   -Y,R30
	LDI  R24,0
	RCALL SUBOPT_0x4
	RCALL SUBOPT_0x15
	__POINTW1FN _120,17
	RCALL SUBOPT_0x16
	RCALL SUBOPT_0x17
	RCALL SUBOPT_0x18
	LDI  R24,12
	RCALL SUBOPT_0x8
	RCALL SUBOPT_0x14
	RCALL SUBOPT_0x19
	LDD  R19,Y+44
_0x86:
	RJMP _0x89
_0x83:
	LDD  R26,Y+44
	CPI  R26,LOW(0x20)
	BRNE _0x8A
	RCALL SUBOPT_0x12
_0x8A:
	LDD  R30,Y+44
	CPI  R30,0
	BRNE _0x8B
	LDI  R30,LOW(31)
	STD  Y+44,R30
_0x8B:
	RCALL SUBOPT_0x13
	BRNE _0x8D
	CP   R17,R18
	BREQ _0x8C
_0x8D:
	RCALL SUBOPT_0x14
	__POINTW1FN _120,38
	ST   -Y,R31
	ST   -Y,R30
	LDI  R24,0
	RCALL SUBOPT_0x4
	RCALL SUBOPT_0x15
	__POINTW1FN _120,55
	RCALL SUBOPT_0x16
	RCALL SUBOPT_0x17
	RCALL SUBOPT_0x18
	LDI  R24,12
	RCALL SUBOPT_0x8
	RCALL SUBOPT_0x14
	RCALL SUBOPT_0x19
	LDD  R19,Y+44
_0x8C:
_0x89:
	RCALL SUBOPT_0x1A
	BRNE _0x92
	LDD  R30,Y+44
	SUBI R30,-LOW(1)
	STD  Y+44,R30
	RJMP _0x91
_0x92:
	CPI  R30,LOW(0x2F)
	BRNE _0x93
	LDD  R30,Y+44
	SUBI R30,LOW(1)
	STD  Y+44,R30
	RJMP _0x91
_0x93:
	CPI  R30,LOW(0x37)
	BRNE _0x94
	LDI  R17,LOW(1)
	RJMP _0x91
_0x94:
	CPI  R30,LOW(0x3B)
	BRNE _0x96
	LDI  R17,LOW(3)
	RJMP _0x91
_0x96:
	LDI  R17,LOW(0)
_0x91:
	LDI  R18,LOW(0)
	RJMP _0x7E
_0x82:
	CPI  R30,LOW(0x1)
	BREQ PC+2
	RJMP _0x97
	RCALL SUBOPT_0x11
	BRNE _0x98
	LDD  R26,Y+43
	CPI  R26,LOW(0x3C)
	BRNE _0x99
	CLR  R30
	STD  Y+43,R30
_0x99:
	LDD  R26,Y+43
	CPI  R26,LOW(0xFF)
	BRNE _0x9A
	LDI  R30,LOW(59)
	STD  Y+43,R30
_0x9A:
	RCALL SUBOPT_0x1B
	BRNE _0x9C
	CP   R17,R18
	BREQ _0x9B
_0x9C:
	RCALL SUBOPT_0x14
	__POINTW1FN _120,72
	ST   -Y,R31
	ST   -Y,R30
	LDI  R24,0
	RCALL SUBOPT_0x4
	RCALL SUBOPT_0x15
	__POINTW1FN _120,89
	RCALL SUBOPT_0x16
	RCALL SUBOPT_0x17
	RCALL SUBOPT_0x18
	LDI  R24,12
	RCALL SUBOPT_0x8
	RCALL SUBOPT_0x14
	RCALL SUBOPT_0x19
	LDD  R20,Y+43
_0x9B:
	RJMP _0x9E
_0x98:
	LDD  R26,Y+43
	CPI  R26,LOW(0xD)
	BRNE _0x9F
	LDI  R30,LOW(1)
	STD  Y+43,R30
_0x9F:
	LDD  R30,Y+43
	CPI  R30,0
	BRNE _0xA0
	LDI  R30,LOW(12)
	STD  Y+43,R30
_0xA0:
	RCALL SUBOPT_0x1B
	BRNE _0xA2
	CP   R17,R18
	BREQ _0xA1
_0xA2:
	RCALL SUBOPT_0x14
	__POINTW1FN _120,110
	ST   -Y,R31
	ST   -Y,R30
	LDI  R24,0
	RCALL SUBOPT_0x4
	RCALL SUBOPT_0x15
	__POINTW1FN _120,127
	RCALL SUBOPT_0x16
	RCALL SUBOPT_0x17
	RCALL SUBOPT_0x18
	LDI  R24,12
	RCALL SUBOPT_0x8
	RCALL SUBOPT_0x14
	RCALL SUBOPT_0x19
	LDD  R20,Y+43
_0xA1:
_0x9E:
	RCALL SUBOPT_0x1A
	BRNE _0xA7
	LDD  R30,Y+43
	SUBI R30,-LOW(1)
	STD  Y+43,R30
	RJMP _0xA6
_0xA7:
	CPI  R30,LOW(0x2F)
	BRNE _0xA8
	LDD  R30,Y+43
	SUBI R30,LOW(1)
	STD  Y+43,R30
	RJMP _0xA6
_0xA8:
	CPI  R30,LOW(0x37)
	BRNE _0xA9
	LDI  R17,LOW(2)
	RJMP _0xA6
_0xA9:
	CPI  R30,LOW(0x3B)
	BRNE _0xAB
	LDI  R17,LOW(3)
	RJMP _0xA6
_0xAB:
	LDI  R17,LOW(1)
_0xA6:
	LDI  R18,LOW(1)
	RJMP _0x7E
_0x97:
	CPI  R30,LOW(0x2)
	BREQ PC+2
	RJMP _0x7E
	RCALL SUBOPT_0x11
	BRNE _0xAD
	LDD  R26,Y+41
	LDD  R27,Y+41+1
	CPI  R26,LOW(0x3C)
	LDI  R30,HIGH(0x3C)
	CPC  R27,R30
	BRNE _0xAE
	CLR  R30
	STD  Y+41,R30
	STD  Y+41+1,R30
_0xAE:
	LDD  R26,Y+41
	LDD  R27,Y+41+1
	CPI  R26,LOW(0xFFFF)
	LDI  R30,HIGH(0xFFFF)
	CPC  R27,R30
	BRNE _0xAF
	LDI  R30,LOW(59)
	LDI  R31,HIGH(59)
	STD  Y+41,R30
	STD  Y+41+1,R31
_0xAF:
	RCALL SUBOPT_0x1C
	BRNE _0xB1
	CP   R17,R18
	BREQ _0xB0
_0xB1:
	RCALL SUBOPT_0x14
	__POINTW1FN _120,144
	ST   -Y,R31
	ST   -Y,R30
	LDI  R24,0
	RCALL SUBOPT_0x4
	RCALL SUBOPT_0x15
	__POINTW1FN _120,161
	RCALL SUBOPT_0x16
	RCALL SUBOPT_0x17
	RCALL SUBOPT_0x18
	LDI  R24,12
	RCALL SUBOPT_0x8
	RCALL SUBOPT_0x14
	RCALL SUBOPT_0x19
	RCALL SUBOPT_0x1D
_0xB0:
	RJMP _0xB3
_0xAD:
	LDD  R26,Y+41
	LDD  R27,Y+41+1
	CPI  R26,LOW(0x834)
	LDI  R30,HIGH(0x834)
	CPC  R27,R30
	BRNE _0xB4
	RCALL SUBOPT_0x1E
_0xB4:
	LDD  R26,Y+41
	LDD  R27,Y+41+1
	CPI  R26,LOW(0x7CF)
	LDI  R30,HIGH(0x7CF)
	CPC  R27,R30
	BRNE _0xB5
	RCALL SUBOPT_0x1E
_0xB5:
	RCALL SUBOPT_0x1C
	BRNE _0xB7
	CP   R17,R18
	BREQ _0xB6
_0xB7:
	RCALL SUBOPT_0x14
	__POINTW1FN _120,182
	ST   -Y,R31
	ST   -Y,R30
	LDI  R24,0
	RCALL SUBOPT_0x4
	RCALL SUBOPT_0x15
	__POINTW1FN _120,199
	RCALL SUBOPT_0x16
	RCALL SUBOPT_0x17
	RCALL SUBOPT_0x18
	LDI  R24,12
	RCALL SUBOPT_0x8
	RCALL SUBOPT_0x14
	RCALL SUBOPT_0x19
	RCALL SUBOPT_0x1D
_0xB6:
_0xB3:
	RCALL SUBOPT_0x1A
	BRNE _0xBC
	RCALL SUBOPT_0x1F
	RJMP _0xBB
_0xBC:
	CPI  R30,LOW(0x2F)
	BRNE _0xBD
	RCALL SUBOPT_0x1F
	RJMP _0xBB
_0xBD:
	CPI  R30,LOW(0x37)
	BRNE _0xBE
	LDI  R17,LOW(0)
	RJMP _0xBB
_0xBE:
	CPI  R30,LOW(0x3B)
	BRNE _0xC0
	LDI  R17,LOW(3)
	RJMP _0xBB
_0xC0:
	LDI  R17,LOW(2)
_0xBB:
	LDI  R18,LOW(2)
_0x7E:
	RJMP _0x79
_0x182:
	RCALL __LOADLOCR5
	ADIW R28,47
	RET
_eeprom_read:
	RCALL __SAVELOCR3
	LDD  R30,Y+3
	LDD  R31,Y+3+1
	MOV  R18,R30
	LDD  R30,Y+4
	ANDI R31,HIGH(0x0)
	MOV  R17,R30
	RCALL SUBOPT_0x20
	RCALL SUBOPT_0x21
	ST   -Y,R17
	RCALL _i2c_write
	ST   -Y,R18
	RCALL _i2c_write
	RCALL SUBOPT_0x20
	RCALL SUBOPT_0x22
	RCALL SUBOPT_0x0
	RCALL SUBOPT_0x23
	RCALL __LOADLOCR3
	ADIW R28,6
	RET
_getchar:
     sbis usr,rxc
     rjmp _getchar
     in   r30,udr
	RET
_putchar:
     sbis usr,udre
     rjmp _putchar
     ld   r30,y
     out  udr,r30
	ADIW R28,1
	RET
__put_G3:
	put:
	RCALL SUBOPT_0x24
	SBIW R30,0
	BREQ _0xF8
	RCALL SUBOPT_0x24
	ADIW R30,1
	RCALL __PUTWP1
	SBIW R30,1
	MOV  R26,R30
	MOV  R27,R31
	LDD  R30,Y+2
	ST   X,R30
	RJMP _0xF9
_0xF8:
	RCALL SUBOPT_0xA
	RCALL _putchar
_0xF9:
	ADIW R28,3
	RET
__print_G3:
	SBIW R28,6
	RCALL __SAVELOCR6
	LDI  R16,0
_0xFB:
	LDD  R30,Y+16
	LDD  R31,Y+16+1
	ADIW R30,1
	STD  Y+16,R30
	STD  Y+16+1,R31
	SBIW R30,1
	LPM
	MOV  R30,R0
	MOV  R19,R30
	CPI  R30,0
	BRNE PC+2
	RJMP _0xFD
	RCALL SUBOPT_0x6
	BRNE _0x101
	CPI  R19,37
	BRNE _0x102
	LDI  R16,LOW(1)
	RJMP _0x103
_0x102:
	RCALL SUBOPT_0x25
_0x103:
	RJMP _0x100
_0x101:
	CPI  R30,LOW(0x1)
	BRNE _0x104
	CPI  R19,37
	BRNE _0x105
	RCALL SUBOPT_0x25
	LDI  R16,LOW(0)
	RJMP _0x100
_0x105:
	LDI  R16,LOW(2)
	LDI  R21,LOW(0)
	LDI  R17,LOW(0)
	CPI  R19,45
	BRNE _0x106
	LDI  R17,LOW(1)
	RJMP _0x100
_0x106:
	CPI  R19,43
	BRNE _0x107
	LDI  R21,LOW(43)
	RJMP _0x100
_0x107:
	CPI  R19,32
	BRNE _0x108
	LDI  R21,LOW(32)
	RJMP _0x100
_0x108:
	RJMP _0x109
_0x104:
	CPI  R30,LOW(0x2)
	BRNE _0x10A
_0x109:
	LDI  R20,LOW(0)
	LDI  R16,LOW(3)
	CPI  R19,48
	BRNE _0x10B
	ORI  R17,LOW(128)
	RJMP _0x100
_0x10B:
	RJMP _0x10C
_0x10A:
	CPI  R30,LOW(0x3)
	BREQ PC+2
	RJMP _0x100
_0x10C:
	CPI  R19,48
	BRLO _0x10F
	CPI  R19,58
	BRLO _0x110
_0x10F:
	RJMP _0x10E
_0x110:
	MOV  R18,R20
	LSL  R20
	LSL  R20
	ADD  R20,R18
	LSL  R20
	MOV  R30,R19
	SUBI R30,LOW(48)
	ADD  R20,R30
	RJMP _0x100
_0x10E:
	MOV  R30,R19
	CPI  R30,LOW(0x63)
	BRNE _0x114
	RCALL SUBOPT_0x26
	LD   R30,X
	RCALL SUBOPT_0x27
	RJMP _0x115
_0x114:
	CPI  R30,LOW(0x73)
	BRNE _0x117
	RCALL SUBOPT_0x26
	RCALL SUBOPT_0x28
	RCALL _strlen
	MOV  R16,R30
	RJMP _0x118
_0x117:
	CPI  R30,LOW(0x70)
	BRNE _0x11A
	RCALL SUBOPT_0x26
	RCALL SUBOPT_0x28
	RCALL _strlenf
	MOV  R16,R30
	ORI  R17,LOW(8)
_0x118:
	ORI  R17,LOW(2)
	ANDI R17,LOW(127)
	LDI  R18,LOW(0)
	RJMP _0x11B
_0x11A:
	CPI  R30,LOW(0x64)
	BREQ _0x11E
	CPI  R30,LOW(0x69)
	BRNE _0x11F
_0x11E:
	ORI  R17,LOW(4)
	RJMP _0x120
_0x11F:
	CPI  R30,LOW(0x75)
	BRNE _0x121
_0x120:
	LDI  R30,LOW(_tbl10_G3*2)
	LDI  R31,HIGH(_tbl10_G3*2)
	STD  Y+6,R30
	STD  Y+6+1,R31
	LDI  R16,LOW(5)
	RJMP _0x122
_0x121:
	CPI  R30,LOW(0x58)
	BRNE _0x124
	ORI  R17,LOW(8)
	RJMP _0x125
_0x124:
	CPI  R30,LOW(0x78)
	BREQ PC+2
	RJMP _0x153
_0x125:
	LDI  R30,LOW(_tbl16_G3*2)
	LDI  R31,HIGH(_tbl16_G3*2)
	STD  Y+6,R30
	STD  Y+6+1,R31
	LDI  R16,LOW(4)
_0x122:
	SBRS R17,2
	RJMP _0x127
	RCALL SUBOPT_0x26
	RCALL SUBOPT_0x29
	LDD  R26,Y+10
	LDD  R27,Y+10+1
	SBIW R26,0
	BRGE _0x128
	LDD  R30,Y+10
	LDD  R31,Y+10+1
	RCALL __ANEGW1
	STD  Y+10,R30
	STD  Y+10+1,R31
	LDI  R21,LOW(45)
_0x128:
	CPI  R21,0
	BREQ _0x129
	SUBI R16,-LOW(1)
	RJMP _0x12A
_0x129:
	ANDI R17,LOW(251)
_0x12A:
	RJMP _0x12B
_0x127:
	RCALL SUBOPT_0x26
	RCALL SUBOPT_0x29
_0x12B:
_0x11B:
	SBRC R17,0
	RJMP _0x12C
_0x12D:
	CP   R16,R20
	BRSH _0x12F
	SBRS R17,7
	RJMP _0x130
	SBRS R17,2
	RJMP _0x131
	ANDI R17,LOW(251)
	MOV  R19,R21
	SUBI R16,LOW(1)
	RJMP _0x132
_0x131:
	LDI  R19,LOW(48)
_0x132:
	RJMP _0x133
_0x130:
	LDI  R19,LOW(32)
_0x133:
	RCALL SUBOPT_0x25
	SUBI R20,LOW(1)
	RJMP _0x12D
_0x12F:
_0x12C:
	MOV  R18,R16
	SBRS R17,1
	RJMP _0x134
_0x135:
	CPI  R18,0
	BREQ _0x137
	SBRS R17,3
	RJMP _0x138
	LDD  R30,Y+6
	LDD  R31,Y+6+1
	ADIW R30,1
	STD  Y+6,R30
	STD  Y+6+1,R31
	SBIW R30,1
	LPM
	MOV  R30,R0
	RJMP _0x184
_0x138:
	LDD  R26,Y+6
	LDD  R27,Y+6+1
	LD   R30,X+
	STD  Y+6,R26
	STD  Y+6+1,R27
_0x184:
	ST   -Y,R30
	RCALL SUBOPT_0x2A
	CPI  R20,0
	BREQ _0x13A
	SUBI R20,LOW(1)
_0x13A:
	SUBI R18,LOW(1)
	RJMP _0x135
_0x137:
	RJMP _0x13B
_0x134:
_0x13D:
	LDI  R19,LOW(48)
	LDD  R30,Y+6
	LDD  R31,Y+6+1
	ADIW R30,2
	STD  Y+6,R30
	STD  Y+6+1,R31
	SBIW R30,2
	RCALL __GETW1PF
	STD  Y+8,R30
	STD  Y+8+1,R31
                                      ldd  r26,y+10  ;R26,R27=n
                                      ldd  r27,y+11
                                  calc_digit:
                                      cp   r26,r30
                                      cpc  r27,r31
                                      brlo calc_digit_done
	SUBI R19,-LOW(1)
	                                  sub  r26,r30
	                                  sbc  r27,r31
	                                  brne calc_digit
                                  calc_digit_done:
                                      std  Y+10,r26 ;n=R26,R27
                                      std  y+11,r27
	LDI  R30,LOW(57)
	CP   R30,R19
	BRSH _0x13F
	SBRS R17,3
	RJMP _0x140
	SUBI R19,-LOW(7)
	RJMP _0x141
_0x140:
	SUBI R19,-LOW(39)
_0x141:
_0x13F:
	SBRC R17,4
	RJMP _0x143
	LDI  R30,LOW(48)
	CP   R30,R19
	BRLO _0x145
	LDD  R26,Y+8
	LDD  R27,Y+8+1
	CPI  R26,LOW(0x1)
	LDI  R30,HIGH(0x1)
	CPC  R27,R30
	BRNE _0x144
_0x145:
	ORI  R17,LOW(16)
	RJMP _0x147
_0x144:
	CP   R20,R18
	BRLO _0x149
	SBRS R17,0
	RJMP _0x14A
_0x149:
	RJMP _0x148
_0x14A:
	LDI  R19,LOW(32)
	SBRS R17,7
	RJMP _0x14B
	LDI  R19,LOW(48)
	ORI  R17,LOW(16)
_0x147:
	SBRS R17,2
	RJMP _0x14C
	ANDI R17,LOW(251)
	ST   -Y,R21
	RCALL SUBOPT_0x2A
	CPI  R20,0
	BREQ _0x14D
	SUBI R20,LOW(1)
_0x14D:
_0x14C:
_0x14B:
_0x143:
	RCALL SUBOPT_0x25
	CPI  R20,0
	BREQ _0x14E
	SUBI R20,LOW(1)
_0x14E:
_0x148:
	SUBI R18,LOW(1)
	LDD  R26,Y+8
	LDD  R27,Y+8+1
	LDI  R30,LOW(1)
	LDI  R31,HIGH(1)
	CP   R30,R26
	CPC  R31,R27
	BRSH _0x13E
	RJMP _0x13D
_0x13E:
_0x13B:
	SBRS R17,0
	RJMP _0x14F
_0x150:
	CPI  R20,0
	BREQ _0x152
	SUBI R20,LOW(1)
	LDI  R30,LOW(32)
	RCALL SUBOPT_0x27
	RJMP _0x150
_0x152:
_0x14F:
_0x153:
_0x115:
	LDI  R16,LOW(0)
_0x100:
	RJMP _0xFB
_0xFD:
	RCALL __LOADLOCR6
	ADIW R28,18
	RET
_sprintf:
	MOV  R15,R24
	SBIW R28,4
	MOV  R26,R28
	MOV  R27,R29
	RCALL __ADDW2R15
	STD  Y+2,R26
	STD  Y+2+1,R27
	MOV  R26,R28
	MOV  R27,R29
	ADIW R26,6
	RCALL SUBOPT_0x2B
	ST   Y,R30
	STD  Y+1,R31
	MOV  R26,R28
	MOV  R27,R29
	ADIW R26,4
	RCALL SUBOPT_0x2B
	ST   -Y,R31
	ST   -Y,R30
	LDD  R30,Y+4
	LDD  R31,Y+4+1
	ST   -Y,R31
	ST   -Y,R30
	MOV  R30,R28
	MOV  R31,R29
	ADIW R30,4
	ST   -Y,R31
	ST   -Y,R30
	RCALL __print_G3
	LD   R26,Y
	LDD  R27,Y+1
	CLR  R30
	ST   X,R30
	RJMP _0x17E
_ds1621_get_status:
	RCALL __SAVELOCR2
	RCALL SUBOPT_0x2C
	RCALL SUBOPT_0x2D
	RCALL SUBOPT_0x2E
	RCALL _i2c_start
	SUBI R16,-LOW(1)
	ST   -Y,R16
	RCALL _i2c_write
	RCALL SUBOPT_0x0
	RCALL _i2c_read
	MOV  R17,R30
	RCALL _i2c_stop
	MOV  R30,R17
	RCALL __LOADLOCR2
	RJMP _0x17F
_ds1621_set_status:
	RCALL _i2c_start
	RCALL SUBOPT_0x2F
	RCALL SUBOPT_0x30
	RCALL SUBOPT_0x2E
	RCALL SUBOPT_0x31
	RCALL _i2c_stop
	RJMP _0x180
_ds1621_set_temp:
	RCALL _i2c_start
	RCALL SUBOPT_0x2C
	RCALL SUBOPT_0x21
	RCALL SUBOPT_0x32
	RCALL SUBOPT_0x31
	RCALL SUBOPT_0x0
	RCALL _i2c_write
	RCALL _i2c_stop
_0x158:
	RCALL SUBOPT_0xA
	RCALL _ds1621_get_status
	ANDI R30,LOW(0x10)
	BRNE _0x158
	RJMP _0x17F
_ds1621_start:
	RCALL _i2c_start
	LD   R30,Y
	LSL  R30
	RCALL SUBOPT_0x30
	LDI  R30,LOW(238)
	RCALL SUBOPT_0x21
	RCALL _i2c_stop
	RJMP _0x181
_ds1621_init:
	RCALL SUBOPT_0x33
	RCALL SUBOPT_0x2F
	SUBI R30,-LOW(8)
	ST   -Y,R30
	RCALL _ds1621_set_status
	RCALL SUBOPT_0x33
	LDI  R30,LOW(162)
	RCALL SUBOPT_0x34
	RCALL SUBOPT_0x35
	LDI  R30,LOW(161)
	RCALL SUBOPT_0x36
	RCALL SUBOPT_0x35
	RCALL _ds1621_start
	RJMP _0x17E
_rtc_read:
	ST   -Y,R16
	RCALL SUBOPT_0x37
	RCALL SUBOPT_0x2D
	RCALL SUBOPT_0x32
	RCALL _i2c_start
	MOV  R30,R16
	RCALL SUBOPT_0x22
	RCALL SUBOPT_0x0
	RCALL SUBOPT_0x23
	LDD  R16,Y+0
	RJMP _0x17F
_rtc_write:
	RCALL _i2c_start
	RCALL SUBOPT_0x37
	RCALL SUBOPT_0x21
	RCALL SUBOPT_0x32
	RCALL SUBOPT_0x31
	RCALL _i2c_stop
	RJMP _0x17F
_rtc_get_status:
	RCALL SUBOPT_0x38
	RCALL _rtc_read
	MOV  R4,R30
	BST  R4,1
	BLD  R2,0
	MOV  R30,R4
	RJMP _0x181
_rtc_init:
	ST   -Y,R16
	LDI  R16,LOW(144)
	LDD  R30,Y+1
	CPI  R30,0
	BREQ _0x168
	LDI  R16,LOW(176)
_0x168:
	CLR  R4
	CLT
	BLD  R2,0
	LDD  R30,Y+2
	RCALL SUBOPT_0x1
	RCALL SUBOPT_0x0
	RCALL SUBOPT_0x39
	LDI  R30,LOW(4)
	RCALL SUBOPT_0x34
	RCALL SUBOPT_0x3A
	RCALL _rtc_read
	ANDI R30,LOW(0x3F)
	ST   -Y,R30
	RCALL SUBOPT_0x39
	LDI  R30,LOW(8)
	ST   -Y,R30
	ST   -Y,R16
	RCALL _rtc_write
	LDD  R16,Y+0
	RJMP _0x17F
_rtc_stop:
	RCALL SUBOPT_0x3B
	ORI  R30,0x80
	RCALL SUBOPT_0x3C
	RCALL SUBOPT_0x3D
	RJMP _0x181
_rtc_start:
	RCALL SUBOPT_0x3B
	ANDI R30,0x7F
	RCALL SUBOPT_0x3C
	RCALL SUBOPT_0x3D
	RJMP _0x181
_rtc_hold_off:
	RCALL SUBOPT_0x3B
	ANDI R30,0xBF
	RCALL SUBOPT_0x3C
	RCALL SUBOPT_0x3D
	RJMP _0x181
_rtc_hold_on:
	RCALL SUBOPT_0x3B
	ORI  R30,0x40
	RCALL SUBOPT_0x3C
	RCALL SUBOPT_0x3D
_0x181:
	ADIW R28,1
	RET
_rtc_read_bcd:
	RCALL SUBOPT_0x3E
	RCALL SUBOPT_0x3E
	RCALL _rtc_read
	ST   -Y,R30
	RCALL _bcd2bin
_0x180:
	ADIW R28,2
	RET
_rtc_write_bcd:
	RCALL SUBOPT_0xA
	RCALL SUBOPT_0xA
	RCALL SUBOPT_0xA
	RCALL _bin2bcd
	RCALL SUBOPT_0x3F
_0x17F:
	ADIW R28,3
	RET
_rtc_write_word:
	RCALL SUBOPT_0x33
	RCALL SUBOPT_0x33
	RCALL SUBOPT_0xA
	RCALL _rtc_write
	RCALL SUBOPT_0x33
	LDD  R30,Y+3
	SUBI R30,-LOW(1)
	STD  Y+3,R30
	ST   -Y,R30
	LDD  R30,Y+3
	ANDI R31,HIGH(0x0)
	RCALL SUBOPT_0x3F
_0x17E:
	ADIW R28,4
	RET
_rtc_write_date:
	LDD  R30,Y+4
	RCALL SUBOPT_0x34
	RCALL SUBOPT_0x40
	RCALL _bin2bcd
	PUSH R30
	LDD  R30,Y+2
	ANDI R30,LOW(0x3)
	SWAP R30
	ANDI R30,0xF0
	LSL  R30
	LSL  R30
	POP  R26
	OR   R30,R26
	RCALL SUBOPT_0x3F
	RJMP _0x17D
_rtc_get_time:
	RCALL SUBOPT_0x41
	RCALL _rtc_hold_on
	RCALL SUBOPT_0x41
	RCALL SUBOPT_0xF
	RCALL _rtc_read_bcd
	LD   R26,Y
	LDD  R27,Y+1
	RCALL SUBOPT_0x42
	LDI  R30,LOW(2)
	RCALL SUBOPT_0x43
	LDD  R26,Y+2
	LDD  R27,Y+2+1
	RCALL SUBOPT_0x42
	LDI  R30,LOW(3)
	RCALL SUBOPT_0x43
	LDD  R26,Y+4
	LDD  R27,Y+4+1
	RCALL SUBOPT_0x42
	RCALL SUBOPT_0x3A
	RCALL _rtc_read_bcd
	LDD  R26,Y+6
	LDD  R27,Y+6+1
	RCALL SUBOPT_0x42
	RCALL _rtc_hold_off
	ADIW R28,9
	RET
_rtc_set_time:
	RCALL SUBOPT_0x40
	RCALL SUBOPT_0x44
	RCALL SUBOPT_0xF
	RCALL SUBOPT_0xA
	RCALL SUBOPT_0x45
	LDI  R30,LOW(2)
	RCALL SUBOPT_0x36
	RCALL SUBOPT_0x45
	LDI  R30,LOW(3)
	RCALL SUBOPT_0x34
	RCALL SUBOPT_0x45
	RCALL SUBOPT_0x3A
	RCALL SUBOPT_0x46
	RCALL SUBOPT_0x45
	RCALL _rtc_start
	RJMP _0x17D
_rtc_set_date:
	RCALL SUBOPT_0x40
	RCALL SUBOPT_0x2
	RCALL SUBOPT_0xE
	RCALL _rtc_write_word
	RCALL SUBOPT_0x40
	RCALL SUBOPT_0x44
	LDI  R30,LOW(5)
	ST   -Y,R30
	RCALL SUBOPT_0x46
	LDD  R30,Y+3
	LDD  R31,Y+3+1
	ST   -Y,R31
	ST   -Y,R30
	RCALL _rtc_write_date
	RCALL SUBOPT_0x40
	LDI  R30,LOW(6)
	RCALL SUBOPT_0x34
	RCALL SUBOPT_0x45
	RCALL _rtc_start
_0x17D:
	ADIW R28,5
	RET

	.DSEG
__base_y_G6:
	.BYTE 0x4
    .equ __lcd_direction=__lcd_port-1
    .equ __lcd_pin=__lcd_port-2
    .equ __lcd_rs=0
    .equ __lcd_rd=1
    .equ __lcd_enable=2
    .equ __lcd_busy_flag=7

	.CSEG
__lcd_ready:
    in    r26,__lcd_direction
    andi  r26,0xf                 ;set as input
    out   __lcd_direction,r26
    sbi   __lcd_port,__lcd_rd     ;RD=1
    cbi   __lcd_port,__lcd_rs     ;RS=0
__lcd_busy:
    rcall __lcd_delay
    sbi   __lcd_port,__lcd_enable ;EN=1
    rcall __lcd_delay
    sbic  __lcd_pin,__lcd_busy_flag
    rjmp  __lcd_busy
    cbi   __lcd_port,__lcd_enable ;EN=0
	RET
__lcd_write_nibble:
    andi  r26,0xf0
    or    r26,r27
    out   __lcd_port,r26          ;write
    sbi   __lcd_port,__lcd_enable ;EN=1
    rcall __lcd_delay
    cbi   __lcd_port,__lcd_enable ;EN=0
__lcd_delay:
    ldi   r31,15
__lcd_delay0:
    dec   r31
    brne  __lcd_delay0
    ret
__lcd_write_data:
    cbi  __lcd_port,__lcd_rd 	  ;RD=0
    in    r26,__lcd_direction
    ori   r26,0xf7                ;set as output
    out   __lcd_direction,r26
    in    r27,__lcd_port
    andi  r27,0xf
    ld    r26,y
    rcall __lcd_write_nibble      ;RD=0, write MSN
    ld    r26,y
    swap  r26
    rcall __lcd_write_nibble      ;write LSN
    sbi   __lcd_port,__lcd_rd     ;RD=1
	ADIW R28,1
	RET
_lcd_gotoxy:
	RCALL __lcd_ready
	LD   R30,Y
	CLR  R31
	SUBI R30,LOW(-__base_y_G6)
	SBCI R31,HIGH(-__base_y_G6)
	LD   R30,Z
	LDD  R26,Y+1
	ADD  R30,R26
	RCALL SUBOPT_0x47
	LDD  R11,Y+1
	LDD  R12,Y+0
	ADIW R28,2
	RET
_lcd_clear:
	RCALL __lcd_ready
	LDI  R30,LOW(12)
	RCALL SUBOPT_0x47
	RCALL __lcd_ready
	RCALL SUBOPT_0xF
	RCALL __lcd_write_data
	CLR  R30
	MOV  R12,R30
	MOV  R11,R30
	RET
_lcd_putchar:
    push r30
    push r31
    ld   r26,y
    set
    cpi  r26,10
    breq __lcd_putchar1
    clt
	INC  R11
	CP   R13,R11
	BRSH _0x179
	__lcd_putchar1:
	INC  R12
	RCALL SUBOPT_0x0
	ST   -Y,R12
	RCALL _lcd_gotoxy
	brts __lcd_putchar0
_0x179:
    rcall __lcd_ready
    sbi  __lcd_port,__lcd_rs ;RS=1
    ld   r26,y
    st   -y,r26
    rcall __lcd_write_data
__lcd_putchar0:
    pop  r31
    pop  r30
	ADIW R28,1
	RET
_lcd_puts:
    ldd  r31,y+1
    ld   r30,y
__lcd_puts0:
    ld   r26,z+
    tst  r26
    breq __lcd_puts1
    st   -y,r26    
    rcall _lcd_putchar
    rjmp __lcd_puts0
__lcd_puts1:
	ADIW R28,2
	RET
__long_delay:
    clr   r26
    clr   r27
__long_delay0:
    sbiw  r26,1         ;2 cycles
    brne  __long_delay0 ;2 cycles
	RET
_lcd_init:
    cbi   __lcd_port,__lcd_enable ;EN=0
    cbi   __lcd_port,__lcd_rs     ;RS=0
	LDD  R13,Y+0
	LD   R30,Y
	SUBI R30,-LOW(128)
	__PUTB1MN __base_y_G6,2
	LD   R30,Y
	SUBI R30,-LOW(192)
	__PUTB1MN __base_y_G6,3
	RCALL SUBOPT_0x48
	RCALL SUBOPT_0x48
	RCALL SUBOPT_0x48
	RCALL __long_delay
	LDI  R30,LOW(32)
	RCALL SUBOPT_0x47
	RCALL __lcd_ready
	LDI  R30,LOW(40)
	RCALL SUBOPT_0x47
	RCALL __lcd_ready
	LDI  R30,LOW(6)
	RCALL SUBOPT_0x47
	RCALL _lcd_clear
	ADIW R28,1
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 19 TIMES
SUBOPT_0x0:
	CLR  R30
	ST   -Y,R30
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 8 TIMES
SUBOPT_0x1:
	ST   -Y,R30
	RJMP SUBOPT_0x0

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x2:
	LDI  R30,LOW(16)
	ST   -Y,R30
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 14 TIMES
SUBOPT_0x3:
	LDI  R30,LOW(_display_buffer_ligne0)
	LDI  R31,HIGH(_display_buffer_ligne0)
	ST   -Y,R31
	ST   -Y,R30
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 18 TIMES
SUBOPT_0x4:
	RCALL _sprintf
	ADIW R28,4
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 14 TIMES
SUBOPT_0x5:
	LDI  R30,LOW(_display_buffer_ligne1)
	LDI  R31,HIGH(_display_buffer_ligne1)
	ST   -Y,R31
	ST   -Y,R30
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x6:
	MOV  R30,R16
	CPI  R30,0
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 16 TIMES
SUBOPT_0x7:
	CLR  R31
	CLR  R22
	CLR  R23
	RCALL __PUTPARD1
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 7 TIMES
SUBOPT_0x8:
	RCALL _sprintf
	ADIW R28,16
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 6 TIMES
SUBOPT_0x9:
	ST   -Y,R31
	ST   -Y,R30
	RJMP _delay_ms

;OPTIMIZER ADDED SUBROUTINE, CALLED 10 TIMES
SUBOPT_0xA:
	LDD  R30,Y+2
	ST   -Y,R30
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 3 TIMES
SUBOPT_0xB:
	LDI  R30,LOW(5000)
	LDI  R31,HIGH(5000)
	RJMP SUBOPT_0x9

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0xC:
	ST   -Y,R19
	ST   -Y,R21
	LDD  R30,Y+5
	ST   -Y,R30
	LDD  R30,Y+3
	LDD  R31,Y+3+1
	ST   -Y,R30
	RJMP _regle_HTR

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0xD:
	LDI  R30,LOW(20)
	LDI  R31,HIGH(20)
	RJMP SUBOPT_0x9

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0xE:
	LDD  R30,Y+2
	LDD  R31,Y+2+1
	ST   -Y,R31
	ST   -Y,R30
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 4 TIMES
SUBOPT_0xF:
	LDI  R30,LOW(1)
	ST   -Y,R30
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x10:
	LDD  R30,Y+46
	ST   -Y,R30
	LDD  R30,Y+45
	ST   -Y,R30
	LDD  R30,Y+45
	ST   -Y,R30
	LDD  R30,Y+44
	LDD  R31,Y+44+1
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 3 TIMES
SUBOPT_0x11:
	LDD  R30,Y+45
	CPI  R30,0
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x12:
	CLR  R30
	STD  Y+44,R30
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x13:
	LDD  R30,Y+44
	CP   R30,R19
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 12 TIMES
SUBOPT_0x14:
	MOV  R30,R28
	MOV  R31,R29
	ADIW R30,22
	ST   -Y,R31
	ST   -Y,R30
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 6 TIMES
SUBOPT_0x15:
	MOV  R30,R28
	MOV  R31,R29
	ADIW R30,5
	ST   -Y,R31
	ST   -Y,R30
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 6 TIMES
SUBOPT_0x16:
	ST   -Y,R31
	ST   -Y,R30
	LDD  R30,Y+48
	RJMP SUBOPT_0x7

;OPTIMIZER ADDED SUBROUTINE, CALLED 6 TIMES
SUBOPT_0x17:
	LDD  R30,Y+51
	RJMP SUBOPT_0x7

;OPTIMIZER ADDED SUBROUTINE, CALLED 6 TIMES
SUBOPT_0x18:
	LDD  R30,Y+53
	LDD  R31,Y+53+1
	RCALL __CWD1
	RCALL __PUTPARD1
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 6 TIMES
SUBOPT_0x19:
	MOV  R30,R28
	MOV  R31,R29
	ADIW R30,7
	ST   -Y,R31
	ST   -Y,R30
	RJMP _Affiche_LCD

;OPTIMIZER ADDED SUBROUTINE, CALLED 3 TIMES
SUBOPT_0x1A:
	MOV  R30,R16
	CPI  R30,LOW(0x1F)
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x1B:
	LDD  R30,Y+43
	CP   R30,R20
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x1C:
	LDD  R30,Y+41
	LDD  R31,Y+41+1
	LDD  R26,Y+39
	LDD  R27,Y+39+1
	CP   R30,R26
	CPC  R31,R27
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x1D:
	LDD  R30,Y+41
	LDD  R31,Y+41+1
	STD  Y+39,R30
	STD  Y+39+1,R31
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x1E:
	MOV  R26,R28
	MOV  R27,R29
	ADIW R26,43
	LDI  R30,LOW(2000)
	LDI  R31,HIGH(2000)
	ST   X,R30
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x1F:
	LDD  R30,Y+41
	LDD  R31,Y+41+1
	ADIW R30,1
	STD  Y+41,R30
	STD  Y+41+1,R31
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x20:
	RCALL _i2c_start
	LDD  R30,Y+5
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 16 TIMES
SUBOPT_0x21:
	ST   -Y,R30
	RJMP _i2c_write

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x22:
	ORI  R30,1
	RJMP SUBOPT_0x21

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x23:
	RCALL _i2c_read
	MOV  R16,R30
	RCALL _i2c_stop
	MOV  R30,R16
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x24:
	LD   R26,Y
	LDD  R27,Y+1
	RCALL __GETW1P
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 4 TIMES
SUBOPT_0x25:
	ST   -Y,R19
	LDD  R30,Y+13
	LDD  R31,Y+13+1
	ST   -Y,R31
	ST   -Y,R30
	RJMP __put_G3

;OPTIMIZER ADDED SUBROUTINE, CALLED 5 TIMES
SUBOPT_0x26:
	LDD  R26,Y+14
	LDD  R27,Y+14+1
	SBIW R26,4
	STD  Y+14,R26
	STD  Y+14+1,R27
	ADIW R26,4
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x27:
	ST   -Y,R30
	LDD  R30,Y+13
	LDD  R31,Y+13+1
	ST   -Y,R31
	ST   -Y,R30
	RJMP __put_G3

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x28:
	RCALL __GETD1P
	STD  Y+6,R30
	STD  Y+6+1,R31
	ST   -Y,R31
	ST   -Y,R30
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x29:
	RCALL __GETW1P
	STD  Y+10,R30
	STD  Y+10+1,R31
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x2A:
	LDD  R30,Y+13
	LDD  R31,Y+13+1
	ST   -Y,R31
	ST   -Y,R30
	RJMP __put_G3

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x2B:
	RCALL __ADDW2R15
	RCALL __GETW1P
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x2C:
	LDD  R30,Y+2
	LSL  R30
	ORI  R30,LOW(0x90)
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x2D:
	MOV  R16,R30
	RCALL _i2c_start
	ST   -Y,R16
	RJMP _i2c_write

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x2E:
	LDI  R30,LOW(172)
	RJMP SUBOPT_0x21

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x2F:
	LDD  R30,Y+1
	LSL  R30
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x30:
	ORI  R30,LOW(0x90)
	RJMP SUBOPT_0x21

;OPTIMIZER ADDED SUBROUTINE, CALLED 3 TIMES
SUBOPT_0x31:
	LD   R30,Y
	RJMP SUBOPT_0x21

;OPTIMIZER ADDED SUBROUTINE, CALLED 3 TIMES
SUBOPT_0x32:
	LDD  R30,Y+1
	RJMP SUBOPT_0x21

;OPTIMIZER ADDED SUBROUTINE, CALLED 9 TIMES
SUBOPT_0x33:
	LDD  R30,Y+3
	ST   -Y,R30
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 5 TIMES
SUBOPT_0x34:
	ST   -Y,R30
	LDD  R30,Y+4
	ST   -Y,R30
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x35:
	RCALL _ds1621_set_temp
	RJMP SUBOPT_0x33

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x36:
	ST   -Y,R30
	RJMP SUBOPT_0x33

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x37:
	LDD  R30,Y+2
	LSL  R30
	ORI  R30,LOW(0xA0)
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 5 TIMES
SUBOPT_0x38:
	LD   R30,Y
	RJMP SUBOPT_0x1

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x39:
	RCALL _rtc_write
	RJMP SUBOPT_0xA

;OPTIMIZER ADDED SUBROUTINE, CALLED 3 TIMES
SUBOPT_0x3A:
	LDI  R30,LOW(4)
	ST   -Y,R30
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 4 TIMES
SUBOPT_0x3B:
	LD   R30,Y
	ST   -Y,R30
	RCALL _rtc_get_status
	MOV  R30,R4
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 4 TIMES
SUBOPT_0x3C:
	MOV  R4,R30
	RJMP SUBOPT_0x38

;OPTIMIZER ADDED SUBROUTINE, CALLED 4 TIMES
SUBOPT_0x3D:
	ST   -Y,R4
	RJMP _rtc_write

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x3E:
	LDD  R30,Y+1
	ST   -Y,R30
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 3 TIMES
SUBOPT_0x3F:
	ST   -Y,R30
	RJMP _rtc_write

;OPTIMIZER ADDED SUBROUTINE, CALLED 12 TIMES
SUBOPT_0x40:
	LDD  R30,Y+4
	ST   -Y,R30
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 6 TIMES
SUBOPT_0x41:
	LDD  R30,Y+8
	ST   -Y,R30
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 4 TIMES
SUBOPT_0x42:
	ST   X,R30
	RJMP SUBOPT_0x41

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x43:
	ST   -Y,R30
	RJMP _rtc_read_bcd

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x44:
	RCALL _rtc_stop
	RJMP SUBOPT_0x40

;OPTIMIZER ADDED SUBROUTINE, CALLED 5 TIMES
SUBOPT_0x45:
	RCALL _rtc_write_bcd
	RJMP SUBOPT_0x40

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x46:
	LDD  R30,Y+5
	ST   -Y,R30
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 8 TIMES
SUBOPT_0x47:
	ST   -Y,R30
	RJMP __lcd_write_data

;OPTIMIZER ADDED SUBROUTINE, CALLED 3 TIMES
SUBOPT_0x48:
	RCALL __long_delay
	LDI  R30,LOW(48)
	RJMP SUBOPT_0x47

	.equ __i2c_dir=__i2c_port-1
	.equ __i2c_pin=__i2c_port-2
_i2c_init:
	cbi  __i2c_port,__scl_bit
	cbi  __i2c_port,__sda_bit
	sbi  __i2c_dir,__scl_bit
	cbi  __i2c_dir,__sda_bit
	rjmp __i2c_delay2
_i2c_start:
	cbi  __i2c_dir,__sda_bit
	cbi  __i2c_dir,__scl_bit
	clr  r30
	nop
	sbis __i2c_pin,__sda_bit
	ret
	sbis __i2c_pin,__scl_bit
	ret
	rcall __i2c_delay1
	sbi  __i2c_dir,__sda_bit
	rcall __i2c_delay1
	sbi  __i2c_dir,__scl_bit
	ldi  r30,1
__i2c_delay1:
	ldi  r22,7
	rjmp __i2c_delay2l
_i2c_stop:
	sbi  __i2c_dir,__sda_bit
	sbi  __i2c_dir,__scl_bit
	rcall __i2c_delay2
	cbi  __i2c_dir,__scl_bit
	rcall __i2c_delay1
	cbi  __i2c_dir,__sda_bit
__i2c_delay2:
	ldi  r22,13
__i2c_delay2l:
	dec  r22
	brne __i2c_delay2l
	ret
_i2c_read:
	ldi  r23,8
__i2c_read0:
	cbi  __i2c_dir,__scl_bit
	rcall __i2c_delay2
	clc
	sbic __i2c_pin,__sda_bit
	sec
	sbi  __i2c_dir,__scl_bit
	rcall __i2c_delay2
	rol  r30
	dec  r23
	brne __i2c_read0
	ld   r23,y+
	tst  r23
	brne __i2c_read1
	cbi  __i2c_dir,__sda_bit
	rjmp __i2c_read2
__i2c_read1:
	sbi  __i2c_dir,__sda_bit
__i2c_read2:
	rcall __i2c_delay1
	cbi  __i2c_dir,__scl_bit
	rcall __i2c_delay2
	sbi  __i2c_dir,__scl_bit
	rcall __i2c_delay1
	cbi  __i2c_dir,__sda_bit
	rjmp __i2c_delay1

_i2c_write:
	ld   r30,y+
	ldi  r23,8
__i2c_write0:
	lsl  r30
	brcc __i2c_write1
	cbi  __i2c_dir,__sda_bit
	rjmp __i2c_write2
__i2c_write1:
	sbi  __i2c_dir,__sda_bit
__i2c_write2:
	rcall __i2c_delay2
	cbi  __i2c_dir,__scl_bit
	rcall __i2c_delay2
	sbi  __i2c_dir,__scl_bit
	dec  r23
	brne __i2c_write0
	cbi  __i2c_dir,__sda_bit
	rcall __i2c_delay1
	cbi  __i2c_dir,__scl_bit
	rcall __i2c_delay2
	ldi  r30,1
	sbic __i2c_pin,__sda_bit
	clr  r30
	sbi  __i2c_dir,__scl_bit
	ret

_strlen:
	ld   r26,y+
	ld   r27,y+
	clr  r30
	clr  r31
__strlen0:
	ld   r22,x+
	tst  r22
	breq __strlen1
	adiw r30,1
	rjmp __strlen0
__strlen1:
	ret

_strlenf:
	clr  r26
	clr  r27
	ld   r30,y+
	ld   r31,y+
__strlenf0:
	lpm 
	tst  r0
	breq __strlenf1
	adiw r26,1
	adiw r30,1
	rjmp __strlenf0
__strlenf1:
	mov  r30,r26
	mov  r31,r27
	ret

_delay_ms:
	ld   r30,y+
	ld   r31,y+
	adiw r30,0
	breq __delay_ms1
__delay_ms0:
	__DELAY_USW 0x3E8
	wdr
	sbiw r30,1
	brne __delay_ms0
__delay_ms1:
	ret

_bcd2bin:
	ld   r30,y
	swap r30
	andi r30,0xf
	mov  r26,r30
	lsl  r26
	lsl  r26
	add  r30,r26
	lsl  r30
	ld   r26,y+
	andi r26,0xf
	add  r30,r26
	ret

_bin2bcd:
	ld   r26,y+
	clr  r30
__bin2bcd0:
	subi r26,10
	brmi __bin2bcd1
	subi r30,-16
	rjmp __bin2bcd0
__bin2bcd1:
	subi r26,-10
	add  r30,r26
	ret

__ADDW2R15:
	CLR  R0
	ADD  R26,R15
	ADC  R27,R0
	RET

__ANEGW1:
	COM  R30
	COM  R31
	ADIW R30,1
	RET

__CWD1:
	CLR  R22
	CLR  R23
	SBRS R31,7
	RET
	SER  R22
	SER  R23
	RET

__GETW1P:
	LD   R30,X+
	LD   R31,X
	SBIW R26,1
	RET

__GETD1P:
	LD   R30,X+
	LD   R31,X+
	LD   R22,X+
	LD   R23,X
	SBIW R26,3
	RET

__PUTWP1:
	ST   X+,R30
	ST   X,R31
	RET

__GETW1PF:
	LPM
	ADIW R30,1
	MOV  R1,R0
	LPM 
	MOV  R31,R0
	MOV  R30,R1
	RET

__PUTPARD1:
	ST   -Y,R23
	ST   -Y,R22
	ST   -Y,R31
	ST   -Y,R30
	RET

__SAVELOCR6:
	ST   -Y,R21
__SAVELOCR5:
	ST   -Y,R20
__SAVELOCR4:
	ST   -Y,R19
__SAVELOCR3:
	ST   -Y,R18
__SAVELOCR2:
	ST   -Y,R17
	ST   -Y,R16
	RET

__LOADLOCR6:
	LDD  R21,Y+5
__LOADLOCR5:
	LDD  R20,Y+4
__LOADLOCR4:
	LDD  R19,Y+3
__LOADLOCR3:
	LDD  R18,Y+2
__LOADLOCR2:
	LDD  R17,Y+1
	LD   R16,Y
	RET

__LOADLOCR2P:
	LD   R16,Y+
	LD   R17,Y+
	RET

