;CodeVisionAVR C Compiler V1.0.2.2d Standard
;(C) Copyright 1998-2002 Pavel Haiduc, HP InfoTech s.r.l.
;http://www.hpinfotech.ro
;e-mail:office@hpinfotech.ro , hpinfotech@xmail.ro

;Chip type           : AT90S8535
;Clock frequency     : 4,000000 MHz
;Memory model        : Small
;Optimize for        : Size
;Internal SRAM size  : 512
;External SRAM size  : 0
;Data Stack size     : 128
;Promote char to int : No
;char is unsigned    : 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 __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 0x11

	.INCLUDE "acces_el.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-R15
	LDI  R24,14
	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(0xDF)
	LDI  R29,HIGH(0xDF)

	RJMP _main

	.ESEG
	.ORG 1

	.DSEG
	.ORG 0xE0
;       1 /*********************************************
;       2 This program was produced by the
;       3 CodeWizardAVR V1.23.6b Evaluation
;       4 Automatic Program Generator
;       5 © Copyright 1998-2002 HP InfoTech s.r.l.
;       6 http://www.hpinfotech.ro
;       7 e-mail:office@hpinfotech.ro , hpinfotech@xnet.ro
;       8 
;       9 Project : PPE contrôle d'accès
;      10 Version : 1
;      11 Date    : 
;      12 Author  : 
;      13 Company : Lycée PE MARTIN
;      14 Comments: Simulation de la lecture du code et de la commande du portail
;      15 Carte en place si Freq = 0, accepté si OK appuyé, refusé si Echap appuyé
;      16 Led 0 = ouverture portail
;      17 
;      18 Chip type           : AT90S8535
;      19 Clock frequency     : 4,000000 MHz
;      20 Memory model        : Small
;      21 Internal SRAM size  : 512
;      22 External SRAM size  : 0
;      23 Data Stack size     : 128
;      24 *********************************************/
;      25 
;      26 #include <90s8535.h>
;      27 // CodeVisionAVR C Compiler
;      28 // (C) 1998-2000 Pavel Haiduc, HP InfoTech S.R.L.
;      29 
;      30 // I/O registers definitions for the AT90S8535
;      31 
;      32 #ifndef _90S8535_INCLUDED_
;      33 #define _90S8535_INCLUDED_
;      34 
;      35 #pragma used+
;      36 sfrb ADCL=4;
;      37 sfrb ADCH=5;
;      38 sfrw ADCW=4;      // 16 bit access
;      39 sfrb ADCSR=6;
;      40 sfrb ADMUX=7;
;      41 sfrb ACSR=8;
;      42 sfrb UBRR=9;
;      43 sfrb UCR=0xa;
;      44 sfrb USR=0xb;
;      45 sfrb UDR=0xc;
;      46 sfrb SPCR=0xd;
;      47 sfrb SPSR=0xe;
;      48 sfrb SPDR=0xf;
;      49 sfrb PIND=0x10;
;      50 sfrb DDRD=0x11;
;      51 sfrb PORTD=0x12;
;      52 sfrb PINC=0x13;
;      53 sfrb DDRC=0x14;
;      54 sfrb PORTC=0x15;
;      55 sfrb PINB=0x16;
;      56 sfrb DDRB=0x17;
;      57 sfrb PORTB=0x18;
;      58 sfrb PINA=0x19;
;      59 sfrb DDRA=0x1a;
;      60 sfrb PORTA=0x1b;
;      61 sfrb EECR=0x1c;
;      62 sfrb EEDR=0x1d;
;      63 sfrb EEARL=0x1e;
;      64 sfrb EEARH=0x1f;
;      65 sfrw EEAR=0x1e;   // 16 bit access
;      66 sfrb WDTCR=0x21;
;      67 sfrb ASSR=0x22;
;      68 sfrb OCR2=0x23;
;      69 sfrb TCNT2=0x24;
;      70 sfrb TCCR2=0x25;
;      71 sfrb ICR1L=0x26;
;      72 sfrb ICR1H=0x27;
;      73 sfrw ICR1=0x26;   // 16 bit access
;      74 sfrb OCR1BL=0x28;
;      75 sfrb OCR1BH=0x29;
;      76 sfrw OCR1B=0x28;  // 16 bit access
;      77 sfrb OCR1AL=0x2a;
;      78 sfrb OCR1AH=0x2b;
;      79 sfrw OCR1A=0x2a;  // 16 bit access
;      80 sfrb TCNT1L=0x2c;
;      81 sfrb TCNT1H=0x2d;
;      82 sfrw TCNT1=0x2c;  // 16 bit access
;      83 sfrb TCCR1B=0x2e;
;      84 sfrb TCCR1A=0x2f;
;      85 sfrb TCNT0=0x32;
;      86 sfrb TCCR0=0x33;
;      87 sfrb MCUSR=0x34;
;      88 sfrb MCUCR=0x35;
;      89 sfrb TIFR=0x38;
;      90 sfrb TIMSK=0x39;
;      91 sfrb GIFR=0x3a;
;      92 sfrb GIMSK=0x3b;
;      93 sfrb SPL=0x3d;
;      94 sfrb SPH=0x3e;
;      95 sfrb SREG=0x3f;
;      96 #pragma used-
;      97 
;      98 // Interrupt vectors definitions
;      99 
;     100 #define EXT_INT0 2
;     101 #define EXT_INT1 3
;     102 #define TIM2_COMP 4
;     103 #define TIM2_OVF 5
;     104 #define TIM1_CAPT 6
;     105 #define TIM1_COMPA 7
;     106 #define TIM1_COMPB 8
;     107 #define TIM1_OVF 9
;     108 #define TIM0_OVF 10
;     109 #define SPI_STC 11
;     110 #define UART_RXC 12
;     111 #define UART_DRE 13
;     112 #define UART_TXC 14
;     113 #define ADC_INT 15
;     114 #define EE_RDY 16
;     115 #define ANA_COMP 17
;     116 
;     117 #endif
;     118 
;     119 
;     120 // Librairies non générées par Wizard (à rajouter)      
;     121 #include <c:\cvavrdemo\ssi1.c>      // contient la fonction Lire_BP et Affiche_LCD
;     122 #include <lcd.h>
;     123 /* LCD driver routines
;     124 
;     125   CodeVisionAVR C Compiler
;     126   (C) 1998-2000 Pavel Haiduc, HP InfoTech S.R.L.
;     127 
;     128   BEFORE #include -ING THIS FILE YOU
;     129   MUST DECLARE THE I/O ADDRESS OF THE
;     130   DATA REGISTER OF THE PORT AT WHICH
;     131   THE LCD IS CONNECTED!
;     132 
;     133   EXAMPLE FOR PORTB:
;     134 
;     135     #asm
;     136         .equ __lcd_port=0x18
;     137     #endasm
;     138     #include <lcd.h>
;     139 
;     140 */
;     141 
;     142 #ifndef _LCD_INCLUDED_
;     143 #define _LCD_INCLUDED_
;     144 
;     145 #pragma used+
;     146 
;     147 void _lcd_ready(void);
;     148 void _lcd_write_data(unsigned char data);
;     149 // write a byte to the LCD character generator or display RAM
;     150 void lcd_write_byte(unsigned char addr, unsigned char data);
;     151 // read a byte from the LCD character generator or display RAM
;     152 unsigned char lcd_read_byte(unsigned char addr);
;     153 // set the LCD display position  x=0..39 y=0..3
;     154 void lcd_gotoxy(unsigned char x, unsigned char y);
;     155 // clear the LCD
;     156 void lcd_clear(void);
;     157 void lcd_putchar(char c);
;     158 // write the string str located in SRAM to the LCD
;     159 void lcd_puts(char *str);
;     160 // write the string str located in FLASH to the LCD
;     161 void lcd_putsf(char flash *str);
;     162 // initialize the LCD controller
;     163 void lcd_init(unsigned char lcd_columns);
;     164 
;     165 #pragma used-
;     166 #pragma library lcd.lib
;     167 
;     168 #endif
;     169 
;     170 #include <delay.h>
;     171 // CodeVisionAVR C Compiler
;     172 // (C) 1998-2000 Pavel Haiduc, HP InfoTech S.R.L.
;     173 
;     174 #ifndef _DELAY_INCLUDED_
;     175 #define _DELAY_INCLUDED_
;     176 
;     177 #pragma used+
;     178 
;     179 void delay_us(unsigned int n);
;     180 void delay_ms(unsigned int n);
;     181 
;     182 #pragma used-
;     183 
;     184 #endif
;     185 
;     186 unsigned char  Lire_BP(void)
;     187 {

	.CSEG
_Lire_BP:
;     188   static unsigned char Etat_BP=0;

	.DSEG

	.CSEG
;     189   unsigned char BP_1, BP; 
;     190   
;     191   BP = PINA;
	RCALL __SAVELOCR2
;	BP_1 -> R16
;	BP -> R17
	IN   R17,25
;     192   BP = BP & 0x1f; // lecture des BP
	ANDI R17,LOW(31)
;     193   
;     194   switch (Etat_BP)
	MOV  R30,R4
;     195    {
;     196     case 1 : if (BP == 0x1f)
	CPI  R30,LOW(0x1)
	BRNE _0x11
	CPI  R17,31
	BRNE _0x12
;     197                {
;     198                  BP_1 = BP;
	MOV  R16,R17
;     199                  delay_ms(20);
	RCALL SUBOPT_0x0
;     200                  BP = PINA;
	IN   R17,25
;     201                  BP = BP & 0x1f; 
	ANDI R17,LOW(31)
;     202                  if (BP_1 == BP)
	CP   R17,R16
	BRNE _0x13
;     203                   {
;     204                    Etat_BP = 0; // BP relâchés (OFF)
	CLR  R4
;     205                    return 0xff;
	LDI  R30,LOW(255)
	RJMP _0x95
;     206                   }
;     207                   else return 0x00; // BP actionnés (ON)
_0x13:
	CLR  R30
	RJMP _0x95
;     208                } 
;     209                else return 0x00; // BP actionnés (ON)
	RJMP _0x15
_0x12:
	CLR  R30
	RJMP _0x95
_0x15:
;     210     break;
	RJMP _0x10
;     211     
;     212     case 0 : if (BP != 0x1f)
_0x11:
	CPI  R30,0
	BRNE _0x10
	CPI  R17,31
	BREQ _0x17
;     213                {
;     214                  BP_1 = BP;
	MOV  R16,R17
;     215                  delay_ms(20);
	RCALL SUBOPT_0x0
;     216                  BP = PINA;
	IN   R17,25
;     217                  BP = BP & 0x1f; 
	ANDI R17,LOW(31)
;     218                  if (BP_1 == BP)
	CP   R17,R16
	BRNE _0x18
;     219                   {
;     220                    Etat_BP = 1; // BP actionnés (ON)
	LDI  R30,LOW(1)
	MOV  R4,R30
;     221                    return BP;
	MOV  R30,R17
	RJMP _0x95
;     222                   }
;     223                   else return 0xFF; // BP relâchés (OFF)
_0x18:
	LDI  R30,LOW(255)
	RJMP _0x95
;     224                } 
;     225                else return 0xFF; // BP relâchés (ON)
	RJMP _0x1A
_0x17:
	LDI  R30,LOW(255)
_0x1A:
;     226     break;
;     227    }
_0x10:
;     228 } 
_0x95:
	RCALL __LOADLOCR2P
	RET
;     229 
;     230 
;     231 
;     232 void Affiche_LCD(char *ligne1,char *ligne2)
;     233 {
_Affiche_LCD:
;     234 	lcd_clear();
	RCALL _lcd_clear
;     235         lcd_puts(ligne1);
	LDD  R30,Y+2
	LDD  R31,Y+2+1
	RCALL SUBOPT_0x1
;     236         lcd_gotoxy(0,1);
	RCALL SUBOPT_0x2
	RCALL SUBOPT_0x3
	RCALL _lcd_gotoxy
;     237         lcd_puts(ligne2);
	LD   R30,Y
	LDD  R31,Y+1
	RCALL SUBOPT_0x1
;     238 }
	ADIW R28,4
	RET
;     239 
;     240 
;     241 #include <delay.h> 		    // contient la fonction delay_ms
;     242 // CodeVisionAVR C Compiler
;     243 // (C) 1998-2000 Pavel Haiduc, HP InfoTech S.R.L.
;     244 
;     245 #ifndef _DELAY_INCLUDED_
;     246 #define _DELAY_INCLUDED_
;     247 
;     248 #pragma used+
;     249 
;     250 void delay_us(unsigned int n);
;     251 void delay_ms(unsigned int n);
;     252 
;     253 #pragma used-
;     254 
;     255 #endif
;     256 #include <stdio.h>      	    // contient la fonction sprintf
;     257 // CodeVisionAVR C Compiler
;     258 // (C) 1998-2002 Pavel Haiduc, HP InfoTech S.R.L.
;     259 
;     260 // Prototypes for standard I/O functions
;     261 
;     262 #ifndef _STDIO_INCLUDED_
;     263 #define _STDIO_INCLUDED_
;     264 
;     265 #ifndef NULL
;     266 #define NULL 0
;     267 #endif
;     268 
;     269 #ifndef EOF
;     270 #define EOF -1
;     271 #endif
;     272 
;     273 #pragma used+
;     274 
;     275 char getchar(void);
;     276 void putchar(char c);
;     277 void puts(char *str);
;     278 void putsf(char flash *str);
;     279 
;     280 #ifdef _MODEL_TINY_
;     281 char *gets(char *str,unsigned char len);
;     282 #endif
;     283 
;     284 #ifdef _MODEL_SMALL_
;     285 char *gets(char *str,unsigned int len);
;     286 #endif
;     287 
;     288 #pragma parptr+
;     289 void printf(char flash *fmtstr);
;     290 void sprintf(char *str, char flash *fmtstr);
;     291 #pragma parptr-
;     292 
;     293 signed char scanf(char flash *fmtstr,...);
;     294 signed char sscanf(char *str, char flash *fmtstr,...);
;     295 
;     296 #ifdef _DEBUG_TERMINAL_IO_
;     297 // Used for AVR Studio Terminal I/O
;     298 // DON'T CHANGE!
;     299 #pragma warn-
;     300 #pragma keep+
;     301 void _c_getchar(void) {}
;     302 
;     303 char getchar(void)
;     304 {
;     305 #asm
;     306      push  r16
;     307      push  r17
;     308 __getchar0:
;     309 #endasm
;     310 _c_getchar();
;     311 #asm
;     312      cpi   r17,0xff
;     313      breq  __getchar0
;     314      mov   r30,r16
;     315      pop   r17
;     316      pop   r16
;     317 #endasm
;     318 }
;     319 
;     320 void _c_putchar(void) {}
;     321 
;     322 void putchar(char c)
;     323 {
;     324 #asm
;     325     mov   r30,r16
;     326     ld    r16,y
;     327 #endasm
;     328 _c_putchar();
;     329 #asm
;     330     mov   r16,r30
;     331 #endasm
;     332 }
;     333 #pragma keep-
;     334 
;     335 #ifdef _WARNINGS_ON_
;     336 #pragma warn+
;     337 #endif
;     338 
;     339 #endif
;     340 #pragma used-
;     341 
;     342 #pragma library stdio.lib
;     343 
;     344 #endif
;     345 
;     346 
;     347 // Etats du graphe des transitions
;     348 #define Attente	 	0
;     349 #define Traitement 	1
;     350 #define Refus 		2
;     351 #define RetraitCarte	3
;     352 #define CdePortail	4
;     353 
;     354 // Codes des BP de la carte DevATMEL ELEC
;     355 #define INC		0x0F
;     356 #define DEC		0x17
;     357 #define OK		0x1B
;     358 #define ECHAP		0x1D
;     359 #define SET		0x1E
;     360 
;     361 // Alphanumeric LCD Module functions
;     362 #asm
   .equ __lcd_port=0x15
;     364 #endasm
;     365 #include <lcd.h>
;     366 /* LCD driver routines
;     367 
;     368   CodeVisionAVR C Compiler
;     369   (C) 1998-2000 Pavel Haiduc, HP InfoTech S.R.L.
;     370 
;     371   BEFORE #include -ING THIS FILE YOU
;     372   MUST DECLARE THE I/O ADDRESS OF THE
;     373   DATA REGISTER OF THE PORT AT WHICH
;     374   THE LCD IS CONNECTED!
;     375 
;     376   EXAMPLE FOR PORTB:
;     377 
;     378     #asm
;     379         .equ __lcd_port=0x18
;     380     #endasm
;     381     #include <lcd.h>
;     382 
;     383 */
;     384 
;     385 #ifndef _LCD_INCLUDED_
;     386 #define _LCD_INCLUDED_
;     387 
;     388 #pragma used+
;     389 
;     390 void _lcd_ready(void);
;     391 void _lcd_write_data(unsigned char data);
;     392 // write a byte to the LCD character generator or display RAM
;     393 void lcd_write_byte(unsigned char addr, unsigned char data);
;     394 // read a byte from the LCD character generator or display RAM
;     395 unsigned char lcd_read_byte(unsigned char addr);
;     396 // set the LCD display position  x=0..39 y=0..3
;     397 void lcd_gotoxy(unsigned char x, unsigned char y);
;     398 // clear the LCD
;     399 void lcd_clear(void);
;     400 void lcd_putchar(char c);
;     401 // write the string str located in SRAM to the LCD
;     402 void lcd_puts(char *str);
;     403 // write the string str located in FLASH to the LCD
;     404 void lcd_putsf(char flash *str);
;     405 // initialize the LCD controller
;     406 void lcd_init(unsigned char lcd_columns);
;     407 
;     408 #pragma used-
;     409 #pragma library lcd.lib
;     410 
;     411 #endif
;     412 
;     413 
;     414 // Declare your global variables here
;     415 char display_buffer_ligne0[17]; // tampon ligne 0 de l'afficheur

	.DSEG
_display_buffer_ligne0:
	.BYTE 0x11
;     416 char display_buffer_ligne1[17]; // tampon ligne 1 de l'afficheur
_display_buffer_ligne1:
	.BYTE 0x11
;     417 
;     418 void main(void)
;     419 {

	.CSEG
_main:
;     420 // Declare your local variables here
;     421 // etat, etat_1 : position dans le graphe des transitions
;     422 // BP : état du clavier
;     423 unsigned char etat=Attente, etat_1 = Attente, BP;
;     424 
;     425 // Input/Output Ports initialization
;     426 // Port A initialization
;     427 // Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In 
;     428 // State0=P State1=P State2=P State3=P State4=P State5=T State6=T State7=T 
;     429 PORTA=0x1F;
;	etat -> R16
;	etat_1 -> R17
;	BP -> R18
	LDI  R16,0
	LDI  R17,0
	LDI  R30,LOW(31)
	OUT  0x1B,R30
;     430 DDRA=0x00;
	CLR  R30
	OUT  0x1A,R30
;     431 
;     432 // Port B initialization
;     433 // Func0=Out Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In 
;     434 // State0=0 State1=T State2=T State3=T State4=T State5=T State6=T State7=T 
;     435 PORTB=0x00;
	OUT  0x18,R30
;     436 DDRB=0x01;
	LDI  R30,LOW(1)
	OUT  0x17,R30
;     437 
;     438 // Port C initialization
;     439 // Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In 
;     440 // State0=T State1=T State2=T State3=T State4=T State5=T State6=T State7=T 
;     441 PORTC=0x00;
	CLR  R30
	OUT  0x15,R30
;     442 DDRC=0x00;
	OUT  0x14,R30
;     443 
;     444 // Port D initialization
;     445 // Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In 
;     446 // State0=T State1=T State2=T State3=T State4=T State5=T State6=T State7=T 
;     447 PORTD=0x40;
	LDI  R30,LOW(64)
	OUT  0x12,R30
;     448 DDRD=0x00;
	CLR  R30
	OUT  0x11,R30
;     449 
;     450 // Timer/Counter 0 initialization
;     451 // Clock source: System Clock
;     452 // Clock value: Timer 0 Stopped
;     453 TCCR0=0x00;
	OUT  0x33,R30
;     454 TCNT0=0x00;
	OUT  0x32,R30
;     455 
;     456 // Timer/Counter 1 initialization
;     457 // Clock source: System Clock
;     458 // Clock value: Timer 1 Stopped
;     459 // Mode: Normal top=FFFFh
;     460 // OC1A output: Discon.
;     461 // OC1B output: Discon.
;     462 // Noise Canceler: Off
;     463 // Input Capture on Falling Edge
;     464 TCCR1A=0x00;
	OUT  0x2F,R30
;     465 TCCR1B=0x00;
	OUT  0x2E,R30
;     466 TCNT1H=0x00;
	OUT  0x2D,R30
;     467 TCNT1L=0x00;
	OUT  0x2C,R30
;     468 OCR1AH=0x00;
	OUT  0x2B,R30
;     469 OCR1AL=0x00;
	OUT  0x2A,R30
;     470 OCR1BH=0x00;
	OUT  0x29,R30
;     471 OCR1BL=0x00;
	OUT  0x28,R30
;     472 
;     473 // Timer/Counter 2 initialization
;     474 // Clock source: System Clock
;     475 // Clock value: Timer 2 Stopped
;     476 // Mode: Normal top=FFh
;     477 // OC2 output: Disconnected
;     478 ASSR=0x00;
	OUT  0x22,R30
;     479 TCCR2=0x00;
	OUT  0x25,R30
;     480 TCNT2=0x00;
	OUT  0x24,R30
;     481 OCR2=0x00;
	OUT  0x23,R30
;     482 
;     483 // External Interrupt(s) initialization
;     484 // INT0: Off
;     485 // INT1: Off
;     486 GIMSK=0x00;
	OUT  0x3B,R30
;     487 MCUCR=0x00;
	OUT  0x35,R30
;     488 
;     489 // Timer(s)/Counter(s) Interrupt(s) initialization
;     490 TIMSK=0x00;
	OUT  0x39,R30
;     491 
;     492 // Analog Comparator initialization
;     493 // Analog Comparator: Off
;     494 // Analog Comparator Input Capture by Timer/Counter 1: Off
;     495 // Analog Comparator Output: Off
;     496 ACSR=0x80;
	LDI  R30,LOW(128)
	OUT  0x8,R30
;     497 
;     498 // LCD module initialization
;     499 lcd_init(16);
	LDI  R30,LOW(16)
	ST   -Y,R30
	RCALL _lcd_init
;     500 
;     501 sprintf(display_buffer_ligne0,"Introduire      ");
	PUSH R29
	PUSH R28
	RCALL SUBOPT_0x4
	__POINTW1FN _37,0
	ST   -Y,R31
	ST   -Y,R30
	RCALL _sprintf
	ADIW R28,4
;     502 sprintf(display_buffer_ligne1,"     votre carte");
	PUSH R29
	PUSH R28
	RCALL SUBOPT_0x5
	__POINTW1FN _37,17
	ST   -Y,R31
	ST   -Y,R30
	RCALL _sprintf
	RCALL SUBOPT_0x6
;     503 Affiche_LCD(display_buffer_ligne0,display_buffer_ligne1); 
	RCALL SUBOPT_0x5
	RCALL _Affiche_LCD
;     504 
;     505 while (1)
_0x26:
;     506       {
;     507       
;     508       BP = Lire_BP();
	RCALL _Lire_BP
	MOV  R18,R30
;     509       
;     510       switch (etat)
	MOV  R30,R16
;     511       {
;     512        case Attente : if (etat_1 != etat)
	CPI  R30,0
	BRNE _0x2C
	CP   R16,R17
	BREQ _0x2D
;     513                        { sprintf(display_buffer_ligne0,"Introduire      ");
	PUSH R29
	PUSH R28
	RCALL SUBOPT_0x4
	__POINTW1FN _37,34
	ST   -Y,R31
	ST   -Y,R30
	RCALL _sprintf
	ADIW R28,4
;     514                          sprintf(display_buffer_ligne1,"     votre carte");
	PUSH R29
	PUSH R28
	RCALL SUBOPT_0x5
	__POINTW1FN _37,51
	ST   -Y,R31
	ST   -Y,R30
	RCALL _sprintf
	RCALL SUBOPT_0x6
;     515                          Affiche_LCD(display_buffer_ligne0,display_buffer_ligne1);
	RCALL SUBOPT_0x5
	RCALL _Affiche_LCD
;     516                        }
;     517                       if (!PIND.6) etat = Traitement;
_0x2D:
	SBIC 0x10,6
	RJMP _0x2E
	LDI  R16,LOW(1)
;     518                               else etat = Attente;
	RJMP _0x2F
_0x2E:
	LDI  R16,LOW(0)
_0x2F:
;     519                       etat_1 = Attente; 
	LDI  R17,LOW(0)
;     520        break;
	RJMP _0x2B
;     521        		   
;     522        case Traitement : 
_0x2C:
	CPI  R30,LOW(0x1)
	BREQ _0x2B
;     523                          // à compléter
;     524        
;     525        break;
;     526                       
;     527        case Refus :   
	CPI  R30,LOW(0x2)
	BREQ _0x2B
;     528                          // à compléter
;     529        
;     530        
;     531        break;
;     532                       		             
;     533        case RetraitCarte :
	CPI  R30,LOW(0x3)
	BREQ _0x2B
;     534                           // à compléter
;     535        
;     536          
;     537        break;
;     538                       
;     539        case CdePortail :     
	CPI  R30,LOW(0x4)
	BREQ _0x2B
;     540        
;     541        			// à compléter
;     542        break;
;     543        
;     544        default: etat = Attente;
	LDI  R16,LOW(0)
;     545 
;     546       };
_0x2B:
;     547     }
	RJMP _0x26
;     548 }
_0x35:
	RJMP _0x35

	.DSEG
__base_y:
	.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:
    nop
    nop
    nop
    nop
    nop
    nop
    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)
	SBCI R31,HIGH(-__base_y)
	LD   R30,Z
	LDD  R26,Y+1
	ADD  R30,R26
	RCALL SUBOPT_0x7
	LDD  R5,Y+1
	LDD  R6,Y+0
	ADIW R28,2
	RET
_lcd_clear:
	RCALL __lcd_ready
	LDI  R30,LOW(12)
	RCALL SUBOPT_0x7
	RCALL __lcd_ready
	RCALL SUBOPT_0x3
	RCALL __lcd_write_data
	CLR  R30
	MOV  R6,R30
	MOV  R5,R30
	RET
_lcd_putchar:
    push r30
    push r31
    ld   r26,y
    set
    cpi  r26,10
    breq __lcd_putchar1
    clt
	INC  R5
	CP   R7,R5
	BRSH _0x3B
	__lcd_putchar1:
	INC  R6
	RCALL SUBOPT_0x2
	ST   -Y,R6
	RCALL _lcd_gotoxy
	brts __lcd_putchar0
_0x3B:
    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  R7,Y+0
	LD   R30,Y
	SUBI R30,-LOW(128)
	__PUTB1MN __base_y,2
	LD   R30,Y
	SUBI R30,-LOW(192)
	__PUTB1MN __base_y,3
	RCALL SUBOPT_0x8
	RCALL SUBOPT_0x8
	RCALL SUBOPT_0x8
	RCALL __long_delay
	LDI  R30,LOW(32)
	RCALL SUBOPT_0x7
	RCALL __lcd_ready
	LDI  R30,LOW(40)
	RCALL SUBOPT_0x7
	RCALL __lcd_ready
	LDI  R30,LOW(6)
	RCALL SUBOPT_0x7
	RCALL _lcd_clear
	ADIW R28,1
	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

	.DSEG
_cc_G3:
	.BYTE 0x1
_pp_G3:
	.BYTE 0x2

	.CSEG

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x0:
	LDI  R30,LOW(20)
	LDI  R31,HIGH(20)
	ST   -Y,R31
	ST   -Y,R30
	RJMP _delay_ms

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x1:
	ST   -Y,R31
	ST   -Y,R30
	RJMP _lcd_puts

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x2:
	CLR  R30
	ST   -Y,R30
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES
SUBOPT_0x3:
	LDI  R30,LOW(1)
	ST   -Y,R30
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 4 TIMES
SUBOPT_0x4:
	LDI  R30,LOW(_display_buffer_ligne0)
	LDI  R31,HIGH(_display_buffer_ligne0)
	ST   -Y,R31
	ST   -Y,R30
	RET

;OPTIMIZER ADDED SUBROUTINE, CALLED 4 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:
	ADIW R28,4
	RJMP SUBOPT_0x4

;OPTIMIZER ADDED SUBROUTINE, CALLED 8 TIMES
SUBOPT_0x7:
	ST   -Y,R30
	RJMP __lcd_write_data

;OPTIMIZER ADDED SUBROUTINE, CALLED 3 TIMES
SUBOPT_0x8:
	RCALL __long_delay
	LDI  R30,LOW(48)
	RJMP SUBOPT_0x7

_isdigit:
	ldi  r30,1
	ld   r31,y+
	cpi  r31,'0'
	brlo __isdigit0
	cpi  r31,'9'+1
	brlo __isdigit1
__isdigit0:
	clr  r30
__isdigit1:
	ret

_isspace:
	ldi  r30,1
	ld   r31,y+
	cpi  r31,' '
	breq __isspace1
	cpi  r31,9
	breq __isspace1
	cpi  r31,13
	breq __isspace1
	clr  r30
__isspace1:
	ret

_sprintf:
	pop  r31
	pop  r30
	pop  r26
	pop  r27
	push r30
	push r31
	ld   r30,-x
	st   -y,r30
	ld   r30,-x
	st   -y,r30
	ld   r31,-x
	ld   r30,-x
	ser  r23
__sprintf0:
	tst  r23
	brmi __sprintf9
	breq __sprintf9
	ldi  r22,' '
	rcall __sprintf_char
	rjmp __sprintf0
__sprintf9:
	ldi  r24,' '
	clr  r25
__sprintf5:
	lpm
	adiw r30,1
	mov  r22,r0
	tst  r22
	brne __sprintf1
	rcall __sprintf_char0
	adiw r28,2
	ret
__sprintf1:
	sbrc r25,0
	rjmp __sprintf3
	cpi  r22,'%'
	breq __sprintf2
__sprintf11:
	rcall __sprintf_char0
	rjmp __sprintf0
__sprintf2:
	sbr  r25,1
	rjmp __sprintf5
__sprintf3:
	cpi  r22,'%'
	brne __sprintf8
	rjmp __sprintf11
__sprintf8:
	cpi  r22,'-'
	brne __sprintf6
__sprintf10:
	sbr  r25,2
	rjmp __sprintf5
__sprintf6:
	cpi  r22,'0'
	brne __sprintf4
	sbrc r25,1
	rjmp __sprintf5
	mov  r24,r22
	rjmp __sprintf5
__sprintf4:
	cpi  r22,'9'+1
	brsh __sprintf7
	subi r22,'0'
	brlo __sprintf7
	cpi  r22,1
	breq __sprintf10
	mov  r23,r22
	rjmp __sprintf5
__sprintf7:
	cpi  r22,'s'
	breq __sprintfs
	cpi  r22,'c'
	breq __sprintfc
	cpi  r22,'d'
	breq __sprintfi
	cpi  r22,'i'
	breq __sprintfi
	cpi  r22,'u'
	breq __sprintfu
	cpi  r22,'X'
	breq __sprintfx1
	cpi  r22,'x'
	brne __sprintf2
	sbr  r25,8
__sprintfx1:
	rjmp __sprintfx
__sprintfs:
	mov  r0,r30
	mov  r1,r31
	ld   r31,-x
	ld   r30,-x
__sprintfs0:
	ld   r22,z+
	tst  r22
	breq __sprintfs1
	rcall __sprintf_char0
	rjmp __sprintfs0
__sprintfs1:
	mov  r30,r0
	mov  r31,r1
	rjmp __sprintf0
__sprintfc:
	sbiw r26,2
	ld   r22,x
	rjmp __sprintf11
__sprintfi:
	ldi  r22,7
	rcall __sprintf_pad0
	sbr  r25,4
	ld   r1,-x
	ld   r0,-x
	push r26
	push r27
	ldi  r26,1
	clr  r27
	cp   r0,r27
	cpc  r1,r27
	brpl __sprintfi0
	com  r0
	com  r1
	add  r0,r26
	adc  r1,r27
	sbr  r25,0x80
	rjmp __sprintfi0
__sprintfu:
	ldi  r22,6
	rcall __sprintf_pad0
	ld   r1,-x
	ld   r0,-x
	push r26
	push r27
__sprintfi0:
	push r30
	ldi  r26,low(10000)
	ldi  r27,high(10000)
	ldi  r30,6
	sbrc r25,2
	inc  r30
	rcall __sprintfu0
	ldi  r26,low(1000)
	ldi  r27,high(1000)
	rcall __sprintfu0
	ldi  r26,100
	clr  r27
	rcall __sprintfu0
	ldi  r26,10
	rcall __sprintfu0
	mov  r22,r0
	pop  r30
	pop  r27
	pop  r26
	rcall __sprintf_digit0
	rjmp __sprintf0
__sprintfx:
	cpi  r23,0xff
	brne __sprintfx2
	cpi  r24,' '
	brne __sprintfx2
	sbr  r25,2
__sprintfx2:
	ldi  r22,5
	rcall __sprintf_pad0
	push r30
	ldi  r30,5
	ld   r22,-x
	rcall __sprintf_xbyte
	ld   r22,-x
	sbr  r25,0x40
	rcall __sprintf_xbyte
	pop  r30
	rjmp __sprintf0
__sprintf_xbyte:
	mov  r0,r22
	swap r22
	rcall __sprintf_xnibble
	mov  r22,r0
	sbrc r25,6
	sbr  r25,0x20
__sprintf_xnibble:
	andi r22,0xf
__sprintf_digit:
	dec  r30
	tst  r22
	brne __sprintf_digit0
	cp   r23,r30
	sbrs r25,4
	brlo __sprintf_left0
	sbrc r25,5
	rjmp __sprintf_digit4
	sbrc r25,1
	rjmp __sprintf_left
	cpi  r24,'0'
	brne __sprintf_pad
	sbrs r25,7
	rjmp __sprintf_pad
	dec  r30
	rcall __sprintf_minus
	rjmp __sprintf_pad
__sprintf_left:
	sbrs r25,7
__sprintf_left0:
	ret
__sprintf_minus:
	cbr  r25,0x84
	ldi  r22,'-'
	rjmp __sprintf_char
__sprintf_pad:
	mov  r22,r24
	rjmp __sprintf_char
__sprintf_digit0:
	sbr  r25,0x10
	sbrs r25,2
	rjmp __sprintf_digit1
	cbr  r25,4
	push r22
	sbrs r25,7
	rjmp __sprintf_digit3
	rcall __sprintf_minus
	rjmp __sprintf_digit2
__sprintf_digit3:
	sbrc r25,1
	rjmp __sprintf_digit2
	rcall __sprintf_pad
__sprintf_digit2:
	pop  r22
__sprintf_digit1:
	cbr  r25,2
	ldi  r24,'0'
__sprintf_digit4:
	subi r22,-0x30
	cpi  r22,'9'+1
	brlo __sprintf_char
	subi r22,-7
	sbrc r25,3
	sbr  r22,0x20
__sprintf_char:
	tst  r23
	brmi __sprintf_char0
	dec  r23
__sprintf_char0:
	push r26
	push r27
	ld   r26,y
	ldd  r27,y+1
	st   x+,r22
	st   y,r26
	std  y+1,r27
	pop  r27
	pop  r26
	ret
__sprintfu0:
	clr  r22
__sprintfu1:
	cp   r0,r26
	cpc  r1,r27
	brlo __sprintf_digit
	inc  r22
	sub  r0,r26
	sbc  r1,r27
	brne __sprintfu1
	rjmp __sprintf_digit

__sprintf_pad0:
	sbrc r25,1
__sprintf_pad2:
	ret
	mov  r1,r22
__sprintf_pad1:
	cp   r23,r1
	brlt __sprintf_pad2
	rcall __sprintf_pad
	rjmp __sprintf_pad1

_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

__SAVELOCR2:
	ST   -Y,R17
	ST   -Y,R16
	RET

__LOADLOCR2P:
	LD   R16,Y+
	LD   R17,Y+
	RET

	.ORG 0x00

;INTERRUPT VECTORS
	RJMP __RESET
	RJMP 0
	RJMP 0
	RJMP 0
	RJMP 0
	RJMP 0
	RJMP 0
	RJMP 0
	RJMP 0
	RJMP 0
	RJMP 0
	RJMP 0
	RJMP 0
	RJMP 0
	RJMP 0
	RJMP 0
	RJMP 0
