Quantcast
Channel: MCS Electronics Forum
Viewing all 20696 articles
Browse latest View live

BASCOM-AVR : Help convert Basic to assembler : REPLY

$
0
0
The Main Loop is quite large and the UART out buffer is always empty when checked before data is written to it. The buffer is used because communication is RTS/CTS controlled. In any case though, from your reply, it seems too complicated for me to try. Thanks for all your help. I'll look for other overhead commands to streamline. E

BASCOM-AVR : RS232 between two AVRs using printbin/inputbin : REPLY

$
0
0
[quote:c3f66cb081="EDC"]This should work better :D [/quote:c3f66cb081] Thanks for your help! but somehow it is stuck at "waiting.." so it doesn't get any data or doesn't recognize it? Anyhow I would need some explanation :D "Buffered" means the AVR is stacking some information in ram? why number 20 at the end? "interrupts" what exactly this do? What does values in () mean? Size? If I understand correctly you are sending 2 numbers as 1 but after you get it you split it back to 2? Sorry I just started with this :)

BASCOM-AVR : RS232 between two AVRs using printbin/inputbin : REPLY

$
0
0
You must recheck your hardware because I test this codes successfully one minute ago.

BASCOM-AVR : RS232 between two AVRs using printbin/inputbin : REPLY

$
0
0
[quote:92afc89056="EDC"]You must recheck your hardware because I test this codes successfully one minute ago. About questions please read Help.pdf first.[/quote:92afc89056] OK thanks alot! Maybe I need to get external crystals but for that I need to wait for 3 weeks to come back to EU.

BASCOM-AVR : RS232 between two AVRs using printbin/inputbin : REPLY

$
0
0
serial communication are not difficult but you need to understand what you do When you do For J = 64 to 200 Print j; next You send j as fast as possible (define by the baud rate) $baud = 9600 if the receiver is not ready you could lost some J... so you have to buffered your serial input but see the help "uart" then "using the uart" and the sample file serial RS232Buffer.bas my config Config Com1 = 38400 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0 Config Com3 = 57600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0 Config Serialin3 = Buffered , Size = 32 size mean 32 bytes don't forget to [b:7632106cb3]clear[/b:7632106cb3] the buffer - use ";" to avoid the automatic send of CHR(13+CHR(10) cr+lf ------------->see the ascii table - use the terminal emulator, It is a very good tool jp :wink:

BASCOM-AVR : RS232 between two AVRs using printbin/inputbin : REPLY

$
0
0
Atmegas new form shop/manufacturer comes with internal 1MHz oscillator. Simply change [b:484173febd]$crystal = 1000000[/b:484173febd] in code. Indeed you don`t have crystals on your picture so this can be a cause of fail :D If you are newbe then you mus also know that Atmega16 comes with JTAG enabled so pins PC2 to PC5 are unusable by default. You can change internal ocsillator to 8MHz and disable JTAG by changing Fuse Bits but don`t ask me how :D

BASCOM-AVR : RS232 between two AVRs using printbin/inputbin : REPLY

$
0
0
Thanks guys for everything, I used 1mhz clock instead of 8mhz but in configuration I left it as 8mhz so it would stretch signals a bit and it works now so looks like the problem was also that I didn't use external crystals but right now this is the best solution because I can't get them here atm.

BASCOM-AVR : RS232 between two AVRs using printbin/inputbin : REPLY

$
0
0
to change Fuse bit you need to have a [b:2899e15ffa]good[/b:2899e15ffa] programmer as the old usb-isp programmer or the programmers from MyAVR I use the mysmartUSB light [url]http://shop.myavr.com/index.php?sp=article.sp.php&artID=200006[/url] dont forget the adapter [url]http://shop.myavr.com/index.php?sp=article.sp.php&artID=100075[/url]

BASCOM-AVR : Help convert Basic to assembler : REPLY

$
0
0
[quote:e86035851b="enniom"]Thanks for all your help. I'll look for other overhead commands to streamline.[/quote:e86035851b] It's possible to improve where it's less obvious. I've already pointed you to that: [code:1:e86035851b]Const Forecolor = 10 Const Backcolor = 20 Dim Pixelcount As Byte , Pixel As Byte , Pixels As Byte , A As Byte , YPos As Byte Pixels = 69 For Pixelcount = 0 To 7 ' 715 cycles Ypos = A + Pixelcount Pixel = Pixels.pixelcount If Pixel = 1 Then Pixel = Forecolor Else Pixel = Backcolor ' other stuff Next Pixels = 69 Dim msk As Byte , tmp As Byte msk = 1 Ypos = A Do ' 425 cycles tmp = Pixels And msk If tmp = 1 Then Pixel = Forecolor Else Pixel = Backcolor Incr YPos Shift msk , Left ' other stuff Loop until msk = 0 Pixels = 69 msk = 1 Ypos = A Do ' 208 cycles !LDI R18, Backcolor !LDS R16, {Pixels} !LDS R17, {msk} !AND R16, R17 !BREQ pix_BC !LDI R18, Forecolor pix_BC: !STS {Pixel}, R18 !LDS R19, {YPos} !INC R19 !STS {YPos}, R19 !LSL R17 !STS {msk}, R17 ' other stuff Loop until msk = 0 end[/code:1:e86035851b] Even if the second code looks a bit bulky because of the temporary variable, alone the different implementation speeds things up. The charm of the second code is that it can be easily transformed into assembler, which is done by the third code. The assembler-block is closed in itself, stores variables needed for the next loop or other Bascom code in SRam and thus can be implanted into Bascom code. As you can notice this speeds it up some more. If everything else in this loop would be done in assembler, one can avoid as much as possible to save to SRam, which every time takes some cycles, and that would run then even faster.

BASCOM-AVR : Help convert Basic to assembler : REPLY

$
0
0
Thanks MWS. I did not expect to consume so much of your personal time. For that, I am grateful. I will study and implement the assembler code you developed. It is incredible that so much efficiency can be gained. E

BASCOM-AVR : Help convert Basic to assembler : REPLY

$
0
0
Just noticed, this part in the second code is wrong: [code:1:9ada7fc344]If tmp = 1 Then Pixel = Forecolor Else Pixel = Backcolor[/code:1:9ada7fc344] It muß read: [code:1:9ada7fc344]If tmp > 0 Then Pixel = Forecolor Else Pixel = Backcolor[/code:1:9ada7fc344]

BASCOM-AVR : Help convert Basic to assembler : REPLY

$
0
0
Yes, noticed that. One other minor change needed is the sequencing: [code:1:bb89980490] msk = 1 Ypos = A Do ' 425 cycles tmp = Pixels And msk If tmp > 0 Then Pixel = Forecolor Else Pixel = Backcolor ' other stuff Incr YPos Shift msk , Left Loop until msk = 0 Re: the assembler code, it may have been difficult to notice that Backcolor, Forecolor and Pixel are Words not Bytes. (Pixels is a Byte) E[/code:1:bb89980490]

BASCOM-AVR : Help convert Basic to assembler : REPLY

$
0
0
[quote:6aacfcf3ea="enniom"]Re: the assembler code, it may have been difficult to notice that Backcolor, Forecolor and Pixel are Words not Bytes.[/quote:6aacfcf3ea] Well, I could have noticed in watching the arguments for the sub, but have to confess my goal was a simple sample showing the opportunities, so I did not care too much. As you've noticed I got it also wrong with the right order. Doesn't matter - you surely want to have some fun and challange too. And btw. , you can leave shift msk where it was, it's perfectly ok there. All you need to change in the assembler code is to move the YPos-LDS/INC/STS block to the bottom and extend the byte to words. For that purpose you use a register pair and do it like that: [code:1:6aacfcf3ea]!LDI R18, lbyte(Backcolor) !LDI R19, hbyte(Backcolor) '...[/code:1:6aacfcf3ea] Not sure whether lbyte/hbyte is correct syntax, it's just from memory, maybe I have to look it up, if it not works. Similar use the same register pair for Frontcolor, to write to Pixel you need two STS to {Pixel} and {Pixel+1}. Notice also in my sample Fore/Backcolor is considered to be a constant. Here ByVal comes into mind, as it allows a constant or variable as argument, something I did not consider at first. With assembler however, there is no way to use both, to load a constant use LDI, for a variable LDS or LD. That info should help to help you to modify the assembly yourself, if not, just ask.

BASCOM-AVR : Help convert Basic to assembler : REPLY

$
0
0
Hi MWS, The performance improvement of the LCD refresh rate is REMARKABLE. THANK-YOU. Visually, it seems as fast at 22MHz as it did at 48! All this while at about half the Power Consumption. In addition, I'm getting a tutorial in simple assembler language fundamentals. Current assembler code is included here: [code:1:1a9430bbc1] For Rowcount = 0 To Row_b Step 8 'Loop for numbers of rows A = Rowcount + Yoffset For Columcount = 0 To Colums 'Loop for numbers of Columns Read Pixels Temp = Dummy * Byteseach Xpos = Columcount + Temp Xpos = Xpos + Xoffset !push R16 !push R17 !push R18 !push R19 !ldi R17, &h01 Ypos = A Do !lds R19, {b_color(1)} ;overlay'd onto Backcolor !LDs R18, {b_color(2)} !LDS R16, {Pixels} ' !LDS R17, {msk} !AND R16, R17 !BREQ set_color !lds R19, {f_color(1)} ;overlay'd onto Forecolor !LDs R18, {f_color(2)} Set_color: !STS {Colh}, R18 ;Colh,Coll are overlayed onto Pixel !STS {coll}, R19 Lcd_cs = 0 Lcd_dc = 0 !Lds R16, {spi_seq(1)} !Sts SPIC_DATA, R16 ; SPIC data register Jspi1: !Lds R16,SPIC_STATUS ; get status !Sbrs R16,7 ; skip if it is set !rjmp jspi1 ' Spiout Spi_seq(1) , 1 Lcd_dc = 1 !Lds R16, {spi_seq(4)} !Sts SPIC_DATA, R16 ; SPIC data register Jspi2: !Lds R16,SPIC_STATUS ; get status !Sbrs R16,7 ; skip if it is set !rjmp jspi2 ' Spiout Spi_seq(4) , 1 !Lds R16, {xpos} !Sts SPIC_DATA, R16 ; SPIC data register Jspi3: !Lds R16,SPIC_STATUS ; get status !Sbrs R16,7 ; skip if it is set !rjmp jspi3 ' Spiout Xpos , 1 Lcd_dc = 0 !Lds R16, {spi_seq(2)} !Sts SPIC_DATA, R16 ; SPIC data register Jspi4: !Lds R16,SPIC_STATUS ; get status !Sbrs R16,7 ; skip if it is set !rjmp jspi4 ' Spiout Spi_seq(2) , 1 Lcd_dc = 1 !Lds R16, {spi_seq(4)} !Sts SPIC_DATA, R16 ; SPIC data register Jspi5: !Lds R16,SPIC_STATUS ; get status !Sbrs R16,7 ; skip if it is set !rjmp jspi5 ' Spiout Spi_seq(4) , 1 !Lds R16, {ypos} !Sts SPIC_DATA, R16 ; SPIC data register Jspi6: !Lds R16,SPIC_STATUS ; get status !Sbrs R16,7 ; skip if it is set !rjmp jspi6 ' Spiout Ypos , 1 Lcd_dc = 0 !Lds R16, {spi_seq(3)} !Sts SPIC_DATA, R16 ; SPIC data register Jspi7: !Lds R16,SPIC_STATUS ; get status !Sbrs R16,7 ; skip if it is set !rjmp jspi7 ' Spiout Spi_seq(3) , 1 Lcd_dc = 1 !Lds R16, {colh} !Sts SPIC_DATA, R16 ; SPIC data register Jspi8: !Lds R16,SPIC_STATUS ; get status !Sbrs R16,7 ; skip if it is set !rjmp jspi8 ' Spiout Colh , 1 !Lds R16, {coll} !Sts SPIC_DATA, R16 ; SPIC data register Jspi9: !Lds R16,SPIC_STATUS ; get status !Sbrs R16,7 ; skip if it is set !rjmp jspi9 ' Spiout Coll , 1 Lcd_cs = 1 !LDS R19, {YPos} !INC R19 !STS {YPos}, R19 !LSL R17 ' !STS {msk}, R17 Loop Until Getreg(r17) = 0 !pop R19 !pop R18 !pop R17 !pop R16 Next Columcount Next Rowcount [/code:1:1a9430bbc1] I too could not figure out the assembler command for the Low and High Bytes of Word Vars, so I used overlays. I also simplified the code by using R17 instead of the Msk RAM variable. E

Share your working BASCOM-AVR code here : Library for ST7735R display : NEWTOPIC

$
0
0
I make asm library for ST7735R. I don't have this display and test it on Proteus-8 model. [URL=http://vfl.ru/fotos/1132de8e16373871.html][img:019ce4cd36]http://images.vfl.ru/ii/1488949023/1132de8e/16373871_s.jpg[/img:019ce4cd36][/URL] Library works with 8-bit color in portrait & landscape modes and have "rotate 180°". If anybody have this display, please check it on real one.

BASCOM-AVR : Help convert Basic to assembler : REPLY

$
0
0
Sounds good. Some hints: - Use register pairs in the right order, i. e. for r18/r19 use r18 for the low byte and r19 for the high. This avoids errors and is of importance if 16bit opcodes like ADIW are used (ADIW works only for certain register pairs btw). - Lbyte() & hbyte() are used to reference the bytes of a constant, referencing a variable is done by {variable+[offset]}, to load a word it goes like: [code:1:3ee5914506]LDS r18, {wvar+0} ' you can omit +0 LDS r19, {wvar+1} [/code:1:3ee5914506] For bigger variables use bigger offsets +2, +3, a.s.o. - The Bascom compiler does not (with a few exclusions) keep data in processor registers. That means after a Bascom function ends, it's save to overwrite processor registers by assembler code. So it's not necessary to push registers in your code, that only wastes cycles. The other way around, to protect assembler from Bascom code, it can make sense. - You do something dangerous, you depend on an undestroyed r17 at the end of your assembler block, while you have used Bascom commands like Lcd_cs = 1. In this case you are lucky, because r17 is not used. Pushing r17 would make sense here. Be sure every push is pop'd, as otherwise the stack corrupts. More sense it would make to replace the remaining commands. To access ports in the IO-range, opcodes IN/OUT can be used, for registers above hex 20 use LDS/STS, you may use LDS/STS for the complete IO range, you may have to add hex 20 to Bascom's address reference.

BASCOM-AVR : ATmega8A and INPUT : NEWTOPIC

$
0
0
Good day to All! There is the following code: [code:1:af3fb8429a]$regfile = "m8Adef.dat" 'specify the used micro $crystal = 8000000 ' xtal used $baud = 9600 $hwstack = 32 ' default use 32 for the hardware stack $swstack = 10 ' default use 10 for the SW stack $framesize = 40 ' default use 40 for the frame space '$sim Config Portb = Input Button Alias Pinb.4 Set Portb.4 Config Portc = Input Config Portd = Input Config Portd.0 = Input 'RXD Config Portd.1 = Output 'TXD Rs485dir Alias Portd.2 'make an alias Config Rs485dir = Output 'set direction register to output Reset Rs485dir ' set the pin to 0 for listening Config Print0 = Portd.2 , Mode = Set ' specify RS-485 and direction pin Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0 'Config Serialin0 = Buffered , Size = 16 , Bytematch = All Dim Tmp_byte As Byte Do Print "Input?:" Input Tmp_byte Noecho Print Tmp_byte Loop End[/code:1:af3fb8429a] This code works without problems in ATMega32A: in Proteus and in hardware. And with ATMega8A problems... In Proteus it works (without simulating RS485) In the hardware in the terminal, only the ENTER accepts. The circuit is connected via USB-485 (FTDI). In the 2.0.7.9 version the same problem. Tell me what could be the problem щr what can I use instead of INPUT? Thanks, Ruslan. P.S. Input "Example", B Mark, in all versions of Input does not switch direction pin 485 to display a message! [b:af3fb8429a][color=red:af3fb8429a](BASCOM-AVR version : 2.0.8.0 , Latest : 2.0.7.8 )[/b:af3fb8429a][/color:af3fb8429a]

BASCOM-AVR : RS232 between two AVRs using printbin/inputbin : REPLY

$
0
0
[quote:20da89f236="Duval JP"]to change Fuse bit you need to have a [b:20da89f236]good[/b:20da89f236] programmer as the old usb-isp programmer or the programmers from MyAVR I use the mysmartUSB light [url]http://shop.myavr.com/index.php?sp=article.sp.php&artID=200006[/url] dont forget the adapter [url]http://shop.myavr.com/index.php?sp=article.sp.php&artID=100075[/url][/quote:20da89f236] Thank you for all the informations! :D

BASCOM-AVR : Help convert Basic to assembler : REPLY

$
0
0
In addition to MWS hints: - encapsulate asm code in $asm..$end asm directives, it will be mandatory in future BASCOM versions - besides the "do-not-touch" registers R4,R5,R6,R8,R9 and R28,R29 (Y) bascom uses R23 and or R0 for "translating" asm mnemonics under some circumstances. The $transform directive is useful in that case, see Help for details. - you can speed up a little bit if you are filling more registers with values before you are entering the loop. I.e. instead of !Lds R16, {spi_seq(1)} !Sts SPIC_DATA, R16 ; SPIC data register Jspi1: !Lds R16,SPIC_STATUS ; get status !Sbrs R16,7 ; skip if it is set !rjmp jspi1 ' Spiout Spi_seq(1) , 1 Lcd_dc = 1 !Lds R16, {spi_seq(4)} !Sts SPIC_DATA, R16 ; SPIC data register Jspi2:[/code]

BASCOM-AVR : Help convert Basic to assembler : REPLY

$
0
0
[quote:2ffea6cf36="laborratte"]- encapsulate asm code in $asm..$end asm directives, it will be mandatory in future BASCOM versions[/quote:2ffea6cf36] Afaik it is mandatory already by now, but placing an exclamation mark in front of the opcode is equivalent to the use of an ASM-block. Personally I prefer the exclamation mark, especially as it's possible to control folding within assembler blocks, simply by adding or removing the exclamation mark in front of a label. Folding of assembler makes no sense most of the time, but sometimes it does. There's no such option for $ASM/$END ASM blocks.
Viewing all 20696 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>