Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
09/08/11 08:54
Read: times


 
#183655 - Code
Responding to: ???'s previous message
Sorry but some code was not printed

/////////////////////////////////////////////////

...

    while (SW1 == 1){


	
   BYTE  save_sfrpage = SFRPAGE;   
   SFRPAGE   = SPI0_PAGE;

   NSSMD0   = 0;                       // Step1.1: Activate Slave Select
   SPI0DAT  = EEPROM_CMD_WREN;         // Step1.2: Send the WREN command
   while (!SPIF);                      // Step1.3: Wait for end of transfer
   SPIF     = 0;                       // Step1.4: Clear the SPI intr. flag
   NSSMD0   = 1;                       // Step1.5: Deactivate Slave Select
   //Delay_us (1);                       // Step1.6: Wait for at least 
                                       //          T_NSS_DISABLE_MIN
   // Step2: Send the WRITE command
   NSSMD0   = 0;
   SPI0DAT  = EEPROM_CMD_WRITE;
   while (!SPIF);
   SPIF     = 0;
   
   
   // Step3: Send the EEPROM destination address (MSB first)
   SPI0DAT  = (BYTE)((counter >> 8) & 0x00FF);
   while (!SPIF);
   SPIF     = 0;
   SPI0DAT  = (BYTE)(counter & 0x00FF);
   while (!SPIF);
   SPIF     = 0;
   //}	
	SFRPAGE = save_sfrpage;


	for (buf=0; buf<32; buf++)  //0-32 as 16bit measurement is splitted to 8bit+8bit
	{
	EA = 0;                          // Disable interrupts

	// The 12-bit ADC value is averaged across INT_DEC measurements.  The result is 
	// then stored in Result, and is right-justified 
	// The measured voltage applied to AIN 0.1 is then:
	//
	//                           Vref (mV)
	//   measurement (mV) =   --------------- * Result (bits) 
	//                       (2^12)-1 (bits)

	measurement[buf] =  Result * 2430 / 4095;

	EA = 1;                          // Re-enable interrupts
	Time0 = ~Time0;					// generate clk at output for frequency check
	counter2++;						// counts # of samples


	Delay_ms(100);
	x1= measurement[buf];				//low value 8bit
	x2= measurement[buf] >> 8 ;			//high value 8bit (recalculated with *256)
	SFRPAGE   = UART1_PAGE;
	//printf("n x1:%d x2:%d",x1,x2);
	printf("n meas_value:%ld x1:%d x2:%d counter:%ld",measurement[buf],x1,x2,counter);
	SFRPAGE   = SPI0_PAGE;
   SPIF     = 0;
   NSSMD0   = 0;
		
   SPI0DAT  = 166;				//perform test (with constant value)
   while (!SPIF);

   SPIF     = 0;
   NSSMD0   = 1;
   //Delay_us (1);
   

   }	 //for end

   // Step5: Poll on the Write In Progress (WIP) bit in Read Status Register
   do
   {
      NSSMD0   = 0;                    // Activate Slave Select
      SPI0DAT  = EEPROM_CMD_RDSR;      // Send the Read Status Register command
     while (!SPIF);                   // Wait for the command to be sent out
      SPIF     = 0;
      SPI0DAT  = 0;                    // Dummy write to output serial clock
     while (!SPIF);                   // Wait for the register to be read
      SPIF     = 0;
      NSSMD0   = 1;                    // Deactivate Slave Select after read
    //  Delay_us (1);
   } while( (SPI0DAT & 0x01) == 0x01 );

   SFRPAGE  = save_sfrpage;
	counter=counter+64;				//go to next page

	}	//while end	 	
 



List of 9 messages in thread
TopicAuthorDate
8051F120 SPI EEPROM Page_write            01/01/70 00:00      
   Code            01/01/70 00:00      
      disable printf?            01/01/70 00:00      
   which '51 derivative?            01/01/70 00:00      
      Isn't that obvious?            01/01/70 00:00      
         I keep missing the titles :(            01/01/70 00:00      
         Working (?)            01/01/70 00:00      
            Wow - now that is fast            01/01/70 00:00      
               Mhz            01/01/70 00:00      

Back to Subject List