Wyświetlacz LCD z enkoderem od drukarki 3D

Miejsce na posty nie związane z powyższymi
ODPOWIEDZ
Awatar użytkownika
Jacek
Posty: 384
Rejestracja: 25 kwie 2016, 19:14

Wyświetlacz LCD z enkoderem od drukarki 3D

Post autor: Jacek » 18 lis 2022, 16:58

Witam - po modyfikacji mojej drukarki 3D Sovol SV01 został mi panel sterujący lcd, enkoder, i buzer.
Chciałbym wykorzystać całość w pewnym projekcie panel ma oznaczenia 12864ZW-10 ESD4K pinologię znalazłem
https://github.com/MarlinFirmware/Marli ... CREALITY.h czy jest do tego lcd biblioteka w Bascom
pozdrawiam Jacek.
Awatar użytkownika
Jacek
Posty: 384
Rejestracja: 25 kwie 2016, 19:14

Re: Wyświetlacz LCD z enkoderem od drukarki 3D

Post autor: Jacek » 21 lis 2022, 19:11

Witam - wyświetlacz działa https://www.youtube.com/watch?v=BCh3mmu4hgI kod znalazłem na elektroda.pl https://www.elektroda.pl/rtvforum/topic3747495.html
autor tematu napisał że jest to kod Bartka.
pozdrawiam Jacek.
Awatar użytkownika
Jacek
Posty: 384
Rejestracja: 25 kwie 2016, 19:14

Re: Wyświetlacz LCD z enkoderem od drukarki 3D

Post autor: Jacek » 27 lis 2022, 18:58

Witam kod testowy do wyświetlacza z drukarki 3D
program główny
  1. '****************************************************************
  2. $regfile = "m328pdef.dat"
  3. $crystal = 16000000
  4. $hwstack = 64
  5. $swstack = 64
  6. $framesize = 128
  7. $baud = 115200
  8. $eepleave
  9. Config Submode = New
  10. '****************************************************************
  11. 'KONFIGURACJA PORTU COM
  12. Config Com1 = 38400 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
  13. Config Serialin = Buffered , Size = 128
  14. Config Serialout = Buffered , Size = 128
  15. Enable Serial
  16. '****************************************************************
  17.  'Debug Off
  18. Debug On
  19. '****************************************************************
  20. $include "Subs\Blink_.inc"
  21. $include "Subs\Display_.inc"
  22. $include "Subs\LCD_ST7920_seriell_declare.inc"
  23. $include "Subs\LCD_ST7920_seriell_sub.inc"
  24. '****************************************************************
  25.     'KONFIGURACJA TIMER'ÓW
  26. Config Timer1 = Timer , Prescale = 8
  27. On Timer1 Przertimer1
  28. Enable Timer1
  29.     'Config Timer1 = Pwm , Pwm = 8 , Compare_a_pwm = Clear_up , Compare_b_pwm = Clear_down , Prescale = 1
  30. Config Timer2 = Pwm , Compare_a_pwm = Clear_up , Prescale = 1024
  31. '****************************************************************
  32. Enable Interrupts
  33. '****************************************************************
  34.  '   *** PINY  ****
  35.  '   LCD ST9720      ATMEGA        LCD 12864ZW-10 ESD4K
  36.  '   RS  (4)   -      PORTD.7                 SPI ---> SS
  37.  '   R/W (5)   -      PORTB.0               SPI --->  MOSI
  38.  '   EN  (6)   -      PORTB.1                SPI ---> SCK
  39.  '   PBS (15) -GROUND                          GND
  40.  '   RST (17)  -    reset processor           RESET
  41. '****************************************************************
  42.     'KONFIGURACJA PORTÓW
  43. Config Portb.5 = Output : Portb.5 = 0                                           'LED_LIVE
  44. '****************************************************************
  45.     'ALIASY PORTÓW
  46. Led_live Alias Portb.5                                                          'Dioda Led sygnalizująca prace układu
  47. '****************************************************************
  48.     'ZMIENNE   CZASU
  49. Dim Timer_tikx10 As Byte                                                        'zmienna liczaca przepełnienie timera
  50. Dim Timertikx100 As Byte
  51. Dim Timertikx200 As Byte
  52. Dim Timer_tik_flag As Byte
  53. Flaga10ms Alias Timer_tik_flag.0
  54. Flaga100ms Alias Timer_tik_flag.1
  55. Flaga500ms Alias Timer_tik_flag.2
  56. Flaga1s Alias Timer_tik_flag.3
  57. Flaga2s Alias Timer_tik_flag.4
  58. Flaga2_5s Alias Timer_tik_flag.5
  59.     'zostaly jeszce trzy wolne flagi
  60.     ' a uzylem tylko jednego bajtu
  61.     ' Paweł - pikczu
  62. '****************************************************************
  63. Waitms 500
  64. '****************************************************************
  65. 'USTAWIENIA POCZATKOWE
  66. ' Hbl on                                                                         'Turn Backlight on
  67. '****************************************************************
  68.     'PĘTLA GŁÓWNA
  69. '****************************************************************
  70. Do
  71. '****************************************************************
  72.    If Timer_tikx10 >= 10 Then                                                   'jesli uplynelo 100ms to
  73.       Flaga100ms = 1                                                            'ustaw flage uplynelo 100ms
  74.       Incr Timertikx100
  75.       Timer_tikx10 = 0                                                          ''zeruj liczenie
  76.    End If
  77.    If Timertikx100 >= 10 Then                                                   'jesli uplynela sekunda
  78.       Flaga1s = 1                                                               'ustaw flage sekundy
  79.       Incr Timertikx200
  80.       Timertikx100 = 0                                                          'zeruj liczenie
  81.    End If
  82.    If Timertikx200 >= 2 Then
  83.       Flaga2s = 1
  84.       Timertikx200 = 0
  85.    End If
  86.    If Flaga10ms = 1 Then
  87.       Flaga10ms = 0
  88.    End If
  89.    If Flaga100ms = 1 Then                                                       'co 100ms
  90.       Call Display_
  91.       Flaga100ms = 0                                                            'wyzeruj Flaga100ms
  92.    End If
  93.    If Flaga1s = 1 Then                                                          'co 1 sekundę
  94.       Call Blink_
  95.       Flaga1s = 0
  96.    End If
  97.    If Flaga2s = 1 Then                                                          'co2s
  98.       Flaga2s = 0
  99.    End If
  100.  
  101. '****************************************************************
  102. Loop
  103. '****************************************************************
  104.  
  105. $include "Font\My6_8.font"
  106. $include "Font\font16x16.font"
  107. $include "Font\My12_16.font"
  108. '****************************************************************
  109. 'include used BGF
  110. $inc Pic , Nosize , "BGF\abc.bgf"                                               '32x32 pixel
  111. $inc Pic1 , Nosize , "BGF\time.bgf"                                             '32x32 Pixel
  112. $inc Pic2 , Nosize , "BGF\music.bgf"                                            '32x32 Pixel
  113. '****************************************************************
  114. End
  115. '****************************************************************
  116.     'PODPROGRAM PRZERWAŃ TIMER1
  117. Przertimer1:
  118.    Timer1 = 45536                                                               'wstawienie do Timer1 wartości 45536
  119.    Incr Timer_tikx10
  120.    If Timer_tikx10 = 1 Then
  121.       Set Flaga10ms
  122.    End If
  123. Return
  124. '****************************************************************

sub od migania ledem co by było widać że atmega się nie powiesiła
  1.        'MRUGANIE DIODĄ LED CO 1 SEKUNDĘ
  2.     ' CO BY BYŁO WIDAĆ ŻE UKŁAD ŻYJE
  3. $nocompile
  4. Sub Blink_
  5.    Toggle Led_live
  6. End Sub

sub od wyświetlania
  1. $nocompile
  2. Sub Display_
  3.  
  4.      Lcds_init 1
  5.  Lcds_cls 1                                                                     'Init LCD in Text-Mode
  6.    Lcds 1 , 1 , "Test LCD-ST7920"
  7.    Lcds 2 , 1 , "Display 4x16"
  8.    Lcds 3 , 1 , "Controller is"
  9.    Lcds 4 , 1 , "HD44780 like"
  10.    Wait 5
  11.  
  12.    Lcds_init 2                                                                  'Init LCD in Grafic-Mode
  13.    Lcds_cls 2
  14.    Call Lcds_text( "Bascom AVR" , 1 , 1 , 1)                                    'Call Lcds_text( "Wiertarka PCB" , 1 , 1 , 1)                                   'Draw Text to Buffer
  15.    Call Lcds_text( "LCD ST7920" , 1 , 16 , 3)                                   'Call Lcds_text( "SQ2EER" , 1 , 16 , 3)                                    'Draw Text to Buffer
  16.    Call Lcds_text( "Grafic 128 x 64" , 1 , 37 , 1)                              'Draw Text to Buffer
  17.    Call Lcds_text( "Version 1.0 /rt" , 1 , 52 , 1)                              'Draw Text to Buffer
  18.    Call Lcds_show()                                                             'Show Buffer
  19.    Wait 5
  20.  
  21.    Lcds_cls 2
  22.    Call Lcds_box(54 , 22 , 74 , 42 , 0 , 0)
  23.    Call Lcds_show()
  24.    Wait 2
  25.    Call Lcds_box(54 , 22 , 74 , 42 , 1 , 0)
  26.    Call Lcds_show()
  27.    Wait 2
  28.  
  29.    Lcds_cls 2
  30.    Call Lcds_circle(64 , 32 , 20 , 0)
  31.    Call Lcds_show()
  32.    Wait 2
  33.    Call Lcds_fill_circle(64 , 32 , 20 , 0)
  34.    Call Lcds_show()
  35.    Wait 2
  36.  
  37.    Call Lcds_line(10 , 22 , 118 , 22 , 1 , 0)
  38.    Call Lcds_show()
  39.    Call Lcds_line(10 , 42 , 118 , 42 , 1 , 0)
  40.    Call Lcds_show()
  41.    Wait 2
  42.  
  43.    Lcds_cls 2
  44.  
  45.    Call Lcds_text( "Show BGF-Files" , 24 , 1 , 1)                               'Draw Text to Buffer
  46.    Restore Pic                                                                  'first restore Pic
  47.    Call Lcds_show_bgf(8 , 15)                                                   'write BGF to Buffer
  48.    Restore Pic1
  49.    Call Lcds_show_bgf(48 , 15)                                                  'write BGF to Buffer
  50.    Restore Pic2
  51.    Call Lcds_show_bgf(88 , 15)                                                  'write BGF to Buffer
  52.    Call Lcds_show()
  53.    Wait 2
  54.    Lcds_cls 2
  55. End Sub

sub deklaracji wyświetlacza (chyba :oops: )
  1. $nocompile
  2.  
  3. '*******************************************************************************
  4. '*  Definitions for Serial-Driver ST7920                                       *
  5. '*******************************************************************************
  6.  
  7. Declare Sub Lcds(byval Y1 As Byte , Byval X1 As Byte , Byval Text1 As String * 20)
  8. Declare Sub Lcds_cls(byval D_type As Byte)
  9. Declare Sub Lcds_init(byval D_type As Byte)
  10. Declare Sub Hbl(byval Ea As Byte)
  11.  
  12. Declare Sub Lcds_command(byval Ch As Byte)
  13. Declare Sub Lcds_data(byval Ch As Byte)
  14. Declare Sub Lcds_wdata(byval Ch As Byte)
  15.  
  16. Config Base = 0
  17.  
  18. Dim Text As String * 20 , Texta As String * 20
  19. Dim Text_o(20) As Byte At Text Overlay                                          'ASCII-Werte der LCD Ausgabe                                         '
  20. Dim Cx As String * 1
  21. Dim Pos As Byte
  22. Dim Zp As Byte
  23. Dim Zlen As Byte
  24. Dim Lcd_zeilen As Byte , Lcd_spalten As Byte
  25.  
  26. Dim Zl1 As String * 20 , Zl2 As String * 20 , Zl3 As String * 20 , Zl4 As String * 20
  27. Dim Zz As Byte                                                                  'Zeichenzähler
  28. Dim Zi As Byte                                                                  'Zeichen-Indexzähler
  29.  
  30. Dim Bl As Byte                                                                  'LCD-HintergrundBeLeuchtung
  31. Dim Ch As Byte , Cha As Byte
  32.  
  33. Dim Lcd_cout As Byte
  34. Dim Lcd_dout As Byte
  35.  
  36. Dclock Alias Portb.1
  37. Dsdata Alias Portb.0
  38. Lcd_hbl Alias Portd.7
  39. Config Lcd_hbl = Output
  40.  
  41. Const On = 1                                                                    'HBL Einschalten
  42. Const Off = 0                                                                   'HBL Ausschalten
  43.  
  44. 'Declares for Grafic-Display
  45. Declare Sub Lcds_show()
  46.  
  47. Declare Sub Lcds_text(byval S As String , Byval Xoffset As Byte , Byval Yoffset As Byte , Byval Fontset As Byte)
  48. Declare Sub Lcds_set_pixel(byval Xp As Byte , Byval Yp As Byte , Byval Colo As Byte)
  49.  
  50. Declare Sub Lcds_fill_circle(byval X As Byte , Byval Y As Byte , Byval Radius As Byte , Byval Color1 As Byte)
  51. Declare Sub Lcds_circle(byval X As Byte , Byval Y As Byte , Byval Radius As Byte , Byval Color As Byte)
  52. Declare Sub Lcds_line(byval X1 As Byte , Byval Y1 As Byte , Byval X2 As Byte , Byval Y2 As Byte , Byval Pen_width As Byte , Byval Color As Byte)
  53. Declare Sub Lcds_box(byval Xs As Byte , Byval Ys As Byte , Byval Xe As Byte , Byval Ye As Byte , Byval Fill As Byte , Byval Color As Byte)
  54. Declare Sub Lcds_show_bgf(byval Xs As Byte , Byval Ys As Byte)
  55.  
  56. Dim Y_cmd As Byte , X_cmd As Byte , X_pos As Byte , Y_pos As Byte
  57. Dim I_byte As Byte , Iw_byte As Byte , I_bit As Byte
  58. Dim O_byte As Byte , O_bit As Integer
  59. Dim I_page As Integer , O_page As Integer , I_page_byte As Integer
  60. Dim W_page_byte As Integer , W_page As Byte , D_pos As Integer
  61.  
  62. Const White = &HFF
  63. Const Black = &H00
  64. Dim Ddata(1025) As Byte                                                         'Display Data Buffer
  65. Dim Ddata2(16) As Byte                                                          'Work-Buffer for ST7920

sub od komunikacji z wyświetlaczem (chyba :oops: )
  1. $nocompile
  2.  
  3. '*******************************************************************************
  4. '*  Init LCD for ST7920  Controller Serial-Mode                   24.02.15/rt  *
  5. '*******************************************************************************
  6. Sub Lcds_init(byval D_type As Byte)                                             '1=Text / 2=Grafic
  7.    Lcds_command 3                                                               'Init LCD with Value 3 for Command (RS=0)
  8.    Waitms 10
  9.  
  10.    Lcds_command 3                                                               'Init LCD with Value 3 for Command (RS=0)
  11.    Waitms 10
  12.  
  13.    Lcds_command 3                                                               'Init LCD with Value 3 for Command (RS=0)
  14.    Waitms 10
  15.  
  16.    Lcds_command 12                                                              'Display control
  17.    Waitms 1
  18.  
  19.    Lcds_command 1                                                               'Dislpay clear
  20.    Waitms 5
  21.  
  22.    Lcds_command 6                                                               'Entry mode
  23.    Waitms 1
  24.  
  25.    Select Case D_type
  26.       Case 1
  27.          Lcds_command 36                                                        'Set Text-Mode
  28.          Waitms 5
  29.          Lcds_command 32                                                        'Set Text-Mode
  30.       Case 2
  31.          Lcds_command 38                                                        'Set Grafic-Mode
  32.          Waitms 5
  33.          Lcds_command 2                                                         'Set Grafic-Mode
  34.    End Select
  35. End Sub
  36.  
  37.  
  38. '*******************************************************************************
  39. '*  Clear Screen Command  1 = Text-Mode   2 = Grafic-Mode                      *
  40. '*******************************************************************************
  41. Sub Lcds_cls(byval D_type As Byte)
  42.    Select Case D_type
  43.       Case 1                                                                    'Clear in Text-Mode
  44.          Lcds_command 1
  45.          Zl1 = Space(20)
  46.          Zl2 = Space(20)
  47.          Zl3 = Space(20)
  48.          Zl4 = Space(20)
  49.          Waitms 100
  50.       Case 2                                                                    'Clear in Grafic-Mode
  51.          For D_pos = 0 To 1025
  52.             Ddata(d_pos) = 0
  53.          Next D_pos
  54.          Call Lcds_show()
  55.    End Select
  56. End Sub
  57.  
  58.  
  59. '*******************************************************************************
  60. '*  Hintergrundbeleuchtung EIN/AUS                                             *
  61. '*******************************************************************************
  62. Sub Hbl(byval Ea As Byte)
  63.    Bl = Ea
  64.    If Ea = 0 Then Reset Lcd_hbl
  65.    If Ea = 1 Then Set Lcd_hbl
  66.    Waitms 10
  67. End Sub
  68.  
  69.  
  70. '*******************************************************************************
  71. '*  Anzeige Wert/String Zeile Y1 Position X1                                   *
  72. '*******************************************************************************
  73. Sub Lcds(byval Y1 As Byte , Byval X1 As Byte , Byval Text1 As String * 20)
  74.  
  75.    If Y1 = 1 Then
  76.       Zz = Len(text1)
  77.       Mid(zl1 , X1 , Zz) = Text1
  78.       Texta = Zl1
  79.       Ch = 128                                                                  'Cursor-Position Row 1, Position 1
  80.    End If
  81.  
  82.    If Y1 = 2 Then
  83.       Zz = Len(text1)
  84.       Mid(zl2 , X1 , Zz) = Text1
  85.       Texta = Zl2
  86.       Ch = 144
  87.    End If
  88.  
  89.    If Y1 = 3 Then
  90.       Zz = Len(text1)
  91.       Mid(zl3 , X1 , Zz) = Text1
  92.       Texta = Zl3
  93.       Ch = 136
  94.    End If
  95.  
  96.    If Y1 = 4 Then
  97.       Zz = Len(text1)
  98.       Mid(zl4 , X1 , Zz) = Text1
  99.       Texta = Zl4                                                               'Cursor-Position Row 4, Position 1
  100.       Ch = 152
  101.  
  102.    End If
  103.  
  104.    Lcds_command Ch                                                              'Set Cursor-Position
  105.  
  106.    For Zi = 1 To zz
  107.      Cx = Mid(texta , Zi , 1)
  108.      Ch = Cx
  109.      Lcds_data Ch
  110.    Next Zi
  111.  
  112. End Sub
  113.  
  114.  
  115. lcds_out:
  116.    Ch = Pos
  117.    Set Ch.7                                                                     'Set Bit 7 FOR Command "Set DDRAM"
  118.    Lcds_command Ch                                                              'Set Cursor-Position
  119.    Waitus 100
  120.  
  121.    Zlen = Len(text)                                                             'LEN of Display-Text
  122.    For Zp = 1 To Zlen
  123.      Ch = Text_o(zp)
  124.      Lcds_data Ch
  125.    Next Zp
  126. Return
  127.  
  128.  
  129. Sub Lcds_command(byval Ch As Byte)
  130.    Reset Lcd_cout.1
  131.    Lcds_wdata Ch
  132. End Sub
  133.  
  134.  
  135. Sub Lcds_data(byval Ch As Byte)
  136.    Set Lcd_cout.1
  137.    Lcds_wdata Ch
  138. End Sub
  139.  
  140.  
  141. Sub Lcds_wdata(byval Ch As Byte)
  142.    Lcd_cout.7 = 1                                                               'Sync
  143.    Lcd_cout.6 = 1                                                               'Sync
  144.    Lcd_cout.5 = 1                                                               'Sync
  145.    Lcd_cout.4 = 1                                                               'Sync
  146.    Lcd_cout.3 = 1                                                               'Sync
  147.    Lcd_cout.2 = 0                                                               'R/W
  148.    Lcd_cout.0 = 0                                                               'leer
  149.    Shiftout Dsdata , Dclock , Lcd_cout , 0 , 8
  150.  
  151.    Lcd_dout = 0
  152.    Lcd_dout.7 = Ch.7
  153.    Lcd_dout.6 = Ch.6
  154.    Lcd_dout.5 = Ch.5
  155.    Lcd_dout.4 = Ch.4
  156.    Shiftout Dsdata , Dclock , Lcd_dout , 0 , 8
  157.  
  158.    Lcd_dout = 0
  159.    Lcd_dout.7 = Ch.3
  160.    Lcd_dout.6 = Ch.2
  161.    Lcd_dout.5 = Ch.1
  162.    Lcd_dout.4 = Ch.0
  163.    Shiftout dsdata , Dclock , Lcd_dout , 0 , 8
  164. End Sub
  165.  
  166. '*******************************************************************************
  167. ' All Grafic-Routines (c) by Heiko Kipnik
  168. '
  169. '*******************************************************************************
  170. ' Show BASCOM Graphic Files (BGF)
  171. ' use the Graphic converter in Uncompressed Mode
  172. ' The Sub do not support RLE compression
  173. ' Set Xs=Start Xpoint  Ys=Start Ypoint
  174. '*******************************************************************************
  175. Sub Lcds_show_bgf(byval Xs As Byte , Byval Ys As Byte)
  176.    Local Xz As Byte , Yz As Byte , Col As Byte
  177.    Local Bnr As Byte , Xdum As Byte , Xend As Byte , Yend As Byte
  178.    Read Yend                                                                    'Read Height
  179.    Read Xend                                                                    'Read Width
  180.  
  181.    Yend = Yend + Ys                                                             'Set end point
  182.    Xend = Xend + Xs                                                             'Set end point
  183.  
  184.    Decr Xend
  185.    Decr Yend
  186.  
  187.    For Yz = Ys To Yend                                                          'Ystart to Yend
  188.      For Xz = Xs To Xend Step 8                                                 'Step 8 Pixel for one Byte
  189.        Read Col                                                                 'Read BGF file 1Byte = 8 Pixel
  190.        Xdum = Xz                                                                'X Start Point
  191.       For Bnr = 7 To 0 Step -1                                                  'MSB first Set 8Bit
  192.        If Col.bnr = 0 Then                                                      'Read pixel
  193.         Call Lcds_set_pixel(xdum , Yz , White)                                  'Set Pixel
  194.        Else
  195.         Call Lcds_set_pixel(xdum , Yz , Black)                                  'Clear Pixel
  196.        End If
  197.        Incr Xdum                                                                'Incr X pointer
  198.       Next
  199.      Next
  200.    Next
  201. End Sub
  202.  
  203. '*******************************************************************************
  204. ' Draw Box Xs-Ys to Xe-Ye fill=1 Fill -- Fill=0 no fill
  205. ' Color=1 Black Pixel  Color=0 White Pixel
  206. '*******************************************************************************
  207. Sub Lcds_box(byval Xs As Byte , Byval Ys As Byte , Byval Xe As Byte , Byval Ye As Byte , Byval Fill As Byte , Byval Color As Byte)
  208.     Local Xza As Byte , Yza As Byte
  209.  
  210.   If Fill = 1 Then
  211.    For Yza = Ys To Ye
  212.     For Xza = Xs To Xe
  213.       Call Lcds_set_pixel(xza , Yza , Color)
  214.     Next
  215.    Next
  216.   Else
  217.    Call Lcds_line(xs , Ys , Xe , Ys , 1 , Color)
  218.    Call Lcds_line(xs , Ye , Xe , Ye , 1 , Color)
  219.  
  220.    Call Lcds_line(xs , Ys , Xs , Ye , 1 , Color)
  221.    Call Lcds_line(xe , Ys , Xe , Ye , 1 , Color)
  222.   End If
  223. End Sub
  224.  
  225. '*******************************************************************************
  226. ' Set or Clear a Pixel to X-Y Position  Colo=1 Set Pixel  Colo=0 Clear Pixel
  227. ' and write Data to Display-Array
  228. '*******************************************************************************
  229. Sub Lcds_set_pixel(byval Xp As Byte , Byval Yp As Byte , Byval Colo As Byte)
  230.    Local B1 As Byte , Zeiger As Word , Bitnr As Byte
  231.    Decr Yp
  232.    B1 = Yp / 8
  233.    Zeiger = B1 * 128
  234.    Zeiger = Zeiger + Xp
  235.  
  236.    Bitnr = Yp Mod 8
  237.    If Colo = Black Then
  238.       Ddata(zeiger).bitnr = 1
  239.    Else
  240.       Ddata(zeiger).bitnr = 0
  241.    End If
  242. End Sub
  243.  
  244. '*******************************************************************************
  245. ' Updated the Display whith Display-Array
  246. '*******************************************************************************
  247. Sub Lcds_show()
  248.    O_byte = 1
  249.    O_bit = 7
  250.    For I_page = 0 To 7
  251.       For I_bit = 0 To 7
  252.          For I_byte = 0 To 127
  253.             O_byte = I_byte / 8
  254.             Iw_byte = I_byte + 1
  255.  
  256.              'Text = "BitI  " + Str(i_bit) + "  "
  257.              'Lcda 1 , 1 , Text
  258.              'Text = "ByteI " + Str(iw_byte) + "  "
  259.              'Lcda 2 , 1 , Text
  260.              'Text = "ByteO " + Str(o_byte) + "  "
  261.              'Lcda 3 , 1 , Text
  262.              'Text = "BitO  " + Str(o_bit) + "  "
  263.              'Lcda 4 , 1 , Text
  264.  
  265.              'Wait 1
  266.             O_page = I_page * 128
  267.             I_page_byte = O_page + I_byte
  268.             W_page_byte = I_page_byte + 1
  269.             'Toggle Ddata(w_page_byte).i_bit
  270.             Ddata2(o_byte).o_bit = Ddata(w_page_byte).i_bit
  271.             Decr O_bit
  272.             If O_bit = -1 Then O_bit = 7
  273.          Next I_byte
  274.  
  275.          X_pos = 0
  276.          For D_pos = 0 To 15 Step + 2                                           'Display one row 2 x 8Bit
  277.  
  278.             If I_page < 4 Then
  279.                Y_pos = I_page * 8
  280.                X_cmd = X_pos + 128
  281.             End If
  282.  
  283.             If I_page > 3 Then
  284.                W_page = I_page - 4
  285.                Y_pos = W_page * 8
  286.                X_cmd = X_pos + 136                                              'Command Grafic 128 + 8 Position
  287.             End If
  288.  
  289.             Y_pos = Y_pos + I_bit
  290.             Y_cmd = Y_pos + 128
  291.  
  292.             Lcds_command Y_cmd
  293.             Lcds_command X_cmd
  294.             Lcds_data Ddata2(d_pos)
  295.             Lcds_data Ddata2(d_pos + 1)
  296.             Incr X_pos
  297.          Next D_pos
  298.  
  299.       Next I_bit
  300.    Next I_page
  301. End Sub
  302.  
  303.  
  304. '*******************************************************************************
  305. 'LCD_Text  String -- X -- Y Start -- Font
  306. '*******************************************************************************
  307. Sub Lcds_text(byval S As String , Xoffset As Byte , Yoffset As Byte , Fontset As Byte)
  308.    Local Tempstring As String * 1 , Temp As Word                                'Dim local the variables
  309.    Local A As Byte , Pixels As Byte , Count As Byte , Carcount As Byte , Lus As Byte
  310.    Local Row As Byte , Block As Byte , Byteseach As Byte , Blocksize As Byte , Dummy As Byte
  311.    Local Colums As Byte , Columcount As Byte , Rowcount As Byte , Stringsize As Byte
  312.    Local Xpos As Byte , Ypos As Byte , Pixel As Word , Pixelcount As Byte
  313.    Local Offset As Word
  314.  
  315.    Stringsize = Len(s) - 1                                                      'Size of the text string -1 because we must start with 0
  316.    Select Case Fontset
  317.       Case 1 :
  318.          Block = Lookup(0 , My6_8)                                              'Add or remove here fontset's that you need or not,
  319.          Byteseach = Lookup(1 , My6_8)
  320.          Blocksize = Lookup(2 , My6_8)
  321.          Dummy = Lookup(3 , My6_8)
  322.  
  323.       Case 2 :
  324.          Block = Lookup(0 , Font16x16)
  325.          Byteseach = Lookup(1 , Font16x16)
  326.          Blocksize = Lookup(2 , Font16x16)
  327.          Dummy = Lookup(3 , Font16x16)
  328.          '
  329.       Case 3 :
  330.          Block = Lookup(0 , My12_16)
  331.          Byteseach = Lookup(1 , My12_16)
  332.          Blocksize = Lookup(2 , My12_16)
  333.          Dummy = Lookup(3 , My12_16)
  334.    End Select
  335.    Colums = Blocksize / Block                                                   'Calculate the numbers of colums
  336.    Row = Block * 8                                                              'Row is always 8 pixels high = 1 byte, so working with row in steps of 8.
  337.    Row = Row - 1                                                                'Want to start with row=0 instead of 1
  338.    Colums = Colums - 1                                                          'Same for the colums
  339.    For Carcount = 0 To Stringsize                                               'Loop for the numbers of caracters that must be displayed
  340.       Temp = Carcount + 1                                                       'Cut the text string in seperate caracters
  341.       Tempstring = Mid(s , Temp , 1)
  342.       Offset = Asc(tempstring) - 32                                             'Font files start with caracter 32
  343.       Offset = Offset * Blocksize
  344.       Offset = Offset + 4
  345.       Temp = Carcount * Byteseach
  346.       Temp = Temp + Xoffset
  347.       For Rowcount = 0 To Row Step 8                                            'Loop for numbers of rows
  348.          A = Rowcount + Yoffset
  349.          Xpos = Temp
  350.          For Columcount = 0 To Colums                                           'Loop for numbers of Colums
  351.             Select Case Fontset
  352.                Case 1 : Pixels = Lookup(offset , My6_8)
  353.                Case 2 : Pixels = Lookup(offset , Font16x16)
  354.                Case 3 : Pixels = Lookup(offset , My12_16)
  355.             End Select
  356.             Ypos = A
  357.             For Pixelcount = 0 To 7                                             'Loop for 8 pixels to be set or not
  358.                Pixel = Pixels.0                                                 'Set the pixel (or not)
  359.                If Pixel = 0 Then
  360.  
  361.                   Call Lcds_set_pixel(xpos , Ypos , White)
  362.                Else
  363.                   Call Lcds_set_pixel(xpos , Ypos , Black)
  364.                End If
  365.                Shift Pixels , Right                                             'Shift the byte 1 bit to the right so the next pixel comes availible
  366.                Incr Ypos                                                        'Each pixel on his own spot
  367.             Next Pixelcount
  368.  
  369.             Incr Offset
  370.             Incr Xpos                                                           'Do some calculation to get the caracter on the correct Xposition
  371.          Next Columcount
  372.       Next Rowcount
  373.    Next Carcount
  374. End Sub
  375.  
  376.  
  377. '*******************************************************************************
  378. ' Draw Fill Circle  X-Y Center - Radius - Color=1 set Pixel  Color=0 clear pixel
  379. '*******************************************************************************
  380. Sub Lcds_fill_circle(byval X As Byte , Byval Y As Byte , Byval Radius As Byte , Byval Color1 As Byte)
  381.    Local Xy_radius As Integer , Zahly As Integer , Zahlx As Integer , Y1 As Integer , X1 As Integer
  382.    Local Y11 As Integer , X11 As Integer , Xy As Integer , X2 As Byte , Y2 As Byte
  383.    Xy_radius = Radius * Radius
  384.    Y1 = -radius
  385.    X1 = -radius
  386.  
  387.    For Zahly = Y1 To Radius
  388.       Y11 = Zahly * Zahly
  389.       For Zahlx = X1 To Radius
  390.          X11 = Zahlx * Zahlx
  391.          Xy = X11 + Y11
  392.          If Xy <= Xy_radius Then
  393.             X2 = X + Zahlx
  394.             Y2 = Y + Zahly
  395.             Call Lcds_set_pixel(x2 , Y2 , Color1)
  396.          End If
  397.       Next
  398.    Next
  399.  
  400. End Sub
  401. '*******************************************************************************
  402. ' Draw Circle  X-Y Center - Radius - Color=1 set Pixel  Color=0 clear pixel
  403. '*******************************************************************************
  404. Sub Lcds_circle(byval X As Byte , Byval Y As Byte , Byval Radius As Byte , Byval Color As Byte)
  405.    Local X0 As Byte , Y0 As Byte , Error As Integer
  406.    Local Xp As Byte , Yp As Byte , Xe As Byte , Ye As Byte
  407.  
  408.    Error = -radius
  409.    Xp = Radius
  410.    Yp = 0
  411.  
  412.    While Xp >= Yp
  413.       X0 = X + Xp : Y0 = Y + Yp
  414.       Call Lcds_set_pixel(x0 , Y0 , Color)
  415.       X0 = X - Xp : Y0 = Y + Yp
  416.       Call Lcds_set_pixel(x0 , Y0 , Color)
  417.       X0 = X + Xp : Y0 = Y - Yp
  418.       Call Lcds_set_pixel(x0 , Y0 , Color)
  419.       X0 = X - Xp : Y0 = Y - Yp
  420.       Call Lcds_set_pixel(x0 , Y0 , Color)
  421.  
  422.       X0 = X + Yp : Y0 = Y + Xp
  423.       Call Lcds_set_pixel(x0 , Y0 , Color)
  424.       X0 = X - Yp : Y0 = Y + Xp
  425.       Call Lcds_set_pixel(x0 , Y0 , Color)
  426.       X0 = X + Yp : Y0 = Y - Xp
  427.       Call Lcds_set_pixel(x0 , Y0 , Color)
  428.       X0 = X - Yp : Y0 = Y - Xp
  429.       Call Lcds_set_pixel(x0 , Y0 , Color)
  430.  
  431.       Error = Error + Yp
  432.       Incr Yp
  433.       Error = Error + Yp
  434.  
  435.       If Error >= 0 Then
  436.          Decr Xp
  437.          Error = Error - Xp
  438.          Error = Error - Xp
  439.       End If
  440.  
  441.    Wend
  442.  
  443. End Sub
  444. '*******************************************************************************
  445. ' Draw line X - Y Start to X - Y End - Pen Width - Color=1 set Pixel  Color=0 clear pixel
  446. '*******************************************************************************
  447. Sub Lcds_line(byval X1 As Byte , Byval Y1 As Byte , Byval X2 As Byte , Byval Y2 As Byte , Byval Pen_width As Byte , Byval Color As Byte)
  448.    Local Y As Word , X As Word , X_diff As Single , Y_diff As Single , Pos As Word
  449.    Local X_factor As Single , X_pos As Word , Y_pos As Word , Base As Word , Pen_count As Byte
  450.    Local Xpoint As Byte , Ypoint As Byte
  451.    Y_diff = Y2 - Y1
  452.    X_diff = X2 - X1
  453.    Pos = 0
  454.  
  455.    X_factor = Abs(y_diff)
  456.    Y = X_factor
  457.    X_factor = Abs(x_diff)
  458.    X = X_factor
  459.  
  460.    If Y > X Then
  461.       X_factor = X_diff / Y_diff
  462.       If Y1 > Y2 Then
  463.          Swap Y1 , Y2
  464.          Base = X2
  465.       Else
  466.          Base = X1
  467.       End If
  468.       For Y = Y1 To Y2
  469.          X_diff = Pos * X_factor
  470.          X_pos = X_diff
  471.          X_pos = X_pos + Base
  472.          Xpoint = X_pos
  473.          Ypoint = Y
  474.          Call Lcds_set_pixel(xpoint , Ypoint , Color)
  475.          For Pen_count = 1 To Pen_width
  476.             Call Lcds_set_pixel(xpoint , Ypoint , Color)
  477.             Incr Xpoint
  478.          Next Pen_count
  479.          Incr Pos
  480.       Next Y
  481.    Else
  482.       X_factor = Y_diff / X_diff
  483.       If X1 > X2 Then
  484.          Swap X1 , X2
  485.          Base = Y2
  486.       Else
  487.          Base = Y1
  488.       End If
  489.       For X = X1 To X2
  490.          Y_diff = Pos * X_factor
  491.          Y_pos = Y_diff
  492.          Y_pos = Y_pos + Base
  493.          Xpoint = X
  494.          Ypoint = Y_pos
  495.          Call Lcds_set_pixel(xpoint , Ypoint , Color)
  496.          For Pen_count = 1 To Pen_width
  497.             Call Lcds_set_pixel(xpoint , Ypoint , Color)
  498.             Incr Ypoint
  499.          Next Pen_count
  500.          Incr Pos
  501.       Next X
  502.    End If
  503.  
  504. End Sub

program kompiluje się nie ma błędów ale po załadowaniu do atmegi ta się wiesza a na lcd kaszanka.
pozdrawiam Jacek.
Awatar użytkownika
niveasoft
Posty: 1213
Rejestracja: 17 sie 2015, 12:13
Kontakt:

Re: Wyświetlacz LCD z enkoderem od drukarki 3D

Post autor: niveasoft » 30 lis 2022, 6:11

Trudno coś powiedzieć nie łącząc tego a trochę nie ma czasu.
U siebie mam to też podłaczone do jakiegoś modułu CNC, ale z Mega2560.
  1. $regfile = "m2560def.dat"                                             '256K FLASH, 8K SRAM, 4K EEPROM
  2. $crystal = 16000000
  3. $hwstack = 64
  4. $swstack = 64
  5. $framesize = 256
Dziwne że Demo działa a nie działa Tobie w programie.
Ten wyświetlacz ma dwa tryby. Zwykły to trym alfanumeryczny kiedy init i wtedy on reaguje jak zwykły 2x20 znaków. Dopiero jak Init=2 to to jest graficzny. Trzeba wiec patrzeć w jakim jest trybie,
Potem w tych subach Call Lcds_text ostatnia cyferka to jeden z trzech dołaczonych do demo fontów. Trzeba te fonty do projetu dołączyć.
ODPOWIEDZ