| 
    
  
    
  7.- Definire la memoria.
  Passiamo
ora alla definizione dell' uso della memoria RAM. 
  Ogni famiglia di PIC dispone di memoria RAM organizzata in modo e in quantità
  differente. Occorrerà quindi conoscere questi dati per poter configurare
  esattamente questa sezione. 
   
  Ecco, ad esempio, la definizione della RAM per un PIC18F. Da notare che, per evitare inutili calcoli manuali, nel sorgente è inserita una
piccola procedura di verifica per assicurare che le assegnazioni non superino la
capacità dei singoli blocchi. 
  
    
      
        
          ;#################################################################### 
          ;==================================================================== 
          ;=                          
          MEMORY USAGE                          
          = 
          ;==================================================================== 
            ;-------------------------------------------------------------------- 
            ;---------  ACCESS BANK  --------- 
            ;--------------------------------- 
          ; first 128 bytes 
          ; -----------------
            ; esempi di assegnazione 
              CBLOCK
          0x00  ; bank 0 
            bcdubuf:6   
          ; BCD unpacked buffer, big endendian, 6 bytes 
            LCDbuf:16   
          ; LCD data buffer, 16 bytes 
            flag        
          ; general flags 
           
          ; automatismo anti overflow  
            end_Accbank0:0         
          ; dummy for overrun check 
             ENDC   
           #if  end_Accbank0 > 0x7F ;
          check for overrun 
              error
          "Access Bank space overrun" 
           #endif 
           
            ;-------------------------------------------------------------------- 
            ;----------- BANK 0 ---------- 
            ;----------------------------- 
          ; second 128 bytes (not Accces Bank) 
            CBLOCK 0x80 
             
          ENDC 
 
           
          ; esempio di assegnazione di area di salvataggio del contesto per 
          ; interrupt a bassa priorità   
           #if INTRPRIORITY
            == 1  
            ; se interrupt con priorità attivo 
              CBLOCK
          0xFD           
            ; definisce area di salvataggio dei 
            wreg_lp
          : 1           
            ; registri sensibili per interrupt 
            bsr_lp  : 1           
            ; a bassa priorità 
            status_lp
          : 1 
           #endif 
          ; automatismo anti overflow 
           end_bank0:0            
          ; dummy for overrun check 
             ENDC   
           #if  end_bank0 > 0xFF   
          ;
          check for overrun 
             error "Bank 0 space overrun" 
           #endif 
           
            
          ;-------------------------------------------------------------------- 
          ;----------- BANK 1 ---------- 
          ;----------------------------- 
          ; 256 bytes 
          ; ------------- 
              CBLOCK
          0x100 
           
          ; automatismo anti overflow     
            end_bank1:0           
          ; dummy for overrun check 
              ENDC 
           #if end_bank1 > 0x1FF  
          ;
          check for overrun 
             error
          "Bank 1 space overrun" 
           #endif 
           
          ;-------------------------------------------------------------------- 
          ;----------- BANK 15 -------- 
          ;---------------------------- 
          ; 128 bytes 
          ; ------------- 
            CBLOCK 0xF00 
           
          ; automatismo anti
          overflow    
            end_bank15:0          
          ; dummy for overrun check 
              ENDC 
           #if end_bank15 > 0xF7F ;
          check for overrun 
             error
          "Bank 15 space overrun" 
           #endif 
           | 
         
      
     
   
  Ovviamente le definizioni potranno anche utilizzare gli statement relativi
  alle assegnazioni di memoria per oggetti rilocabili. Ad esempio: 
  
    
      
        
          ; Esempio di uso della GPR Uninitialized Data 
            ; variabili uetente posizionate dal linker 
             
            GPR_VAR         UDATA           0x20 
             
            MYVAR1 res 1  
            MYVAR2 res 1 
            MYVAR3 res 1 
            MYFLAG res        1 | 
         
      
     
   
  E' possibile anche qui utilizzare una forma "grafica" per
  visualizzare meglio una definizione di memoria: 
  
    
      
        
          ;==================================================================== 
            ; definizione dei flag nel byte MYFLAG 
            ;|  7  |  6  |  5   | 
            4   |  3  |   2  |  1  | 
            0  | 
            ;|----|-----|------|------|-----|------|-----|-----| 
            ;|    |    
            |i2cdok|totovf|undff|by3ovf|taokf|wedgf| 
            ; 
            #define   wedgf 
            MYFLAG,0  ; waiting transition (1st=0 2nd=1) 
            #define taokf 
            MYFLAG,1   ; tacho data ok 
            #define by3ovf
            MYFLAG,2  ; byte3 counter overflow 
            #define undff 
            MYFLAG,3  ; sub underf 
            #define totovf
            MYFLAG,4  ; totalizer overflow 
            #define i2cdok
            MYFLAG,5 
            ;#define      
            MYFLAG,5 : spare 
            ;#define       MYFLAG,7  ;
            spare
         |    
   
  In questa sezione andrà definita, se usata, anche la EEPROM, ad esempio
  precaricandola: 
  
    ;==================================================================== 
    ;               DATI PRECARICATI IN EEPROM 
    ;==================================================================== 
    DATAEE     ORG  0xF000 
     
    eep0 DE "Questo è un messaggio"    ; testo in eeprom 
    eep1 DE 0xAA, 0xFF, 0x55       
    ; valori in eeprom 
     
    TXTE_EE  EQU low (eep0)    ; indirizzo relativo del messagggio 
    VAL1_EEP  EQU low (eep1)    ; indirizzo relativo del primo valore 
    VAL2_EEP  EQU low (eep1+1)  ; indirizzo relativo del secondo valore 
    VAL3_EEP  EQU low (eep1+2)  ; indirizzo relativo del terzo valore
   
    
   
   
          |