23k256 ile SRAM uygulaması (pic 18F45K20 ve c18)

23k256 ile SRAM uygulaması (pic 18F45K20 ve c18)

PIC mikrodenetyici kullanmaktan vazgeçemiyorsunuz ancak RAM yetmiyor bunu artırmanın bir yolu yok mu diye düşünüyorsanız 23k256 ile 256 kilobitlik extra bir ram elde edebilirsiniz.

256 kilobit ne demek?

8 bit = 1 byte ettiğine göre

256 kilobit=256/8=32 kilobyte eder

32 kilobyte’lık alan kolay kolay dolmaz ancak yetmezse veya fazla gelirse 64 kbit ila 1mbit arasında tercih yapabilirsiniz:

64Kbit 256Kbit 512Kbit 1Mbit
23k640 23k256 23k512 23k1024

Burdan 23k256 ile ilgili bütün bilgilere: http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en539039

Burdan 18f serisi için olan döküman ve kaynak kodlara erişebilirsiniz:  http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en544429

 

Projeyi derlemeden önce pinlerinizi devrenizin yapısına göre ayarlamanız gerekiyor.

 

 

 

ISIS’te hangi adrese ne yazılmış öğrenmek istiyorsanız aşağıdaki resimlerde yazılanları uygulayınız:

 

 

 

 

Main_Demo.c dosyası:

/*********************************************************************
;* FileName     : Main_Demo.c
;* Dependencies : See INCLUDES section below
;* Processor    : PIC18F family of PICmicro - 8 bit MCU      
;* Assembler/
;* Linker       : MPLAB C18 V3.20
;* Company      : Microchip Technology, Inc.
;* 
;* Bu proje www.GokhanBeken.com da paylaşılmıştır
*/

#include <p18F45K20.h>

#include <delays.h>

#include "SRAM_main.h"

#pragma config WDTEN= OFF,BOREN =OFF ,MCLRE =ON,LVP =OFF
#pragma config FOSC = HS,FCMEN =ON,PWRT = ON,HFOFST = OFF    

void main()
{   
    unsigned char low_addr,high_addr,data;

	unsigned char i=0;  

    TRISD=0x00;

    Init_SPI();	/*spi için gerekli pinlerin ayarlarının uygulanması için çağırıyoruz
    bu ayarları değiştirmek için  SRAM_Driver.asm ve SRAM_Driver.inc dosyalarını inceleyiniz...	
	*/ 

	SRAMWriteStatusReg(Byte_Mode); //byte modu seçilerek byte byte yazıp okuyabileceğiz
    SRAMReadStatusReg(); // Durumu kontrol et.	             	     

	for(i=0;i<=15;i++) // 15 adet veriyi 15 farklı adrese yazıyoruz
	{	
		low_addr=i; //0 ila 15 arasındaki i değerini sırasıyla alacak
		high_addr=0x00; //8. bitten daha büyük adreslere hiç geçmeyeceğimiz için 0 veriyoruz
		data=i; //i verisini data olarak yükleyeceğiz.

		//yazdığımız değerler 0b00000000,0b00000001,0b00000010,0b00000011,0b00000100,0b00000101,0b00000110,0b00000111,0b00001000,0b00001001,0b00001010,0b00001011,0b00001100,0b00001101,0b00001111
		//yazdığımız adresler 0b00000000,0b00000001,0b00000010,0b00000011,0b00000100,0b00000101,0b00000110,0b00000111,0b00001000,0b00001001,0b00001010,0b00001011,0b00001100,0b00001101,0b00001111
        SRAMWriteByte(high_addr,low_addr,data); //verilen adrese data değişkenini yaz		
	}		

	for(i=0;i<=15;i++) //döngü ile 0x0000 ila 0x00FF arasındaki tüm verileri sırasıyla okuyup PORTD'de göster
	{				
        SRAMReadByte(0x00,i); //0x00xx adresini okur ve Data_In değişkenine yazar
		LATD=Data_In;  //okuduğu değeri PORTD'de gösterir
		Delay10KTCYx(100); //bekle		
	}		

    while(1);	
}

 

SRAM_Driver.asm dosyası

;*********************************************************************
;* FileName     : SRAM_Driver.asm
;* Dependencies : See INCLUDES section below
;* Processor    : PIC18 family of PICmicro - 8 bit MCU      
;* Assembler/
;* Linker       : MPASM v5.30
;* Company      : Microchip Technology, Inc.
;*
;*                     Software License Agreement                      
;*                                                                     
;* Microchip Technology Inc. (“Microchip”) licenses this software to you
;* solely for use with Microchip microcontrollers and Microchip serial
;* EEPROM products.  The software is owned by Microchip and/or its
;* licensors, and is protected under applicable copyright laws.  All
;* rights reserved.
;*
;* SOFTWARE IS PROVIDED "AS IS."  MICROCHIP AND ITS LICENSOR EXPRESSLY
;* DISCLAIM ANY WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED,
;* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
;* NON-INFRINGEMENT. IN NO EVENT SHALL MICROCHIP AND ITS LICENSORS BE
;* LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL
;* DAMAGES, LOST PROFITS OR LOST DATA, HARM TO YOUR EQUIPMENT, COST OF
;* PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
;* BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF),
;* ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER SIMILAR COSTS.
;*
;* Author                   Date                Version         Comment
;*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;* Deepak Kumar Rana        20-Feb-08           V1.0            Original
;*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

;*******************Includes**************************************
 #include    "SRAM_Driver.inc" 				; This includes file where the constants,variables decalred for the SPI

 Driver Code 
;**************************************************************************
; Function              :Init_SPI
; Precondition          :Make sure that the controller has an on chip MSSP module 
; Side Effect           :Make sure that the SPI mode and the SCK frequecy are as per the specifications of SRAM  
; Overview              :Initializes the MSSP moudle of the controller for SPI mode 1
;                        CKP =0 CKE=1
;**************************************************************************

Init_SPI:

	global Init_SPI    						;Make function available to across files

	bcf  TRISC,2,0   							;CE  pin output
	bcf  TRISC,3,0    							;SCK pin output
	bsf  TRISC,4,0    							;SDI pin input
	bcf  TRISC,5,0    							;SDO pin output 
	bsf  CE,0        							;Disabling the chip
 					                        	;initialize the SPI configurataion register
    clrf  SSPCON2,0    						    ;clearing the flags
	clrf  SSPSTAT,0		  					    ;SMP=0 sampling at the middle of data ouptut time 
	bsf   SSPSTAT,CKE,0    						;CKE =1
    clrf  SSPCON1,0								;SCK = Fosc/4
    bcf   SSPCON1,CKP,0							;CKP = 0,enable the port pins for SPI (SSPEN=1)
	bsf   SSPCON1,SSPEN,0						;SPI enable, SPI mode 1 (CKP=0,CKE=1)                 					    

	return 0

;**************************************************************************
; Function              :Init_Datamem
; Precondition          :The data to be written to Data_Writepage is passed in the fuction call from Main_Demo.c
; Side Effect           :We are writing the same data to all the 32 bytes to the location for demo. In your
;						 application modify the routine appropriately
; Overview              :To read the function passed by the calling fuction in the C file we are reading from the
;  						 Software stack of C18. For details refer the C18 user guide 
;						 "Under Content >Run-time Model>Calling Conventions" 
;						 Initializes the data memory location of the controller to store 
;						 the values that need to written to the SRAM. We use indirect addressing
;						 and store the data that in location defined in Data_Writepage
;                  
;**************************************************************************

   Init_Datamem:

   global Init_Datamem

    movff  POSTDEC1,0;  					;FSR1 points to one location higer 
    movff  POSTDEC1,count;					;Copy the number of bytes from software stack to count and decrement the FSR1 pointer
    movff  POSTDEC1,Data_Out;				;Copy the data to be written from the software stack

    movlw  low (Data_Writepage)				;intialize the FSR0 to the controller data memory Data_Writepage
    movwf  FSR0L,0
    movlw  high(Data_Writepage)
    movwf  FSR0H,0

write_ConRam
    movff  Data_Out,POSTINC0	   			;data that is being stored  to location pointed by the FSR0 , FSR0 location incremented
    decfsz count,1,0	     				;check if all data has been written or not
    bra write_ConRam

    return 0

;**************************************************************************
; Function              : SRAMWritePage  
; Precondition          : Configure SRAM for page mode before calling this routine.The address location and number of 
;						  bytes to be written are passed from the fuction call in main.c 
; Side Effects          : User needs to make sure that he writing within the page  
; Overview              : To read the function passed by the calling fuction in the C file we are reading from the
;  						  Software stack of C18. For details refer the C18 user guide 
;						  "Under Content >Run-time Model>Calling Conventions" This performs the operation of writing to a page in the SRAM.
;						  Indirect addressing is used to access the data from location  
;						  Data_Writepage and write to SRAM
;                        
;**************************************************************************

   SRAMWritePage:
     global SRAMWritePage

	movff  POSTDEC1,0;  						;FSR1 points to one location higer 
	movff  POSTDEC1,Addr_High;					;Copy the Address information from software stack to Addr_High
	movff  POSTDEC1,Addr_Low;
	movff  POSTDEC1,count;

 	movlw  low (Data_Writepage	)				;intialize the FSR0 to the controller data memory
    movwf  FSR0L,0
    movlw  high(Data_Writepage)
    movwf  FSR0H,0

    bcf     CE        							;enable SRAM

    movlw   Write    							;give the write command 0x02
    movwf   SSPBUF,0							;transmit the write comand
    btfss   SSPSTAT,BF,0						;check for the transmission of the byte
    bra     $-2

    movf    Addr_High,0,0 						;High byte of the address location to be read
    movwf   SSPBUF,0
    btfss   SSPSTAT,BF,0  						;check for the succesfull trasmission of the byte
    bra   $-2

    movf    Addr_Low,0,0 						;High byte of the address location to be read
    movwf   SSPBUF,0
    btfss   SSPSTAT,BF,0  						;check for the succesfull trasmission of the byte
    bra   $-2

  Write_SRAM 

    movf  POSTINC0,0,0           				;move the contents from data location pointed by FSR0
    movwf SSPBUF,0 
    btfss SSPSTAT,BF,0      					;check if the byte has been trasmitted
    bra    $-2  

    decfsz  count,1,0     						;check if all the bytes have been transmitted
    bra   Write_SRAM        					;if not then trasmit the remaining bytes  

    bsf      CE 			 					;Disable SRAM

 	return

;**************************************************************************
; Function              : SRAMReadPage  
; Precondition          : SRAM needs to be configured for page mode before calling this routine.The address location and number of 
;						  bytes to be read are passed from the fuction call in main.c
; Side Effects          : User needs to make sure that he is reading within the page    
; Overview              : To read the function passed by the calling fuction in the C file we are reading from the
;  						  Software stack of C18. For details refer the C18 user guide 
;						  "Under Content >Run-time Model>Calling Conventions".
;						  This performs the operation of reading from a page in SRAM.
;						  Indirect addressing is used to copy the data to data memory location  
;						  pointed by Data_Readpage                         
;**************************************************************************

  SRAMReadPage:

  global  SRAMReadPage

    movff  POSTDEC1,0	  					;FSR1 points to one location higer, decrement the FSR1 pointer to point to passed varibales in software stack
    movff  POSTDEC1,Addr_High				;Copy the Address information from software stack to Addr_High
    movff  POSTDEC1,Addr_Low				;
    movff  POSTDEC1,count					;Copy the number of byte information from software stack to count

    movlw  low (Data_Readpage)				; intialize the FSR0 to the controller data memory Data_Readpage
    movwf  FSR0L,0
    movlw  high(Data_Readpage)
    movwf  FSR0H,0

    bcf     CE        						;enable SRAM

    movlw   Read     						;give the read command 0x3  
    movwf   SSPBUF,0
    btfss   SSPSTAT,BF,0 					;check for the successful transmission of the byte
    bra   $-2

    movf    Addr_High,0,0 					;High byte of the address location to be read
    movwf   SSPBUF,0
    btfss   SSPSTAT,BF,0  					;check for the succesfull trasmission of the byte
    bra   $-2

    movf    Addr_Low,0,0 					;High byte of the address location to be read
    movwf   SSPBUF,0
    btfss   SSPSTAT,BF,0  					;check for the succesfull trasmission of the byte
    bra   $-2

  Read_SRAM 
    movlw   0xFF     						;do the dumy write to SSBUF to read the SRAM
    movwf   SSPBUF,0
    btfss   SSPSTAT,BF,0 					;check for the succesfull reception of the byte
    bra   $-2

    movff   SSPBUF,POSTINC0                 ;store the content read from SRAM to location pointer by FSR0
    decfsz  count,1,0 						;check if all the data has been read
    bra     Read_SRAM     					;if not then read the remaining bytes

    bsf      CE 							;Disable SRAM

 	return 0

;**************************************************************************
; Function              :SRAMWriteSeq
; PreCondition          :User needs to make sure that the SRAM has be configured to Sequential mode.The address location and number of 
;						 bytes to be written are passed from the fuction call in main.c  
; Side Effects          :Location pointed to by FSR will change at the end of this function.
; Overview              :To read the function passed by the calling fuction in the C file we are reading from the
;  						 Software stack of C18. For details refer the C18 user guide 
;						 "Under Content >Run-time Model>Calling Conventions".
;						 This performs the operation of writing to memory locations in the SRAM.
;						 Indirect addressing is used to access the data from location  
;						 Data_Writepage and write to SRAM                       
;**************************************************************************

     SRAMWriteSeq:
     global SRAMWriteSeq

	movff  POSTDEC1,0;  						;FSR1 points to one location higer 
	movff  POSTDEC1,Addr_High;					;Copy the Address information from software stack to Addr_High
	movff  POSTDEC1,Addr_Low;
	movff  POSTDEC1,count;

 	movlw  low (Data_Writepage	)				;intialize the FSR0 to the controller data memory
    movwf  FSR0L,0
    movlw  high(Data_Writepage)
    movwf  FSR0H,0

    bcf     CE        							;enable SRAM

    movlw   Write    							;give the write command 0x02
    movwf   SSPBUF,0							;transmit the write comand
    btfss   SSPSTAT,BF,0						;check for the transmission of the byte
    bra     $-2

    movf    Addr_High,0,0 						;High byte of the address location to be read
    movwf   SSPBUF,0
    btfss   SSPSTAT,BF,0  						;check for the succesfull trasmission of the byte
    bra   $-2

    movf    Addr_Low,0,0 						;High byte of the address location to be read
    movwf   SSPBUF,0
    btfss   SSPSTAT,BF,0  						;check for the succesfull trasmission of the byte
    bra   $-2

  WriteSeq_SRAM 

    movf  POSTINC0,0,0           				;move the contents from data location pointed by FSR0
    movwf SSPBUF,0 
    btfss SSPSTAT,BF,0      					;check if the byte has been trasmitted
    bra    $-2  

    decfsz  count,1,0     						;check if all the bytes have been transmitted
    bra   WriteSeq_SRAM        					;if not then trasmit the remaining bytes  

    bsf      CE 			 					;Disable SRAM

 	return  0

;**************************************************************************
; Function              :SRAMReadSeq
; Precondition          :User needs to make sure that the SRAM has been configured to Sequential mode.The address location and number of 
;						  bytes to be read are passed from the fuction call in main.c 
; Side Effects          :Location pointed to by FSR will change at the end of this function 
; Overview              :To read the function passed by the calling fuction in the C file we are reading from the
;  						 Software stack of C18. For details refer the C18 user guide 
;						 "Under Content >Run-time Model>Calling Conventions".This performs the operation of writing to SRAM from the controller across the page boundaries
;						 Indirect addressing is used to write the data Read from SRAM to location  
;						 Data_Readpage in controller data memory                       
;**************************************************************************

   SRAMReadSeq:

   global  SRAMReadSeq

    movff  POSTDEC1,0	  					;FSR1 points to one location higer, decrement the FSR1 pointer to point to passed varibales in software stack
    movff  POSTDEC1,Addr_High				;Copy the Address information from software stack to Addr_High
    movff  POSTDEC1,Addr_Low				;
    movff  POSTDEC1,count					;Copy the number of byte information from software stack to count

    movlw  low (Data_Readpage)				; intialize the FSR0 to the controller data memory Data_Readpage
    movwf  FSR0L,0
    movlw  high(Data_Readpage)
    movwf  FSR0H,0

    bcf     CE        						;enable SRAM

    movlw   Read     						;give the read command 0x3  
    movwf   SSPBUF,0
    btfss   SSPSTAT,BF,0 					;check for the successful transmission of the byte
    bra   $-2

    movf    Addr_High,0,0 					;High byte of the address location to be read
    movwf   SSPBUF,0
    btfss   SSPSTAT,BF,0  					;check for the succesfull trasmission of the byte
    bra   $-2

    movf    Addr_Low,0,0 					;High byte of the address location to be read
    movwf   SSPBUF,0
    btfss   SSPSTAT,BF,0  					;check for the succesfull trasmission of the byte
    bra   $-2

  ReadSeq_SRAM 
    movlw   0xFF     						;do the dumy write to SSBUF to read the SRAM
    movwf   SSPBUF,0
    btfss   SSPSTAT,BF,0 					;check for the succesfull reception of the byte
    bra   $-2

    movff   SSPBUF,POSTINC0                 ;store the content read from SRAM to location pointer by FSR0
    decfsz  count,1,0 						;check if all the data has been read
    bra     ReadSeq_SRAM   					;if not then read the remaining bytes

    bsf      CE 							;Disable SRAM

 	return 0

;**************************************************************************
; Function              :SRAMWriteByte
; Precondition          :Make sure that before calling this function the status register of SRAM is configured for Byte Mode 
; Side Effects          :None
; Overview              :This performs the operation of writing byte stored in Data_Out location to SRAM. 
;						                      
;**************************************************************************

	SRAMWriteByte:

	 global SRAMWriteByte
	 movff  POSTDEC1,0						;FSR1 points to one location higer, decrement the FSR1 pointer to point to passed varibales in software stack
     movff  POSTDEC1,Addr_High				;Copy the Address information from software stack to Addr_High
     movff  POSTDEC1,Addr_Low				;
     movff  POSTDEC1,Data_Out				;Copy the Data information from software stack to Data_Out

     bcf     CE        						;enable SRAM

   	 movlw   Write   						;give the write command to the SRAM
     movwf   SSPBUF,0
     btfss   SSPSTAT,BF,0  					;check for the succesfull trasmission of the byte
     bra   $-2

     movf    Addr_High,0,0  				;give the high byte of the address
     movwf   SSPBUF,0
     btfss   SSPSTAT,BF						;check for the succesfull trasmission of the byte
     bra   $-2

     movf    Addr_Low,0,0  					;give the low byte of the address
     movwf   SSPBUF,0
     btfss   SSPSTAT,BF,0  					;check for the succesfull trasmission of the byte
     bra   $-2    

     movf    Data_Out,0,0 					;write the data to be written to SRAM on to the SSPBUF
     movwf   SSPBUF,0    					;start the trasmission
     btfss   SSPSTAT,BF,0     				;check for the succesfull trasmission of the byte
     bra   $-2    

     bsf     CE   							;disable RAM  
     return  0

;**************************************************************************
; Function              :SRAMReadByte
; Precondition          :Make sure that before calling this fuction the status register of SRAM is configured for Byte Mode 
; Side Effects          :After the end of this function Data_In contains the data read from the SRAM
; Overview              :This performs the operation of reading byte from SRAM.The read content is stored at location Data_In 
;						                      
;**************************************************************************

;Read a Byte from the location
    SRAMReadByte
    global SRAMReadByte

    movff  POSTDEC1,0						   ;FSR1 points to one location higer 
    movff  POSTDEC1,Addr_High;
    movff  POSTDEC1,Addr_Low;

    bcf     CE        							;enable SRAM

    movlw   Read    							;give the read command to the SRAM   
    movwf   SSPBUF,0
    btfss   SSPSTAT,BF,0  						;check for the succesfull trasmission of the byte
    bra   $-2

    movf    Addr_High,0,0 						;High byte of the address location to be read
    movwf   SSPBUF,0
    btfss   SSPSTAT,BF,0  						;check for the succesfull trasmission of the byte
    bra   $-2

    movf     Addr_Low,0,0 						;Low byte of the address location to read 
    movwf    SSPBUF,0
    btfss    SSPSTAT,BF,0 						;check for the succesfull trasmission of the byte 
    bra   $-2    

    movlw   0xFF    							;perform the dummy write to read the SRAM location
    movwf   SSPBUF,0  
    btfss   SSPSTAT,BF,0 						;check for the succesfull reception of the byte
    bra   $-2    

    movff    SSPBUF,Data_In							;save the data read from SSPBUF to Data_In
  ;  movwf   Data_In,0

    bsf     CE  								 ;disable RAM  

    return  0

;**************************************************************************
; Function              :SRAMWriteStatusReg
; Precondition          :The mode of operation to be writen to status register is passed from main.asm
; Side Effects          :Writing to the status register changes the SRAM operation mode.
; Overview              :This performs the operation of writing to the status register of SRAM 
;						 This fuction is used to configure SRAM for byte,page,sequential mode                     
;**************************************************************************

   SRAMWriteStatusReg:

   global SRAMWriteStatusReg

   	movff  POSTDEC1,0							;FSR1 points to one location higer 
    movff  POSTDEC1,mode; 

    bcf     CE,0        						;enable SRAM
    nop

    movlw   WRSR       						   ;issue the write to status register command to SRAM 
    movwf   SSPBUF,0
    btfss   SSPSTAT,BF,0  					 	;check for the succesfull trasmission of the byte
    bra   $-2

;    movff   mode,SSPBUF
;    btfss   SSPSTAT,BF,0 					  	;scope 0 check for the succesfull trasmission of the byte
;    bra   $-2

    movf   mode,0,0       						;issue the write to status register command to SRAM 
    movwf   SSPBUF,0
    btfss   SSPSTAT,BF,0  					 	;check for the succesfull trasmission of the byte
    bra   $-2

    bsf      CE,0 							  ;Disable SRAM
    return  0

;**************************************************************************
; Function              :SRAMReadStatusReg
; Precondition          :Make sure that the MSSP module is initialized for SPI
; Side Effects          :None 
; Overview              :This performs the operation of reading from the status register of SRAM 
;						 This fuction is used to check the configuration of SRAM .Data_In contain the data read 
;						 from status register                      
;**************************************************************************

  SRAMReadStatusReg:

    global SRAMReadStatusReg

    bcf     CE,0       							 ; enable SRAM
   	nop

    movlw   RDSR      							;issue the read status register command to the SRAM
    movwf   SSPBUF,0
    btfss   SSPSTAT,BF,0 						;check for the succesfull trasmission of the byte
    bra     $-2

    movlw   0xFF     							;dummy write to SSPBUF to read form SRAM status register 
    movwf   SSPBUF,0
    btfss   SSPSTAT,BF,0  						;check for the succesfull reception of the byte
    bra     $-2

    movff   SSPBUF,Data_In

    nop
    nop
    bsf      CE,0 								;Disable SRAM

    return 

;**************************************************************************

    END

SRAM_Driver.inc dosyası:

;*********************************************************************
;* FileName     : SRAM_Driver.inc
;* Dependencies : See INCLUDES section below
;* Processor    : PIC18F family of PICmicro - 8 bit MCU      
;* Assembler/
;* Linker       : MPASM v5.30
;* Company      : Microchip Technology, Inc.
;*
;*                     Software License Agreement                      
;*                                                                     
;* Microchip Technology Inc. (“Microchip”) licenses this software to you
;* solely for use with Microchip microcontrollers and Microchip serial
;* EEPROM products.  The software is owned by Microchip and/or its
;* licensors, and is protected under applicable copyright laws.  All
;* rights reserved.
;*
;* SOFTWARE IS PROVIDED "AS IS."  MICROCHIP AND ITS LICENSOR EXPRESSLY
;* DISCLAIM ANY WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED,
;* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
;* NON-INFRINGEMENT. IN NO EVENT SHALL MICROCHIP AND ITS LICENSORS BE
;* LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL
;* DAMAGES, LOST PROFITS OR LOST DATA, HARM TO YOUR EQUIPMENT, COST OF
;* PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
;* BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF),
;* ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER SIMILAR COSTS.
;*
;* Author                   Date                Version         Comment
;*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;* Deepak Kumar Rana        20-Feb-08           V1.0            Original
;*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 #include "P18F45K20.inc"

	errorlevel  -302   			;Turn off banking message
    errorlevel  -205   			;Turn off found directive in column 1
   	errorlevel  -207   			;Turn off warnings of found label after column 1

;**************************************************************************
	;Hardware Definations
    ;Verify the header file before commenting or uncommeting the definations
    ;In case of PIC18F45K20 already the SCK,SDI and SDO are defined in header file
;**************************************************************************	
	#define  CE    PORTC,2    	;RC2 pin(17) is CS 
;	#define  SCK   PORTC,3    	;RC3 pin(18) is SCK
;	#define  SDI   PORTC,4    	;RC4 pin(23) is SDI
;	#define  SDO   PORTC,5    	;RC5 pin(24) is SDO

;**************************************************************************	
	;Define SPI commands for the SRAM
;**************************************************************************	
	#define  Read   0x03     	;read from memory array beginning at the selected address
	#define  Write  0x02     	;write to memory array beginning at the selected address
	#define  RDSR   0x05     	;read the status register
	#define  WRSR   0x01     	;write the status register

;*******************RAM register definitions********************** 
     UDATA_ACS

    Addr_High      res  1 		;address location where to write/read
    Addr_Low       res  1 		;address location where to write/read
    Data_Out       res  1 		;data to be written to SRAM
    Data_In        res  1 		;data read from SRAM
     count		   res  1 		;number of bytes/location in SRAM to be read/written
     mode          res  1 		;mode of operation for SRAM

;*******************RAM register definitions**********************

    write	UDATA  
    Data_Writepage res 32 		;data to be written SRAM is saved here

 ;*******************RAM register definitions********************** 
    read	UDATA  
    Data_Readpage  res 32 		;data read from the SRAM is saved here

 ;**************************************************************************    	
;Allow following variables to access from other files.
   	global	Data_Out
   	global	Data_In
   	global	Addr_High
   	global	Addr_Low
   	global  Data_Writepage
   	global  Data_Readpage
   	global  count
    global  mode

 ;**************************************************************************

 

 

SRAM_main.h dosyası:

/*********************************************************************
;* FileName     : SRAM_Main.h
;* Dependencies : See INCLUDES section below
;* Processor    : PIC18F family of PICmicro - 8 bit MCU      
;* Assembler/
;* Linker       : MPLAB C18 V3.20
;* Company      : Microchip Technology, Inc.
;*
;*                     Software License Agreement                      
;*                                                                     
;* Microchip Technology Inc. (“Microchip”) licenses this software to you
;* solely for use with Microchip microcontrollers and Microchip serial
;* EEPROM products.  The software is owned by Microchip and/or its
;* licensors, and is protected under applicable copyright laws.  All
;* rights reserved.
;*
;* SOFTWARE IS PROVIDED "AS IS."  MICROCHIP AND ITS LICENSOR EXPRESSLY
;* DISCLAIM ANY WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED,
;* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
;* NON-INFRINGEMENT. IN NO EVENT SHALL MICROCHIP AND ITS LICENSORS BE
;* LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL
;* DAMAGES, LOST PROFITS OR LOST DATA, HARM TO YOUR EQUIPMENT, COST OF
;* PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
;* BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF),
;* ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER SIMILAR COSTS.
;*
;* Author                   Date                Version         Comment
;*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;* Deepak Kumar Rana        20-Feb-08           V1.0            Original
;*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/

	#define Byte_Mode 0x01  		// ;bit7 =0 bit6 =0 Byte Mode setting LSB 1 disables the hold functionality
	#define Page_Mode 0x81  		// ;bit7 =1 bit6 =0 Page Mode 
	#define Seq_Mode  0x41  		// ;bit7 =0 bit6 =1 Sequential mode

	extern char 	Data_Out;
	extern char     Data_In ;
	extern char  	Addr_High;
	extern char	    Addr_Low;
	extern char     Data_Writepage;
	extern char     Data_Readpage;
	extern char     count;
	extern char     mode;

	extern void 	Init_SPI(void);
	extern void 	SRAMWriteStatusReg(unsigned const char);
	extern void 	SRAMReadStatusReg(void);
	extern void 	SRAMWriteByte(unsigned char,unsigned char,unsigned char);
	extern unsigned char 	SRAMReadByte(unsigned char,unsigned char);
	extern void 	Init_Datamem(unsigned char,unsigned char);
	extern void 	SRAMWritePage(unsigned char,unsigned char,unsigned char); 
	extern void 	SRAMReadPage(unsigned char,unsigned char,unsigned char); 
	extern void 	SRAMReadSeq(unsigned char,unsigned char,unsigned char);
	extern void 	SRAMWriteSeq(unsigned char,unsigned char,unsigned char);

Dosyaları proje dosyası halinde indirmek için linke tıklayınız: http://gokhanbeken.com/dosyalar/ledler_ve_23k256.rar

 

4 thoughts on “23k256 ile SRAM uygulaması (pic 18F45K20 ve c18)

  1. Teşekkürler güzel bir yazı olmuş. Peki hız konusunda bir hesaplamnız oldumu yazma ve okuma olarak ne kadar hıza çıkabiliyor.

Bir Cevap Yazın