read/write large number from 0 to 15000 to EEPROM

General discussion on mikroBasic PRO for PIC.
Author
Message
MAN
Posts: 437
Joined: 11 Jan 2006 18:32
Location: Brasil

Re: read/write large number from 0 to 15000 to EEPROM

#16 Post by MAN » 24 Aug 2010 01:19

hi guys;
sohailimdad wrote: please post your code including circuit which help others to understand, that the delay is not necessary between write and read cycles. :idea: .

waiting for your new idea :idea:
regards
sohail
Well like janni say, he's is not a mBasic user then probably that janni's don't have one code segment in mB but he's know well about. :wink: So I
wrote some functions that not need delay to work with ME's EEPROM lib for Read has two choose one..

This is a small example, these functions can be improved as needed. The idea is to write/read any value up to 32bit's or any other data type.

Code: Select all

sub function Read_E2P_8To32Bit(dim Start_Addr as byte, dim const DataType as byte) as longWord   
dim Count as byte
    Count = 0
    result = 0
    while WR_EECON1_bit wend
    FSR1PTR = @Result
    POSTINC1 = Eeprom_Read(Start_Addr)
    inc(Count)
    while (Count < DataType)
          POSTINC1 = Eeprom_Read(Start_Addr+Count)
          inc(Count)
    wend
end sub


sub procedure Write_E2P_8To32bit(dim Start_addr as byte,dim const Datatype as byte, dim DataPtr as ^byte)
dim Count as byte
FSR1PTR = DataPtr
Count   = 0
    while (Count < DataType)
      EEPROM_Write(Start_addr+Count, POSTINC1)
      inc(Count)
    wend
end sub


sub function Read_E2PROM_8_32bit(dim Start_addr as byte, dim const DataType as byte) as longword
dim Count as byte
    while WR_EECON1_bit wend
    Count = 0
    result = Eeprom_Read(Start_Addr+Count)
    inc(Count)
    while (Count < DataType)
      result = (result << 8) or Eeprom_Read(Start_Addr+Count)
      inc(Count)
    wend
end sub
Parameters;

"Start_addr"+Offset, for any eeprom address up to 256Bytes.

"DataType"
1-> 08 data bit's (Byte)
2-> 16 data bit's(integer,word)
3-> 24 data bit's(any value between this range, but return will be ever 4Bytes)
4-> 32 data bit's(longword, longint, float)

"DataPtr" = the pointer that holds it's value data. Can be a byte, word, longint,longword, float or any given array from 0 up to 255.

note:
when working with values, depending of the data type the return value will need to be cast to it's type.

I hope that helps.

Regards;
Working with you, for you!
MAN

sohailimdad
Posts: 16
Joined: 26 Jun 2010 04:27

Re: read/write large number from 0 to 15000 to EEPROM

#17 Post by sohailimdad » 24 Aug 2010 17:26

MAN wrote:hi guys;
sohailimdad wrote: please post your code including circuit which help others to understand, that the delay is not necessary between write and read cycles. :idea: .

waiting for your new idea :idea:
regards
sohail
Well like janni say, he's is not a mBasic user then probably that janni's don't have one code segment in mB but he's know well about. :wink: So I
wrote some functions that not need delay to work with ME's EEPROM lib for Read has two choose one..

This is a small example, these functions can be improved as needed. The idea is to write/read any value up to 32bit's or any other data type.

Code: Select all

sub function Read_E2P_8To32Bit(dim Start_Addr as byte, dim const DataType as byte) as longWord   
dim Count as byte
    Count = 0
    result = 0
    while WR_EECON1_bit wend
    FSR1PTR = @Result
    POSTINC1 = Eeprom_Read(Start_Addr)
    inc(Count)
    while (Count < DataType)
          POSTINC1 = Eeprom_Read(Start_Addr+Count)
          inc(Count)
    wend
end sub


sub procedure Write_E2P_8To32bit(dim Start_addr as byte,dim const Datatype as byte, dim DataPtr as ^byte)
dim Count as byte
FSR1PTR = DataPtr
Count   = 0
    while (Count < DataType)
      EEPROM_Write(Start_addr+Count, POSTINC1)
      inc(Count)
    wend
end sub


sub function Read_E2PROM_8_32bit(dim Start_addr as byte, dim const DataType as byte) as longword
dim Count as byte
    while WR_EECON1_bit wend
    Count = 0
    result = Eeprom_Read(Start_Addr+Count)
    inc(Count)
    while (Count < DataType)
      result = (result << 8) or Eeprom_Read(Start_Addr+Count)
      inc(Count)
    wend
end sub
Parameters;

"Start_addr"+Offset, for any eeprom address up to 256Bytes.

"DataType"
1-> 08 data bit's (Byte)
2-> 16 data bit's(integer,word)
3-> 24 data bit's(any value between this range, but return will be ever 4Bytes)
4-> 32 data bit's(longword, longint, float)

"DataPtr" = the pointer that holds it's value data. Can be a byte, word, longint,longword, float or any given array from 0 up to 255.

note:
when working with values, depending of the data type the return value will need to be cast to it's type.

I hope that helps.

Regards;

Dear Man
Professional approach great
thanks for help and share ideas/code. :D :idea: :)

regards
sohail

sohailimdad
Posts: 16
Joined: 26 Jun 2010 04:27

Re: read/write large number from 0 to 15000 to EEPROM

#18 Post by sohailimdad » 23 Jan 2011 14:46

Dear team

thanks for support
i use following code and this works as per my project requirements please check it, i like to share it.

Code: Select all

sub procedure t_eprom       'total  write to EEPROM
    dim x as byte
       'write lower byte
   x = lo(totalvote)
   EEPROM_Write(5,x)
   delay_ms(20)

   x = hi(totalvote)
   EEPROM_Write(6, x)
   delay_ms(20)
end sub
                          ' write to EEPROM
sub procedure candvs(dim cadv as integer, dim ee_add as byte)
     dim p as byte

     p = lo(cadv)
    EEPROM_Write(ee_add,p)
    delay_ms(20)

    p = hi(cadv)
    EEPROM_Write(ee_add+1, p)

    delay_ms(20)
end sub

sub procedure Disp_cResults    'disp total  on LCD from EEProm internal
       dim tvdisp  as integer
       dim tvtxt, cadtxt as string[8]
       dim i as byte
       dim addv as byte
       addv = 7
    for i = 1 to 16

       tvdisp = 256*Eeprom_Read(addv+1) + Eeprom_Read(addv)
       IntToStr(tvdisp, tvtxt)
       ByteToStr(i, cadtxt)
       Lcd_Cmd(_LCD_CLEAR)               ' Clear display
       Lcd_Cmd(_LCD_CURSOR_OFF)          ' Cursor off
       Lcd_Out(1,1,"Cad No:")                 ' Write text in first row
       lcd_out(1,9,cadtxt)
       LCD_out(2,1,"result")
       Lcd_Out(2,9,tvtxt)                 'cand total
       addv = addv+2
       delay_ms(1100)
    next i
end sub

sub procedure Disp_TResults   'disp total result on LCD from EEProm internal
       dim tvdisp  as integer
       dim tvtxt as string[8]
       tvotedisp = 256*Eeprom_Read(6) + Eeprom_Read(5)
       IntToStr(tvdisp, tvtxt)
       Lcd_Cmd(_LCD_CLEAR)               ' Clear display
       Lcd_Cmd(_LCD_CURSOR_OFF)          ' Cursor off
       Lcd_Out(1,1,"Total:")                 ' Write text in first row
       Lcd_Out(1,7,tvtxt)                 ' Write text in first row
       delay_ms(2000)        'delay for access key
end sub
sub procedure initDisp_tvResult    'disp total result on LCD from EEProm internal
       dim tvdisp  as integer
       dim tvtxt as string[8]
       tvotedisp = 256*Eeprom_Read(6) + Eeprom_Read(5)
       IntToStr(tvdisp, tvtxt)
       Lcd_Cmd(_LCD_CLEAR)               ' Clear display
       Lcd_Cmd(_LCD_CURSOR_OFF)          ' Cursor off
       Lcd_Out(1,1,"Total:")                 ' Write text in first row
       Lcd_Out(1,7,tvtxt)                 ' Write text in first row
       delay_ms(5000)        'delay for access key
end sub
please check and if any suggestion for improvement must share.

regards
sohail

Post Reply

Return to “mikroBasic PRO for PIC General”