Odczyt id DS18B20 problem

Pytania, kody i porady dotyczące nie tylko Bascom.
ODPOWIEDZ
Awatar użytkownika
Michał6201
Posty: 146
Rejestracja: 03 paź 2015, 20:07

Odczyt id DS18B20 problem

Post autor: Michał6201 » 14 wrz 2025, 15:51

Cześć


Mam program, którym odczytywałem kiedyś ID DS18B20 przy użyciu zwykłego wyświetlacza LCD 16X2 i wszystko działało.

Chciałem dziś odczytać tym samym programem ale przy użyciu wyświetlacza OLED i niby odczytuje ID, ale wszystkie 8 części tego numery bardzo szybko wyświetla w jednym miejscu na 2 znakach.

W załączeniu ten mój kod. Prośba do Was o podpowiedź co jest nie tak w tym przypadku
  1.  $Regfile="m32adef.dat"
  2. $Crystal=8000000
  3. $hwstack=40
  4. $swstack=16
  5. $framesize=32
  6.  
  7.  
  8.    '
  9.    '  * OLED Initial Settings *
  10.    '
  11.    Const Rotate_180 = 0                                     'OLED screen installation direction (180degree rotation).
  12.                                                             ' (Connector: 0 = Right side, 1 = Left side)
  13.    Const Spi_wire_selection = 4                             'Select the number of lines for SPI connection.
  14.                                                             ' (3 = 3-wire: drawing spd low, 4 = 4-wire: drawing spd high)
  15.    '
  16. $lib "glcdSSD1322-SPI.lib"                                  'Embedded SSD1322 3.12inch 256x64 SPI library.
  17.    ' Specifies the connection port for OLED. Cs1 = [/CS] , Rst = [/RES] , A0 = [D/C] , Si = [SDIN] , Sclk = [SCLK]
  18.    Config Graphlcd = Color , Cs1 = Portc.6 , Rst = Portc.5 , A0 = Portc.4 , Si = Portc.3 , Sclk = Portc.2       '[Cs1]&[Rst] optional.
  19.  
  20.    ' Character drawing commands : [Lcdat Y , X , Character , FG , BG]
  21.    '   Y = Y(row) address (0 - 63) , X = X(column) address (0 - 255) , Character = String or variable to display
  22.    '   FG = Foreground Grayscale Value (0 - 15) , BG = Background Grayscale Value (0 - 15) / (0:dark - 15:bright)
  23.    '   Note: Since the SSD1322 writes 4-bit grayscale data in word units, set the X address in 4-dot intervals. (ex. 0,4,8 - 248,252)
  24.  
  25.    ' Command to draw BGC image data in RLE compressed format : [Showpic X , Y , label]
  26.    '   X = X(column) address (0 - 255), Y = Y (row)address (0 - 63), label = label of image data to display.
  27.    '     See the help for SHOWPIC command.
  28.    '   To create RLE compressed BGC image data from BMP images, use the LCD RGB-8 converter [LCDconvert.exe].
  29.    ' Below is a table that maps 8-bit BGC format RGB8 code (RRRG_GGBB) to a 4-bit grayscale brightness value (0 - 15).
  30.    Const _bgc_r2 = &B0000_1000                              'BGC RGB8 code [Red2]
  31.    Const _bgc_r1 = &B0000_0000                              'BGC RGB8 code [Red1]
  32.    Const _bgc_r0 = &B0000_0000                              'BGC RGB8 code [Red0]
  33.    Const _bgc_g2 = &B0000_0100                              'BGC RGB8 code [Green2]
  34.    Const _bgc_g1 = &B0000_0000                              'BGC RGB8 code [Green1]
  35.    Const _bgc_g0 = &B0000_0000                              'BGC RGB8 code [Green0]
  36.    Const _bgc_b1 = &B0000_0010                              'BGC RGB8 code [Blue1]
  37.    Const _bgc_b0 = &B0000_0000                              'BGC RGB8 code [Blue0]
  38.    ' By default, the intermediate luminance value for each of the colors R,G,B is the lower 4bits(0-15) of the grayscale luminance value.
  39.    ' Adjust the grayscale to match the color scheme of the original image.
  40.  
  41.    '
  42.    '  *****************
  43.    '  * Drawing Tests *
  44.    '  *****************
  45.    '
  46.  
  47.  
  48.          Glcdcmd &HC1 : Glcddata 30                            'Contrast setting. (0-255)
  49.           Glcdcmd &HAF
  50.              Glcdcmd &HA6
  51.  
  52.  
  53. 'Konfiguracja 1-WIRE dla DS18B20
  54. Config 1wire = PortD.7
  55.  
  56.  
  57. Dim Dsid(8) As Byte
  58. Dim Dsid1(8) As Byte
  59. Dsid(1) = 1wsearchfirst()
  60. Dsid1(1) = 1wsearchnext()
  61. Dim B As Byte
  62.  
  63.  
  64.    Do
  65.       Setfont Color8x8
  66.       Lcdat 5 , 0 , "ID DS18B20 (hex)" , 15 , 0
  67.  
  68.  
  69.       If Dsid(8) = Crc8(dsid(1) , 7) Then
  70.       For B = 1 To 8
  71.       Lcdat 20 , 10 , Hex(dsid(b)) , 15 , 0        ' Wyświetlenie ID czujnika DS18B20 w postaci HEX
  72.           Next
  73. End If
  74.    Loop
  75.    End
  76.  
  77.      $INCLUDE "color8x8.font"
  78.      $INCLUDE "color16x16.font"
Poradziłem sobie trochę w inny sposób jakby ręcznie i moim zdaniem bez sensu, ale teraz zadziałało i odczytałem całe ID czujnika.
Oto kod działający na OLED:
  1.  
  2.              $Regfile="m32adef.dat"
  3. $Crystal=8000000
  4. $hwstack=40
  5. $swstack=16
  6. $framesize=32
  7.  
  8.  
  9.    '
  10.    '  * OLED Initial Settings *
  11.    '
  12.    Const Rotate_180 = 0                                     'OLED screen installation direction (180degree rotation).
  13.                                                             ' (Connector: 0 = Right side, 1 = Left side)
  14.    Const Spi_wire_selection = 4                             'Select the number of lines for SPI connection.
  15.                                                             ' (3 = 3-wire: drawing spd low, 4 = 4-wire: drawing spd high)
  16.    '
  17. $lib "glcdSSD1322-SPI.lib"                                  'Embedded SSD1322 3.12inch 256x64 SPI library.
  18.    ' Specifies the connection port for OLED. Cs1 = [/CS] , Rst = [/RES] , A0 = [D/C] , Si = [SDIN] , Sclk = [SCLK]
  19.    Config Graphlcd = Color , Cs1 = Portc.6 , Rst = Portc.5 , A0 = Portc.4 , Si = Portc.3 , Sclk = Portc.2       '[Cs1]&[Rst] optional.
  20.  
  21.    ' Character drawing commands : [Lcdat Y , X , Character , FG , BG]
  22.    '   Y = Y(row) address (0 - 63) , X = X(column) address (0 - 255) , Character = String or variable to display
  23.    '   FG = Foreground Grayscale Value (0 - 15) , BG = Background Grayscale Value (0 - 15) / (0:dark - 15:bright)
  24.    '   Note: Since the SSD1322 writes 4-bit grayscale data in word units, set the X address in 4-dot intervals. (ex. 0,4,8 - 248,252)
  25.  
  26.    ' Command to draw BGC image data in RLE compressed format : [Showpic X , Y , label]
  27.    '   X = X(column) address (0 - 255), Y = Y (row)address (0 - 63), label = label of image data to display.
  28.    '     See the help for SHOWPIC command.
  29.    '   To create RLE compressed BGC image data from BMP images, use the LCD RGB-8 converter [LCDconvert.exe].
  30.    ' Below is a table that maps 8-bit BGC format RGB8 code (RRRG_GGBB) to a 4-bit grayscale brightness value (0 - 15).
  31.    Const _bgc_r2 = &B0000_1000                              'BGC RGB8 code [Red2]
  32.    Const _bgc_r1 = &B0000_0000                              'BGC RGB8 code [Red1]
  33.    Const _bgc_r0 = &B0000_0000                              'BGC RGB8 code [Red0]
  34.    Const _bgc_g2 = &B0000_0100                              'BGC RGB8 code [Green2]
  35.    Const _bgc_g1 = &B0000_0000                              'BGC RGB8 code [Green1]
  36.    Const _bgc_g0 = &B0000_0000                              'BGC RGB8 code [Green0]
  37.    Const _bgc_b1 = &B0000_0010                              'BGC RGB8 code [Blue1]
  38.    Const _bgc_b0 = &B0000_0000                              'BGC RGB8 code [Blue0]
  39.    ' By default, the intermediate luminance value for each of the colors R,G,B is the lower 4bits(0-15) of the grayscale luminance value.
  40.    ' Adjust the grayscale to match the color scheme of the original image.
  41.  
  42.    '
  43.    '  *****************
  44.    '  * Drawing Tests *
  45.    '  *****************
  46.    '
  47.  
  48.  
  49.          Glcdcmd &HC1 : Glcddata 30                            'Contrast setting. (0-255)
  50.           Glcdcmd &HAF
  51.              Glcdcmd &HA6
  52.  
  53.  
  54. 'Konfiguracja 1-WIRE dla DS18B20
  55. Config 1wire = PortD.7
  56.  
  57.  
  58. Dim Dsid(8) As Byte
  59. Dim Dsid1(8) As Byte
  60. Dsid(1) = 1wsearchfirst()
  61. Dsid1(1) = 1wsearchnext()
  62. Dim B As Byte
  63.  
  64.  
  65.    Do
  66.       Setfont Color8x8
  67.       Lcdat 5 , 0 , "ID DS18B20 (hex)" , 15 , 0
  68.  
  69.  
  70.       If Dsid(8) = Crc8(dsid(1) , 7) Then
  71.       For B = 1 To 1
  72.       Lcdat 20 , 0 , Hex(dsid(b)) , 15 , 0        ' Wyświetlenie ID czujnika DS18B20 w postaci HEX
  73.           Next
  74. End If
  75. For B = 2 To 2
  76.   Lcdat 20 , 20 , Hex(dsid(b)) , 15 , 0
  77.   next
  78. '  end if
  79.   For B = 3 To 3
  80.     Lcdat 20 , 40 , Hex(dsid(b)) , 15 , 0
  81.     next
  82.  '   end if
  83.          For B = 4 To 4
  84.     Lcdat 20 , 60 , Hex(dsid(b)) , 15 , 0
  85.     next
  86.   '  end if
  87.        For B = 5 To 5
  88.     Lcdat 20 , 80 , Hex(dsid(b)) , 15 , 0
  89.         next
  90.      '   end if
  91.             For B = 6 To 6
  92.     Lcdat 20 , 100 , Hex(dsid(b)) , 15 , 0
  93.         next
  94.       '  end if
  95.             For B = 7 To 7
  96.     Lcdat 20 , 120 , Hex(dsid(b)) , 15 , 0
  97.         next
  98.       '  end if
  99.                      For B = 8 To 8
  100.     Lcdat 20 , 140 , Hex(dsid(b)) , 15 , 0
  101.         next
  102.      '   end if
  103.  
  104.  
  105.  
  106.    Loop
  107.    End
  108.  
  109.      $INCLUDE "color8x8.font"
  110.      $INCLUDE "color16x16.font"
ODPOWIEDZ