File "debug.s"

Full Path: /home/analogde/www/private/Projet/debug/debug.s
File size: 9.51 KB
MIME-type: text/plain
Charset: 8 bit

	.module debug.c
	.area text
;           baud -> 2,x
_init_SCI::
; #include "HC12.H"
; 
; int Mille,Centaine,Dizaine,Unite;
; 
; int val;
; 
; unsigned int canal[8]; 
; char ascii[8];
; 
; /**************************************************************************/
; void init_SCI(unsigned int baud)
; {
; 	asm(" SEI");
		 SEI

; 
; 	SCICR1 = 0x00; /* 0 0 0 0 0 0 0 0	/* 8bits et pas de parit */
	clr 0xca
; /*                          | | | | | | | |
;                           | | | | | | | \____ Even Parity
;                           | | | | | | \______ Parity Disabled
;                           | | | | | \________ Short IDLE line mode (not used)
;                           | | | | \__________ Wakeup by IDLE line rec (not used)
;                           | | | \____________ 8 data bits
;                           | | \______________ Not used (loopback disabled)
;                           | \________________ SCI1 enabled in wait mode
;                           \__________________ Normal (not loopback) mode
; */
; 	SCICR2 = 0x2C; /* 0 0 1 0 1 1 0 0	/* TX et RX actif + RX int*/
	ldab #44
	stab 0xcb
; /*		          | | | | | | | |
; 		          | | | | | | | \____ No Break
; 		          | | | | | | \______ Not in wakeup mode (always awake)
; 		          | | | | | \________ Reciever enabled
; 		          | | | | \__________ Transmitter disabled
; 		          | | | \____________ No IDLE Interrupt
; 		          | | \______________ Reciever Interrupts used
; 		          | \________________ No Tranmit Complete Interrupt
; 		          \__________________ No Tranmit Ready Interrupt
; */
; 	SCIBDH = 0x00;	
	clr 0xc8
; 	SCIBDL = 0x34;  // 9600 bauds (52 en dcimal)
	ldab #52
	stab 0xc9
; 	asm(" CLI");
		 CLI

; }
L1:
	.dbline 0 ; func end
	rts
_initialise_SCI::
; 
; /**************************************************************************/
; void initialise_SCI(void)
; {
;  	    SCIBDH = 0x34;		    // 9600bps @ 8MHz Mclk
	ldab #52
	stab 0xc8
; 		SCIBDL = 0x00;
	clr 0xc9
; 		SCICR1 = 0x00;	        // mode normal 8bits
	clr 0xca
; 		SCICR2 = 0x0C;	        // pas d'interruption, pas de parit
	ldab #12
	stab 0xcb
; }
L2:
	.dbline 0 ; func end
	rts
_init_ADC::
; /**************************************************************************/
; void init_ADC(void)
; {
;  	 ATDCTL2 = 0xC0; /* dmarrage ADC */
	ldab #192
	stab 0x122
; 	 ATDCTL3 = 0x00; /* cycle de 8 conversions */
	clr 0x123
; 	 ATDCTL4 = 0x75; /* mode 10 bits */
	ldab #117
	stab 0x124
; 	 ATDCTL5 = 0x90; /* 1 0 0 1 0 0 0 0 
	ldab #144
	stab 0x125
; 			   		 	 | | | |   \__/
; 					     | | | |    |
; 					     | | | |    \___ First channel = 2
; 					     | | | \________ MULT = 1 => multiple channels
; 					     | | \__________ SCAN = 0 => one set of conversions
; 					     | \____________ DSGN = 0 => unsigned
; 					     \______________ DJM = 1 => right justified
; 					  */
; }
L3:
	.dbline 0 ; func end
	rts
;              i -> -2,x
;           data -> 3,x
_ecrire_data::
	pshd
	pshx
	tfr s,x
	leas -2,sp
; /**********************************************************/
; void ecrire_data(char data)
; {
;  	 int i;
; 	
; 	 i= 0x55;
	ldd #85
	std -2,x
; 
; return;
L4:
	tfr x,s
	pulx
	leas 2,sp
	.dbline 0 ; func end
	rts
;         buffer -> 2,x
_ecrire_chaine::
	pshd
	pshx
	tfr s,x
; }
; /**********************************************************/
; void ecrire_chaine(char *buffer)
; {
	bra L7
L6:
	ldy 2,x
	ldab 0,y
	clra
	jsr _ecrire_data
	ldd 2,x
	addd #1
	std 2,x
L7:
;  	 while(*buffer) 
	ldy 2,x
	tst 0,y
	bne L6
;           { ecrire_data(*buffer); 
;             buffer++; 
;           }
; return;
L5:
	tfr x,s
	pulx
	leas 2,sp
	.dbline 0 ; func end
	rts
;        compare -> -2,x
_conversion_decimal::
	pshx
	tfr s,x
	leas -2,sp
; }
; /**********************************************************/
; void conversion_decimal(void)
; {
; 
; 	 int compare;
; 
; 	 Mille = 0;
	ldd #0
	std _Mille
; 	 Centaine = 0;
	ldd #0
	std _Centaine
; 	 Dizaine = 0;
	ldd #0
	std _Dizaine
; 	 Unite = 0;
	ldd #0
	std _Unite
; 
; 	 // recherche du nombre en dcimal - 4 chiffres
; 
;     compare=val; 
	movw _val,-2,x
	bra L11
L10:
	ldd _Mille
	addd #1
	std _Mille
	ldd -2,x
	subd #1000
	std -2,x
L11:
;    
;    while( compare  > 1000 )  	 // nombre de paquets de 1000
	ldd -2,x
	cpd #1000
	bgt L10
	bra L14
L13:
	ldd _Centaine
	addd #1
	std _Centaine
	ldd -2,x
	subd #100
	std -2,x
L14:
;         { Mille++; 
; 		  compare=compare-1000; 
; 		}
;    while( compare  > 100 )  	// nombre de centaines
	ldd -2,x
	cpd #100
	bgt L13
	bra L17
L16:
	ldd _Dizaine
	addd #1
	std _Dizaine
	ldd -2,x
	subd #10
	std -2,x
L17:
;         { Centaine++; 
; 		  compare=compare-100; 
; 		}
;    while( compare  > 10 )  	   // nombre de dizaines
	ldd -2,x
	cpd #10
	bgt L16
;         { Dizaine++; 
; 		  compare=compare-10; 
; 		}
;    
;    Unite=compare;	
	movw -2,x,_Unite
; }   
L9:
	tfr x,s
	pulx
	.dbline 0 ; func end
	rts
_conversion_Ascii::
; /**********************************************************/
; void conversion_Ascii(void)
; {
; 
;  	 ascii[0]=Mille+0x30;	
	ldd _Mille
	addd #48
	stab _ascii
; 	 ascii[1]='.';		        // affiche virgule
	ldab #46
	stab _ascii+1
; 	 ascii[2]=Centaine+0x30; 	// centaines de mV
	ldd _Centaine
	addd #48
	stab _ascii+2
; 	 ascii[3]=Dizaine+0x30;     // dizaines de mV
	ldd _Dizaine
	addd #48
	stab _ascii+3
; 	 ascii[4]=Unite+0x30;       // affiche les mV
	ldd _Unite
	addd #48
	stab _ascii+4
; 	 ascii[5]='V';              // affiche le V de Volt
	ldab #86
	stab _ascii+5
; }	 
L19:
	.dbline 0 ; func end
	rts
_acquisition::
; /**********************************************************/
; void acquisition(void)
; {
;  	  ATDCTL5 = 0x90;	// lance la conversion
	ldab #144
	stab 0x125
L26:
L27:
; 	  
; 	  while ((ADSTAT0 & 0x80) == 0 ) ; /* attendre la fin de la conversion */
	brclr 0x126,#128,L26
; 	  canal[0] = ADR0;
	; vol
	ldy 0x130
	sty _canal
; 	  canal[1] = ADR1;
	; vol
	ldy 0x132
	sty _canal+2
; 	  canal[2] = ADR2;
	; vol
	ldy 0x134
	sty _canal+4
; 	  canal[3] = ADR3;
	; vol
	ldy 0x136
	sty _canal+6
; 	  canal[4] = ADR4;
	; vol
	ldy 0x138
	sty _canal+8
; 	  canal[5] = ADR5;
	; vol
	ldy 0x13a
	sty _canal+10
; 	  canal[6] = ADR6;
	; vol
	ldy 0x13c
	sty _canal+12
; 	  canal[7] = ADR7;
	; vol
	ldy 0x13e
	sty _canal+14
; }
L25:
	.dbline 0 ; func end
	rts
_traitement::
; /**************************************************************************/
; void traitement(void)
; {
;  	 
; 	 // lire le rsultat + stockage
; 	 canal[6]= ADR6;	 
	; vol
	ldy 0x13c
	sty _canal+12
; 
; 	 val= (ADR6 * 4888)/10000;
	ldd #4888
	; vol
	ldy 0x13c
	emul
	ldy #10000
	exg x,y
	idiv
	exg x,y
	sty _val
; 		
; }
L36:
	.dbline 0 ; func end
	rts
;              c -> 3,x
_envoi_caractere::
	pshd
	pshx
	tfr s,x
; /**************************************************************************/
; void envoi_caractere(char c)
; {
L39:
L40:
; 	while( (SCISR1 & 0x80 )== 0 );	// attendre la monte du flag TDRE
	brclr 0xcc,#128,L39
; 	SCIDRL = c;
	movb 3,x,0xcf
; 
; }
L38:
	tfr x,s
	pulx
	leas 2,sp
	.dbline 0 ; func end
	rts
;            ptr -> -2,x
;            str -> 2,x
_envoi_chaine::
	pshd
	pshx
	tfr s,x
	leas -2,sp
; /**********************************************************/
; void envoi_chaine(char str[])
; {
; 	char *ptr;
; 	
; 	for(ptr = str; *ptr != '\0' ; ptr++  )
	movw 2,x,-2,x
	bra L46
L43:
	ldy -2,x
	ldab 0,y
	clra
	jsr _envoi_caractere
L44:
	ldd -2,x
	addd #1
	std -2,x
L46:
	ldy -2,x
	tst 0,y
	bne L43
; 	   { envoi_caractere(*ptr);
; 	   }
; }
L42:
	tfr x,s
	pulx
	leas 2,sp
	.dbline 0 ; func end
	rts
_transmettre_CRLF::
; /**************************************************************************/
; void transmettre_CRLF(void)
; {
;  	   SCIDRL = 0x0A;    // fin de ligne = end of line																
	ldab #10
	stab 0xcf
L48:
L49:
; 	   while ( (SCISR1 & 0x80) == 0) ;	// attendre le flag TDRE									
	brclr 0xcc,#128,L48
; 	   SCIDRL = 0x0D;    // retour  la ligne = line feed																
	ldab #13
	stab 0xcf
L51:
L52:
; 	   while ( (SCISR1 & 0x80) == 0) ;	// attendre le flag TDRE
	brclr 0xcc,#128,L51
; 	   
; }
L47:
	.dbline 0 ; func end
	rts
;            ptr -> -2,x
_main::
	pshx
	tfr s,x
	leas -2,sp
; /**************************************************************************/
; void main(void)
; {
;  	 /*char buffer[10]="";
; 	 
; 	 char v;
; 	 char *ptr;
; 	 
; 	 buffer[0]='A';
;      buffer[1]='b';
;      buffer[2]='c';
;      buffer[3]='d';	 
; 	 
; 	 v=buffer[2];
; 	 p=ascii; 	 
; 	 ecrire_chaine(p);*/
; 	 
; 	 char *ptr;	 
; 		 
; 	 COPCTL=0x00;
	clr 0x3c
; 	 init_ADC();
	jsr _init_ADC
; 	 init_SCI(9600);
	ldd #9600
	jsr _init_SCI
	bra L56
L55:
	jsr _transmettre_CRLF
	jsr _acquisition
	jsr _traitement
	jsr _conversion_decimal
	jsr _conversion_Ascii
	ldd #_ascii
	std -2,x
	ldd -2,x
	jsr _envoi_chaine
L56:
; 	  
; 	 while(1)
	bra L55
X0:
; 	      { transmettre_CRLF();
; 	        acquisition();
; 	        traitement();
; 	        conversion_decimal();
; 	        conversion_Ascii();		
; 			ptr=ascii; 	 
; 	        envoi_chaine(ptr);     		  	
; 		  } 
; }
L54:
	tfr x,s
	pulx
	.dbline 0 ; func end
	rts
	.area bss
_ascii::
	.blkb 8
_canal::
	.blkb 16
_val::
	.blkb 2
_Unite::
	.blkb 2
_Dizaine::
	.blkb 2
_Centaine::
	.blkb 2
_Mille::
	.blkb 2