Study the concept of the program I've written below. It took me about 20 minutes, which in real money is the cost of half a shop full of Thorntons chocolate...

When Green LED lights, press the button to start taking 65 seconds worth of samples at 10mS intervals. When the samples are being taken, the RED LED is illuminated. There is no need to keep the button pressed - it's just there to start the process... timing is within the program thereafter.

It'll capture SIX ADC's the first 10mS into six bytes, one for each ADC. In the next 10mS, it'll omit the 6th ADC, the sixth byte in this case will be a dummy preset to zero. The following 10mS it'll revert back to saving all six samples, and so on.

After 100mS worth of samples (ten times 10mS) you've captured 60 bytes of data. This is then written out as an EEPROM 'Page'. Although 64 bytes are written out, only the first 60 are data, and the four on the end are unused.

This continues for 650 pages. The first 512 pages are saved into EEPROM 1 (24LC256 device address $A0), and the remaining 138 pages are saved into EEPROM 2 (Address $A1).

Once 65 seconds worth of samples are stored, the Green LED blinks to tell you all is done.

Study what's going on line by line BEFORE you ask any questions... and bear in mind that I'll probably won't get around to answering until next week - which gives you lots of time to study and sort out things on your own.

' Start Button and LED's
' =====================
StartButton var PortB.0
' Button connected between this PIC pin and Vss
' Pin is pulled-up by using internal Weak Pull-up's
' 65 Second Sampling commences when this button is pressed
' ie PIC pin goes to 0v.
' Button does NOT need to be held down for the duration
' as 65 second counting is done in the program.
GreenLED var PortB.1
' LED connected between Vdd and this pin via Resistor
' Green LED indicates Ready to Sample
' When Green LED blinks, this indicates Sampling Completed
RedLED var PortB.2
' LED connected between Vdd and this pin via Resistor
' Red LED indicates Sampling in Progress
'
' ADC's
' =====
' AN0 through AN4 are sampled every 10mS
' AN5 is only sampled every 20mS
'
' External EEPROM
' ===============
SCL var PortB.3
SDA var PortB.4
'
' RAM Usage
' =========
EEAddress var Byte
' Used to Address the physical EEPROM (ie EEPROM 1 or EEPROM 2)
EEPageStart var Word ' Pointer to start of Page boundary
PageAddress var Byte ' Location of Data in Page
PageCount var Word ' Counter for number of completed Pages
PageData var Byte [64] ' 100mS Data Buffer
SampleCount var Byte ' Counter for number of Sample Batches
'
' Constants
' =========
LoopCount con 650
' number of loops to perform...
' (650 pages of 100mS worth of samples equals 65 seconds)

'
' Initialise Program
' ==================
TRISA=%11111111
' All pins input
ADCON1=%00000000
' Left-Justify ADC Results
' Read 8-bit Results from ADRESH Register only
' Enable all ADC's
TRISB=%00000001
OPTION_REG.7=0 ' Enable Weak Pull-Up's
Pause 1000 ' Wait for external world to settle
High GreenLED ' OFF LED's
High RedLED
PageData[60]=0 ' Zero unused Portion of Databuffer
PageData[61]=0
PageData[62]=0
PageData[63]=0
'
' Ready to Sample
' ===============
Low GreenLED ' Indicate Ready to take sample
While StartButton=1:Wend
'
' Start Logging Sample
' ====================
High GreenLED ' Green OFF
Low RedLED ' Red ON to indicate sampling in progress
PageCount=0 ' Start at beginning of EEPROM
PageCountLoop:
PageAddress=0 ' Start each page at beginning of Data Buffer
SampleCount=0 ' Reset Page Sample Counter
SampleCountLoop:
'
' Read the Five Channels AN0-AN4
' ------------------------------
ADCON0=%01000001:Gosub GetSample:PageData[PageAddress]=ADRESH
ADCON0=%01001001:Gosub GetSample:PageData[PageAddress+1]=ADRESH
ADCON0=%01010001:Gosub GetSample:PageData[PageAddress+2]=ADRESH
ADCON0=%01011001:Gosub GetSample:PageData[PageAddress+3]=ADRESH
ADCON0=%01100001:Gosub GetSample:PageData[PageAddress+4]=ADRESH
'
' Read the Sixth Channel AN5 only every other 10mS
' ------------------------------------------------
If SampleCount.0=0 then
ADCON0=%01101001:Gosub GetSample:PageData[PageAddress+5]=ADRESH
else
PageData[PageAddress+5]=0 ' Save dummy (zero) sample
endif
'
' Determine if PageWrite dump to EEPROM required
' ----------------------------------------------
SampleCount=SampleCount+1 ' Increment Completed Sample Count
PageAddress=PageAddress+6 ' Increment Buffer Data Pointer
If SampleCount < 10 then
Pause 10 ' Wait 10mS
Goto SampleCountLoop ' Loop for next Capture Sequence
Endif
'
' Dump entire Data Buffer to EEPROM Page
' This takes 10mS to complete so there's no Pause in this section
' ================================================== =============
' I've assumed that 24LC256 EEPROM 1 is wired for Address $A0
' and EEPROM 2 is wired for Address $A1
If PageCount < 512 then
EEAddress=$A0
EEPageStart=PageCount*64
else
EEAddress=$A1
EEPageStart=(PageCount-512)*64
endif
I2CWRITE SDA,SCL,EEAddress,EEPageStart,[str PageData\64]
PageCount=PageCount+1 ' Increment completed EEPROM Page Counter
'
' Loop around for next 100mS Data Slice
' =====================================
If PageCount < LoopCount then goto PageCountLoop
'
' Indicate Sampling Completed
' ===========================
High RedLED ' Red OFF
CompletedLoop:
Low GreenLED ' Blink Green to indicate samples captured
Pause 750
High GreenLED
Pause 750
Goto CompletedLoop

'
' Subroutine Captures ADC Sample
' ------------------------------
GetSample:
PauseUS 50
' 50uS Pause to allow sampling Capacitor to charge
ADCON0.1=1
' Start Conversion
While ADCON0.1=1:Wend
' Wait for conversion to complete
Return

'
End


PS. ensure you spell my name right on either the college certificate or preferably the client cheque... *smiles*

Melanie