#avr | Logs for 2015-07-26

Back
[04:52:19] <Jartza> seems the avr-libc manual has some strange stuff in it :)
[04:52:20] <Jartza> In order to reuse your assembler language parts, it is useful to define them as macros and put them into include files. AVR Libc comes with a bunch of them, which could be found in the directory avr/include. Using such include files may produce compiler warnings, if they are used in modules, which are compiled in strict ANSI mode. To avoid that, you can write asm instead of asm and volatile instead of volatile. These are equivalent aliases.
[04:52:33] <Jartza> mmkay. I can use asm instead of asm? very useful :)
[05:16:36] <antto> i will not call you Jartza, i'll call you Jartza instead
[05:20:00] <Jartza> antto: good call :)
[05:21:02] <antto> maybe it means "asm" vs something like "__asm__" or "_asm" and the underlines vanished
[05:35:38] <Jartza> I think so
[05:35:46] <Jartza> I guess it should be __asm__ and __volatile__
[11:02:55] <Tom_itx> i'll assume he posted to the wrong channel and move on for now. he wasn't part of the active discussion anyway
[11:04:02] <Tom_itx> sry, cleaning kbd and that was in the buffer
[11:04:37] <sabesto> could have been worse :P
[11:06:00] <Casper> yeah, could have been his favorite web site address...
[11:06:28] <sabesto> yep, since he had to clean the keyboard and all after
[12:12:57] <MasterChief8964> Hello, what means "printf("x=%4ld, ", x);" in C? what this will print if "x" is long int?
[12:13:40] <Lambda_Aurigae> hmmm
[12:14:14] <Lambda_Aurigae> %4ld
[12:14:31] <Lambda_Aurigae> spedifies that it is a long integer and prints with 4 significant digits.
[12:14:34] <Lambda_Aurigae> so will print
[12:14:37] <Lambda_Aurigae> 13
[12:14:40] <Lambda_Aurigae> 1222
[12:14:42] <Lambda_Aurigae> 233
[12:14:45] <Lambda_Aurigae> 3
[12:14:48] <Lambda_Aurigae> etc.
[12:15:05] <Lambda_Aurigae> if the number is longer than 4 digits then it will just add them on and push the rest over.
[12:15:10] <Lambda_Aurigae> so
[12:15:14] <Lambda_Aurigae> 13
[12:15:14] <MasterChief8964> thanks ))
[12:15:17] <Lambda_Aurigae> 233
[12:15:20] <Lambda_Aurigae> 1444
[12:15:23] <Lambda_Aurigae> 15222
[12:15:26] <Lambda_Aurigae> such as that.
[12:15:31] <Lambda_Aurigae> it's all there in the manual..
[12:15:45] <Lambda_Aurigae> any printf tutorial worth it's weight in electrons will have it.
[12:15:53] <Lambda_Aurigae> or the basic printf() man page.
[12:16:03] <Lambda_Aurigae> http://pubs.opengroup.org/onlinepubs/009695399/functions/fprintf.html
[12:17:02] <MasterChief8964> I need to replace that code with own "usart0_send_string("string here");" how to take long integers first 4 digit and print it as ASCII string?
[12:17:58] <MasterChief8964> sorry, I missed about googling this last question at first
[12:17:59] <Lambda_Aurigae> sprintf(char *restrict s, const char *restrict format, ...);
[12:18:28] <Lambda_Aurigae> sprintf will output to a string variable...also known as a character array.
[12:18:47] <MasterChief8964> I have no sprintf
[12:19:02] <MasterChief8964> just own simple char printing routine
[12:19:10] <Lambda_Aurigae> you have printf but not sprintf?
[12:20:05] <MasterChief8964> I have no printf too, I'm trying to do the same what was done with printf with my "usart0_send_string("string here");" instead
[12:20:13] <Lambda_Aurigae> you will need an itoa() function and a left() function of some sort...or just take the first 4 characters of the output of the itoa().
[12:21:30] <Lambda_Aurigae> unfortunately, the old itoa() function was considered insecure and deprecated so you will have to use an external one or write one yourself.
[12:22:16] <MasterChief8964> so this will not work? https://fresh2refresh.com/c/c-type-casting/c-itoa-function/
[12:22:54] <Lambda_Aurigae> only if your libc includes itoa()
[12:26:16] <Lambda_Aurigae> which appears it is included in my string.h for avr-gcc
[12:26:31] <Lambda_Aurigae> it compiles anyhow.
[12:26:43] <MasterChief8964> yes it's included, compiled successfully, now flashing to ic
[12:27:02] <Lambda_Aurigae> interestingly, my gcc on my linux box here does not include it.
[12:28:26] <Lambda_Aurigae> or, rather, the libc does not include it.
[12:28:34] <Lambda_Aurigae> both gcc and avr-gcc are 4.8.2
[12:48:31] <rue_bed> do realize that on an 8 bit microcontroller, you use different methods for handling strings than you do on an x86 or arm computer
[12:52:00] <Lambda_Aurigae> yup.
[12:52:10] <Lambda_Aurigae> and itoa is implemented different on different platforms too.
[12:52:40] <rue_bed> I wrote mine
[12:52:59] <Lambda_Aurigae> I always used the one from K&R.
[12:55:51] <rue_bed> void printNumber16(unsigned int n) {
[12:55:52] <rue_bed> unsigned int d;
[12:55:52] <rue_bed>
[12:55:52] <rue_bed> d = n/10000;
[12:55:52] <rue_bed> printDigit(d);
[12:55:53] <rue_bed> n -= d * 10000;
[12:55:55] <rue_bed>
[12:55:56] <rue_bed> d = n/1000;
[12:56:00] <rue_bed> printDigit(d);
[12:56:02] <rue_bed> n -= d * 1000;
[12:56:04] <rue_bed>
[12:56:06] <rue_bed> d = n/100;
[12:56:08] <rue_bed> printDigit(d);
[12:56:10] <rue_bed> n -= d * 100;
[12:56:12] <rue_bed>
[12:56:14] <rue_bed> d = n/10;
[12:56:16] <rue_bed> printDigit(d);
[12:56:18] <rue_bed> n -= d * 10;
[12:56:18] <Lambda_Aurigae> looks kinda like my itohex only in decimal.
[12:56:20] <rue_bed>
[12:56:22] <rue_bed> printDigit(n);
[12:56:24] <rue_bed> }
[12:56:49] <rue_bed> its not good practice to go using buffers for strings your just going to transmitt anyhow
[12:57:17] <Lambda_Aurigae> true, he could just send the data straight from within that.
[12:57:27] <Lambda_Aurigae> replace printDigit() with his output routine.
[12:57:48] <rue_bed> void USART_printhex(uint8_t i)
[12:57:48] <rue_bed> {
[12:57:49] <rue_bed> uint8_t hi,lo;
[12:57:49] <rue_bed> hi=i&0xF0; // High nibble
[12:57:49] <rue_bed> hi=hi>>4;
[12:57:49] <rue_bed> hi=hi+'0';
[12:57:51] <rue_bed> if (hi>'9')
[12:57:53] <rue_bed> hi=hi+7;
[12:57:55] <rue_bed> lo=(i&0x0F)+'0'; // Low nibble
[12:57:57] <rue_bed> if (lo>'9')
[12:58:01] <rue_bed> lo=lo+7;
[12:58:03] <rue_bed> USART_Transmit( hi );
[12:58:05] <rue_bed> USART_Transmit( lo );
[12:58:07] <rue_bed> }
[12:58:09] <rue_bed> exactly
[12:58:38] <Tom_itx> well you didn't float away in your bed
[12:58:49] <Lambda_Aurigae> lots of ways to optimize depending on what you have, what you are doing, and such.
[12:58:49] <rue_bed> its 5 feet off the floor
[12:58:58] <Lambda_Aurigae> get lots of rain there rue_bed ?
[12:59:08] <rue_bed> well at 4am there was
[12:59:21] <rue_bed> sounded like a bomber dropped a load of marbles
[12:59:25] <Tom_itx> we got 4" in a couple hrs the other day
[12:59:28] <Lambda_Aurigae> we got it sometime last night after midnight and before 5am.
[12:59:43] <Lambda_Aurigae> pretty heavy from the looks of things but I slept right through it.
[13:00:02] <rue_bed> its good, we were almost at level 4 water restrictions, and the forrest fire is contained but not out
[13:00:23] <rue_bed> I'm gonna go for a walk, bbl
[13:00:35] <Tom_itx> not from one of your fire experiments was it?
[13:01:30] <Lambda_Aurigae> those fires were bad enough we got the smoke down here.
[13:04:07] <martinus> Is camelCase the norm in C? Would I be an inhuman monster if I adopted underscored names? (I find the latter easier to read)
[13:04:37] <Tom_itx> it is your code to read
[13:05:16] <martinus> I guess I'm thinking from a "I may want someone to hire me at some point in the future and they will want to read my code"
[13:05:28] <martinus> ...perspective.
[13:19:40] <Lambda_Aurigae> I've seen both ways in commercial code.