home *** CD-ROM | disk | FTP | other *** search
/ 8051 Assembly Language Programming / easm51.iso / ECLAIR.BAK < prev    next >
Encoding:
Text File  |  1997-01-11  |  19.2 KB  |  726 lines

  1.  
  2. ;       Modele de micro-contrôleur: 80C31
  3.     Model 31
  4. ;
  5. ;---------------------------------------------------------------------------
  6. ; Définition des constantes
  7. ;
  8. V24SPD          EQU     243
  9. t10msH          EQU     0D8h
  10. t10msL          EQU     0F0h
  11. EEPROM        EQU    10100000b
  12. TypeSW_EEPROM    EQU    25h        ; prevois 37 (25h) sorties
  13. AlarmSW_EEPROM    EQU    50h
  14.  
  15. ;       Adresse de commande des sorties:
  16. ;
  17. ; Triac1          EQU     000
  18. ; Triac2          EQU     001
  19. ; Triac3          EQU     002
  20. ; Triac4          EQU     003
  21. ; Triac5          EQU     004
  22. ; Triac6          EQU     005
  23. ; Triac7          EQU     006
  24. ; Triac8          EQU     007
  25. ; Triac9          EQU     008
  26. ; Triac10         EQU     009
  27. ; Triac11         EQU     010
  28. ; Triac12         EQU     011
  29. ; Triac13         EQU     012
  30.  
  31. ; Grad1           EQU     013
  32. ; Grad2           EQU     014
  33. ; Grad3           EQU     015
  34.  
  35. ; Relais1         EQU     016
  36. ; Relais2         EQU     017
  37. ; Relais3         EQU     018
  38. ; Relais4         EQU     019
  39. ;
  40. ;       Les entrées se font sur le port P1
  41. ;       Les bits de 0 à 6 servent pour le codage des B.P.
  42. ;       Le P1.7 est l'entrée d'alarme (Entrée +12V quand alarme non active)
  43. ;
  44. ;---------------------------------------------------------------------------
  45. ;       Définition des diverses zones de stockage en RAM interne
  46. ;       Mémoire pour état des sorties (en RAM interne)
  47. ;
  48.         ORG     0020h           ; debut zone adressable par bit (0-7F)
  49.         DS      1               ; Réserve bytes de stockage
  50. Flag1           EQU     000h            ; Adresse 1er bit
  51. Flag2           EQU     001h            ; Adresse 2eme bit
  52. Flag3        EQU    002h        ; Adresse 3eme Bit
  53. TMP             DS      1               ; Variable TMP
  54. Last_Code       DS      1               ; Dernier code lu
  55. DPL_232         DS      1
  56. DPH_232         DS      1
  57. EOT             EQU     003h            ; End Of Transmit  (! Bit = 20.3h !)
  58. Flag4        EQU    004h        ; Traitement ALARM ?
  59.  
  60. MemoOut         DS      35              ; Memoire etat sortie
  61. TypeSW        DS    35        ; Type de SWITCH (Interrupteur / BP)
  62.                     ;         (    00       / FF )
  63.                               
  64. ;
  65. ;---------------------------------------------------------------------------
  66. ; Programme
  67. ;
  68.     ORG     0000
  69.     LJMP    Debut
  70.  
  71.     ORG     000Bh
  72.     LJMP    IntrT0
  73.  
  74.     ORG     0023h
  75.     LJMP    IntrSerie
  76.     DM    "ADAM E. 1996"
  77.     LJMP    0100h
  78.     
  79.     ORG     0100h
  80.  
  81. Debut   CLR     Flag1
  82.     CLR     Flag2
  83.     CLR    Flag4            ; Pas en traitement d'alarm
  84.     MOV     Last_Code,#0
  85.     LCALL   InitIntr
  86.     LCALL   InitTimer0
  87.     LCALL   InitRS232               ; initialisation du port RS232
  88.     MOV     DPTR,#Welcome           ; } envoi du message de connection.
  89.     LCALL   SendTxt                 ; }
  90.     LCALL    InitTypeSW        ; Initialise le type de sortie
  91.     LCALL    InitSorties        ; Initialise les sorties
  92.     LCALL   ResetSorties            ; Place les sorties à 0 (1 pour relais)
  93.     AJMP    $
  94.  
  95.     
  96. ;        
  97. ;---------------------------------------------------------------------------
  98. ; Initialise des interruptions  
  99. ; All (80h) ; Série (10h) ; Timer 0 (02h)
  100. InitIntr        MOV     IP,#02H      
  101.         MOV     IE,#92H
  102.         RET
  103. ;
  104. ;---------------------------------------------------------------------------
  105. ; Initialise le port série à 4800 bauds, 8 bits, pas de parité et 1 stop bit
  106. ;
  107. InitRS232       MOV     PSW,#0          ; reset register banks
  108.         MOV     PCON,#080H      ; SMOD=1
  109.         MOV     TMOD,#22H       ; modes are timer
  110.         MOV     TH1,#V24SPD     ; preload value
  111.         MOV     TL1,#V24SPD
  112.         MOV     TMOD,#21H
  113.         SETB    TCON.6          ; start counter
  114.         MOV     SCON,#050H      ; mode 1 , Enable receiver=10H
  115.         SETB    EOT             ; Positionne Flag End Of Transmit
  116.         RET
  117.  
  118. ;----------------------------------------------------------------------------
  119. ; Initialisation du Timer 0 (Tempo de 10 ms)
  120. ;
  121. InitTimer0      MOV     TH0,#t10msH
  122.         MOV     TL0,#t10msL
  123.         SETB    TR0
  124.         RET
  125.     
  126. ;---------------------------------------------------------------------------
  127. ; Envoi la valeur de l'accu (00->99) par le port série
  128. ;
  129. Send_Val        PUSH    ACC             ; Empile l'accu
  130.         MOV     B,#10           ; } Divise par 10
  131.         DIV     AB              ; }
  132.         ADD     A,#'0'
  133.         MOV     SBUF,A
  134.         JNB     TI,$
  135.         CLR     TI
  136.         MOV     A,B
  137.         ADD     A,#'0'
  138.         MOV     SBUF,A
  139.         JNB     TI,$
  140.         CLR     TI
  141.         LCALL   Send_CRLF
  142.         POP     ACC
  143.         RET
  144. ;                
  145. ;---------------------------------------------------------------------------
  146. ; envoi d'un CR et d'un LF par le port série
  147. ;
  148. Send_CRLF       PUSH    DPL             ; Sauve le DPL tâche principale
  149.         PUSH    DPH             ; IDEM
  150.         JNB     EOT,$           ; Attend End of Transmit
  151.         CLR     EOT
  152.         MOV     DPTR,#Txt_CRLF  ; Pointe chaîne CRLF
  153.         MOV     DPL_232,DPL     ; } Sauve le DPTR pour le port série
  154.         MOV     DPH_232,DPH     ; }
  155.         SETB    TI              ; Lance l'écriture série
  156.         RET
  157. ;
  158. ;---------------------------------------------------------------------------
  159. ; Envoi d'un texte présent en ROM (DPTR pointe sur la chaîne)
  160. ;
  161. SendTxt         JNB     EOT,$           ; Attend End Of Transmit
  162.         CLR     EOT
  163.         MOV     DPL_232,DPL
  164.         MOV     DPH_232,DPH
  165.         SETB    TI              ; Lance l'écriture par RS232
  166.         RET
  167. ;
  168. ;---------------------------------------------------------------------------
  169. ; Coupe toutes les sorties
  170. ;
  171. ResetSorties    MOV     A,#0
  172.         MOV     R0,#35            ; 16 sorties
  173.         MOV     DPTR,#0
  174. RstOut1         MOVX    @DPTR,A              
  175.         INC     DPTR
  176.         DJNZ    R0,RstOut1
  177.  
  178.         MOV     R0,#35                  ; Init 16 sorties
  179.         MOV     R1,#MemoOut             ; R1 pointe sur MemoOut                      
  180. RstOut3         MOV     @R1,#0                  ; Ecrit des 0
  181.         INC     R1                      ; Passe sortie suivante
  182.         DJNZ    R0,RstOut3              ; Décremente R0
  183.         
  184.         RET
  185.  
  186. ;---------------------------------------------------------------------------
  187. ; Gestion de l'interruption série
  188. ;
  189. IntrSerie       JB      RI,IntrReceive  ; si RI = 1 on continue
  190.         LJMP    IntrSend        ; Sinon Gestion Envoi par Série
  191.  
  192. IntrReceive     EQU $                   ; Coupe l'interruption serie
  193.         CLR     RI              ; Efface le RI
  194.         PUSH    ACC             ; Sauve l'accu
  195.         MOV     A,SBUF          ; Lecture du caractère recu
  196.         
  197.         CJNE    A,#'?',SerieCase1
  198.         MOV     DPTR,#TextHelp  ;} 
  199.         LCALL   SendTxt2         ;} Envoi du texte d'aide
  200.         AJMP    FinIntr         ; Fin d'interruption
  201.  
  202. SerieCase1      CJNE    A,#'a',SerieCase2
  203. ;        LCALL   LectChanel
  204. ;        LCALL   ON_Sortie
  205.         AJMP    FinIntr
  206.  
  207. SerieCase2      CJNE    A,#'e',SerieCase3
  208. ;        LCALL   LectChanel
  209. ;        LCALL   OFF_Sortie
  210.         AJMP    FinIntr
  211.  
  212. SerieCase3      CJNE    A,#'t',SerieCase4
  213.         LCALL   LectChanel
  214.         LCALL   TOG_Sortie
  215.         AJMP    FinIntr
  216.  
  217. SerieCase4    CJNE    A,#'s',SerieCase5
  218.         LCALL    LectChanel
  219.         LCALL    ChangeTypeSW
  220.         AJMP    FinIntr
  221.         
  222. SerieCase5    CJNE    A,#'d',SerieCase6
  223.         LCALL    LectChanel
  224.         LCALL    DefSortieAlarm
  225.         AJMP    FinIntr
  226.  
  227. SerieCase6    CJNE    A,#'v',FinIntr
  228. ;        LCALL    AffTypeSW
  229.  
  230. FinIntr         MOV     DPTR,#Prompt
  231.         LCALL   SendTxt2
  232.         POP     ACC
  233.         SETB    ET0                    ; Active les interruptions
  234.         RETI
  235. ;
  236. ;---------------------------------------------------------------------------                
  237. ; Routine d'envoi d'un texte présent en ROM (Appellé par Intr)
  238. ;
  239. IntrSend        PUSH    ACC             ; Empile l'Accu
  240.         PUSH    DPL             ; Empile le DPL
  241.         PUSH    DPH             ; Bien tu as deviné !
  242.         CLR     TI              ; Efface le bit TI
  243.         MOV     DPL,DPL_232     ; Restaure le pointeur pour RS232
  244.         MOV     DPH,DPH_232     ; IDEM
  245.         MOV     A,#0            
  246.         MOVC    A,@A+DPTR       ; Lecture du caractère à afficher
  247.         JZ      FinSndTxt       ; Si 0 Termine
  248.         MOV     SBUF,A
  249.         INC     DPTR
  250.         MOV     DPL_232,DPL     ; Sauve le pointeur pour RS232
  251.         MOV     DPH_232,DPH     ; IDEM
  252.         AJMP    NextSnd
  253. FinSndTxt       SETB    EOT             ; SET End Of Transmit
  254.     
  255. NextSnd         POP     DPH             ; Restaure le DPH tâche principale
  256.         POP     DPL             ; IDEM
  257.         POP     ACC             ; Restaure l'acccu tâche principale
  258.         RETI                    ; Termine gestion intr Send RS232
  259.  
  260. ;---------------------------------------------------------------------------                
  261. ; Routine d'envoi d'un texte présent en ROM 
  262. ;
  263. SendTxt2        MOV     A,#0            
  264.         MOVC    A,@A+DPTR       ; Lecture du caractère à afficher
  265.         JZ      FinSnd2         ; Si 0 Termine
  266.         MOV     SBUF,A
  267.         JNB     TI,$
  268.         CLR     TI              ; Efface le bit TI
  269.         INC     DPTR
  270.         AJMP    SendTxt2
  271. FinSnd2         SETB    EOT             ; SET End Of Transmit
  272.         RET                     ; Termine Routine Send RS232 sans
  273.                     ; les interruptions
  274. ;
  275. ;
  276. ;---------------------------------------------------------------------------
  277. ; Gestion de l'interruption Timer 0
  278. ;
  279. IntrT0          CLR     TR0             ; Stop Timer 0
  280.         CPL     Flag1           ; Complemente le Flag 10 ms ecoule
  281.         MOV     TL0,#t10msL
  282.         MOV     TH0,#t10msH
  283.         SETB    TR0
  284.         CPL    P3.5        ; sortie de Flag1 sur T1 (Pin 15)
  285.         PUSH    ACC
  286.         PUSH    DPL
  287.         PUSH    DPH        
  288.         MOV    A,P1
  289.         CJNE    A,#255,Intr_1
  290.         CLR    Flag2
  291.         JNB    Flag4,Intr_0
  292.         LCALL    InitSorties
  293.         CLR    Flag4        ; Efface traitement d'alarm
  294. Intr_0        MOV    Last_Code,#255
  295.         LCALL    Stop_Grad
  296.         AJMP    Fin_IntrT0
  297.         
  298. Intr_1        JB    Flag2,Intr_2    
  299.         SETB    Flag2
  300.         AJMP    Fin_IntrT0
  301.                 
  302. Intr_2        JNB    P1.7,Intr_Alarm
  303.         JNB    Flag4,Intr_3
  304.         LCALL    InitSorties
  305.         CLR    Flag4            ; Traitement ALARM = NON
  306. Intr_3        LCALL    Gestion_BP
  307.         AJMP    Fin_IntrT0
  308.                 
  309. Intr_Alarm    LCALL    Alarm
  310.  
  311. Fin_IntrT0    POP    DPH
  312.         POP    DPL
  313.         POP    ACC
  314.         RETI
  315. ;
  316. ;---------------------------------------------------------------------------
  317. ; Gestion des boutons poussoirs
  318. ;
  319. Gestion_BP    MOV    A,P1
  320.         ANL    A,#07Fh            ; masque pour supprimer P1.7
  321.         MOV    TMP,A
  322.         CJNE    A,Last_Code,Gestion_1
  323.         
  324.         AJMP    Fin_Gestion
  325.  
  326. Gestion_1    MOV    A,#0
  327.         MOV    DPTR,#Tab_Code
  328.  
  329. Gestion_2    PUSH    ACC
  330.         MOVC    A,@A+DPTR
  331.         CJNE    A,TMP,Gestion_4
  332.         
  333.         POP    ACC
  334.         INC    A
  335.         LCALL    TOG_Sortie
  336.         MOV    Last_Code,TMP
  337.         AJMP    Fin_Gestion
  338.         
  339. Gestion_4    POP    ACC
  340.         CJNE    A,#34,Gestion_5        ; Test BP35 ?
  341.         AJMP    Fin_Gestion
  342.  
  343. Gestion_5    INC    A
  344.         AJMP    Gestion_2
  345.  
  346. Fin_Gestion    RET
  347.  
  348. ;
  349. ;--------------------------------------------------------------------------
  350. ; Alarm
  351. ;
  352. Alarm        EQU    $
  353.         JNB    Flag4,Alarm_ON
  354.         RET                ; Si Flag4=1 on termine
  355. Alarm_ON    SETB    Flag4            
  356.         LCALL    StartI2C
  357.         MOV    A,#EEPROM
  358.         LCALL    SendByteI2C
  359.         MOV    A,#AlarmSW_EEPROM
  360.         MOV    R5,#35            ; Lit les 35 sorties        
  361.         MOV    DPTR,#0
  362.         LCALL    SendByteI2C        ; Envoi adresse 1ere sortie
  363.         LCALL    StartI2C        ; Start I2C
  364.         MOV    A,#EEPROM+1
  365.         LCALL    SendByteI2C        ; Envoi adresse EEPROM (RD)
  366.         
  367. Alarm_Bcl    LCALL    RecByteI2C        ; Lecture de la sorrtie 
  368.         LCALL    AckI2C            ; Acquitte la lecture
  369.         MOVX    @DPTR,A            ; Ecriture sur la sortie
  370.         INC    DPTR
  371.         DJNZ    R5,Alarm_Bcl
  372.         
  373.         LCALL    RecByteI2C
  374.         LCALL    StopI2C
  375.             
  376. ;Alarm_Wait    MOV    A,P1
  377. ;        JNB    ACC.7,Alarm_Wait
  378. ;        LCALL    InitSorties
  379.                                 
  380.         RET
  381.  
  382. ;
  383. ; --------------------------------------------------------------------------
  384. ; Routine de tempo d'anti-rebond (basé sur timer 0 et Flag 1)
  385. ;
  386. Wait            JNB     Flag1,$         ; Attend au minimum 10 mS
  387.         JB      Flag1,$         ; Et au Maximum 30 mS
  388.         JNB     Flag1,$
  389.         RET
  390. ;
  391. ;---------------------------------------------------------------------------
  392. ; Routine de lecture du n° de canal (en sortie A = n° canal)
  393. ;
  394. LectChanel      EQU     $
  395.         MOV     DPTR,#TextChanel
  396.         LCALL   SendTxt2
  397.         MOV     R3,#0
  398. LECTCH0         JNB     RI,$
  399.         CLR     RI
  400.         MOV     A,SBUF
  401.         CJNE    A,#13,LECTCh1
  402.         MOV     A,R3
  403.         RET
  404.  
  405. LECTCh1         MOV     SBUF,A
  406.         JNB     TI,$
  407.         CLR     TI
  408.         SUBB    A,#'0'
  409.         JC      LECTCH0
  410.         MOV     R4,A
  411.         SUBB    A,#10
  412.         JNC     LECTCH0
  413.         MOV     A,R3
  414.         MOV     B,#10
  415.         MUL     AB
  416.         ADD     A,R4
  417.         MOV     R3,A
  418.         AJMP    LECTCH0
  419.  
  420. ;---------------------------------------------------------------------------
  421. ; Routine Toggel Sortie Change l'état de la sortie n° A
  422. ;
  423. TOG_Sortie      EQU     $
  424.         DEC     A                       ; Convertion N° sortie -> Adr
  425.         MOV    R1,A
  426.         
  427.         ADD    A,#TypeSW
  428.         MOV    R0,A
  429.         MOV    A,@R0
  430.         
  431.         CJNE    A,#0FFh,Tog_1
  432.         MOV    DPL,R1
  433.         MOV    DPH,#00
  434.         MOV    A,#0FFh
  435.         MOVX    @DPTR,A
  436.         LJMP    Fin_Tog        
  437.  
  438. Tog_1        LCALL    Stop_Grad
  439.         LCALL    StartI2C        ; Start I2C
  440.         MOV    A,#EEPROM
  441.         LCALL    SendByteI2C        ; Adresse EEPROM
  442.         MOV    A,R1
  443.         LCALL    SendByteI2C        ; Envoi Adresse (N° Sortie)
  444.         MOV    A,R1
  445.         ADD     A,#MemoOut              ; Calcul Ptr sur Memo sortie
  446.         MOV     R0,A                    ; Place Ptr dans R0
  447.         MOV     A,@R0                   ; Lit l'état actuel
  448.         CPL     A                       ; Complemente l'état
  449.         MOV     @R0,A                   ; Sauvegarde nouvel état
  450.         MOV     DPH,#00                 ; 
  451.         MOV     DPL,R1                  ; Prépare Ptr pour écriture 
  452.         MOVX    @DPTR,A                 ; Ecrit nouvelle état
  453.         LCALL    SendByteI2C        ; Ecrit état sortie / I2C
  454.         LCALL    StopI2C            ; Stop I2C
  455. Fin_Tog        RET
  456.  
  457. ;---------------------------------------------------------------------------
  458.  
  459. Stop_Grad    PUSH    ACC
  460.         PUSH    DPL
  461.         PUSH    DPH
  462.         MOV    R0,#TypeSW
  463. Stop_Grad1    MOV    A,@R0
  464.         CJNE    A,#0FFh,Stop_Grad2
  465.         MOV    A,R0
  466.         SUBB    A,#TypeSW
  467.         MOV    DPL,A
  468.         MOV    DPH,#00
  469.         MOV    A,#00
  470.         MOVX    @DPTR,A
  471. Stop_Grad2    INC    R0
  472.         CJNE    R0,#TypeSW+20,Stop_Grad1
  473.         POP    DPH
  474.         POP    DPL
  475.         POP    ACC
  476.         RET
  477.         
  478.         
  479.  
  480. ON_Sortie    RET
  481.  
  482. OFF_Sortie      RET
  483.  
  484. DefSortieAlarm    DEC    A
  485.         MOV    R1,A
  486.         MOV    DPTR,#Txt_DefAlarm
  487.         LCALL    SendTxt2
  488.  
  489. DefAlarm1    JNB    RI,$            ; Attent touche
  490.         CLR    RI
  491.         MOV    A,SBUF            ; Lecture touche
  492.         CJNE    A,#'a',DefAlarm2
  493.         LCALL    StartI2C        ; Start I2C
  494.         MOV    A,#EEPROM
  495.         LCALL    SendByteI2C        ; Adresse EEPROM
  496.         MOV    A,R1
  497.         ADD    A,#AlarmSW_EEPROM    ; Adresse en EEPROM de TypeSW
  498.         LCALL    SendByteI2C        ; Envoi Adresse (N° Sortie)
  499.         MOV    A,#0FFh
  500.         LCALL    SendByteI2C        ; Ecriture du type (00 = Int)
  501.         LCALL    StopI2C
  502.         AJMP    Fin_DefAlarm
  503.  
  504. DefAlarm2    CJNE    A,#'n',DefAlarm1                        
  505.         LCALL    StartI2C        ; Start I2C
  506.         MOV    A,#EEPROM
  507.         LCALL    SendByteI2C        ; Adresse EEPROM
  508.         MOV    A,R1
  509.         ADD    A,#AlarmSW_EEPROM    ; Adresse en EEPROM de TypeSW
  510.         LCALL    SendByteI2C        ; Envoi Adresse (N° Sortie)
  511.         MOV    A,#00
  512.         LCALL    SendByteI2C        ; Ecriture du type (00 = Int)
  513.         LCALL    StopI2C
  514.  
  515. Fin_DefAlarm    RET
  516. ;    
  517. ;---------------------------------------------------------------------------
  518. ; Change le type de sortie (Interrupteur 00   ou  Poussoir FFh )
  519. ;
  520. ChangeTypeSW    DEC    A            ; Convertion Canal -> adresse
  521.         MOV    R1,A
  522.         MOV    DPTR,#Txt_TypeSW
  523.         LCALL    SendTxt2
  524.  
  525. ChType1        JNB    RI,$            ; Attent touche
  526.         CLR    RI
  527.         MOV    A,SBUF            ; Lecture touche
  528.         CJNE    A,#'i',ChType2
  529.         MOV    A,#TypeSW
  530.         ADD    A,R1
  531.         MOV    R0,A
  532.         MOV    A,#00
  533.         MOV    @R0,A
  534.         LCALL    StartI2C        ; Start I2C
  535.         MOV    A,#EEPROM
  536.         LCALL    SendByteI2C        ; Adresse EEPROM
  537.         MOV    A,R1
  538.         ADD    A,#TypeSW_EEPROM    ; Adresse en EEPROM de TypeSW
  539.         LCALL    SendByteI2C        ; Envoi Adresse (N° Sortie)
  540.         MOV    A,#00
  541.         LCALL    SendByteI2C        ; Ecriture du type (00 = Int)
  542.         LCALL    StopI2C
  543.         AJMP    Fin_ChType
  544.  
  545. ChType2        CJNE    A,#'p',ChType1                        
  546.         MOV    A,#TypeSW
  547.         ADD    A,R1
  548.         MOV    R0,A
  549.         MOV    A,#0FFh
  550.         MOV    @R0,A
  551.         LCALL    StartI2C        ; Start I2C
  552.         MOV    A,#EEPROM
  553.         LCALL    SendByteI2C        ; Adresse EEPROM
  554.         MOV    A,R1
  555.         ADD    A,#TypeSW_EEPROM    ; Adresse en EEPROM de TypeSW
  556.         LCALL    SendByteI2C        ; Envoi Adresse (N° Sortie)
  557.         MOV    A,#0FFh
  558.         LCALL    SendByteI2C        ; Ecriture du type (00 = Int)
  559.         LCALL    StopI2C
  560.  
  561. Fin_ChType    RET
  562. ;
  563. ;---------------------------------------------------------------------------
  564. ; Initialise les sorties en fonction de l'EEPROM (I2C)
  565. ;
  566. InitSorties    LCALL    StartI2C        ; Start bus I2C
  567.         MOV    A,#EEPROM        ; Adresse de l'EEPROM
  568.         LCALL    SendByteI2C        ; Envoi
  569.         MOV    A,#00
  570.         MOV    R5,#20            ; Lit les 20 sorties        
  571.         MOV    DPTR,#0
  572.         MOV    R0,#MemoOut
  573.         LCALL    SendByteI2C        ; Envoi adresse 1ere sortie
  574.         LCALL    StartI2C        ; Start I2C
  575.         MOV    A,#EEPROM+1
  576.         LCALL    SendByteI2C        ; Envoi adresse EEPROM (RD)
  577.         
  578. Init_Bcl    LCALL    RecByteI2C        ; Lecture de la sorrtie 
  579.         LCALL    AckI2C            ; Acquitte la lecture
  580.         MOV    @R0,A            ; Sauve l'état de la sortie
  581.         MOVX    @DPTR,A            ; Ecriture sur la sortie
  582.         INC    R0
  583.         INC    DPTR
  584.         DJNZ    R5,Init_Bcl
  585.         
  586.         LCALL    RecByteI2C
  587.         LCALL    StopI2C
  588.         RET
  589. ;
  590. ;---------------------------------------------------------------------------
  591. ; initialise le type de sortie
  592. ;
  593. InitTypeSW    LCALL    StartI2C        ; Start bus I2C
  594.         MOV    A,#EEPROM        ; Adresse de l'EEPROM
  595.         LCALL    SendByteI2C        ; Envoi
  596.         MOV    A,#TypeSW_EEPROM
  597.         MOV    R5,#20            ; Lit les 20 sorties        
  598.         MOV    DPTR,#0
  599.         MOV    R0,#TypeSW
  600.         LCALL    SendByteI2C        ; Envoi adresse 1ere sortie
  601.         LCALL    StartI2C        ; Start I2C
  602.         MOV    A,#EEPROM+1
  603.         LCALL    SendByteI2C        ; Envoi adresse EEPROM (RD)
  604.         
  605. Init_Type    LCALL    RecByteI2C        ; Lecture de la sorrtie 
  606.         LCALL    AckI2C            ; Acquitte la lecture
  607.         MOV    @R0,A            ; Sauve l'état de la sortie
  608.         MOVX    @DPTR,A            ; Ecriture sur la sortie
  609.         INC    R0
  610.         INC    DPTR
  611.         DJNZ    R5,Init_Type
  612.         
  613.         LCALL    RecByteI2C
  614.         LCALL    StopI2C
  615.         RET
  616.  
  617. ;---------------------------------------------------------------------------
  618. ; Lecture des type de SW et envoi par série
  619.  
  620. AffTypeSW    MOV    R1,#20
  621.         MOV    R0,#TypeSW
  622.         CLR    TI
  623. AffTyp1        MOV    A,@R0
  624.         CJNE    A,#00,AffTyp2
  625.         MOV    SBUF,#'I'
  626.         AJMP    AffTyp3
  627. AffTyp2        MOV    SBUF,#'P'
  628. AffTyp3        JNB    TI,$
  629.         CLR    TI
  630.         MOV    SBUF,#10
  631.         JNB    TI,$
  632.         CLR    TI
  633.         MOV    SBUF,#13
  634.         JNB    TI,$
  635.         CLR    TI
  636.         INC    R0
  637.         DJNZ    R1,AffTyp1
  638.         RET
  639.         
  640.         
  641.         
  642. ;---------------------------------------------------------------------------        
  643. #include "L:I2C.LIB"
  644. ;---------------------------------------------------------------------------
  645. ; Messages   Messages   Messages   Messages   Messages   Messages  Messages
  646. ;---------------------------------------------------------------------------
  647. ;
  648. Welcome         DM      "Connection a 4800 bauds, 8 bits, pas de parite, 1 stop"
  649.         DB      10,13,10,13
  650.         DM      "Centrale d'eclairage AE-135.  Copywrite ADAM E. 1996"
  651.         DB      10,13,10,13
  652.         DM      "En attende de commande. (? = aide)"
  653.         DB      10,13
  654.         DM      "AE-135>"
  655.         DB      0
  656.  
  657. TextHelp        DM      "Aide des commande de la centrale d'eclairage"
  658.         DB      10,13,10,13
  659. ;        DM      "a   =   Allume une sortie"
  660. ;        DB      10,13
  661. ;        DM      "e   =   Etteint une sortie"   
  662. ;        DB      10,13
  663.         DM    "s   =   Type de sortie (Interrupteur / Bouton poussoir)"
  664.         DB    10,13
  665.         DM    "d   =   Programmation pour alarme"
  666.         DB    10,13
  667.         DM      "t   =   Change l'etat d'une sortie"
  668.         DB      10,13,0
  669.  
  670. Prompt          DB      10,13
  671.         DM      "AE-135>"
  672.         DB      0
  673.  
  674. TextChanel      DB      10,13
  675.         DM      "Canal n.: (1-35)"
  676.         DB      0
  677.  
  678. Txt_CRLF        DB      10,13,0
  679.  
  680. Txt_TypeSW    DB    10,13
  681.         DM    "i = Interrupteur      p = bouton Poussoir"
  682.         DB    10,13,0
  683.  
  684. Txt_DefAlarm    DB    10,13
  685.         DM    "a = ON si alarm       n = OFF si alarm"
  686.         DB    10,13,0            
  687.  
  688. Tab_Code        EQU     $
  689. BP1     DB      01111000b
  690. BP2     DB      01110100b
  691. BP3     DB      01110010b
  692. BP4     DB      01110001b
  693. BP5     DB      00111100b
  694. BP6     DB      01101100b
  695. BP7     DB      01101010b
  696. BP8     DB      01100110b
  697. BP9     DB      01100101b
  698. BP10    DB      01100011b
  699. BP11    DB      01011100b
  700. BP12    DB      01011010b
  701. BP13    DB      01011001b
  702. BP14    DB      01010110b
  703. BP15    DB      01010101b
  704. BP16    DB      01010011b
  705. BP17    DB      01001110b
  706. BP18    DB      01001101b
  707. BP19    DB      01001011b
  708. BP20    DB      01000111b
  709. BP21    DB    00111100b
  710. BP22    DB    00111010b
  711. BP23    DB    00111001b
  712. BP24    DB    00110110b
  713. BP25    DB    00110101b
  714. BP26    DB    00110011b
  715. BP27    DB    00101110b
  716. BP28    DB    00101101b
  717. BP29    DB    00101011b
  718. BP30    DB    00100111b
  719. BP31    DB    00011110b
  720. BP32    DB    00011101b
  721. BP33    DB    00011011b
  722. BP34    DB    00010111b
  723. BP35    DB    00011111b
  724.  
  725.     END
  726.