Администрация форума не несёт ответственности за достоверность информации и оставляет за собой право редактировать или в особых случаях даже удалять посты без предупреждения. Спасибо за понимание.

Программирование ATMEL в BASCOM.

Информация о пользователе

Привет, Гость! Войдите или зарегистрируйтесь.


Вы здесь » Программирование ATMEL в BASCOM. » Вопросы - ответы » AtXmega128a1au + oled ssd1306 (spi) проблема.


AtXmega128a1au + oled ssd1306 (spi) проблема.

Сообщений 1 страница 10 из 10

1

Прошу помощи не могу разобраться.
Использую библиотеку  SSD1306  BASCOM-AVR - Mrshilov 2016
С at90128 дисплей работает как положено.
$regfile = "m128can.dat"
$crystal = 8000000
$hwstack = 70                                             
$swstack = 80                                           
$framesize = 120                                     
$lib "glcdSSD1306-SPI.lib"
Config Graphlcd = 128x64sed , Si = Portb.2 , Sclk = Portb.1 , Cs1 = Portb.7 , Rst = Portb.5 , A0 = Portb.6
Setfont Font_5x8
Lcdat 1 , 1 , "SSD1306"

С Atxmega мусор (вместо строки текста - символы и цыфры)
$regfile = "xm128a1def.dat"
$crystal = 8000000                                     
$hwstack = 128
$swstack = 128
$framesize = 80
$lib "xmega.lib" : $external _xmegafix_clear : $external _xmegafix_rol_r1014
$lib "glcdSSD1306-SPI.lib"                               
Config Graphlcd = 128x64sed , Si = Portb.0 , Sclk = Portb.2 , Cs1 = Portd.2 , Rst = Portd.0 , A0 = Portd.1
$xramstart = &H8000
$xramsize = &H8000
Config Osc = Enabled , 32mhzosc = Enabled
Config Sysclock = 32mhz , Prescalea = 4 , Prescalebc = 1_1
Config Graphlcd = Custom , Cols = 128 , Rows = 64 , Lcdname = "SSD1306"
Setfont Font_5x8
Lcdat 1 , 1 , "SSD1306"
С xmega раньше не работал - ткните носом что не так делаю.

0

2

Не факт, что эта либа работает с ХМегой.

0

3

Раз с ХМегами не работали, то: вначале убедитесь, что код вообще стартует/работает. Помигайте светодиодом...

0

4

RDW написал(а):

Раз с ХМегами не работали, то: вначале убедитесь, что код вообще стартует/работает. Помигайте светодиодом...

Мигал сразу же.
Светодиод переключал (toggle) и с (deleyms 500) при этом менял частоту 2-8-32 МГц.  С задержкой период миганий не изменялся . Без задержки при 2 МГц заметны мигания светодиода . То есть работает как надо.
Причём индикатор выводит строку символов (мусорных) именно там где я указываю.
Есть подозрение что нужно настроить spi. Но как ?
Может кто поделиться кодом под xmega + oled ssd1306(spi)

0

5

OLED 128x64 (UG-2864HSWEG01) на SSD1306

0

6

RDW написал(а):

OLED 128x64 (UG-2864HSWEG01) на SSD1306

Читал ранее . Помогло разобраться на mega128(spi,i2c) запускал то и то.

что-то не то 

$regfile = "xm128a1def.dat"
$crystal = 8000000
$hwstack = 128
$swstack = 128
$framesize = 80
Config Osc = Enabled , 32mhzosc = Enabled
Config Sysclock = 32mhz , Prescalea = 4 , Prescalebc = 1_1
$lib "xmega.lib" : $external _xmegafix_clear : $external _xmegafix_rol_r1014
$xramstart = &H8000
$xramsize = &H8000
$lib "glcdSSD1306-SPI.lib"
Config Graphlcd = 128x64sed , Si = Portc.5 , Sclk = Portc.7 , Cs1 = Portd.2 , Rst = Portd.0 , A0 = Portd.1
Dim I As Byte , N As Byte
Config Portd.3 = Output
Cls
Setfont Font_6x8
Do
Setfont Font_6x8
Toggle Portd.3
Lcdat 0 , 0 , "1111111"
Wait 1
Lcdat 2 , 44 , "2344567" , 1                                ' inverse text
Wait 1
For N = 255 To 0 Step - 1
   Lcdcontrast N
   Lcdat 6 , 52 , N ; "  "
   Waitms 2
Next N
Wait 1
For N = 1 To 255
   Lcdcontrast N
   Lcdat 6 , 52 , N ; "  "
   Waitms 2
Next N
Wait 1
Cls
Loop
End
'===============================================================================
$include "Font_6x8.font"

Контраст.инвертирование всё работает. вместо текста
http://s9.uploads.ru/t/GqmZc.jpg

0

7

RDW написал(а):

Не факт, что эта либа работает с ХМегой.

С картинкой - пустой экран.
Пожалуй соглашусь что эта библиотека некорректно работает с atxmega.

0

8

Поборол так

Код:
$regfile = "xm128a1def.dat"
$crystal = 8000000
$hwstack = 128
$swstack = 128
$framesize = 80
Config Osc = Enabled , 32mhzosc = Enabled
Config Sysclock = 32mhz , Prescalea = 4 , Prescalebc = 1_1
 $lib "xmega.lib" : $external _xmegafix_clear : $external _xmegafix_rol_r1014
$xramstart = &H8000
$xramsize = &H8000

Config Portd.2 = Output                                     'DISPLAY_SS CS
Lcd_cs Alias Portd.2
Lcd_cs = 1

Config Portd.1 = Output                                     'DISPLAY_RS  DC
Lcd_rs Alias Portd.1

Config Portc.5 = Output                                     'Spi_mosi   D1
Data_out Alias Portc.5

Config Portc.7 = Output                                     'SPI_SCK    D0
Lcd_clk Alias Portc.7
Lcd_clk = 1

Config Portd. 0 = Output                                    'DISPLAY_Reset
Lcd_rst Alias Portd. 0

Config Porta.4 = Output                                     'OLED ON
Oled_on Alias Porta.4
Oled_on = 1

Declare Sub Lcd_init()
Declare Sub Lcd_data_out(byval Data1 As Byte)
Declare Sub Lcd_comm_out(byval Comm As Byte)
Declare Sub Lcd_clear(byval Colo As Byte)
Declare Sub Lcd_show()

Declare Sub Lcd_text(byval S As String , Byval Xoffset As Byte , Byval Yoffset As Byte , Byval Fontset As Byte)
Declare Sub Lcd_set_pixel(byval Xp As Byte , Byval Yp As Byte , Byval Colo As Byte)

Const White = &HFF
Const Black = &H00
Dim Ddata(1024) As Byte                                     'Display Data Buffer

Const Driver_typ = 0
Call Lcd_init()                                             'Init Display

Dim Zab As Byte
Dim Text11 As String * 20

'*******************************************************************************
Do
   Call Lcd_text( "TEST" , 32 , 9 , 3)                      'Draw Text to Buffer
   Call Lcd_text( "OLED" , 26 , 30 , 2)                     'Draw Text to Buffer
   Call Lcd_text( "SSD1306" , 0 , 55 , 1)                   'Draw Text to Buffer
   Call Lcd_show()
   Wait 10
Call Lcd_clear(black)                                       'Clear black
Wait 2
Call Lcd_clear(white)                                       'Clear white
Wait 2
Loop

End
'*******************************************************************************

$include "My6_8.font"
$include "My12_16.font"
$include "Font.font"

Sub Lcd_set_pixel(byval Xp As Byte , Byval Yp As Byte , Byval Colo As Byte)
   Local B1 As Byte , Zeiger As Word , Bitnr As Byte
   Decr Yp
   B1 = Yp / 8
   Zeiger = B1 * 128
   Zeiger = Zeiger + Xp

   Bitnr = Yp Mod 8
   If Colo = Black Then
      Ddata(zeiger).bitnr = 0
   Else
      Ddata(zeiger).bitnr = 1
   End If
End Sub

Sub Lcd_show()
   Local Page As Byte , Zab1 As Byte , Zab2 As Byte
   Local Point As Word
   Point = 1
   Page = &HB0                                              'Page Address + 0xB0
   Call Lcd_comm_out(&H40)                                  'Display start address + 0x40

   For Zab1 = 0 To 7
      Call Lcd_comm_out(page)                               'send page address
      Call Lcd_comm_out(&H10)                               'column address upper 4 bits + 0x10
   #if Driver_typ = 1
      Call Lcd_comm_out(&H00)                               'column address lower 4 bits + 0x00
   #else
      Call Lcd_comm_out(&H02)
   #endif
      Lcd_cs = 0
      Lcd_rs = 1
      For Zab2 = 1 To 128                                   '128 columns wide
         Shiftout Data_out , Lcd_clk , Ddata(point) , 1 , 8 ', 2
         Incr Point
      Next
      Lcd_cs = 1
      Incr Page                                             'after 128 columns, go to next page
   Next

End Sub

Sub Lcd_clear(byval Colo As Byte)
   Local Page As Byte , Zab1 As Byte , Zab2 As Word

   Page = &HB0                                              'Page Address + 0xB0
   Call Lcd_comm_out(&H40)                                  'Display start address + 0x40

   For Zab1 = 0 To 7
      Call Lcd_comm_out(page)                               'send page address
      Call Lcd_comm_out(&H10)                               'column address upper 4 bits + 0x10
   #if Driver_typ = 1
      Call Lcd_comm_out(&H00)                               'column address lower 4 bits + 0x00 H02 for SH1106
   #else
      Call Lcd_comm_out(&H02)
   #endif
      Lcd_cs = 0
      Lcd_rs = 1
      For Zab2 = 1 To 128                                   '128 columns wide
         Shiftout Data_out , Lcd_clk , Colo , 1 , 8         ', 2
      Next
      Lcd_cs = 1
      Incr Page                                             'after 128 columns, go to next page
   Next

   For Zab2 = 1 To 1024
      Ddata(zab2) = 0                                       'Clear Display Data Buffer
   Next

End Sub

Sub Lcd_data_out(byval Data1 As Byte)
   Lcd_cs = 0
   Lcd_rs = 1
   Shiftout Data_out , Lcd_clk , Data1 , 1 , 8              ', 10
   Lcd_cs = 1
End Sub

Sub Lcd_comm_out(byval Comm As Byte)
   Lcd_rs = 0
   Lcd_cs = 0
   Shiftout Data_out , Lcd_clk , Comm , 1 , 8               ', 10
   Lcd_cs = 1
End Sub

Sub Lcd_init()
   Lcd_rst = 0
   Waitms 100                                               'Reset Display
   Lcd_rst = 1
   Waitms 100

   Call Lcd_comm_out(&Hae)                                  'DISPLAYOFF
   Call Lcd_comm_out(&Hd5)                                  'SETDISPLAYCLOCKDIV
   Call Lcd_comm_out(&H80)                                  'ratio 0x80
   Call Lcd_comm_out(&Ha8)                                  'SETMULTIPLEX
   Call Lcd_comm_out(&H3f)                                  '  1f 128x32
   Call Lcd_comm_out(&Hd3)                                  'SETDISPLAYOFFSET
   Call Lcd_comm_out(&H00)

   Call Lcd_comm_out(&H8d)                                  'CHARGEPUMP
   Call Lcd_comm_out(&H14)                                  'vccstate 14
   Call Lcd_comm_out(&H20)                                  'MEMORYMODE
   Call Lcd_comm_out(&H00)                                  '
   Call Lcd_comm_out(&Ha1)                                  'SEGREMAP  a0
   Call Lcd_comm_out(&Hc8)                                  'COMSCANDEC

   Call Lcd_comm_out(&Hda)                                  'SETCOMPINS
   Call Lcd_comm_out(&H12)                                  ' 02 128x32  12
   Call Lcd_comm_out(&H81)                                  'SETCONTRAST
   Call Lcd_comm_out(85)                                    'value 1-->256
   Call Lcd_comm_out(&Hd9)                                  'SETPRECHARGE
   Call Lcd_comm_out(&Hf1)                                  'vccstate  f1
   Call Lcd_comm_out(&Hdb)                                  'SETVCOMDETECT

   Call Lcd_comm_out(&Ha4)                                  'DISPLAYALLON_RESUME
   Call Lcd_comm_out(&Ha6)                                  'NORMALDISPLAY

   Call Lcd_comm_out(&Haf)

   Waitms 100
End Sub

Sub Lcd_text(byval S As String , Xoffset As Byte , Yoffset As Byte , Fontset As Byte)
   Local Tempstring As String * 1 , Temp As Word
   Local A As Byte , Pixels As Byte , Count As Byte , Carcount As Byte , Lus As Byte
   Local Row As Byte , Block As Byte , Byteseach As Byte , Blocksize As Byte , Dummy As Byte
   Local Colums As Byte , Columcount As Byte , Rowcount As Byte , Stringsize As Byte
   Local Xpos As Byte , Ypos As Byte , Pixel As Word , Pixelcount As Byte
   Local Offset As Word

   Stringsize = Len(s) - 1                                  'Size of the text string -1 because we must start with 0
   Select Case Fontset
      Case 1 :
         Block = Lookup(0 , My6_8)                          'Add or remove here fontset's that you need or not,
         Byteseach = Lookup(1 , My6_8)
         Blocksize = Lookup(2 , My6_8)
         Dummy = Lookup(3 , My6_8)
      Case 2 :
         Block = Lookup(0 , My12_16)
         Byteseach = Lookup(1 , My12_16)
         Blocksize = Lookup(2 , My12_16)
         Dummy = Lookup(3 , My12_16)
      Case 3 :
         Block = Lookup(0 , Font)
         Byteseach = Lookup(1 , Font)
         Blocksize = Lookup(2 , Font)
         Dummy = Lookup(3 , Font)
   End Select
   Colums = Blocksize / Block                               'Calculate the numbers of colums
   Row = Block * 8                                          'Row is always 8 pixels high = 1 byte, so working with row in steps of 8.
   Row = Row - 1                                            'Want to start with row=0 instead of 1
   Colums = Colums - 1                                      'Same for the colums
   For Carcount = 0 To Stringsize                           'Loop for the numbers of caracters that must be displayed
      Temp = Carcount + 1                                   'Cut the text string in seperate caracters
      Tempstring = Mid(s , Temp , 1)
      Offset = Asc(tempstring) - 32                         'Font files start with caracter 32
      Offset = Offset * Blocksize
      Offset = Offset + 4
      Temp = Carcount * Byteseach
      Temp = Temp + Xoffset
      For Rowcount = 0 To Row Step 8                        'Loop for numbers of rows
         A = Rowcount + Yoffset
         Xpos = Temp
         For Columcount = 0 To Colums                       'Loop for numbers of Colums
            Select Case Fontset
               Case 1 : Pixels = Lookup(offset , My6_8)
               Case 2 : Pixels = Lookup(offset , My12_16)
               Case 3 : Pixels = Lookup(offset , Font)
            End Select
            Ypos = A

            For Pixelcount = 0 To 7                         'Loop for 8 pixels to be set or not
               Pixel = Pixels.0                             'Set the pixel (or not)
               If Pixel = 1 Then
                  Call Lcd_set_pixel(xpos , Ypos , White)
               Else
                  Call Lcd_set_pixel(xpos , Ypos , Black)
               End If
               Shift Pixels , Right                         'Shift the byte 1 bit to the right so the next pixel comes availible
               Incr Ypos                                    'Each pixel on his own spot
            Next Pixelcount

            Incr Offset
            Incr Xpos                                       'Do some calculation to get the caracter on the correct Xposition
         Next Columcount
      Next Rowcount
   Next Carcount
End Sub

http://s6.uploads.ru/t/p8TaF.jpg

подсмотрено здесь http://www.elektroda.pl/rtvforum/topic3 … l#15600236

Отредактировано s-psix (2017-05-24 21:13:02)

+3

9

Полезно, спасибо, что разобрались и выложили.)

0

10

Добавлю SH1106 - SSD1306 128x64  вот .
Вывод графики, рисует (круги,прямоугольники,линии - с заливкой и без), прогресс бар, бегущая строка.
Проверено ( SSD1306 128x64 Pixel ) и работает.

Код:
' Date:22.05.2014
' Email: Hkipnik@aol.com
' Copyright (c) 2013 Hkipnik. All rights reserved.
'
' http://creativecommons.org/licenses/by-sa/3.0/de/
'
' Sie dA?rfen:
'
' * das Werk bzw. den Inhalt vervielfA¤ltigen, verbreiten und A¶ffentlich zugA¤nglich machen
'
' * Abwandlungen und Bearbeitungen des Werkes bzw. Inhaltes anfertigen
'
' Zu Den Folgenden Bedingungen:
'
' * Namensnennung.
' Sie mA?ssen den Namen des Autors/Rechteinhabers in der von ihm festgelegten Weise nennen.
'
' * Keine kommerzielle Nutzung.
' Dieses Werk darf nicht fA?r kommerzielle Zwecke verwendet werden.
'
' * Weitergabe unter gleichen Bedingungen.
' Wenn Sie das lizenzierte Werk bzw. den lizenzierten Inhalt bearbeiten
' oder in anderer Weise erkennbar als Grundlage fA?r eigenes Schaffen verwenden,
' dA?rfen Sie die daraufhin neu entstandenen Werke bzw. Inhalte nur
' unter Verwendung von Lizenzbedingungen weitergeben, die mit denen
' dieses Lizenzvertrages identisch oder vergleichbar sind.
'
'*******************************************************************************



'*******************************************************************************
Config Portd.2 = Output                                     'DISPLAY_SS CS
Lcd_cs Alias Portd.2
Lcd_cs = 1

Config Portd.1 = Output                                     'DISPLAY_RS  DC
Lcd_rs Alias Portd.1

Config Portc.5 = Output                                     'Spi_mosi   D1
Data_out Alias Portc.5

Config Portc.7 = Output                                     'SPI_SCK    D0
Lcd_clk Alias Portc.7
Lcd_clk = 1

Config Portd. 0 = Output                                    'DISPLAY_Reset
Lcd_rst Alias Portd. 0

Config Porta.4 = Output                                     'OLED ON
Oled_on Alias Porta.4
Oled_on = 1
'*******************************************************************************
'Declare Subs
Declare Sub Lcd_init()
Declare Sub Lcd_data_out(byval Data1 As Byte)
Declare Sub Lcd_comm_out(byval Comm As Byte)
Declare Sub Lcd_clear(byval Colo As Byte)
Declare Sub Lcd_show()

Declare Sub Lcd_text(byval S As String , Byval Xoffset As Byte , Byval Yoffset As Byte , Byval Fontset As Byte)
Declare Sub Lcd_set_pixel(byval Xp As Byte , Byval Yp As Byte , Byval Colo As Byte)

Declare Sub Lcd_fill_circle(byval X As Byte , Byval Y As Byte , Byval Radius As Byte , Byval Color1 As Byte)
Declare Sub Lcd_circle(byval X As Byte , Byval Y As Byte , Byval Radius As Byte , Byval Color As Byte)
Declare Sub Lcd_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)
Declare Sub Lcd_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)

Declare Sub Lcd_scroll(byval Start1 As Byte , Byval Ende As Byte , Byval Leftright As Byte)
Declare Sub Scroll_end()

Declare Sub Lcd_show_bgf(byval Xs As Byte , Byval Ys As Byte)



Const White = &HFF
Const Black = &H00
Dim Ddata(1024) As Byte 'Display Data Buffer
'*******************************************************************************
'Init Display SSD1306 oder Treiber IC SH1106 wird hA¤ufig als Ersatz geliefert.
'*******************************************************************************
Const Driver_typ = 1 'SSD1306 =1 SH1106 =0
Call Lcd_init() 'Init Display
'*******************************************************************************

'use for Demo
Dim Zab As Byte
Dim Text11 As String * 20
Wait 1

'*******************************************************************************
Do

Call Lcd_clear(white) 'Clear White
Wait 1
Call Lcd_clear(black) 'Clear black
'-------------------------------------------------------------------------------
Call Lcd_text( "BGF Demo" , 20 , 1 , 2) 'Draw Text to Buffer
Restore Pic 'first restore Pic
Call Lcd_show_bgf(8 , 20) 'write BGF to Buffer
Restore Pic1
Call Lcd_show_bgf(48 , 20) 'write BGF to Buffer
Restore Pic2
Call Lcd_show_bgf(88 , 20) 'write BGF to Buffer
Call Lcd_show() 'show Buffer
Wait 5
'-------------------------------------------------------------------------------
Call Lcd_clear(black) 'Clear black
Call Lcd_box(1 , 1 , 128 , 64 , 0 , White)
Call Lcd_text( "Bascom" , 32 , 9 , 2) 'Draw Text to Buffer
Call Lcd_text( "SSD1306" , 26 , 30 , 2) 'Draw Text to Buffer
Call Lcd_text( "SPI + Frame Buffer" , 10 , 54 , 1) 'Draw Text to Buffer
Call Lcd_show()
Wait 2 'show Buffer
Call Lcd_clear(black) 'Clear black

'-------------------------------------------------------------------------------
Call Lcd_text( "12345" , 14 , 1 , 3)
Call Lcd_text( "67890" , 14 , 32 , 3)
Call Lcd_show()
Wait 3
Call Lcd_scroll(0 , 3 , 1) 'Scroll 4 Page right
Wait 10
Call Scroll_end()
Call Lcd_clear(black) 'Clear black
Call Lcd_text( "12345" , 14 , 1 , 3)
Call Lcd_text( "67890" , 14 , 32 , 3)
Call Lcd_show()
Wait 1
Call Lcd_scroll(4 , 7 , 0) 'Scroll 4 Page left
Wait 10
Call Scroll_end()
'-------------------------------------------------------------------------------

Call Lcd_clear(black)
Call Lcd_text( "Circle fill" , 10 , 3 , 1) 'Draw Text to Buffer
Call Lcd_fill_circle(64 , 32 , 8 , White) 'Draw Circle to Buffer
Call Lcd_fill_circle(30 , 32 , 10 , White) 'Draw Circle to Buffer
Call Lcd_fill_circle(98 , 32 , 10 , White) 'Draw Circle to Buffer
Call Lcd_show() 'show Buffer
Wait 2
Call Lcd_fill_circle(64 , 32 , 8 , Black) 'clear Circle
Call Lcd_show() 'show Buffer
Wait 2


Call Lcd_clear(black)
Call Lcd_text( "Circle" , 10 , 3 , 1)
Call Lcd_circle(64 , 32 , 8 , White) 'Circle
Call Lcd_circle(30 , 32 , 10 , White)
Call Lcd_circle(98 , 32 , 10 , White)
Call Lcd_show()
Wait 2
Call Lcd_clear(black)
Call Lcd_text( "Line" , 50 , 5 , 1)
Call Lcd_line(1 , 1 , 128 , 1 , 1 , White) 'Line
Call Lcd_line(1 , 64 , 128 , 64 , 1 , White)
Call Lcd_line(1 , 1 , 1 , 64 , 1 , White)
Call Lcd_line(128 , 1 , 128 , 64 , 1 , White)

Call Lcd_line(1 , 1 , 128 , 64 , 2 , White) 'Line 2 Pixel wide
Call Lcd_line(1 , 64 , 128 , 1 , 2 , White)
Call Lcd_show()
Wait 2
Call Lcd_clear(black)
Call Lcd_text( "Box fill" , 10 , 3 , 1)
Call Lcd_box(10 , 20 , 54 , 44 , 1 , White) 'Box fill
Call Lcd_box(75 , 30 , 100 , 50 , 1 , White)
Call Lcd_show()

Wait 2
Call Lcd_clear(black)
Call Lcd_text( "Box" , 10 , 3 , 1)
Call Lcd_box(10 , 20 , 54 , 44 , 0 , White) 'Box
Call Lcd_box(75 , 30 , 100 , 50 , 0 , White)
Call Lcd_show()
Wait 2
Call Lcd_clear(black)
Call Lcd_box(1 , 40 , 128 , 60 , 0 , White)

For Zab = 1 To 128
Text11 = Str(zab)
Text11 = Format(text11 , "000")
Call Lcd_text(text11 , 40 , 15 , 2)
Call Lcd_box(2 , 41 , Zab , 59 , 1 , White)
Call Lcd_show()
' Waitms 100
Next

For Zab = 128 To 2 Step -1
Text11 = Str(zab)
Text11 = Format(text11 , "000")
Call Lcd_text(text11 , 40 , 15 , 2)
Call Lcd_box(zab , 41 , 127 , 59 , 1 , Black)
Call Lcd_show()
' Waitms 100
Next

Wait 2

Call Lcd_clear(black)
Call Lcd_box(1 , 1 , 128 , 64 , 0 , White) 'small Demo

For Zab = 1 To 100
Text11 = Str(zab)
Text11 = Format(text11 , "0000")

Call Lcd_text(text11 , 40 , 24 , 2)
Call Lcd_show()
Waitms 10
Next
Wait 1

Loop

End
'*******************************************************************************
'*******************************************************************************
'include used fonts
$include "My6_8.font"
$include "My12_16.font"
$include "Digital20x32.font" 'Font nur Zahlen Punkt und Komma
'$include "Digital10x16.font"

'include used BGF
$inc Pic , Nosize , "BGF\abc.bgf" '32x32 pixel
$inc Pic1 , Nosize , "BGF\time.bgf" '32x32 Pixel
$inc Pic2 , Nosize , "BGF\music.bgf" '32x32 Pixel
'*******************************************************************************
'Routines
'*******************************************************************************
' Show BASCOM Graphic Files (BGF)
' use the Graphic converter in Uncompressed Mode
' The Sub do not support RLE compression
' Set Xs=Start Xpoint Ys=Start Ypoint
'*******************************************************************************
Sub Lcd_show_bgf(byval Xs As Byte , Byval Ys As Byte)
Local Xz As Byte , Yz As Byte , Col As Byte
Local Bnr As Byte , Xdum As Byte , Xend As Byte , Yend As Byte
Read Yend 'Read Height
Read Xend 'Read Width

Yend = Yend + Ys 'Set end point
Xend = Xend + Xs 'Set end point

Decr Xend
Decr Yend

For Yz = Ys To Yend 'Ystart to Yend
For Xz = Xs To Xend Step 8 'Step 8 Pixel for one Byte
Read Col 'Read BGF file 1Byte = 8 Pixel
Xdum = Xz 'X Start Point
For Bnr = 7 To 0 Step -1 'MSB first Set 8Bit
If Col.bnr = 1 Then 'Read pixel
Call Lcd_set_pixel(xdum , Yz , White) 'Set Pixel
Else
Call Lcd_set_pixel(xdum , Yz , Black) 'Clear Pixel
End If
Incr Xdum 'Incr X pointer
Next
Next
Next
End Sub
'*******************************************************************************
' Horizontal scrolling
' Set Page Start1 to Page End 0-->7 (8 Page) Leftright 1=right 0=left
'*******************************************************************************
'Set Time interval
'Column shift 2Frames 0x7
'Column shift 3Frames 0x4
'Column shift 4Frames 0x5
'Column shift 5Frames 0x0
'Column shift 25Frames 0x6
'Column shift 64Frames 0x1
'Column shift 128Frames 0x2
'Column shift 256frames 0x3
'*******************************************************************************
Sub Lcd_scroll(byval Start1 As Byte , Byval Ende As Byte , Byval Leftright As Byte)

If Leftright = 1 Then
Call Lcd_comm_out(&H26) 'Shift right
Else
Call Lcd_comm_out(&H27) 'Shift left
End If

Call Lcd_comm_out(&H00) 'Dummy Byte
Call Lcd_comm_out(start1) 'Start Page
Call Lcd_comm_out(&H07) 'Column shift 2 Frames
Call Lcd_comm_out(ende) 'End Page
Call Lcd_comm_out(&H00)
Call Lcd_comm_out(&Hff)
Call Lcd_comm_out(&H2f) 'Activat Scrolling
End Sub
'*******************************************************************************
' Stop Scroll
'*******************************************************************************
Sub Scroll_end()
Call Lcd_comm_out(&H2e)
End Sub
'*******************************************************************************
' Draw Box Xs-Ys to Xe-Ye fill=1 Fill -- Fill=0 no fill
' Color=1 Set Pixel Color=0 clear Pixel
'*******************************************************************************
Sub Lcd_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)
Local Xza As Byte , Yza As Byte

If Fill = 1 Then
For Yza = Ys To Ye
For Xza = Xs To Xe
Call Lcd_set_pixel(xza , Yza , Color)
Next
Next
Else
Call Lcd_line(xs , Ys , Xe , Ys , 1 , Color)
Call Lcd_line(xs , Ye , Xe , Ye , 1 , Color)

Call Lcd_line(xs , Ys , Xs , Ye , 1 , Color)
Call Lcd_line(xe , Ys , Xe , Ye , 1 , Color)
End If

End Sub
'*******************************************************************************
' Set or Clear a Pixel to X-Y Position White= Set Pixel Black= Clear Pixel
' and write Data to Display-Array
'*******************************************************************************
Sub Lcd_set_pixel(byval Xp As Byte , Byval Yp As Byte , Byval Colo As Byte)
Local B1 As Byte , Zeiger As Word , Bitnr As Byte
Decr Yp
B1 = Yp / 8
Zeiger = B1 * 128
Zeiger = Zeiger + Xp

Bitnr = Yp Mod 8
If Colo = Black Then
Ddata(zeiger).bitnr = 0
Else
Ddata(zeiger).bitnr = 1
End If
End Sub
'*******************************************************************************
' Updated the Display whith Display-Array
'*******************************************************************************
Sub Lcd_show()
Local Page As Byte , Zab1 As Byte , Zab2 As Byte
Local Point As Word
Point = 1
Page = &HB0 'Page Address + 0xB0
Call Lcd_comm_out(&H40) 'Display start address + 0x40

For Zab1 = 0 To 7
Call Lcd_comm_out(page) 'send page address
Call Lcd_comm_out(&H10) 'column address upper 4 bits + 0x10
#if Driver_typ = 1
Call Lcd_comm_out(&H00) 'column address lower 4 bits + 0x00 H02 for SH1106
#else
Call Lcd_comm_out(&H02)
#endif
Lcd_cs = 0
Lcd_rs = 1
For Zab2 = 1 To 128 '128 columns wide
Shiftout Data_out , Lcd_clk , Ddata(point) , 1 , 8 ', 2
Incr Point
Next
Lcd_cs = 1
Incr Page 'after 128 columns, go to next page
Next

End Sub
'*******************************************************************************
' Clear Display and Display-Array
'*******************************************************************************
Sub Lcd_clear(byval Colo As Byte)
Local Page As Byte , Zab1 As Byte , Zab2 As Word

Page = &HB0 'Page Address + 0xB0
Call Lcd_comm_out(&H40) 'Display start address + 0x40

For Zab1 = 0 To 7
Call Lcd_comm_out(page) 'send page address
Call Lcd_comm_out(&H10) 'column address upper 4 bits + 0x10
#if Driver_typ = 1
Call Lcd_comm_out(&H00) 'column address lower 4 bits + 0x00 H02 for SH1106
#else
Call Lcd_comm_out(&H02)
#endif
Lcd_cs = 0
Lcd_rs = 1
For Zab2 = 1 To 128 '128 columns wide
Shiftout Data_out , Lcd_clk , Colo , 1 , 8 ', 2
Next
Lcd_cs = 1
Incr Page 'after 128 columns, go to next page
Next

For Zab2 = 1 To 1024
Ddata(zab2) = 0 'Clear Display Data Buffer
Next

End Sub
'*******************************************************************************
' Send Data to SSD1306 not use
'*******************************************************************************
Sub Lcd_data_out(byval Data1 As Byte)
Lcd_cs = 0
Lcd_rs = 1
Shiftout Data_out , Lcd_clk , Data1 , 1 , 8 ', 10
Lcd_cs = 1
End Sub
'*******************************************************************************
' Send Command to SSD1306
'*******************************************************************************
Sub Lcd_comm_out(byval Comm As Byte)
Lcd_rs = 0
Lcd_cs = 0
Shiftout Data_out , Lcd_clk , Comm , 1 , 8 ', 10
Lcd_cs = 1
End Sub
'*******************************************************************************
' Init the Driver SSD1306
'*******************************************************************************
Sub Lcd_init()
Lcd_rst = 0
Waitms 100 'Reset Display
Lcd_rst = 1
Waitms 100

Call Lcd_comm_out(&Hae) 'DISPLAYOFF
Call Lcd_comm_out(&Hd5) 'SETDISPLAYCLOCKDIV
Call Lcd_comm_out(&H80) 'ratio 0x80
Call Lcd_comm_out(&Ha8) 'SETMULTIPLEX
Call Lcd_comm_out(&H3f) ' 1f 128x32
Call Lcd_comm_out(&Hd3) 'SETDISPLAYOFFSET
Call Lcd_comm_out(&H00)

Call Lcd_comm_out(&H8d) 'CHARGEPUMP
Call Lcd_comm_out(&H14) 'vccstate 14
Call Lcd_comm_out(&H20) 'MEMORYMODE
Call Lcd_comm_out(&H00) '
Call Lcd_comm_out(&Ha1) 'SEGREMAP a0
Call Lcd_comm_out(&Hc8) 'COMSCANDEC

Call Lcd_comm_out(&Hda) 'SETCOMPINS
Call Lcd_comm_out(&H12) ' 02 128x32 12
Call Lcd_comm_out(&H81) 'SETCONTRAST
Call Lcd_comm_out(200) 'value 1-->256
Call Lcd_comm_out(&Hd9) 'SETPRECHARGE
Call Lcd_comm_out(&Hf1) 'vccstate f1
Call Lcd_comm_out(&Hdb) 'SETVCOMDETECT
Call Lcd_comm_out(&H40) 'deselect level
'
Call Lcd_comm_out(&Ha4) 'DISPLAYALLON_RESUME
Call Lcd_comm_out(&Ha6) 'NORMALDISPLAY

Call Lcd_comm_out(&Haf)

Waitms 100
End Sub
'*******************************************************************************
'LCD_Text String -- X -- Y Start -- Font
'*******************************************************************************
Sub Lcd_text(byval S As String , Xoffset As Byte , Yoffset As Byte , Fontset As Byte)
Local Tempstring As String * 1 , Temp As Word
Local A As Byte , Pixels As Byte , Count As Byte , Carcount As Byte , Lus As Byte
Local Row As Byte , Block As Byte , Byteseach As Byte , Blocksize As Byte , Dummy As Byte
Local Colums As Byte , Columcount As Byte , Rowcount As Byte , Stringsize As Byte
Local Xpos As Byte , Ypos As Byte , Pixel As Word , Pixelcount As Byte
Local Offset As Word

Stringsize = Len(s) - 1 'Size of the text string -1 because we must start with 0
Select Case Fontset
Case 1 :
Block = Lookup(0 , My6_8) 'Add or remove here fontset's that you need or not,
Byteseach = Lookup(1 , My6_8)
Blocksize = Lookup(2 , My6_8)
Dummy = Lookup(3 , My6_8)
Case 2 :
Block = Lookup(0 , My12_16)
Byteseach = Lookup(1 , My12_16)
Blocksize = Lookup(2 , My12_16)
Dummy = Lookup(3 , My12_16)
Case 3 :
Block = Lookup(0 , Digital20x32)
Byteseach = Lookup(1 , Digital20x32)
Blocksize = Lookup(2 , Digital20x32)
Dummy = Lookup(3 , Digital20x32)
End Select
Colums = Blocksize / Block 'Calculate the numbers of colums
Row = Block * 8 'Row is always 8 pixels high = 1 byte, so working with row in steps of 8.
Row = Row - 1 'Want to start with row=0 instead of 1
Colums = Colums - 1 'Same for the colums
For Carcount = 0 To Stringsize 'Loop for the numbers of caracters that must be displayed
Temp = Carcount + 1 'Cut the text string in seperate caracters
Tempstring = Mid(s , Temp , 1)
Offset = Asc(tempstring) - 32 'Font files start with caracter 32
Offset = Offset * Blocksize
Offset = Offset + 4
Temp = Carcount * Byteseach
Temp = Temp + Xoffset
For Rowcount = 0 To Row Step 8 'Loop for numbers of rows
A = Rowcount + Yoffset
Xpos = Temp
For Columcount = 0 To Colums 'Loop for numbers of Colums
Select Case Fontset
Case 1 : Pixels = Lookup(offset , My6_8)
Case 2 : Pixels = Lookup(offset , My12_16)
Case 3 : Pixels = Lookup(offset , Digital20x32)
End Select
Ypos = A

For Pixelcount = 0 To 7 'Loop for 8 pixels to be set or not
Pixel = Pixels.0 'Set the pixel (or not)
If Pixel = 1 Then
Call Lcd_set_pixel(xpos , Ypos , White)
Else
Call Lcd_set_pixel(xpos , Ypos , Black)
End If
Shift Pixels , Right 'Shift the byte 1 bit to the right so the next pixel comes availible
Incr Ypos 'Each pixel on his own spot
Next Pixelcount

Incr Offset
Incr Xpos 'Do some calculation to get the caracter on the correct Xposition
Next Columcount
Next Rowcount
Next Carcount
End Sub


'*******************************************************************************
' Draw Fill Circle X-Y Center - Radius - Color=1 set Pixel Color=Black - White
'*******************************************************************************
Sub Lcd_fill_circle(byval X As Byte , Byval Y As Byte , Byval Radius As Byte , Byval Color1 As Byte)
Local Xy_radius As Integer , Zahly As Integer , Zahlx As Integer , Y1 As Integer , X1 As Integer
Local Y11 As Integer , X11 As Integer , Xy As Integer , X2 As Byte , Y2 As Byte
Xy_radius = Radius * Radius
Y1 = -radius
X1 = -radius

For Zahly = Y1 To Radius
Y11 = Zahly * Zahly
For Zahlx = X1 To Radius
X11 = Zahlx * Zahlx
Xy = X11 + Y11
If Xy <= Xy_radius Then
X2 = X + Zahlx
Y2 = Y + Zahly
Call Lcd_set_pixel(x2 , Y2 , Color1)
End If
Next
Next

End Sub
'*******************************************************************************
' Draw Circle X-Y Center - Radius - Color=1 set Pixel Color=Black - White
'*******************************************************************************
Sub Lcd_circle(byval X As Byte , Byval Y As Byte , Byval Radius As Byte , Byval Color As Byte)
Local X0 As Byte , Y0 As Byte , Error As Integer
Local Xp As Byte , Yp As Byte , Xe As Byte , Ye As Byte

Error = -radius
Xp = Radius
Yp = 0

While Xp >= Yp
X0 = X + Xp : Y0 = Y + Yp
Call Lcd_set_pixel(x0 , Y0 , Color)
X0 = X - Xp : Y0 = Y + Yp
Call Lcd_set_pixel(x0 , Y0 , Color)
X0 = X + Xp : Y0 = Y - Yp
Call Lcd_set_pixel(x0 , Y0 , Color)
X0 = X - Xp : Y0 = Y - Yp
Call Lcd_set_pixel(x0 , Y0 , Color)

X0 = X + Yp : Y0 = Y + Xp
Call Lcd_set_pixel(x0 , Y0 , Color)
X0 = X - Yp : Y0 = Y + Xp
Call Lcd_set_pixel(x0 , Y0 , Color)
X0 = X + Yp : Y0 = Y - Xp
Call Lcd_set_pixel(x0 , Y0 , Color)
X0 = X - Yp : Y0 = Y - Xp
Call Lcd_set_pixel(x0 , Y0 , Color)

Error = Error + Yp
Incr Yp
Error = Error + Yp

If Error >= 0 Then
Decr Xp
Error = Error - Xp
Error = Error - Xp
End If

Wend

End Sub
'*******************************************************************************
' Draw line X - Y Start to X - Y End - Pen Width - Color= Black - White
'*******************************************************************************
Sub Lcd_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)
Local Y As Byte , X As Byte , X_diff As Single , Y_diff As Single , Pos As Word
Local X_factor As Single , X_pos As Byte , Y_pos As Byte , Base As Word , Pen_count As Byte
Local Xpoint As Byte , Ypoint As Byte
Local Y_count As Byte , X_count As Byte
Y_diff = Y2 - Y1
X_diff = X2 - X1
Pos = 0

X_factor = Abs(y_diff)
Y = X_factor
X_factor = Abs(x_diff)
X = X_factor

If Y > X Then
X_factor = X_diff / Y_diff
If Y1 > Y2 Then
Swap Y1 , Y2
Base = X2
Else
Base = X1
End If
For Y = Y1 To Y2
X_diff = Pos * X_factor
X_pos = X_diff
X_pos = X_pos + Base
For Pen_count = 1 To Pen_width
Call Lcd_set_pixel(x_pos , Y , Color)
Incr X_pos
Next Pen_count
Incr Pos
Next Y
Else
X_factor = Y_diff / X_diff
If X1 > X2 Then
Swap X1 , X2
Base = Y2
Else
Base = Y1
End If
For X = X1 To X2
Y_diff = Pos * X_factor
Y_pos = Y_diff
Y_pos = Y_pos + Base
For Pen_count = 1 To Pen_width
Call Lcd_set_pixel(x , Y_pos , Color)
Incr Y_pos
Next Pen_count
Incr Pos
Next X
End If

End Sub
'*******************************************************************************

+2


Вы здесь » Программирование ATMEL в BASCOM. » Вопросы - ответы » AtXmega128a1au + oled ssd1306 (spi) проблема.