AT25/45 DATAFLASH add programm on VB6 (C++)

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Code for reading a Sound file using the library mat.midlight.eu/wiki/index.php?title=SPI_DataFlash_Library

      Flash_get_info Flashbuffer(1)
      Setfont Color16x16
      Lcdat 94 , 4 , "Flash ID:" ; HEX(Flashbuffer(3)) ; " " ; HEX(Flashbuffer(4)) ; " " ; HEX(Flashbuffer(5)) ; " " ; HEX(Flashbuffer(6)), Violet , BLACK
      If Flashbuffer(4) = &H12 Then
      FLASH = "W25Q04" : SECT = 2047
      ELSEIf Flashbuffer(4) = &H13 Then
      FLASH = "W25Q08" : SECT = 4095
      ELSEIf Flashbuffer(4) = &H14 Then
      FLASH = "W25Q08" : SECT = 4095
      ELSEIf Flashbuffer(4) = &H15 Then
      FLASH = "W25Q16" : SECT = 8191
      ELSEIf Flashbuffer(4) = &H16 Then
      FLASH = "W25Q32" : SECT = 16383
      ELSEIf Flashbuffer(4) = &H17 Then
      FLASH = "W25Q64" : SECT = 32767
      ELSEIf Flashbuffer(4) = &H20 Then
      FLASH = "W25Q128" : SECT = 65535
      ELSE
      FLASH = "Unknow!" : SECT = 2047
      END IF
      ' Setfont Color8x8
      Lcdat 104 , 4 , "Flash:" ; FLASH , ORANGE , BLACK
      FOR Address = 0 TO SECT
      Flash_beginread Address ' , Flashbuffer(1) , 256
      FOR N = 1 TO 256
      Flashbuffer(N) = Flash_readbyte()
      D = Flashbuffer(N)
      Pwm1B = D
      Waitus 51 ' 14745600Hz
      NEXT N
      NEXT Address
      Flash_endread
    • $regfile = "m328pdef.dat"
      $crystal = 22118400
      $hwstack = 100
      $swstack = 100
      $framesize = 250
      $baud = 115200
      '*******************************************************************************
      A0 ALIAS PIND.2
      A1 ALIAS PIND.3
      A2 ALIAS PIND.4
      A3 ALIAS PIND.5
      Config PORTD.2 = INPUT
      Config PORTD.3 = INPUT
      Config PORTD.4 = INPUT
      Config PORTD.5 = INPUT
      A0 = 1 : A1 = 1 : A2 = 1 : A3 = 1

      GREEN Alias PortC.2
      RED Alias PortC.3
      Config GREEN = Output
      Config RED = Output
      Speaker Alias PortD.6
      '*******************************************************************************
      $lib "lcd_i2c_pcf8574.lib"
      '$lib "YwRobot_Lcd_i2c.lib"
      $lib "Lcd_i2c_v3.lib"
      Dim _out_rw As Byte
      Dim _out_e2 As Byte
      Dim _lcd_e As Byte
      Dim _backlight As Byte
      Dim Lcd_backlight As Byte
      Config Scl = PortC.5
      Config Sda = PortC.4
      Config I2cdelay = 1
      Const Pcf8574_lcd = &H4E ' PCF8574 address
      Const Pcf_e2_is_output = 1
      Const Pcf_rw_is_output = 1
      Const Pcf_rs = 0
      Const Pcf_rw = 1
      Const Pcf_e1 = 2 '2
      Const Pcf_e2 = 3 '3
      Const Pcf_d4 = 4
      Const Pcf_d5 = 5
      Const Pcf_d6 = 6
      Const Pcf_d7 = 7
      Const PCF_BL = 1
      _lcd_e = 192 ' 64=E2 (3 & 4 stering) 128=E1 (1 & 2 string) 192=E1+E2 (all 4 strings)
      _out_rw = 1
      _out_e2 = 1
      _backlight = 0
      Lcd_backlight = 1
      '*******************************************************************************
      Select_memory Alias Portb.2
      Set Select_memory
      '***************
      Const Buff1_write = &H84
      Const Buff2_write = &H87
      Const Buff1_mem_write = &H83
      Const Buff2_mem_write = &H86
      Const Current_page_read = &HD2
      Const Current_page_write = &H82
      Const Deep_power_down = &HB9
      Const Resume_deep_power_down = &HAB

      Dim Buf(528) As Byte
      Dim Page_mem As Word
      Dim A As Word
      Dim Temp As Byte
      Dim N As Byte , Temp1 As Word
      Declare Sub Db45down
      Declare Sub Db45up
      Declare Sub Wordout()
      Declare Sub Byteout()
      Declare Sub Bytein()
      Declare Sub Page_read(byval Page_mem As Word)
      Declare Sub Page_write(byval Page_mem As Word)
      Declare Sub Buffer1_to_flash(byval Page_mem As Word)
      Declare Sub Buffer1_write
      Config Spi = Hard , Interrupt = OFF , Data Order = Msb , Master = Yes , Polarity = High , Phase = 1 , Clockrate = 4 , Noss = 1

      Dim Spi_read(256) As Byte
      Dim Spi_write(256) As Byte
      dim i as word
      dim flash_addr1 as long

      Dim Cim(5) As Byte
      Dim AB(4) As Byte
      Dim Pagge As Word , Addresse As Word

      Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Down , Prescale = 1
      Config PORTB.1 = Output
      '**********************************************************************
      Spiinit
      Toggle _out_rw
      MAIN:
      Do
      ' YOUR PROGRAM ;)
      GOTO AT45DB
      LOOP
      '*******************************************************************************
      AT45DB:
      CLS
      Reset Select_memory
      Waitus 10
      CALL Db45up()
      Waitus 10
      Set Select_memory
      Wait 1
      Locate 1 , 1 : Lcd "Reading Device...."
      Reset Select_memory
      Waitus 10
      Cim(1) = &H57
      Spiout Cim(1) , 1
      Spiin AB(1) , 1 ' read A(1) from SPI
      Waitus 5
      Set Select_memory
      Locate 2 , 1 : Lcd Cim(1) ; " " ; AB(1)
      Shift AB(1) , Right , 3
      AB(1) = AB(1) And &H07
      GREEN = 1
      If AB(1) = 1 Then
      Locate 3 , 1 : MSG = "AT45DB011 264 / 512" : LCD MSG
      Elseif AB(1) = 2 Then
      Locate 3 , 1 : MSG = "AT45DB021 264 / 1024" : LCD MSG
      Elseif AB(1) = 3 Then
      Locate 3 , 1 : MSG = "AT45DB041 264 / 2048" : LCD MSG
      Elseif AB(1) = 4 Then
      Locate 3 , 1 : MSG = "AT45DB081 264 / 4096" : LCD MSG
      Elseif AB(1) = 5 Then
      Locate 3 , 1 : MSG = "AT45DB161 528 / 4096" : LCD MSG
      Elseif AB(1) = 6 Then
      Locate 3 , 1 : MSG = "AT45DB321 528 / 8192" : LCD MSG ' now I use AT45DB321D (I also tried DB161E(D) , DB081D(B) , DB041D(B) , DB011B) CHECKED PERSONALLY ME ALL WORKS
      End If
      Wait 2
      CLS
      Locate 1 , 1 : Lcd "KEY0 - PROGRAMM MODE"
      Locate 2 , 1 : Lcd "KEY1 - PLAY AUDIO"
      LOCATE 3 , 1 : LCD "KEY2 - ERASE ALL"
      LOCATE 4 , 1 : LCD "KEY3 - EXIT"
      DO
      IF A0 = 0 THEN
      RED = 1 : GOSUB TAD : WAITMS 250
      RED = 0 ': GOTO PRGMODE ' IN THE PROCESS OF IMPLEMENTATION
      END IF
      IF A1 = 0 THEN
      GREEN = 1 : GOSUB TAD : WAITMS 250
      GREEN = 0 : GOTO PLAYFLASH
      END IF
      IF A2 = 0 THEN
      CLS
      LOCATE 1 , 1 : LCD "*ERASE ALL*"
      RED = 1 : GOSUB TAD : WAITMS 250
      RED = 0 ': GOTO FERASE ' IN THE PROCESS OF IMPLEMENTATION
      END IF
      IF A3 = 0 THEN
      CLS
      GREEN = 1 : GOSUB TAD : WAITMS 250
      GREEN = 0 : CALL Db45down() : GOTO MAIN
      END IF
      LOOP
      '*******************************************************************************
      ' PLAYBACK SUBPROGRAM WAV FILE 8 BIT MONO 16000Hz (THE FREQUENCY MAY BE MORE OR LESS BUT THEN YOU HAVE TO CHOOSE Waitus)
      PLAYFLASH:
      CLS
      LOCATE 1 , 1 : LCD "PLAY AUDIO! [AT45DB]"
      LOCATE 2 , 1 : LCD MSG
      Locate 3 , 1 : Lcd "Address:"
      LOCATE 4 , 1 : LCD "Page:"
      FOR Pagge = 0 TO 8191
      Call Page_read(Pagge)
      FOR NN = 1 TO 528
      N = Buf(NN)
      Pwm1A = N
      Waitus 55
      IF A3 = 0 THEN
      GOTO AT45DB
      END IF
      NEXT NN
      NEXT Pagge
      WAIT 2 : GOSUB TADAN
      GOTO AT45DB
      Return
      '**********************************************************************
      TAD:
      Sound Speaker , 133 , 285
      Sound Speaker , 77 , 260
      RETURN
      '*******************************************************************************
      TADAN:
      Sound Speaker , 213 , 271
      Sound Speaker , 125 , 237
      RETURN
      '*******************************************************************************
      '-------------------------------------------------------------------------------
      Sub Page_read(byval Page_mem As Word)
      '-------------Flash read subroutine---------------------------------------------
      'Subroutine to read a given page of memory
      'Login ------- page_Mem (0-8191)
      'Output ------ buf (528) 528 byte array
      Reset Select_memory 'select flash ram
      N = Current_page_read 'command Current_page_read
      Call Byteout() 'out 3 bytes of adress
      Shift Page_mem , Left , 2 'For 264 pages the value is 1, for 528 pages the value is 2

      A = Page_mem
      Call Wordout()
      N = 0
      Call Byteout()
      '-------------
      Call Byteout()
      Call Byteout()
      Call Byteout()
      Call Byteout()
      'transmit 32 dont care bits
      For Temp1 = 1 To 528
      Call Bytein()
      Buf(temp1) = N
      Next Temp1
      Set Select_memory
      End Sub
      '*******************************************************************************
      Sub Buffer1_to_flash(byval Page_mem As Word)
      '-------------Flash write subroutine---------------------------------------------
      'The subroutine for writing buffer 1 to the memory page
      'Login ------- page_Mem (0-8191)
      Reset Select_memory
      N = Buff1_mem_write ' command write buffer to flash
      Call Byteout()
      Shift Page_mem , Left , 2 'For 264 pages the value is 1, for 528 pages the value is 2

      A = Page_mem
      Call Wordout()
      N = 0
      Call Byteout()
      Set Select_memory 'deselect memory
      Waitms 30
      End Sub
      '*******************************************************************************
      Sub Buffer1_write
      Reset Select_memory
      N = Buff1_write ' command write in buffer
      Call Byteout()
      N = &H00 '
      Call Byteout()
      N = &H00 '
      Call Byteout()
      N = &H00 '
      Call Byteout()
      'Set Select_memory
      End Sub
      '*******************************************************************************
      Sub Page_write(page_mem As Word)
      Reset Select_memory
      N = Current_page_write ' command write buffer to flash
      Call Byteout()
      Shift Page_mem , Left , 2 'For 264 pages the value is 1, for 528 pages the value is 2
      A = Page_mem
      Call Wordout()
      N = 0
      Call Byteout()
      'Waitms 30
      End Sub
      '*******************************************************************************
      Sub Bytein()
      !ldi r23,0
      !Out Spdr , R23
      Wairh:
      !sbis spsr, spif
      !rjmp wairh
      !in r23,spdr
      !sts {n},r23
      End Sub
      '*******************************************************************************
      Sub Byteout
      !lds r23, {n}
      !out spdr, r23
      Waitresult:
      !sbis spsr, spif
      !rjmp waitresult
      End Sub
      '*******************************************************************************
      Sub Db45down
      Reset Select_memory
      N = Deep_power_down
      Call Byteout()
      Set Select_memory
      End Sub
      '*******************************************************************************
      Sub Db45up
      Reset Select_memory
      N = Resume_deep_power_down
      Call Byteout()
      Set Select_memory
      End Sub
      '*******************************************************************************
      End

      If someone has the opportunity and desire to help remake the file loader from a computer to a microcontroller (there are ready-made loaders written in Visual BASIC), I have not yet managed to figure out how to write a receiving program in Bascom.

      The post was edited 2 times, last by Sonic ().

    • Here is an archive with loaders for PC (one in Visual Basic, the second in C), but I think that the programs for the PC themselves can not be altered, for them you just need to write a program in Bascom.

      (Immediately I apologize for the translation, since I use Google translator, if something is not clear, then say I will try to write in other words) :D
      Files
      • LOADER.zip

        (795.4 kB, downloaded 4 times, last: )