Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Function added to OLED library 'glcdSSD1306-I2C.lib'
Goto page Previous  1, 2
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here
View previous topic :: View next topic  
Author Message
timbak

Bascom Member



Joined: 18 Oct 2018
Posts: 8

blank.gif
PostPosted: Wed May 26, 2021 7:15 pm    Post subject: Reply with quote

O-Family hello again!

Still try to work with OLED 0.66" 64x48 and Atxmega32A4. Some strange behavior with display increment values.

This code works perfect:
Code:
Do
...  
   Setfont Font6x8
   Lcdat 1 , 1 , "1234567890"
...
Loop


i can see the whole string on display 1234567890

But these examples don't work as expected:
Code:
Do
...
   Setfont Font6x8
   Lcdat 1 , 1 , Increment

   Incr Increment
   Waitms 500
...
Loop
or
Code:
Do
...  
   Tempstr = Str(increment)
   Setfont Font6x8
   Lcdat 1 , 1 , Tempstr

   Incr Increment
   Waitms 500
...
Loop
I see only one last digit.

Actually if value is SINGLE, i can see incrementation on screen - after 9.0 i got 10.0.. 11.0.. 12.00 and ect.
Back to top
View user's profile
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 248
Location: Japan

japan.gif
PostPosted: Sat May 29, 2021 1:48 am    Post subject: Reply with quote

I tried to test with ATXmega128A1, but the display itself does not work properly.
There may be a problem with the original "SSD1306-I2C" library.

Please show your source code.
Back to top
View user's profile Visit poster's website
timbak

Bascom Member



Joined: 18 Oct 2018
Posts: 8

blank.gif
PostPosted: Sat May 29, 2021 11:14 am    Post subject: Reply with quote

Code:
$regfile = "xm32a4udef.dat"
$crystal = 32000000
$hwstack = 180
$swstack = 180
$framesize = 180

'$noramclear
Config Submode = New

'''******************************** SYS CLOCK CONFIG *****************************

Config Osc = Enabled , 32mhzosc = Enabled
Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1

Config Single = Scientific , Digits = 1
Config Priority = Static , Vector = Application , Lo = Enabled , Med = Enabled , Hi = Enabled

'********************************* CONFIG TWI ************************************

Dim Twi_start As Byte
Open "twic" For Binary As #2
Config Twic = 100000
I2cinit #2

'************************* CONFIG OLED 0.66 SSD1306 64x48  ***********************

Config Portd.0 = Output : Oled_rst Alias Portd.0 : Oled_rst = 1       'OLED RESET

'$lib "glcdSSD1306-I2C_V2.lib"
$lib "glcdSSD1306-I2C_V2_0R66_64x48.lib"

Dim _contrast As Byte                                       ' Contrast value of OLED. [0-255]
Const Ssd1306_rotate = 1
Config Graphlcd = Custom , Cols = 64 , Rows = 48 , Lcdname = "SSD1306"
Cls

'Glcdcmd &HA7                                                'Inversion
Glcdcmd &HAF                                                'Display ON

'*********************************************************************************

Dim Increment As Byte , Tempval As Single , Tempstr As String * 8 , Strlen As Byte

Setfont Font6x8

Enable Interrupts

Do

   Waitms 500
   Incr Increment
'__________________________________________________________________________________

   'This is what i want to do: increment the value "Increment" and show it on display.
   'It doen't works - i see only last digit. I.e if Increment = 123 on display i see only "3"
   'It works if Increment value dimensioned as a single: "Dim Increment As Single"
   'But in this case i see on display 123.0

   Lcdat 1 , 1 , Increment ; "  "

'________________________________________________________________________________

   'This is my workaround: Tempval(single) get value of Increment(byte)
   'Represent Tempval as a string
   'and then i delete from the string fractional part with point and send it to the screen

   Tempval = Increment
   Tempstr = Str(tempval)
   Strlen = Len(tempstr) - 2
   Tempstr = Left(tempstr , Strlen )

   Lcdat 1 , 1 , Tempstr ; "  "

Loop
End


$include "Font6x8.font"
$include "font12x16.font"
Back to top
View user's profile
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 248
Location: Japan

japan.gif
PostPosted: Sat May 29, 2021 3:14 pm    Post subject: Reply with quote

Certainly my ATXmega128A1 had the same symptoms.

It is only the last digit when displaying a variable with the LCDAT instruction using Xmega.
It works fine with normal AVR.

I tried to save all the registers in the [_gwrite_lcdchar] routine of the library, but the symptom does not change.
This may be a problem with BASCOM's internal processing, so please check with Mark.
Back to top
View user's profile Visit poster's website
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 248
Location: Japan

japan.gif
PostPosted: Sun May 30, 2021 1:18 am    Post subject: Reply with quote

A remedy was found.
Code:
'The following behaves abnormally.
$hwstack = 180
$swstack = 180
$framesize = 180

'Of the three stack settings, setting one or more to something other than 180 will be normal.
$hwstack = 181
$swstack = 180
$framesize = 180

This is a very strange behaviour, and it seems that setting the stack to 180 for all three will corrupt the contents of the registers or the data passed by the stack.

There seems to be a strange and fatal bug in the operation of the stack.
Nothing more can be solved by me.

It can be verified with the following simple program.
(You can also check it in the simulator)
Code:
$regfile = "xm128A1def.dat"
$crystal = 32000000

$hwstack = 180                                              'An abnormality occurs.
'$hwstack = 181                                              'It works normally.
$swstack = 180
$framesize = 180

   Config Osc = Enabled , 32mhzosc = Enabled
   Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1

   Config Com1 = 9600 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8

   Dim Temp1 As Byte

   Do
      Print Temp1
      Incr Temp1
      Waitms 300
   Loop

   End
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5234
Location: Holland

blank.gif
PostPosted: Tue Jun 01, 2021 9:47 am    Post subject: Reply with quote

and what happens ? it seems to run normal in the sim. I also see no problem with the stacks.
i do not know which version you use? or the TS ?

also, to use xmega with ssd1306 there is the lib for xmega named : glcdSSD1306-I2C-TWI.lib

_________________
Mark
Back to top
View user's profile Visit poster's website
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 248
Location: Japan

japan.gif
PostPosted: Tue Jun 01, 2021 1:35 pm    Post subject: Reply with quote

Check the difference in the simulator results.

Compiler version :2.0.8.3
Compiler build :2.0.8.3.005
IDE version :2.0.8.3.003

"glcdSSD1306-I2C-TWI.lib" is a version with added support for Xtiny, and I think "glcdSSD1306-I2C.lib" also supports Xmega's TWIC.
Back to top
View user's profile Visit poster's website
timbak

Bascom Member



Joined: 18 Oct 2018
Posts: 8

blank.gif
PostPosted: Sun Jun 06, 2021 7:41 pm    Post subject: Reply with quote

albertsm wrote:
and what happens ? it seems to run normal in the sim. I also see no problem with the stacks.
i do not know which version you use? or the TS ?

also, to use xmega with ssd1306 there is the lib for xmega named : glcdSSD1306-I2C-TWI.lib


Compiler version :2.0.8.3
Compiler build :2.0.8.3.005
IDE version :2.0.8.3.003
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here All times are GMT + 1 Hour
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum