Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Carte secondaire - Voiture Autonome 5
- ; Antoine, Paul, Nimesh
- ; Scrutation sur code recu, detection du 4,qui declenche un autre timer pour
- ; la duree de passage devant les cibles
- ; Variables
- PREV_CODE data 7Fh
- CPT_Tours data 7Eh ; Compteur du nombre de tours
- CPT_D data 7Dh ; Compteur de cibles droites touches
- CPT_C data 7Ch ; Compteur de cibles centres touches
- CPT_G data 7Bh ; Compteur de cibles gauches touches
- MAX_TOURS equ 33h ; Nb de tours max en ascii
- CODE_0 equ 0B0h ; Valeur hexa du ascii de '0' + 7e bit de parite
- CODE_4 equ 0B4h ; Valeur hexa du ascii de '4' + 7e bit de parite
- CODE_G equ 47h ; Valeur hexa du ascii de 'G' + 7e bit de parite
- CODE_C equ 0C3h ; Valeur hexa du ascii de 'C' + 7e bit de parite
- CODE_D equ 44h ; Valeur hexa du ascii de 'D' + 7e bit de parite
- NEW_4 bit 00h ; '1' : on peut recevoir un nouveau '4'
- CMD_Moteur bit P3.2 ; Commande la marche/arret du moteur en communicant avec la carte principale
- ETAT_Moteur bit 01h
- LED bit P1.0 ; LED de test : '0' ON - '1' OFF
- LASER bit P1.2 ; LASER : '1' ON - '0' OFF
- SIRENE bit P1.3 ; SIRENE : '1' ON - '0' OFF
- ;-------------------------
- ; Parametres ecran LCD
- ;-------------------------
- BusyFlag bit P2.7
- RS bit P0.5
- RW bit P0.6
- E bit P0.7
- LCD_DB equ P2
- POS_Tours equ 0C6h
- POS_G equ 0C9h
- POS_C equ 0CCh
- POS_D equ 0CFh
- ;-------------------------
- ;-------------------------
- ; Variables extras
- ;-------------------------
- N_AFF data 02h ; Valeur a partir de laquelle on affiche le mot
- N_CHAR data 03h ; Caracteres affichees
- PTR_CHAR data 04h
- ;-------------------------
- ; Vectorisation
- org 0000h
- SJMP debut
- org 0030h
- Ligne_1: db 'JOYEUX NOEL *V5*',00h
- Victoire: db 'BONNE ANNEE *V5*',00h
- Ligne_2: db 'TOURS 0 G0 C0 D0',00h
- ; Programme Principal
- debut: MOV SP,#2Fh ; La pile commencera a #30h
- LCALL Rt_Init
- rpt:
- att_rx:
- si_TF0: JNB TF0,fsi_TF0 ; On scrute l'etat de TF0
- si_cpt_T0: DJNZ R2,sn_cpt_T0 ; On decremente R2 pour compter plusieurs fois la duree max de TIMER0
- CLR SIRENE
- CLR LASER
- CLR TR0
- SJMP fsi_cpt_T0
- sn_cpt_T0: CLR TF0
- fsi_cpt_T0:
- fsi_TF0:
- jsq_rx: JNB RI,att_rx ; tant que pas de Rx
- MOV A,SBUF ; Copie de SBUF dans A
- CLR RI ; Peut recevoir a nouveau
- si_old: CJNE A,PREV_CODE,sn_old ; Si A != PREV_CODE, on entre dans le case
- LJMP fsi_old ; sinon end_case
- sn_old:
- ; Debut case
- case_0: CJNE A,#CODE_0,case_4 ; Si '0' reçu, on change l'etat du bit de commande du moteur
- CLR CMD_Moteur ; On laisse CMD_Moteur a 0 pendant plusieurs CMs (1/2)
- CPL ETAT_Moteur
- CPL LED ; LED de test qui indique l'etat du moteur
- si_stop: JB ETAT_Moteur,sn_stop ; Si l'etat du moteur passe a '0', on incremente le nb de tours
- INC CPT_Tours ; Debut ecriture du nb de tours LCD
- MOV LCD_DB,#POS_Tours
- LCALL Rt_LCD_Code
- MOV LCD_DB,CPT_Tours
- LCALL Rt_LCD_Data ; Fin ecriture du nb de tours LCD
- MOV R0,CPT_TOURS
- si_max: CJNE R0,#MAX_TOURS,sn_max
- LJMP fin_partie ; On a fait 3 tours, on a fini
- sn_max: LCALL Rt_tempo_2500 ; Une fois arrete, on temporise pendant 2.5s
- MOV PREV_CODE,#00h ; On met 00h pour pouvoir traite le prochain '0'
- fsi_max: SJMP fsi_stop
- sn_stop: MOV PREV_CODE,A
- MOV R2,#0A0h ; Valeur permettant la temporisation entre un '0' d'arret et un '0' de depart
- SETB NEW_4 ; Peut traiter un nouveau '4'
- fsi_stop: SETB CMD_Moteur ; On laisse CMD_Moteur a 0 pendant plusieurs CMs (2/2)
- SJMP end_case
- case_4: CJNE A,#CODE_4,case_G ; On allume le laser et la sirene si on reçoit le code '4' la premiere fois
- si_new_4: JNB NEW_4,fin_new_4
- SETB LASER
- SETB SIRENE
- CLR NEW_4
- MOV TH0,#00h
- MOV TL0,#00h
- CLR TF0
- SETB TR0
- MOV PREV_CODE,A
- fin_new_4: SJMP end_case
- case_G: CJNE A,#CODE_G,case_C ; Si 'G', on incremente le compteur de cibles gauches touchees
- INC CPT_G
- MOV LCD_DB,#POS_G
- LCALL Rt_LCD_Code
- MOV LCD_DB,CPT_G
- LCALL Rt_LCD_Data
- MOV PREV_CODE,A
- SJMP end_case
- case_C: CJNE A,#CODE_C,case_D ; Si 'C', on incremente le compteur de cibles centres touchees
- INC CPT_C
- MOV LCD_DB,#POS_C
- LCALL Rt_LCD_Code
- MOV LCD_DB,CPT_C
- LCALL Rt_LCD_Data
- MOV PREV_CODE,A
- SJMP end_case
- case_D: CJNE A,#CODE_D,default ; Si 'D', on incremente le compteur de cibles droites touchees
- INC CPT_D
- MOV LCD_DB,#POS_D
- LCALL Rt_LCD_Code
- MOV LCD_DB,CPT_D
- LCALL Rt_LCD_Data
- MOV PREV_CODE,A
- SJMP end_case
- default:
- end_case:
- fsi_old:
- jsq: LJMP rpt
- fin_partie: MOV DPTR,#80h ; On place le curseur a la premiere ligne
- LCALL Rt_LCD_Code
- MOV DPTR,#Victoire
- LCALL Rt_LCD_Msg
- LCALL Rt_MSG_Defil
- fin: SJMP fin
- ; Routines
- ; Routine d'initialisation
- Rt_Init:
- SETB CMD_Moteur ; Mise a 1 de la commande du marche/arret moteur (actif sur front descendant)
- CLR ETAT_Moteur
- CLR LASER ; eteint le laser
- CLR SIRENE ; eteint la sirene
- SETB LED ; eteint la LED
- MOV CPT_Tours,#30h ; Init du compteur de tours a 0 (important au reset)
- MOV CPT_G,#30h ; Init du compteur de cibles gauches a 0
- MOV CPT_C,#30h ; Init du compteur de cibles centres a 0
- MOV CPT_D,#30h ; Init du compteur de cibles droites a 0
- MOV TMOD,#21h ; Mode 2 Timer 1 et Mode 1 Timer 0
- LCALL Rt_LCD_Init
- LCALL Rt_Rx_Init ; Initialisation de la reception serie
- MOV DPTR,#Ligne_1
- LCALL Rt_LCD_Msg
- MOV LCD_DB,#0C0h ; Place le curseur a la deuxieme ligne
- LCALL Rt_LCD_Code
- MOV DPTR,#Ligne_2
- LCALL Rt_LCD_Msg
- RET
- ; Routine d'initialisation pour une reception a 1200 Bauds
- ; en utilisant le Timer 1 en mode autorechargement
- Rt_Rx_Init:
- MOV TL1,#0E6h
- MOV TH1,#0E6h
- MOV SCON,#50h
- MOV PCON,#00h
- SETB TR1
- RET
- ;Routine LCD_BF
- Rt_LCD_BF:
- MOV P2,#0FFh
- CLR RS
- SETB RW
- busy: CLR E
- SETB E
- JB BusyFlag,busy
- CLR E
- RET
- ;Routine LCD_Code
- Rt_LCD_Code:
- CLR RS
- CLR RW
- SETB E
- CLR E
- LCALL Rt_LCD_BF
- RET
- ;Routine LCD_Data
- Rt_LCD_Data:
- SETB RS
- CLR RW
- SETB E
- CLR E
- LCALL Rt_LCD_BF
- RET
- ;Routine LCD_Init
- Rt_LCD_Init:
- CLR E
- MOV LCD_DB,#00h
- LCALL Rt_tempo_50
- MOV LCD_DB,#30h
- CLR RS
- CLR RW
- SETB E
- CLR E
- LCALL Rt_tempo_50
- MOV LCD_DB,#30h
- CLR RS
- CLR RW
- SETB E
- CLR E
- LCALL Rt_tempo_50
- MOV LCD_DB,#30h
- CLR RS
- CLR RW
- SETB E
- CLR E
- LCALL Rt_tempo_50
- MOV LCD_DB,#38h
- LCALL Rt_LCD_Code
- MOV LCD_DB,#0Ch
- LCALL Rt_LCD_Code
- MOV LCD_DB,#01h
- LCALL Rt_LCD_Code
- MOV LCD_DB,#06h
- LCALL Rt_LCD_Code
- RET
- ;LCD Msg
- Rt_LCD_Msg:
- PUSH ACC
- tq_LCD_msg:CLR A
- MOVC A,@A+DPTR
- JZ ftq_LCD_msg
- MOV LCD_DB,A
- LCALL Rt_LCD_Data
- INC DPTR
- SJMP tq_LCD_msg
- ftq_LCD_msg:
- POP ACC
- RET
- ;Temporisation 50 ms
- Rt_tempo_50:
- MOV TH0,#3Ch
- MOV TL0,#0B0h
- CLR TF0
- SETB TR0
- att_TF0: JNB TF0,att_TF0
- CLR TR0
- RET
- ; Temporisation 5s
- Rt_tempo_5000:
- MOV R1,#64h
- rpt_100: LCALL Rt_tempo_50
- jsq_100: DJNZ R1,rpt_100
- RET
- ; Temporisation 2.5s
- Rt_tempo_2500:
- MOV R1,#32h
- rpt_50: LCALL Rt_tempo_50
- jsq_50: DJNZ R1,rpt_50
- RET
- ; Temporisation 1s
- Rt_tempo_500:
- MOV R1,#0Ah
- rpt_10: LCALL Rt_tempo_50
- jsq_10: DJNZ R1,rpt_10
- RET
- ; Message defilante
- Rt_MSG_Defil:
- PUSH ACC
- MOV N_AFF,#0
- MOV PTR_CHAR,#0
- rpt_aff_16:
- MOV N_CHAR,#0
- MOV DPTR,#Victoire
- MOV PTR_CHAR,N_AFF ; case ou commence l'affichage
- rpt_aff_c:
- MOV A,#0
- MOVC A,@A+DPTR
- INC DPTR
- si_c_fin:JZ sn_c_fin ;si A egal char de fin,
- SJMP fsi_c_fin
- sn_c_fin:MOV DPTR,#Victoire
- MOVC A,@A+DPTR
- fsi_c_fin:
- PUSH ACC
- MOV A,#80h
- ADD A,PTR_CHAR
- MOV LCD_DB,A
- LCALL Rt_LCD_Code
- POP ACC
- MOV LCD_DB,A
- LCALL Rt_LCD_Data
- INC PTR_CHAR
- INC N_CHAR
- jsq_aff: CJNE R4,#10h,si_16
- MOV PTR_CHAR,#0
- si_16: CJNE R3,#10h,rpt_aff_c
- INC N_AFF
- si_n_16: CJNE R2,#10h,fsi_n_16
- MOV N_AFF,#0
- fsi_n_16:LCALL Rt_tempo_500
- SJMP rpt_aff_16
- POP ACC
- RET
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement