欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 464|回復: 0
打印 上一主題 下一主題
收起左側

23LC1024 SRAM 綜合測試(BASCOM-AVR版)

[復制鏈接]
跳轉到指定樓層
樓主


程序:
rem Main.bas file generated by New Project wizard
rem
rem Created:   周日 10月 5 2025
rem Processor: ATmega16
rem Compiler:  BASCOM-AVR

rem 23LC1024 SRAM 綜合測試(BASCOM-AVR版)

$regfile = "m16def.dat"
$crystal = 8000000
$hwstack = 64
$swstack = 64
$framesize = 64

' 引腳定義
'如果不配置Noss = 1就不能使用硬件spi的ss管腳Portb.2!。。∵@時須選擇其他端口管腳單獨配置如PortD.2。
'或者加實物上拉電阻可取消Portb.2 = 1
'Config PinD.2 = Output
'PortD.2 = 1
Cs Alias Portb.4

' SPI 配置
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Noss = 1
Spiinit

' 變量定義
Dim Write_byte As Byte , Read_byte As Byte
Dim Temp As Byte
Dim i As Byte , j As Byte
Dim Test_data As Byte
Dim Addr As Long
Dim Error_count As Word
Dim Addr_high As Byte
Dim Addr_mid As Byte
Dim Addr_low As Byte
Dim Pass_count As Word

' 串口配置
'Config Com1 = 9600 , Parity = None , Stopbits = 1 , Databits = 8
$baud = 9600
' 聲明子程序
Declare Sub Spi_write()
Declare Sub Spi_read()
Declare Sub Test_single_address()
Declare Sub Test_multiple_addresses()
Declare Sub Test_sequential_addresses()
Declare Sub Test_boundary_addresses()
Declare Sub Test_data_patterns()

' 主程序
Print
Print "   ========================================"
Print "        23LC1024 SRAM 綜合測試"
Print "   ========================================"
Print

Waitms 1000

' 運行各種測試
Call Test_single_address
Call Test_multiple_addresses
Call Test_sequential_addresses
Call Test_boundary_addresses
Call Test_data_patterns

Print
Print "   ========================================"
Print "   所有測試已完成!"
Print "   ========================================"

Do
   ' 主循環
Loop
End

' SPIWrite子程序
Sub Spi_write()
   Addr_high = Addr / 65536
   Addr_mid = Addr / 256
   Addr_low = Addr And &HFF

   Reset Cs
   Temp = &H02 : Spiout Temp , 1                    ' WRITE命令
   Spiout Addr_high , 1                             ' 地址高字節
   Spiout Addr_mid , 1                              ' 地址中字節
   Spiout Addr_low , 1                              ' 地址低字節
   Spiout Write_byte , 1                            ' 數據
   Set Cs
   Waitms 5                                         ' Write周期等待
End Sub

' SPI讀子程序
Sub Spi_read()
   Addr_high = Addr / 65536
   Addr_mid = Addr / 256
   Addr_low = Addr And &HFF

   Reset Cs
   Temp = &H03 : Spiout Temp , 1                    ' READ命令
   Spiout Addr_high , 1                             ' 地址高字節
   Spiout Addr_mid , 1                              ' 地址中字節
   Spiout Addr_low , 1                              ' 地址低字節
   Spiin Read_byte , 1                              ' 讀取數據
   Set Cs
End Sub

' 測試1: 單地址基本功能
Sub Test_single_address()
   Print "   測試 1:單地址基本功能"
   Print "   ----------------------------------------"

   Addr = &H1234
   Write_byte = &HA5

   Call Spi_write
   Call Spi_read

   Print "   Address: 0x" ; Hex(addr) ; "  Write: 0x" ; Hex(write_byte) ; "  Read: 0x" ; Hex(read_byte)

   If Write_byte = Read_byte Then
      Print "   >>> 單地址測試:通過"
   Else
      Print "   >>> 單一地址測試:失敗"
   End If
   Print
End Sub

' 測試2: 多地址測試
Sub Test_multiple_addresses()
   Print "   測試 2:多地址測試"
   Print "----------------------------------------"

   Error_count = 0

   For i = 1 To 10
      Addr = i * &H1000                            ' 遞增地址
      Write_byte = i * &H11                        ' 遞增數據

      Call Spi_write
      Call Spi_read

      Print "   Addr: 0x" ; Hex(addr) ; "  Write: 0x" ; Hex(write_byte) ; "  Read: 0x" ; Hex(read_byte)

      If Write_byte <> Read_byte Then
         Incr Error_count
         Print "   *** 地址 0x 處出錯" ; Hex(addr)
      End If
   Next i

   Pass_count = 10 - Error_count
   Print "   多個地址測試: " ;Pass_count ;"/10 通過"
   Print
End Sub

' 測試3: 連續地址測試
Sub Test_sequential_addresses()
   Print "   測試 3:連續地址測試"
   Print "   ----------------------------------------"

   Error_count = 0
   Addr = &H5000

   For i = 0 To 15
      Write_byte = &H40 + i                        ' 連續數據

      Call Spi_write
      Call Spi_read

      If Write_byte <> Read_byte Then
         Incr Error_count
         Print "   *** 在順序地址處出現錯誤 " ; i
      End If
      Addr = Addr + 1
Print  "   Addr: 0x" ; Hex(addr) ;"Write 0x" ; Hex(write_byte);" Read 0x" ;Hex(read_byte)
   Next i

   Pass_count = 16 - Error_count
   Print"   連續地址測試: " ;Pass_count ;"/16 通過"
   Print
End Sub

' 測試4: 邊界地址測試
Sub Test_boundary_addresses()
   Print "   測試 4:邊界地址測試"
   Print "   ----------------------------------------"

   Error_count = 0

   ' 測試邊界地址
   Write_byte = &H5A

   ' 最低地址
   Addr = &H00000
   Call Spi_write
   Call Spi_read
   Print "   邊界 0x" ; Hex(addr) ; " : Write 0x" ; Hex(write_byte) ; " Read 0x" ; Hex(read_byte)
   If Write_byte <> Read_byte Then Incr Error_count

   ' 第一頁結束
   Addr = &H000FF
   Call Spi_write
   Call Spi_read
   Print "   邊界 0x" ; Hex(addr) ; " : Write 0x" ; Hex(write_byte) ; " Read 0x" ; Hex(read_byte)
   If Write_byte <> Read_byte Then Incr Error_count

   ' 最后頁開始
   Addr = &H1FF00
   Call Spi_write
   Call Spi_read
   Print "   邊界 0x" ; Hex(addr) ; " : Write 0x" ; Hex(write_byte) ; " Read 0x" ; Hex(read_byte)
   If Write_byte <> Read_byte Then Incr Error_count

   ' 最高地址 (128KB)
   Addr = &H1FFFF
   Call Spi_write
   Call Spi_read
   Print "   邊界 0x" ; Hex(addr) ; " : Write 0x" ; Hex(write_byte) ; " Read 0x" ; Hex(read_byte)
   If Write_byte <> Read_byte Then Incr Error_count

   Pass_count = 4 - Error_count
   Print "   邊界地址測試: " ;Pass_count ;"/4 通過"
   Print
End Sub

' 測試5: 數據模式測試
Sub Test_data_patterns()
   Print "   測試 5:數據模式測試"
   Print "----------------------------------------"

   Error_count = 0
   Addr = &H8000

   ' 測試各種數據模式
   Write_byte = &H00                               ' 全0
   Call Spi_write : Call Spi_read
   Print "   模式 1:Write 0x" ; Hex(write_byte) ; " Read 0x" ; Hex(read_byte)
   If Write_byte <> Read_byte Then Incr Error_count
   Addr = Addr + 1

   Write_byte = &HFF                               ' 全1
   Call Spi_write : Call Spi_read
   Print "   模式 2:Write 0x" ; Hex(write_byte) ; " Read 0x" ; Hex(read_byte)
   If Write_byte <> Read_byte Then Incr Error_count
   Addr = Addr + 1

   Write_byte = &H55                               ' 01010101
   Call Spi_write : Call Spi_read
   Print "   模式 3:Write 0x" ; Hex(write_byte) ; " Read 0x" ; Hex(read_byte)
   If Write_byte <> Read_byte Then Incr Error_count
   Addr = Addr + 1

   Write_byte = &HAA                               ' 10101010
   Call Spi_write : Call Spi_read
   Print "   模式 4:Write 0x" ; Hex(write_byte) ; " Read 0x" ; Hex(read_byte)
   If Write_byte <> Read_byte Then Incr Error_count
   Addr = Addr + 1

   Write_byte = &H0F                               ' 00001111
   Call Spi_write : Call Spi_read
   Print "   模式 5:Write 0x" ; Hex(write_byte) ; " Read 0x" ; Hex(read_byte)
   If Write_byte <> Read_byte Then Incr Error_count
   Addr = Addr + 1

   Write_byte = &HF0                               ' 11110000
   Call Spi_write : Call Spi_read
   Print "   模式 6:Write 0x" ; Hex(write_byte) ; " Read 0x" ; Hex(read_byte)
   If Write_byte <> Read_byte Then Incr Error_count
   Addr = Addr + 1

   Write_byte = &H33                               ' 00110011
   Call Spi_write : Call Spi_read
   Print "   模式 7:Write 0x" ; Hex(write_byte) ; " Read 0x" ; Hex(read_byte)
   If Write_byte <> Read_byte Then Incr Error_count
   Addr = Addr + 1

   Write_byte = &HCC                               ' 11001100
   Call Spi_write : Call Spi_read
   Print "   模式 8:Write 0x" ; Hex(write_byte) ; " Read 0x" ; Hex(read_byte)
   If Write_byte <> Read_byte Then Incr Error_count

   Pass_count = 8 - Error_count
   Print "   數據模式測試: " ;Pass_count ;"/8 通過"
   Print
End Sub

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表