From b0e0a8d9a493b99c5f4c684205e8d80bc23fdcb9 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Thu, 4 May 2017 18:39:58 +0200 Subject: [PATCH] =?UTF-8?q?TP2=20fait=20en=20s=C3=A9ance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TP2/TP20.asm | 84 +++++++++++ TP2/TP20.txt | 6 +- TP2/TP21.asm | 384 +++++++++++++++++++++++++++++++++++++++++++++++++++ TP2/TP21.txt | 87 ++++++++++++ TP2/TP22.asm | 212 ++++++++++++++++++++++++++++ TP2/TP22.txt | 99 +++++++++++++ TP2/TP23.asm | 312 +++++++++++++++++++++++++++++++++++++++++ TP2/TP23.txt | 135 ++++++++++++++++++ 8 files changed, 1317 insertions(+), 2 deletions(-) create mode 100644 TP2/TP20.asm create mode 100644 TP2/TP21.asm create mode 100644 TP2/TP21.txt create mode 100644 TP2/TP22.asm create mode 100644 TP2/TP22.txt create mode 100644 TP2/TP23.asm create mode 100644 TP2/TP23.txt diff --git a/TP2/TP20.asm b/TP2/TP20.asm new file mode 100644 index 0000000..88f26d2 --- /dev/null +++ b/TP2/TP20.asm @@ -0,0 +1,84 @@ +.equ PINA = 0x00 ; définition des adresses des ports +.equ DDRA = 0x01 +.equ PORTA = 0x02 + +.equ WDTCSR = 0x60 + +.equ RAMEND = 0x21FF +.equ SPH = 0x3E ; initialisation de la pile +.equ SPL = 0x3D + +.org 0x000 + ; Vecteur RESET + jmp debut + +.org 0x0080 + +debut: + ; DDRA@IO <- 0x01 ; Configuration du port pour mettre la LED en sortie et le bouton en entrée + LDI R16,0x01 + OUT DDRA,R16 + + +attend: + ; On reste là si le bouton n'est pas appuyé + ; si (PINA@IO & 0x02) == 0 saut attend + IN R16,PINA + ANDI R16,0x02 + PUSH R16 + LDI R16,0 + POP R17 + CP R17,R16 + BREQ eti0 + CLR R16 + RJMP eti1 +eti0: + LDI R16,0x01 +eti1: + TST R16 + BREQ eti2 + JMP attend +eti2: + + + ; Dès que le bouton est appuyé + cli ; Activation du chien de garde en mode RESET + ; WDTCSR <- 0b00010000 ; Autorise la modification du chien de garde + LDI R16,0b00010000 + STS WDTCSR,R16 + + ; WDTCSR <- 0b00001110 ; Reset le programme après 1 seconde + LDI R16,0b00001110 + STS WDTCSR,R16 + + sei + + ; PORTA@IO <- 0x01 ; On allume la LED + LDI R16,0x01 + OUT PORTA,R16 + + +boucle: + ; On reste ici en attendant que le watchdog arrive à expiration si le bouton est relâché + ; si (PINA@IO & 0x02) = 0 saut boucle + IN R16,PINA + ANDI R16,0x02 + PUSH R16 + LDI R16,0 + POP R17 + CP R17,R16 + BREQ eti3 + CLR R16 + RJMP eti4 +eti3: + LDI R16,0x01 +eti4: + TST R16 + BREQ eti5 + JMP boucle +eti5: + + wdr ; Sinon si le bouton est appuyé on bloque le watchdog à 1s + jmp boucle + + diff --git a/TP2/TP20.txt b/TP2/TP20.txt index af6ad83..85ce07a 100644 --- a/TP2/TP20.txt +++ b/TP2/TP20.txt @@ -18,7 +18,8 @@ debut: DDRA@IO <- 0x01 ; Configuration du port pour mettre la LED en sortie et le bouton en entrée attend: - si (PINA@IO & 0x02) == 0 saut attend ; On reste là si le bouton n'est pas appuyé + ; On reste là si le bouton n'est pas appuyé + si (PINA@IO & 0x02) == 0 saut attend ; Dès que le bouton est appuyé cli ; Activation du chien de garde en mode RESET @@ -29,7 +30,8 @@ attend: PORTA@IO <- 0x01 ; On allume la LED boucle: - si (PINA@IO & 0x02) == 0 saut boucle ; On reste ici en attendant que le watchdog arrive à expiration si le bouton est relâché + ; On reste ici en attendant que le watchdog arrive à expiration si le bouton est relâché + si (PINA@IO & 0x02) = 0 saut boucle wdr ; Sinon si le bouton est appuyé on bloque le watchdog à 1s jmp boucle diff --git a/TP2/TP21.asm b/TP2/TP21.asm new file mode 100644 index 0000000..5eec1c5 --- /dev/null +++ b/TP2/TP21.asm @@ -0,0 +1,384 @@ +.equ PINA = 0x00 ; définition des adresses des ports +.equ DDRA = 0x01 +.equ PORTA = 0x02 +.equ PINB = 0x03 +.equ DDRB = 0x04 +.equ PORTB = 0x05 + +.equ EIMSK = 0x3D +.equ EICRA = 0x69 +.equ EICRB = 0x6A +.equ SREG = 0x3F + +.equ WDTCSR = 0x60 + +.equ RAMEND = 0x21FF +.equ SPH = 0x3E ; initialisation de la pile +.equ SPL = 0x3D + +.def chen = r19 +.def port = r20 + +.org 0x000 + ; Vecteur RESET + jmp debut + +.org 0x0002 ; Définition du code à éxecuter lors des interruption + jmp horaire + +.org 0x0004 ; Définition du code à éxecuter lors des interruption + jmp antihoraire + +.org 0x0080 + +debut: + ; DDRA@IO <- 0xFF ; Configuration des ports A et B en sortie + LDI R16,0xFF + OUT DDRA,R16 + + ; DDRB@IO <- 0xFF + LDI R16,0xFF + OUT DDRB,R16 + + + ; EIMSK <- 0b00000011 ; On active les interruptions PD0 et PD1 sur front descendant + LDI R16,0b00000011 + STS EIMSK,R16 + + ; EICRA <- 0b00001010 + LDI R16,0b00001010 + STS EICRA,R16 + + ; EICRB <- 0b00000000 + LDI R16,0b00000000 + STS EICRB,R16 + + ; On active les interruptions au niveau du µP + ; SREG <- 0b10000000 + LDI R16,0b10000000 + STS SREG,R16 + + + ; chen <- 0b00000001 + LDI R16,0b00000001 + STS chen,R16 + + ; chen <- 0xAA + LDI R16,0xAA + STS chen,R16 + + ; port <- 0x00 ; pair : port A, impair : port B + LDI R16,0x00 + STS port,R16 + + call afficher + sei + +boucle: + sleep ; On ne fait rien jusqu'à la prochaine interruption + ; jump boucle + JMP boucle + + +horaire: + ; si (port & 0x01) == 0 alors lsl chen + ; si (port & 0x01) == 0 alors chen <- chen * 2 + LDS R16,port + ANDI R16,0x01 + PUSH R16 + LDI R16,0 + POP R17 + CP R17,R16 + BREQ eti0 + CLR R16 + RJMP eti1 +eti0: + LDI R16,0x01 +eti1: + TST R16 + BREQ eti2 + LDS R16,chen + LDI R17,2 + MUL R16,R17 + MOV R16,R0 + STS chen,R16 +eti2: + + ; si (port & 0x01) == 1 alors lsr chen + ; si (port & 0x01) == 1 alors chen <- chen / 2 + LDS R16,port + ANDI R16,0x01 + PUSH R16 + LDI R16,1 + POP R17 + CP R17,R16 + BREQ eti3 + CLR R16 + RJMP eti4 +eti3: + LDI R16,0x01 +eti4: + TST R16 + BREQ eti6 + LDS R16,chen + LDI R17,2 + SER R18 +eti5: + INC R18 + SUB R16,R17 + BRCC eti5 + MOV R16,R18 + STS chen,R16 +eti6: + + ; si chen != 0 saut finhoraire + LDS R16,chen + PUSH R16 + LDI R16,0 + POP R17 + CP R17,R16 + BRNE eti7 + CLR R16 + RJMP eti8 +eti7: + LDI R16,0x01 +eti8: + TST R16 + BREQ eti9 + JMP finhoraire +eti9: + + + ; si (port & 0x01) == 0 alors chen <- 0b10000000 + LDS R16,port + ANDI R16,0x01 + PUSH R16 + LDI R16,0 + POP R17 + CP R17,R16 + BREQ eti10 + CLR R16 + RJMP eti11 +eti10: + LDI R16,0x01 +eti11: + TST R16 + BREQ eti12 + LDI R16,0b10000000 + STS chen,R16 +eti12: + + ; si (port & 0x01) == 1 alors chen <- 0b00000001 + LDS R16,port + ANDI R16,0x01 + PUSH R16 + LDI R16,1 + POP R17 + CP R17,R16 + BREQ eti13 + CLR R16 + RJMP eti14 +eti13: + LDI R16,0x01 +eti14: + TST R16 + BREQ eti15 + LDI R16,0b00000001 + STS chen,R16 +eti15: + + inc port +finhoraire: + call afficher + reti + +antihoraire: + ; si (port & 0x01) == 0 alors lsr chen + ; si (port & 0x01) == 0 alors chen <- chen / 2 + LDS R16,port + ANDI R16,0x01 + PUSH R16 + LDI R16,0 + POP R17 + CP R17,R16 + BREQ eti16 + CLR R16 + RJMP eti17 +eti16: + LDI R16,0x01 +eti17: + TST R16 + BREQ eti19 + LDS R16,chen + LDI R17,2 + SER R18 +eti18: + INC R18 + SUB R16,R17 + BRCC eti18 + MOV R16,R18 + STS chen,R16 +eti19: + + ; si (port & 0x01) == 1 alors lsl chen + ; si (port & 0x01) == 1 alors chen <- chen * 2 + LDS R16,port + ANDI R16,0x01 + PUSH R16 + LDI R16,1 + POP R17 + CP R17,R16 + BREQ eti20 + CLR R16 + RJMP eti21 +eti20: + LDI R16,0x01 +eti21: + TST R16 + BREQ eti22 + LDS R16,chen + LDI R17,2 + MUL R16,R17 + MOV R16,R0 + STS chen,R16 +eti22: + + ; si chen != 0 saut finantihoraire + LDS R16,chen + PUSH R16 + LDI R16,0 + POP R17 + CP R17,R16 + BRNE eti23 + CLR R16 + RJMP eti24 +eti23: + LDI R16,0x01 +eti24: + TST R16 + BREQ eti25 + JMP finantihoraire +eti25: + + + ; si (port & 0x01) == 0 alors chen <- 0b00000001 + LDS R16,port + ANDI R16,0x01 + PUSH R16 + LDI R16,0 + POP R17 + CP R17,R16 + BREQ eti26 + CLR R16 + RJMP eti27 +eti26: + LDI R16,0x01 +eti27: + TST R16 + BREQ eti28 + LDI R16,0b00000001 + STS chen,R16 +eti28: + + ; si (port & 0x01) == 1 alors chen <- 0b10000000 + LDS R16,port + ANDI R16,0x01 + PUSH R16 + LDI R16,1 + POP R17 + CP R17,R16 + BREQ eti29 + CLR R16 + RJMP eti30 +eti29: + LDI R16,0x01 +eti30: + TST R16 + BREQ eti31 + LDI R16,0b10000000 + STS chen,R16 +eti31: + + inc port +finantihoraire: + call afficher + reti + +afficher: + ; si (port & 0x01) == 0 alors PORTB@IO <- 0x00 + LDS R16,port + ANDI R16,0x01 + PUSH R16 + LDI R16,0 + POP R17 + CP R17,R16 + BREQ eti32 + CLR R16 + RJMP eti33 +eti32: + LDI R16,0x01 +eti33: + TST R16 + BREQ eti34 + LDI R16,0x00 + OUT PORTB,R16 +eti34: + + ; si (port & 0x01) == 1 alors PORTA@IO <- 0x00 + LDS R16,port + ANDI R16,0x01 + PUSH R16 + LDI R16,1 + POP R17 + CP R17,R16 + BREQ eti35 + CLR R16 + RJMP eti36 +eti35: + LDI R16,0x01 +eti36: + TST R16 + BREQ eti37 + LDI R16,0x00 + OUT PORTA,R16 +eti37: + + ; si (port & 0x01) == 0 alors PORTA@IO <- chen + LDS R16,port + ANDI R16,0x01 + PUSH R16 + LDI R16,0 + POP R17 + CP R17,R16 + BREQ eti38 + CLR R16 + RJMP eti39 +eti38: + LDI R16,0x01 +eti39: + TST R16 + BREQ eti40 + LDS R16,chen + OUT PORTA,R16 +eti40: + + ; si (port & 0x01) == 1 alors PORTB@IO <- chen + LDS R16,port + ANDI R16,0x01 + PUSH R16 + LDI R16,1 + POP R17 + CP R17,R16 + BREQ eti41 + CLR R16 + RJMP eti42 +eti41: + LDI R16,0x01 +eti42: + TST R16 + BREQ eti43 + LDS R16,chen + OUT PORTB,R16 +eti43: + + ret diff --git a/TP2/TP21.txt b/TP2/TP21.txt new file mode 100644 index 0000000..7f88a15 --- /dev/null +++ b/TP2/TP21.txt @@ -0,0 +1,87 @@ +.equ PINA = 0x00 ; définition des adresses des ports +.equ DDRA = 0x01 +.equ PORTA = 0x02 +.equ PINB = 0x03 +.equ DDRB = 0x04 +.equ PORTB = 0x05 + +.equ EIMSK = 0x3D +.equ EICRA = 0x69 +.equ EICRB = 0x6A +.equ SREG = 0x3F + +.equ WDTCSR = 0x60 + +.equ RAMEND = 0x21FF +.equ SPH = 0x3E ; initialisation de la pile +.equ SPL = 0x3D + +.def chen = r19 +.def port = r20 + +.org 0x000 + ; Vecteur RESET + jmp debut + +.org 0x0002 ; Définition du code à éxecuter lors des interruption + jmp horaire + +.org 0x0004 ; Définition du code à éxecuter lors des interruption + jmp antihoraire + +.org 0x0080 + +debut: + DDRA@IO <- 0xFF ; Configuration des ports A et B en sortie + DDRB@IO <- 0xFF + + EIMSK <- 0b00000011 ; On active les interruptions PD0 et PD1 sur front descendant + EICRA <- 0b00001010 + EICRB <- 0b00000000 + ; On active les interruptions au niveau du µP + SREG <- 0b10000000 + + chen <- 0b00000001 + chen <- 0xAA + port <- 0x00 ; pair : port A, impair : port B + call afficher + sei + +boucle: + sleep ; On ne fait rien jusqu'à la prochaine interruption + jump boucle + +horaire: + ; si (port & 0x01) == 0 alors lsl chen + si (port & 0x01) == 0 alors chen <- chen * 2 + ; si (port & 0x01) == 1 alors lsr chen + si (port & 0x01) == 1 alors chen <- chen / 2 + si chen != 0 saut finhoraire + + si (port & 0x01) == 0 alors chen <- 0b10000000 + si (port & 0x01) == 1 alors chen <- 0b00000001 + inc port +finhoraire: + call afficher + reti + +antihoraire: + ; si (port & 0x01) == 0 alors lsr chen + si (port & 0x01) == 0 alors chen <- chen / 2 + ; si (port & 0x01) == 1 alors lsl chen + si (port & 0x01) == 1 alors chen <- chen * 2 + si chen != 0 saut finantihoraire + + si (port & 0x01) == 0 alors chen <- 0b00000001 + si (port & 0x01) == 1 alors chen <- 0b10000000 + inc port +finantihoraire: + call afficher + reti + +afficher: + si (port & 0x01) == 0 alors PORTB@IO <- 0x00 + si (port & 0x01) == 1 alors PORTA@IO <- 0x00 + si (port & 0x01) == 0 alors PORTA@IO <- chen + si (port & 0x01) == 1 alors PORTB@IO <- chen + ret \ No newline at end of file diff --git a/TP2/TP22.asm b/TP2/TP22.asm new file mode 100644 index 0000000..e25d477 --- /dev/null +++ b/TP2/TP22.asm @@ -0,0 +1,212 @@ +.equ PINA = 0x00 ; définition des adresses des ports +.equ DDRA = 0x01 +.equ PORTA = 0x02 +.equ PINB = 0x03 +.equ DDRB = 0x04 +.equ PORTB = 0x05 +.equ PINC = 0x06 +.equ DDRC = 0x07 +.equ PORTC = 0x08 + +.equ SREG = 0x3F + +.equ WDTCSR = 0x60 +.equ TCCR0A = 0x24 +.equ TCCR0B = 0x25 +.equ TIMSK0 = 0x6E +.equ TIFR0 = 0x35 + +.equ RAMEND = 0x21FF +.equ SPH = 0x3E ; initialisation de la pile +.equ SPL = 0x3D + +.def d2 = r19 +.def d1 = r20 +.def d0 = r21 +.def select = r22 + +.org 0x000 + ; Vecteur RESET + jmp debut + +.org 0x0018 + jmp wd + +.org 0x002E + jmp tm + +.org 0x0080 + +afficheur: + .DB 0x7E, 0x0C, 0x37, 0x9F, 0x4D, 0xDB, 0xFB, 0x0E, 0xFF, 0xDF + ; 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 + +debut: + ; d2 <- 0 + LDI R16,0 + STS d2,R16 + + ; d1 <- 0 + LDI R16,0 + STS d1,R16 + + ; d0 <- 0 + LDI R16,0 + STS d0,R16 + + ; select <- 0x01 + LDI R16,0x01 + STS select,R16 + + + cli + ; SREG <- 0b10000000 + LDI R16,0b10000000 + STS SREG,R16 + + + ; Configuration des ports + ; DDRA@IO <- 0xFF + LDI R16,0xFF + OUT DDRA,R16 + + ; DDRB@IO <- 0xFF + LDI R16,0xFF + OUT DDRB,R16 + + ; DDRC@IO <- 0xFF + LDI R16,0xFF + OUT DDRC,R16 + + + ; Watchdog toutes les secondes + ; WDTCSR <- 0x10 + LDI R16,0x10 + STS WDTCSR,R16 + + ; WDTCSR <- 0b01000110 + LDI R16,0b01000110 + STS WDTCSR,R16 + + + ; Timer toutes les 8-16ms + ;TCCR0A@IO <- 0x00 + ;TCCR0B@IO <- 0x04 + ;TIMSK0 <- 0x01 + ;TIFR0 <- 0x01 + sei + +boucle: + sleep + ; jump boucle + JMP boucle + + +wd: + inc d0 + ; si d0 < 10 saut finwd + LDS R16,d0 + PUSH R16 + LDI R16,10 + POP R17 + CP R17,R16 + BRLO eti0 + CLR R16 + RJMP eti1 +eti0: + LDI R16,0x01 +eti1: + TST R16 + BREQ eti2 + JMP finwd +eti2: + + ; d0 <- 0 + LDI R16,0 + STS d0,R16 + + inc d1 + ; si d1 < 10 saut finwd + LDS R16,d1 + PUSH R16 + LDI R16,10 + POP R17 + CP R17,R16 + BRLO eti3 + CLR R16 + RJMP eti4 +eti3: + LDI R16,0x01 +eti4: + TST R16 + BREQ eti5 + JMP finwd +eti5: + + ; d1 <- 0 + LDI R16,0 + STS d1,R16 + + inc d2 + ; si d2 < 10 saut finwd + LDS R16,d2 + PUSH R16 + LDI R16,10 + POP R17 + CP R17,R16 + BRLO eti6 + CLR R16 + RJMP eti7 +eti6: + LDI R16,0x01 +eti7: + TST R16 + BREQ eti8 + JMP finwd +eti8: + + ; d2 <- 0 + LDI R16,0 + STS d2,R16 + +finwd: + ; PORTA@IO <- afficheur@ROM[d1] + LDS R16,d1 + LDI R30,low(afficheur<<1) + LDI R31,high(afficheur<<1) + CLR R17 + ADD R30,R16 + ADC R31,R17 + LPM R16,Z + OUT PORTA,R16 + + ; PORTC@IO <- 0x40 + LDI R16,0x40 + OUT PORTC,R16 + + reti + +tm: + ;PortC@IO <- select + ;si select = 0x80 alors PortA@IO <- afficheur@ROM[d0] + ;si select = 0x40 alors PortA@IO <- afficheur@ROM[d1] + ;si select = 0x20 alors PortA@IO <- afficheur@ROM[d2] + ;lsl select + ;si select = 0 alors select <- 0x20 + ;PORTC@IO <- afficheur@ROM[d0] + ;PORTB@IO <- afficheur@ROM[d1] + ; PORTA@IO <- afficheur@ROM[d2] + LDS R16,d2 + LDI R30,low(afficheur<<1) + LDI R31,high(afficheur<<1) + CLR R17 + ADD R30,R16 + ADC R31,R17 + LPM R16,Z + OUT PORTA,R16 + + ; PORTC@IO <- 0x40 + LDI R16,0x40 + OUT PORTC,R16 + + reti diff --git a/TP2/TP22.txt b/TP2/TP22.txt new file mode 100644 index 0000000..5fc20ed --- /dev/null +++ b/TP2/TP22.txt @@ -0,0 +1,99 @@ +.equ PINA = 0x00 ; définition des adresses des ports +.equ DDRA = 0x01 +.equ PORTA = 0x02 +.equ PINB = 0x03 +.equ DDRB = 0x04 +.equ PORTB = 0x05 +.equ PINC = 0x06 +.equ DDRC = 0x07 +.equ PORTC = 0x08 + +.equ SREG = 0x3F + +.equ WDTCSR = 0x60 +.equ TCCR0A = 0x24 +.equ TCCR0B = 0x25 +.equ TIMSK0 = 0x6E +.equ TIFR0 = 0x35 + +.equ RAMEND = 0x21FF +.equ SPH = 0x3E ; initialisation de la pile +.equ SPL = 0x3D + +.def d2 = r19 +.def d1 = r20 +.def d0 = r21 +.def select = r22 + +.org 0x000 + ; Vecteur RESET + jmp debut + +.org 0x0018 + jmp wd + +.org 0x002E + jmp tm + +.org 0x0080 + +afficheur: + .DB 0x7E, 0x0C, 0x37, 0x9F, 0x4D, 0xDB, 0xFB, 0x0E, 0xFF, 0xDF + ; 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 + +debut: + d2 <- 0 + d1 <- 0 + d0 <- 0 + select <- 0x01 + + cli + SREG <- 0b10000000 + + ; Configuration des ports + DDRA@IO <- 0xFF + DDRB@IO <- 0xFF + DDRC@IO <- 0xFF + + ; Watchdog toutes les secondes + WDTCSR <- 0x10 + WDTCSR <- 0b01000110 + + ; Timer toutes les 8-16ms + ;TCCR0A@IO <- 0x00 + ;TCCR0B@IO <- 0x04 + ;TIMSK0 <- 0x01 + ;TIFR0 <- 0x01 + sei + +boucle: + sleep + jump boucle + +wd: + inc d0 + si d0 < 10 saut finwd + d0 <- 0 + inc d1 + si d1 < 10 saut finwd + d1 <- 0 + inc d2 + si d2 < 10 saut finwd + d2 <- 0 +finwd: + PORTA@IO <- afficheur@ROM[d1] + PORTC@IO <- 0x40 + reti + +tm: + ;PortC@IO <- select + ;si select = 0x80 alors PortA@IO <- afficheur@ROM[d0] + ;si select = 0x40 alors PortA@IO <- afficheur@ROM[d1] + ;si select = 0x20 alors PortA@IO <- afficheur@ROM[d2] + ;lsl select + ;si select = 0 alors select <- 0x20 + ;PORTC@IO <- afficheur@ROM[d0] + ;PORTB@IO <- afficheur@ROM[d1] + PORTA@IO <- afficheur@ROM[d2] + PORTC@IO <- 0x40 + reti \ No newline at end of file diff --git a/TP2/TP23.asm b/TP2/TP23.asm new file mode 100644 index 0000000..f4d9b78 --- /dev/null +++ b/TP2/TP23.asm @@ -0,0 +1,312 @@ +.equ PINA = 0x00 ; définition des adresses des ports +.equ DDRA = 0x01 +.equ PORTA = 0x02 +.equ PINB = 0x03 +.equ DDRB = 0x04 +.equ PORTB = 0x05 +.equ PIND = 0x09 +.equ DDRD = 0x0A +.equ PORTD = 0x0B + +.equ SREG = 0x3F + +.equ WDTCSR = 0x60 +.equ TCCR0A = 0x24 +.equ TCCR0B = 0x25 +.equ TIMSK0 = 0x6E +.equ TIFR0 = 0x35 + +.equ EIMSK = 0x3D +.equ EICRA = 0x69 +.equ EICRB = 0x6A + +.equ RAMEND = 0x21FF +.equ SPH = 0x3E ; initialisation de la pile +.equ SPL = 0x3D + +.def d1 = r20 +.def d0 = r21 +.def route = r22 + +.org 0x000 + ; Vecteur RESET + jmp debut + +.org 0x0002 + jmp b10s + +.org 0x0004 + jmp b1s + +.org 0x0006 + jmp marche + +.org 0x0008 + jmp arret + +.org 0x0018 + jmp wd + +.org 0x0080 + +afficheur: + .DB 0x7E, 0x0C, 0x37, 0x9F, 0x4D, 0xDB, 0xFB, 0x0E, 0xFF, 0xDF + ; 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 + +debut: + ; d1 <- 0 + LDI R16,0 + STS d1,R16 + + ; d0 <- 0 + LDI R16,0 + STS d0,R16 + + ; route <- 0 + LDI R16,0 + STS route,R16 + + + cli + ; SREG <- 0b10000000 + LDI R16,0b10000000 + STS SREG,R16 + + + ; Configuration des ports + ; DDRA@IO <- 0xFF + LDI R16,0xFF + OUT DDRA,R16 + + ; DDRB@IO <- 0xFF + LDI R16,0xFF + OUT DDRB,R16 + + ; DDRD@IO <- 0x80 + LDI R16,0x80 + OUT DDRD,R16 + + + ; Interruptions + ; EIMSK <- 0b00001111 ; On active les interruptions PD[3:0] sur front descendant + LDI R16,0b00001111 + STS EIMSK,R16 + + ; EICRA <- 0b10101010 + LDI R16,0b10101010 + STS EICRA,R16 + + ; EICRB <- 0b00000000 + LDI R16,0b00000000 + STS EICRB,R16 + + + ; Watchdog toutes les secondes + ; WDTCSR <- 0x10 + LDI R16,0x10 + STS WDTCSR,R16 + + ; WDTCSR <- 0b01000110 + LDI R16,0b01000110 + STS WDTCSR,R16 + + + sei + + call affiche + +boucle: + sleep + ; jump boucle + JMP boucle + + +b1s: + inc d0 + ; si d0 < 10 saut finb1s + LDS R16,d0 + PUSH R16 + LDI R16,10 + POP R17 + CP R17,R16 + BRLO eti0 + CLR R16 + RJMP eti1 +eti0: + LDI R16,0x01 +eti1: + TST R16 + BREQ eti2 + JMP finb1s +eti2: + + ; d0 <- 0 + LDI R16,0 + STS d0,R16 + + ; jump b10s + JMP b10s + +finb1s: + call affiche + reti + +b10s: + inc d1 + ; si d1 < 10 saut finb10s + LDS R16,d1 + PUSH R16 + LDI R16,10 + POP R17 + CP R17,R16 + BRLO eti3 + CLR R16 + RJMP eti4 +eti3: + LDI R16,0x01 +eti4: + TST R16 + BREQ eti5 + JMP finb10s +eti5: + + ; d0 <- 9 + LDI R16,9 + STS d0,R16 + + ; d1 <- 9 + LDI R16,9 + STS d1,R16 + +finb10s: + call affiche + reti + +affiche: + ; PORTA@IO <- afficheur@ROM[d1] + LDS R16,d1 + LDI R30,low(afficheur<<1) + LDI R31,high(afficheur<<1) + CLR R17 + ADD R30,R16 + ADC R31,R17 + LPM R16,Z + OUT PORTA,R16 + + ; PORTB@IO <- afficheur@ROM[d0] + LDS R16,d0 + LDI R30,low(afficheur<<1) + LDI R31,high(afficheur<<1) + CLR R17 + ADD R30,R16 + ADC R31,R17 + LPM R16,Z + OUT PORTB,R16 + + ret + +marche: + ; route <- 1 + LDI R16,1 + STS route,R16 + + ; PORTD@IO <- 0x80 + LDI R16,0x80 + OUT PORTD,R16 + + reti + +arret: + ; route <- 0 + LDI R16,0 + STS route,R16 + + ; d0 <- 0 + LDI R16,0 + STS d0,R16 + + ; d1 <- 0 + LDI R16,0 + STS d1,R16 + + call affiche + reti + +wd: + ; si route = 0 saut finwd + LDS R16,route + PUSH R16 + LDI R16,0 + POP R17 + CP R17,R16 + BREQ eti6 + CLR R16 + RJMP eti7 +eti6: + LDI R16,0x01 +eti7: + TST R16 + BREQ eti8 + JMP finwd +eti8: + + dec d0 + ; si d0 < 10 saut prefinwd + LDS R16,d0 + PUSH R16 + LDI R16,10 + POP R17 + CP R17,R16 + BRLO eti9 + CLR R16 + RJMP eti10 +eti9: + LDI R16,0x01 +eti10: + TST R16 + BREQ eti11 + JMP prefinwd +eti11: + + ; d0 <- 9 + LDI R16,9 + STS d0,R16 + + dec d1 + ; si d1 < 10 saut prefinwd + LDS R16,d1 + PUSH R16 + LDI R16,10 + POP R17 + CP R17,R16 + BRLO eti12 + CLR R16 + RJMP eti13 +eti12: + LDI R16,0x01 +eti13: + TST R16 + BREQ eti14 + JMP prefinwd +eti14: + + ; route <- 0 + LDI R16,0 + STS route,R16 + + ; PORTD@IO <- 0x00 + LDI R16,0x00 + OUT PORTD,R16 + + ; d0 <- 0 + LDI R16,0 + STS d0,R16 + + ; d1 <- 0 + LDI R16,0 + STS d1,R16 + +prefinwd: + call affiche +finwd: + reti diff --git a/TP2/TP23.txt b/TP2/TP23.txt new file mode 100644 index 0000000..6d409d7 --- /dev/null +++ b/TP2/TP23.txt @@ -0,0 +1,135 @@ +.equ PINA = 0x00 ; définition des adresses des ports +.equ DDRA = 0x01 +.equ PORTA = 0x02 +.equ PINB = 0x03 +.equ DDRB = 0x04 +.equ PORTB = 0x05 +.equ PIND = 0x09 +.equ DDRD = 0x0A +.equ PORTD = 0x0B + +.equ SREG = 0x3F + +.equ WDTCSR = 0x60 +.equ TCCR0A = 0x24 +.equ TCCR0B = 0x25 +.equ TIMSK0 = 0x6E +.equ TIFR0 = 0x35 + +.equ EIMSK = 0x3D +.equ EICRA = 0x69 +.equ EICRB = 0x6A + +.equ RAMEND = 0x21FF +.equ SPH = 0x3E ; initialisation de la pile +.equ SPL = 0x3D + +.def d1 = r20 +.def d0 = r21 +.def route = r22 + +.org 0x000 + ; Vecteur RESET + jmp debut + +.org 0x0002 + jmp b10s + +.org 0x0004 + jmp b1s + +.org 0x0006 + jmp marche + +.org 0x0008 + jmp arret + +.org 0x0018 + jmp wd + +.org 0x0080 + +afficheur: + .DB 0x7E, 0x0C, 0x37, 0x9F, 0x4D, 0xDB, 0xFB, 0x0E, 0xFF, 0xDF + ; 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 + +debut: + d1 <- 0 + d0 <- 0 + route <- 0 + + cli + SREG <- 0b10000000 + + ; Configuration des ports + DDRA@IO <- 0xFF + DDRB@IO <- 0xFF + DDRD@IO <- 0x80 + + ; Interruptions + EIMSK <- 0b00001111 ; On active les interruptions PD[3:0] sur front descendant + EICRA <- 0b10101010 + EICRB <- 0b00000000 + + ; Watchdog toutes les secondes + WDTCSR <- 0x10 + WDTCSR <- 0b01000110 + + sei + + call affiche + +boucle: + sleep + jump boucle + +b1s: + inc d0 + si d0 < 10 saut finb1s + d0 <- 0 + jump b10s +finb1s: + call affiche + reti + +b10s: + inc d1 + si d1 < 10 saut finb10s + d0 <- 9 + d1 <- 9 +finb10s: + call affiche + reti + +affiche: + PORTA@IO <- afficheur@ROM[d1] + PORTB@IO <- afficheur@ROM[d0] + ret + +marche: + route <- 1 + PORTD@IO <- 0x80 + reti + +arret: + route <- 0 + d0 <- 0 + d1 <- 0 + call affiche + reti + +wd: + si route = 0 saut finwd + dec d0 + si d0 < 10 saut prefinwd + d0 <- 9 + dec d1 + si d1 < 10 saut prefinwd + route <- 0 + PORTD@IO <- 0x00 + d0 <- 0 + d1 <- 0 +prefinwd: + call affiche +finwd: + reti \ No newline at end of file