Advertisement
Guest User

Untitled

a guest
Jan 9th, 2020
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Carte secondaire - Voiture Autonome 5
  2. ; Antoine, Paul, Nimesh
  3.                            
  4. ; Scrutation sur code recu, detection du 4,qui declenche un autre timer pour
  5. ; la duree de passage devant les cibles
  6.  
  7.  
  8.  
  9. ; Variables
  10. PREV_CODE   data        7Fh
  11.  
  12. CPT_Tours   data        7Eh             ; Compteur du nombre de tours      
  13. CPT_D       data     7Dh            ; Compteur de cibles droites touches
  14. CPT_C       data     7Ch                ; Compteur de cibles centres touches
  15. CPT_G       data     7Bh                ; Compteur de cibles gauches touches
  16.  
  17. MAX_TOURS   equ     33h             ; Nb de tours max en ascii
  18.  
  19. CODE_0      equ     0B0h                ; Valeur hexa du ascii de '0' + 7e bit de parite
  20. CODE_4      equ     0B4h                ; Valeur hexa du ascii de '4' + 7e bit de parite
  21. CODE_G      equ     47h             ; Valeur hexa du ascii de 'G' + 7e bit de parite
  22. CODE_C      equ     0C3h            ; Valeur hexa du ascii de 'C' + 7e bit de parite
  23. CODE_D      equ     44h         ; Valeur hexa du ascii de 'D' + 7e bit de parite
  24.  
  25. NEW_4           bit     00h             ; '1' : on peut recevoir un nouveau '4'
  26.  
  27. CMD_Moteur  bit     P3.2                                                                                                                                                                                                                                                                                    ; Commande la marche/arret du moteur en communicant avec la carte principale
  28. ETAT_Moteur bit     01h
  29.  
  30. LED         bit     P1.0                ; LED de test : '0' ON - '1' OFF
  31. LASER           bit         P1.2                ; LASER : '1' ON - '0' OFF
  32. SIRENE      bit     P1.3           ; SIRENE : '1' ON - '0' OFF
  33. ;-------------------------
  34. ; Parametres ecran LCD
  35. ;-------------------------
  36. BusyFlag        bit     P2.7
  37. RS              bit     P0.5   
  38. RW              bit     P0.6
  39. E               bit     P0.7
  40. LCD_DB      equ     P2
  41.  
  42. POS_Tours   equ     0C6h
  43. POS_G       equ      0C9h
  44. POS_C       equ      0CCh
  45. POS_D       equ      0CFh
  46. ;-------------------------
  47.  
  48. ;-------------------------
  49. ; Variables extras
  50. ;-------------------------
  51. N_AFF           data        02h     ; Valeur a partir de laquelle on affiche le mot
  52. N_CHAR      data        03h      ; Caracteres affichees
  53. PTR_CHAR        data        04h
  54. ;-------------------------
  55.  
  56. ; Vectorisation
  57.                 org     0000h
  58.  
  59.                 SJMP        debut
  60.                 org     0030h
  61.  
  62.  
  63. Ligne_1:        db          'JOYEUX NOEL *V5*',00h
  64. Victoire:   db          'BONNE ANNEE *V5*',00h
  65. Ligne_2:        db          'TOURS 0 G0 C0 D0',00h
  66.                
  67. ; Programme Principal
  68. debut:      MOV     SP,#2Fh                     ; La pile commencera a #30h
  69.                
  70.                 LCALL       Rt_Init
  71. rpt:
  72. att_rx:
  73. si_TF0:     JNB     TF0,fsi_TF0                 ; On scrute l'etat de TF0
  74.  
  75. si_cpt_T0DJNZ        R2,sn_cpt_T0            ; On decremente R2 pour compter plusieurs fois la duree max de TIMER0
  76.                 CLR     SIRENE
  77.                 CLR     LASER
  78.                 CLR     TR0
  79.                 SJMP        fsi_cpt_T0
  80.  
  81. sn_cpt_T0:  CLR     TF0
  82. fsi_cpt_T0:
  83. fsi_TF0:
  84.        
  85. jsq_rx:     JNB     RI,att_rx                   ; tant que pas de Rx
  86.                 MOV     A,SBUF                      ; Copie de SBUF dans A
  87.                 CLR     RI                          ; Peut recevoir a nouveau
  88.                
  89. si_old:     CJNE        A,PREV_CODE,sn_old      ; Si A != PREV_CODE, on entre dans le case
  90.                 LJMP        fsi_old                     ; sinon end_case
  91. sn_old:
  92.  
  93. ; Debut case
  94. case_0:     CJNE        A,#CODE_0,case_4            ; Si '0' reçu, on change l'etat du bit de commande du moteur
  95.                 CLR     CMD_Moteur                  ; On laisse CMD_Moteur a 0 pendant plusieurs CMs (1/2)
  96.                 CPL     ETAT_Moteur    
  97.                 CPL     LED                         ; LED de test qui indique l'etat du moteur
  98. si_stop:        JB      ETAT_Moteur,sn_stop     ; Si l'etat du moteur passe a '0', on incremente le nb de tours
  99.                 INC     CPT_Tours                   ; Debut ecriture du nb de tours LCD
  100.                 MOV     LCD_DB,#POS_Tours
  101.                 LCALL       Rt_LCD_Code
  102.                 MOV     LCD_DB,CPT_Tours           
  103.                 LCALL       Rt_LCD_Data             ; Fin ecriture du nb de tours LCD
  104.                 MOV     R0,CPT_TOURS
  105. si_max:     CJNE        R0,#MAX_TOURS,sn_max
  106.                 LJMP        fin_partie                  ; On a fait 3 tours, on a fini
  107. sn_max:     LCALL       Rt_tempo_2500           ; Une fois arrete, on temporise pendant 2.5s
  108.                 MOV     PREV_CODE,#00h              ; On met 00h pour pouvoir traite le prochain '0'
  109. fsi_max:        SJMP        fsi_stop
  110. sn_stop:        MOV     PREV_CODE,A
  111.                 MOV     R2,#0A0h                        ; Valeur permettant la temporisation entre un '0' d'arret et un '0' de depart
  112.                 SETB        NEW_4                           ; Peut traiter un nouveau '4'
  113. fsi_stop:   SETB        CMD_Moteur                  ; On laisse CMD_Moteur a 0 pendant plusieurs CMs (2/2)
  114.                 SJMP        end_case
  115.                        
  116. 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
  117. si_new_4:   JNB     NEW_4,fin_new_4
  118.                 SETB        LASER
  119.                 SETB        SIRENE
  120.                 CLR     NEW_4
  121.                 MOV     TH0,#00h
  122.                 MOV     TL0,#00h
  123.                 CLR     TF0
  124.                 SETB        TR0
  125.                 MOV     PREV_CODE,A
  126. fin_new_4:  SJMP        end_case
  127.  
  128. case_G:     CJNE        A,#CODE_G,case_C            ; Si 'G', on incremente le compteur de cibles gauches touchees
  129.                 INC     CPT_G
  130.                 MOV     LCD_DB,#POS_G
  131.                 LCALL       Rt_LCD_Code
  132.                 MOV     LCD_DB,CPT_G
  133.                 LCALL       Rt_LCD_Data
  134.                 MOV     PREV_CODE,A
  135.                 SJMP        end_case
  136.                
  137. case_C:     CJNE        A,#CODE_C,case_D            ; Si 'C', on incremente le compteur de cibles centres touchees
  138.                 INC     CPT_C
  139.                 MOV     LCD_DB,#POS_C
  140.                 LCALL       Rt_LCD_Code
  141.                 MOV     LCD_DB,CPT_C
  142.                 LCALL       Rt_LCD_Data
  143.                 MOV     PREV_CODE,A
  144.                 SJMP        end_case
  145.                
  146. case_D:     CJNE        A,#CODE_D,default           ; Si 'D', on incremente le compteur de cibles droites touchees
  147.                 INC     CPT_D
  148.                 MOV     LCD_DB,#POS_D
  149.                 LCALL       Rt_LCD_Code
  150.                 MOV     LCD_DB,CPT_D
  151.                 LCALL       Rt_LCD_Data
  152.                 MOV     PREV_CODE,A
  153.                 SJMP        end_case
  154.                
  155. default:                       
  156.                
  157. end_case:
  158.  
  159. fsi_old:
  160.  
  161. jsq:            LJMP        rpt        
  162.  
  163. fin_partie: MOV     DPTR,#80h                   ; On place le curseur a la premiere ligne
  164.                 LCALL       Rt_LCD_Code
  165.                 MOV     DPTR,#Victoire
  166.                 LCALL       Rt_LCD_Msg
  167.                
  168.                 LCALL       Rt_MSG_Defil
  169.  
  170. fin:            SJMP        fin            
  171.  
  172.  
  173. ; Routines
  174.  
  175. ; Routine d'initialisation
  176. Rt_Init:
  177.                 SETB        CMD_Moteur          ; Mise a 1 de la commande du marche/arret moteur (actif sur front descendant)
  178.                 CLR     ETAT_Moteur
  179.                
  180.                 CLR     LASER               ; eteint le laser
  181.                 CLR     SIRENE              ; eteint la sirene
  182.                 SETB        LED                 ; eteint la LED
  183.                  
  184.             MOV     CPT_Tours,#30h  ; Init du compteur de tours a 0 (important au reset)
  185.                 MOV     CPT_G,#30h          ; Init du compteur de cibles gauches a 0
  186.                 MOV     CPT_C,#30h          ; Init du compteur de cibles centres a 0
  187.                 MOV     CPT_D,#30h          ; Init du compteur de cibles droites a 0
  188.                
  189.                 MOV     TMOD,#21h           ; Mode 2 Timer 1 et Mode 1 Timer 0
  190.                
  191.                 LCALL       Rt_LCD_Init
  192.                 LCALL       Rt_Rx_Init          ; Initialisation de la reception serie
  193.                
  194.                 MOV     DPTR,#Ligne_1
  195.                 LCALL       Rt_LCD_Msg
  196.                 MOV     LCD_DB,#0C0h        ; Place le curseur a la deuxieme ligne
  197.                 LCALL       Rt_LCD_Code
  198.                 MOV     DPTR,#Ligne_2
  199.                 LCALL       Rt_LCD_Msg
  200.            
  201.                 RET
  202.  
  203.  
  204. ; Routine d'initialisation pour une reception a 1200 Bauds
  205. ; en utilisant le Timer 1 en mode autorechargement
  206. Rt_Rx_Init:
  207.                 MOV     TL1,#0E6h
  208.                 MOV     TH1,#0E6h
  209.                 MOV     SCON,#50h
  210.                 MOV     PCON,#00h
  211.                 SETB        TR1
  212.                 RET
  213.  
  214. ;Routine LCD_BF
  215. Rt_LCD_BF:
  216.             MOV     P2,#0FFh
  217.             CLR     RS
  218.             SETB        RW
  219. busy:       CLR     E
  220.             SETB        E
  221.             JB          BusyFlag,busy
  222.             CLR     E          
  223.             RET
  224.            
  225. ;Routine LCD_Code
  226. Rt_LCD_Code:
  227.             CLR     RS     
  228.             CLR     RW
  229.             SETB        E
  230.             CLR     E
  231.             LCALL   Rt_LCD_BF
  232.             RET
  233.  
  234. ;Routine LCD_Data
  235. Rt_LCD_Data:
  236.             SETB        RS     
  237.             CLR     RW
  238.             SETB        E
  239.             CLR     E
  240.             LCALL   Rt_LCD_BF
  241.             RET
  242.  
  243. ;Routine LCD_Init
  244. Rt_LCD_Init:
  245.             CLR     E
  246.             MOV     LCD_DB,#00h
  247.             LCALL       Rt_tempo_50
  248.            
  249.             MOV     LCD_DB,#30h
  250.             CLR     RS
  251.             CLR     RW
  252.             SETB        E
  253.             CLR     E
  254.             LCALL       Rt_tempo_50
  255.            
  256.             MOV     LCD_DB,#30h
  257.             CLR     RS
  258.             CLR     RW
  259.             SETB        E
  260.             CLR     E
  261.             LCALL       Rt_tempo_50
  262.            
  263.             MOV     LCD_DB,#30h
  264.             CLR     RS
  265.             CLR     RW
  266.             SETB        E
  267.             CLR     E
  268.             LCALL       Rt_tempo_50
  269.            
  270.             MOV     LCD_DB,#38h
  271.             LCALL       Rt_LCD_Code
  272.            
  273.             MOV     LCD_DB,#0Ch
  274.             LCALL   Rt_LCD_Code
  275.            
  276.             MOV     LCD_DB,#01h
  277.             LCALL       Rt_LCD_Code
  278.            
  279.             MOV     LCD_DB,#06h
  280.             LCALL       Rt_LCD_Code
  281.             RET
  282.  
  283.  
  284. ;LCD Msg
  285. Rt_LCD_Msg:
  286.             PUSH        ACC
  287. tq_LCD_msg:CLR      A
  288.             MOVC        A,@A+DPTR
  289.             JZ          ftq_LCD_msg
  290.             MOV     LCD_DB,A
  291.             LCALL       Rt_LCD_Data    
  292.             INC     DPTR
  293.             SJMP        tq_LCD_msg
  294. ftq_LCD_msg:
  295.             POP     ACC
  296.             RET
  297.            
  298. ;Temporisation 50 ms
  299. Rt_tempo_50:
  300.             MOV     TH0,#3Ch
  301.             MOV     TL0,#0B0h  
  302.             CLR     TF0
  303.             SETB        TR0
  304. att_TF0:    JNB     TF0,att_TF0
  305.             CLR     TR0
  306.             RET
  307.  
  308. ; Temporisation 5s
  309. Rt_tempo_5000:
  310.             MOV     R1,#64h
  311. rpt_100:    LCALL       Rt_tempo_50
  312. jsq_100:    DJNZ        R1,rpt_100
  313.             RET            
  314.  
  315. ; Temporisation 2.5s
  316. Rt_tempo_2500:
  317.             MOV     R1,#32h
  318. rpt_50: LCALL       Rt_tempo_50
  319. jsq_50: DJNZ        R1,rpt_50
  320.             RET
  321.  
  322. ; Temporisation 1s
  323. Rt_tempo_500:
  324.             MOV     R1,#0Ah
  325. rpt_10: LCALL       Rt_tempo_50
  326. jsq_10: DJNZ        R1,rpt_10
  327.             RET
  328.            
  329. ; Message defilante
  330. Rt_MSG_Defil:
  331.             PUSH        ACC
  332.             MOV     N_AFF,#0           
  333.            
  334.             MOV     PTR_CHAR,#0        
  335. rpt_aff_16:
  336.             MOV     N_CHAR,#0
  337.             MOV     DPTR,#Victoire
  338.             MOV     PTR_CHAR,N_AFF      ; case ou commence l'affichage
  339. rpt_aff_c:
  340.             MOV     A,#0
  341.             MOVC        A,@A+DPTR
  342.             INC     DPTR
  343. si_c_fin:JZ         sn_c_fin            ;si A egal char de fin,
  344.             SJMP        fsi_c_fin
  345. sn_c_fin:MOV        DPTR,#Victoire
  346.             MOVC        A,@A+DPTR
  347. fsi_c_fin:
  348.             PUSH        ACC
  349.             MOV     A,#80h
  350.             ADD     A,PTR_CHAR
  351.             MOV     LCD_DB,A
  352.             LCALL       Rt_LCD_Code
  353.             POP     ACC
  354.             MOV     LCD_DB,A
  355.           LCALL     Rt_LCD_Data
  356.           INC       PTR_CHAR
  357.           INC       N_CHAR                     
  358. jsq_aff:    CJNE        R4,#10h,si_16
  359.             MOV     PTR_CHAR,#0        
  360. si_16:  CJNE        R3,#10h,rpt_aff_c
  361.             INC     N_AFF
  362. si_n_16:    CJNE        R2,#10h,fsi_n_16
  363.             MOV     N_AFF,#0
  364. fsi_n_16:LCALL      Rt_tempo_500
  365.             SJMP        rpt_aff_16         
  366.             POP     ACC
  367.             RET    
  368.                                        
  369.             end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement