Below is code for an eight output project based on time and eventually either time or rpm of an engine. I have done something similar earlier yet with only two outputs.

So I have to store the "On" time or rpm and also the "Off" time of the time or rpm. I have a membrane switch that allows the user to configure the sixteen variables (eight stages each with an 'On' and an 'Off' time.

Currently I have the code to do a WRITE and READ after each update of a stage/On or Off. The WRITE and READ commands eat up alot of code space quickly.

My question is they are cleaner approach to a WRITE and READ? Instead of doing 16 Writes and Reads then updating the LCD, can I do sometype of Loop with one Write and Read command? Or anything else?

BTW, I am working on a few other things in the code trying to simplify code in other areas aswell so the posted code in other areas might not make sense. The WRITE/READ portion is what I am talking about for this case. Also I had to shorten the code to fit under the character limit for this thread

Thanks
Toby

Code:
DEFINE OSC 20  

Start           var     PortB.5    'Input to start timers
Up1             var     PortA.2    'Up button to change seconds
Down1           var     PortA.3    'Down button to change seconds. 
Up01            var     PortE.1    'Up button to change tenths of second. 
Down01          var     PortE.0    'Down button to change tenths of second. 
Up001           var     PortA.5    'Up button to change hundredths of a second
Down001         var     PortA.4    'Down button to change hundredths of a second
Tool            var     PortB.4    'Button to change to diffent menu
UpStage         var     PortC.3    'Button to change stages
DownStage       var     PortD.0    'Button to change stages
LCD             VAR     PortC.4    'LCD output
RPM             var     PortC.2

StageCounter    var     byte
ActiveType      var     Byte            'Toggles between On/Off part of a Stage
Stage1OnS       data    word      100
Stage1OffS      data    word      110
Stage2OnS       data    word      200
Stage2OffS      data    word      220
Stage3OnS       data    word      300
Stage3OffS      data    word      330
Stage4OnS       data    word      400
Stage4OffS      data    word      440
Stage5OnS       data    word      500
Stage5OffS      data    word      550
Stage6OnS       data    word      600
Stage6OffS      data    word      660
Stage7OnS       data    word      700
Stage7OffS      data    word      770
Stage8OnS       data    word      800
Stage8OffS      data    word      880
 
Stage1On        VAR     word      
Stage1Off       VAR     word 
Stage1Type      var     Bit 
Stage2On        VAR     word      
Stage2Off       VAR     word
Stage2Type      var     BIT       
Stage3On        VAR     word      
Stage3Off       VAR     word
Stage3Type      var     BIT       
Stage4On        VAR     word      
Stage4Off       VAR     word 
Stage4Type      var     BIT      
Stage5On        VAR     word      
Stage5Off       VAR     word  
Stage5Type      var     BIT     
Stage6On        VAR     word      
Stage6Off       VAR     word
Stage6Type      var     BIT       
Stage7On        VAR     word      
Stage7Off       VAR     word
Stage7Type      var     BIT       
Stage8On        VAR     word      
Stage8Off       VAR     word
Stage8Type      var     BIT          
     
Checker         var     byte
PreStage        var     byte
CurStage        var     Byte
NxtStage        var     byte
PreOn           var     word
PreOff          var     word
CurOn           Var     word
CurOff          var     word
NxtOff          var     word
NxtOn           var     word
LRPM            var     word
HRPM            var     word      
RPMTotal        VAR     Word 

BL              var     byte


OPTION_REG.7 = 0 'Pull Ups enabled
INTCON.7=0
ADCON0.0 =0
ADCON1 =7

StageCounter = 0

'---------Display Start-Up Info-------
Include "modedefs.bas"	' Mode definitions for Serout
Include "Elapsed.bas"
gosub ClearScreen
pause 200

gosub Read_Data

'------------Sets up backlighting--------------
Repeat
    Gosub Change_Stage
    Gosub Change_Type
    Gosub Change_Time
    Gosub SetBackLight
until Start = 0
'Repeat    'Transbrake button pushed                         
'  HDSRPM = 0
'  LDSRPM = 0
'  DSRPMCounter = 0
'Until Start = 1

Gosub StartTimer
Gosub ClearScreen
Serout LCD,T9600,["On"]

gosub StopTimer

Change_Stage:
    If UpStage = 0 then
       if StageCounter < 15 then
          StageCounter = StageCounter +1
       endif
       
       IF StageCounter = 15 then
          StageCounter = 0
       endif
    endif
    
    If DownStage = 0 then
       if StageCounter >0 then
          StageCounter = StageCounter -1
       endif
       
       IF StageCounter = 0 then
          StageCounter = 15
       endif
    endif
    
    Gosub Set_Display 
return

Change_Type:
  If Tool = 0 and Up1= 0 then
    If ActiveType = 0 then
       ActiveType = 1
    else
       ActiveType = 0
    endif
  endif
Return

Change_Time:
'----Change Seconds----
  If ActiveType = 1 then 'Changes On Time
    If Up1 = 0 then
       'Stage1on= Stage1On + 1
       CurOn = CurOn +100
    endif
    If Down1 = 0 Then
       CurOn = Curon - 100
    endif 
  endif
  
  If ActiveType = 0 then  'Changes Off Time
    If Up1 = 0 then
       'Stage1on= Stage1On + 1
       CurOff = CurOff +100
    endif
    If Down1 = 0 Then
       CurOff = CurOff - 100
    endif 
  endif
'----Change Tenths----
  If ActiveType = 1 then
    If Up01 = 0 then
       'Stage1on= Stage1On + 1
       CurOn = CurOn +10
    endif
    If Down01 = 0 Then
       CurOn = CurOn - 10
    endif 
  endif
  
  If ActiveType = 0 then
    If Up01 = 0 then
       'Stage1on= Stage1On + 1
       CurOff = CurOff +10
    endif
    If Down01 = 0 Then
       CurOff = CurOff - 10
    endif 
  endif
'----Change Hundreths----
  If ActiveType = 1 then
    If Up001 = 0 then
       'Stage1on= Stage1On + 1
       CurOn = CurOn +1
    endif
    If Down001 = 0 Then
       CurOn = CurOn - 1
    endif 
  endif
  
  If ActiveType = 0 then
    If Up001 = 0 then
       'Stage1on= Stage1On + 1
       CurOff = CurOff +1
    endif
    If Down001 = 0 Then
       CurOff = CurOff - 1
    endif 
  endif
  
  Gosub Set_Display 
  gosub Write_Data
  gosub Read_Data
return

Set_Display:
    Select Case StageCounter
    Case 1
         PreStage = 8
         CurStage = 1
         NxtStage = 2
         PreOn = Stage8On
         PreOff = Stage8Off
         CurOn = Stage1On
         CurOff = Stage1Off
         NxtOn = Stage2On
         NxtOff = Stage2Off
    ..........
    Case 8
         PreStage = 7
         CurStage = 8
         NxtStage = 1
         PreOn = Stage7On
         PreOff =Stage7Off
         CurOn = Stage8On
         CurOff = Stage8Off
         NxtOn = Stage1On
         NxtOff = Stage1Off
    end select 
    Gosub Display_Stage
Return 

Display_Stage:
gosub FirstLine
If ActiveType = 1 then
   gosub On_Channel
endif
If ActiveType = 0 then
   gosub Off_Channel
endif
Return




On_Channel:                              
   Serout LCD,T9600,[Prefix,CursorPS,61,#PreStage,Prefix,CursorPS,70,#PreOn,Prefix,CursorPS,75,#PreOff, Prefix,CursorPS,LcdLine3,#CurStage,Prefix,CursorPS,26,#CurOn, Prefix,CursorPS,31, #CurOff, Prefix,CursorPS,36,"<ON", Prefix,CursorPS,LcdLine4, #NxtStage, Prefix,CursorPS,90, #NxtOn, Prefix,CursorPS,95, #NxtOff]
return

Off_Channel:                              
   Serout LCD,T9600,[Prefix,CursorPS,61,#PreStage,Prefix,CursorPS,70,#PreOn,Prefix,CursorPS,75,#PreOff, Prefix,CursorPS,LcdLine3,#CurStage,Prefix,CursorPS,26,#CurOn, Prefix,CursorPS,31, #CurOff, Prefix,CursorPS,36,"<OFF", Prefix,CursorPS,LcdLine4, #NxtStage, Prefix,CursorPS,90, #NxtOn, Prefix,CursorPS,95, #NxtOff]
return 

Read_Data:
    Read 0, Stage1On.LowByte
    REad 1, Stage1On.HighByte
    Read 2, Stage1Off.LowByte
    REad 3, Stage1Off.HighByte
    ......
    Read 28, Stage8On.LowByte
    REad 29, Stage8On.HighByte
    Read 30, Stage8Off.LowByte
    REad 31, Stage8Off.HighByte
return

Write_Data:
    Write 0, Stage1On.LowByte
    Write 1, Stage1On.HighByte
    Write 2, Stage1Off.LowByte
    Write 3, Stage1Off.HighByte
    ..........
    Write 28, Stage8On.LowByte
    Write 29, Stage8On.HighByte
    Write 30, Stage8Off.LowByte
    Write 31, Stage8Off.HighByte
return