Just for fun as function:
[code:1:5ab9883977]dim c as byte
CONFIG SUBMODE = NEW
function SubtractLowerFromHigher(byval a as byte, byval b as byte) as byte
'Load a
!LDD r26 , y + 2
!LDD r27 , y + 3
!ld r16,x
'Load b
!LDD r26 , y + 0
!LDD r27 , y + 1
!ld r17,x
'Substraction
!sub r16,r17
'Overflow?
!BRCC SubtractLowerFromHigher_1
'Yes: negate
!NEG R16
SubtractLowerFromHigher_1:
'Save to Result
!LDD r26 , y + 4
!LDD r27 , y + 5
!ST x,r16
end function
'Test it!
c = SubtractLowerFromHigher(18,88)
print c
c = SubtractLowerFromHigher(77,27)
print c
end
[/code:1:5ab9883977]
↧
BASCOM-AVR : absolute value of difference : REPLY
↧
BASCOM-AVR : absolute value of difference : REPLY
More simple:
[code:1:1485a22284]C = A - B
If SREG.0 = 1 Then C = 256 - C[/code:1:1485a22284]
↧
↧
BASCOM-AVR : Xmega256a3bu backup battery for rtc32 : NEWTOPIC
Dear to all
I'm using this code to have a rtc.
This micro have a dedicated pins for the crystal and battery backup.
In the config clock of rtc32 it is remarked that backup battery is enabled but any time I switch off and on the clock is reset.
Can any one of you help me to set properly the code.
Thank you
Gino
$regfile = "xm256a3budef.dat"
$crystal = 32000000
$hwstack = 64
$swstack = 64
$framesize = 64
$lib "glcdEADOGM128x3.lib"
Config Osc = Enabled , 32mhzosc = Enabled , 32khzosc = Enabled
Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1
$prog &HFF , &HFF , &H00 , &HFE , &HFF , &HFE , &HEF ' generated. Take care that the chip supports all fuse bytes.
'fuse 2 BOD enabled continuously fuse 5 BOD enabled continuously
'******************************RTC32 config *****************
Config Clock = Soft , Rtc32 = 1khz_32khz_crystosc , Gosub = Sectic
Config Date = Dmy , Separator = Minus
' QUESTE VARIABILI SONO DIMENSIONATE COME BYTE
'_sec
'_min
'_hour
'_day
'_month
'_year
'*******TIMER 0 CONFIGURAZIONE **********
Config Tce0 = Pwm_topbot , Prescale = 8 , Comparea = Disabled , Compareb = Disabled , Comparec = Disabled , Compared = Disabled , Resolution = Normal
Tce0_per = 55400 ' 360 GRADI CORRISPONDONO A CIRCA 46480
'**************** CONFIGURAZIONE LCD XPLAINED ***********
Config Graphlcd = 128x64eadogm , Si = Portd.3 , Sclk = Portd.1 , A0 = Portd.0 , Rst = Porta.3 , Cs1 = Portf.3
Cls
[b:f915bb7a1d][color=red:f915bb7a1d](BASCOM-AVR version : 2.0.8.1 )[/b:f915bb7a1d][/color:f915bb7a1d]
↧
BASCOM-AVR : Xmega256a3bu backup battery for rtc32 : REPLY
[quote:00789d48d5="Gino_71"]In the config clock of rtc32 it is remarked that backup battery is enabled[/quote:00789d48d5]I see no matching line in your code.
[quote:00789d48d5]but any time I switch off and on the clock is reset.[/quote:00789d48d5]Sure, what do you expect?
Maybe you should try to understand what you're dealing with.
The Bascom Config Clock is a [b:00789d48d5]soft-RTC[/b:00789d48d5], which uses the output from a 32768 crystal-oscillator, puts it on a counter/prescaler, drives an ISR with it and updates the soft-clock within the ISR.
Variables in SRam used by this soft-clock are _sec, _min, a.s.o. At power-up SRam-variables are invalid, thus SRam and containing variables are erased by Bascom's init routine, it will always start from zero, or whatever time you write into the variables at time of init.
The RTC within this kind of ATXMega however is a [b:00789d48d5]hardware-RTC[/b:00789d48d5] and consists out of an crystal-oscillator, prescaler and 32bit-wide counter, which can be kept running for the cost of some nano-Amperes from a backup-battery. This hard-RTC can be fed by 1Hz or 1024Hz, at 1Hz the theoretical life till overflow is about 136 years.
Do you at least read the data sheet before starting something like that, or do you believe magic functionality will appear somehow, if you only write code that contains somewhere the word 'RTC'?
There is a solution of course, similar to how it would be done by an I2C-RTC, a bit more complicated however, as you need to write the code which converts the hard-RTC's 32bit value into sec, min, hour, day, ..., and vice versa.
For this a code frame would look like:
[code:1:00789d48d5]Config Clock = User
Getdatetime:
Return
Setdate:
Return
Settime:
Return[/code:1:00789d48d5]
In Getdatetime you need to write routines, which convert the RTC's 32bit value into regular _sec, _min, ..., in SetDate/SetTime routines to convert _sec, _min, ... into the RTC's 32bit value.
↧
Share your working BASCOM-AVR code here : 2.8inch 65K FullColorLCD 240x320dot [ILI9341] : REPLY
If the virtual port connected to the LCD is the same port, it will operate normally.
The problem with multiple virtual ports is unknown.
I do not know I am not familiar with Xmega.
↧
↧
Share your working BASCOM-AVR code here : 2.8inch 65K FullColorLCD 240x320dot [ILI9341] : REPLY
A bug was found in the original [glcd-ST7735R.lib].
It does not work if A0=[DC] and Sclk=[SCK] are assigned to another port.
* Sbi _glcd_port_scl, _glcd_a0 -> * Sbi _glcd_port_a0, _glcd_a0
* Cbi _glcd_port_scl, _glcd_a0 -> * Cbi _glcd_port_a0, _glcd_a0
This bug also occurs in the ST7735R library and the same symptoms occur on both regular AVR and Xmega.
Attach the corrected [glcd-ILI9341_2R8_240x320.lib].
↧
Share your working BASCOM-AVR code here : 2.8inch 65K FullColorLCD 240x320dot [ILI9341] : REPLY
O-Family thank you, thank you very much.
It works now perfect also on ATXMEGA128A3U.
But I have one question more:
How can I transform my fonts (I use them on monocrome LCD) like color fonts. I tryed to do it with TT Font maker (EDC), but unsucsessful.
It works only with color8x8.fonts and color16x16.fonts.
Best regards M.
↧
BASCOM-AVR : Xmega256a3bu backup battery for rtc32 : REPLY
Hi MWS
Thank you for your kind words.
I will go deep in the data sheet and try to write the code to do per your tip.
I just write on the forum because no example and or info are provided around rtc32.
Thank you again for your input.
↧
BASCOM-AVR : Xmega256a3bu backup battery for rtc32 : REPLY
Oh, my words have not been that kind. In case that suddenly happens, start to worry about me :D
However they should have been able to push you into the right direction, for the conversion routines SYSSEC and friends will make your day easier.
As you have to use Config Clock = User, Bascom will not set up the crystal oscillator and channel it to the 32bit counter.
You have to set it up by the related registers as the data sheet tells you.
↧
↧
Share your working BASCOM-AVR code here : 2.8inch 65K FullColorLCD 240x320dot [ILI9341] : REPLY
Hi,
It was good to work well!
The font for monochrome and the font for color are different in data arrangement.
It is due to the structure of the internal memory of each LCD.
Furthermore, BASCOM's early color LCD library and the original ST7735R library created by "Mrshilov" do not support through type fonts.
It takes a great deal of effort to make this possible, so expect other users' efforts.
↧
BASCOM-AVR : Calculating date from # of occurance of Sunday in a month? : NEWTOPIC
So I've been using the following to determine the nth occurrence of a day within a month
[code:1:1a2ea0fed7]Function DayNameCountCurrentMonth() As Byte
Local Temp_Day As Integer
Local Day_Name_Counter as Byte
Day_Name_Counter = 1
Temp_Day = _DAY 'here we get a number from 1 to 31 (Current system date).
Temp_Day = Temp_Day - 7 'previous week
While Temp_Day > 0
Incr Day_Name_Counter
Temp_Day = Temp_Day - 7 'previous week
Wend
DayNameCountCurrentMonth = Day_Name_Counter
End Function[/code:1:1a2ea0fed7]
So far, so good
But how to determine the date of a specific weekly occurrence of a day based on the actual date? In other words, if I have a date of 07.24.19, how can I calculate that is the 4th Wednesday of July?
[b:1a2ea0fed7][color=red:1a2ea0fed7](BASCOM-AVR version : 2.0.8.1 )[/b:1a2ea0fed7][/color:1a2ea0fed7]
↧
BASCOM-AVR : Calculating date from # of occurance of Sunday in a month? : REPLY
Are you aware of the https://avrhelp.mcselec.com/datetime.htm date time function's in Bascom?
I think you can come with DayOfWeek and SysDay where you want.
At the moment I don't have a running Bascom to test somethings
↧
BASCOM-AVR : Calculating date from # of occurance of Sunday in a month? : REPLY
Indeed I have. In fact, I've been playing with it trying to accomplish what I need.
↧
↧
BASCOM-AVR : Calculating date from # of occurance of Sunday in a month? : REPLY
Ken,
from what I did experience with you, especially your most unclear problem descriptions (like this time again), I was thinking about not answering anymore any of your requests.
In this case at least your code tells what you want to achieve and the solution is that simple, I'm wondering if you simply try to troll people.
In case you're not trolling, I suggest to improve your programming skills, if your code-fuss is the only thing you was able to come out.
[code:1:5b0cbc30f6]Temp_Day = _DAY + 6
Day_Name_Counter = Temp_Day / 7[/code:1:5b0cbc30f6]
↧
BASCOM-AVR : AVR MKII Programmer not found : NEWTOPIC
Hi,
I set up a new Bascom (with new lizense) at my new office.
To get the AVRISP MKII Programmer to work, I Installed Atmel Studio 7.
In Studio 7, I get the Programmer connented and can read fuses and lockbits. Programmer works this far.
In Bascom, when trying to identify the chip, I get a message
"could not initialize Programmer"
":usbdev_open(): did not find any USB device "MK2"
The programmer option are set the same as on my other computers.
Thanks for hints!
Marc
[b:5488accf91][color=red:5488accf91](BASCOM-AVR version : 2.0.8.1 )[/b:5488accf91][/color:5488accf91]
↧
BASCOM-AVR : AVR MKII Programmer not found : REPLY
please read the LIBUSB topic in the help and follow the instructions.
you need to install libusb, then install a filter driver for the programmer.
after that it should work just fine.
↧
BASCOM-AVR : AVR MKII Programmer not found : REPLY
Hi Mark,
will try it next week, need the companies admin...
Thank you,
Marc
↧
↧
BASCOM-AVR : Calculating date from # of occurance of Sunday in a month? : REPLY
Thank you MWS
↧
BASCOM-AVR : Calculating date from # of occurance of Sunday in a month? : REPLY
Ok. so far so good
Now, suppose I want to know the date of the 3rd occurrence of a Tuesday of a given month?
For example, all I know is the month (1-12) and 3rd occurrence of Wednesday in that month. How do I determine the actual date of that day? Or the 2nd Friday?
Is this where syssec() might come in handy?
↧
BASCOM-AVR : Calculating date from # of occurance of Sunday in a month? : REPLY
If you know month and year, you can calculate the day of week for the first day of said month.
In case it's a Monday, the first Wednesday will be the 3rd, thus the third Wednesday will be the 17th.
Plausibility checks for the result need to be done, here again the date/time functions come handy.
↧