|
1936
|
Using Arduino / Microcontrollers / Re: i want to learn how to program a microcontroller...
|
on: December 22, 2011, 05:49:16 pm
|
So im sure we all know how to use a arduino. Its so easy, the arduino enviroment does everything for you! I want to learn how to use a avr or pic. For testing purposes im planning on using it to control relays which will control christmas lights. Can someone point me in the right direction(some tutorials or something) and should i start with a pic or avr? my main concern is the software because i have a mac and no access to windows. The only microcontrollers that ive used are arduino and picaxe. Thanks  Well, Arduino is built around an AVR, so you're already partway there. I got an ICSP programmer and downloaded WinAVR, that's one path you could go down. Or get AVR Studio from Atmel (no experience there, it's another one of those things I'm not getting around to). Also plan on spending considerable time reading the AVR datasheet(s). But that's half the fun!
|
|
|
|
|
1937
|
Using Arduino / Programming Questions / Re: When does -1 != -1 ?
|
on: December 22, 2011, 05:42:49 pm
|
If I change the -1 to -2, then the LED stays off The difference between the two HEX files is what would be expected (four bytes different). The difference between the two ELF files is exactly what would be expected. And, that test eliminates #1. Thanks for the input. What would be the next step? How do we validate #2?
|
|
|
|
|
1938
|
Using Arduino / Programming Questions / Re: When does -1 != -1 ?
|
on: December 22, 2011, 01:56:40 pm
|
both turn the LED on for my uno but not on my duemilanove.
Got me to thinking. Loaded the sketch with ICSP, LED stays off. Burned the ATmegaBOOT_168_atmega328.hex bootloader (Arduino Duemilanove or Nano w/ ATmega328) and loaded the sketch with the bootloader, LED stays off. Something funny with Optiboot?
|
|
|
|
|
1941
|
Using Arduino / Programming Questions / Re: When does -1 != -1 ?
|
on: December 22, 2011, 01:16:30 pm
|
Attached is avr-objdump output with Serial.begin added as follows. Edit: The code generated by the if statement appears the same, except for different addresses, which would be expected. #define TEST_VALUE -1 int foo = TEST_VALUE;
void setup(void) { Serial.begin(9600); pinMode(13, OUTPUT); if (foo != TEST_VALUE) digitalWrite(13, HIGH); }
void loop(void) { }
|
|
|
|
|
1942
|
Using Arduino / Programming Questions / Re: When does -1 != -1 ?
|
on: December 22, 2011, 01:12:52 pm
|
If I change the -1 to -2, then the LED stays off. I compared the avr-objdump output from the two and only found the following, which is about what I'd expect. Scary. Compare: (<)C:\Documents and Settings\Jack\Desktop\objdump-2.txt (18814 bytes) with: (>)C:\Documents and Settings\Jack\Desktop\objdump-1.txt (18814 bytes)
134c134 < 112: 8e 5f subi r24, 0xFE ; 254 --- > 112: 8f 5f subi r24, 0xFF ; 255
|
|
|
|
|
1946
|
Using Arduino / Programming Questions / Re: When does -1 != -1 ?
|
on: December 22, 2011, 12:38:33 pm
|
@lefty, I'm not familiar with the diode trick. @udo, it's the "pin 13 LED" .. I'm using a standard, official Arduino Uno board. Have reproduced the behavior with a breadboarded ATmega328P. Was playing with avr-objdump earlier, don't know AVR assembler though. I'll post the output. I found that this works around the issue: #define TEST_VALUE -1 long int foo = TEST_VALUE;
void setup(void) { foo = -1; pinMode(13, OUTPUT); if (foo != TEST_VALUE) digitalWrite(13, HIGH); }
void loop(void) { }
|
|
|
|
|
1947
|
Using Arduino / Programming Questions / Re: When does -1 != -1 ?
|
on: December 22, 2011, 12:23:13 pm
|
ok, I just ran that code n my Uno (IDE 1.0) and the LED turned on and stayed on.
let me see what I can find.
Jason, many thanks! I really thought I was losing it there! BTW, I just got confirmation from a local friend that he also reproduced the behavior, again on an Uno.
|
|
|
|
|
1948
|
Using Arduino / Programming Questions / Re: When does -1 != -1 ?
|
on: December 22, 2011, 12:12:30 pm
|
My assumption has been that the sketch compares a variable to a constant. That is as maybe but the result is the same and correct. So:- if (foo != TEST_VALUE) digitalWrite(13, HIGH); if (foo != -1) digitalWrite(13, HIGH); if (foo != foo) digitalWrite(13, HIGH);
Are all the same thing and none of then results in the LED being turned on. Do you think it should? No, no, believe me, I get all that completely. The thing is, when I run the sketch that I originally posted, it does turn on the LED. So something is wrong but I haven't discovered what.
|
|
|
|
|
1949
|
Using Arduino / Programming Questions / Re: When does -1 != -1 ?
|
on: December 22, 2011, 12:05:41 pm
|
Quote from: JasonK on Today at 03:59:43 PM x != x is always going to return false because x == x is true
Agree with that statement, but that's not exactly what is in the sketch...
In effect it is what is in your sketch. Because of compiler optimization? My assumption has been that the sketch compares a variable to a constant.
|
|
|
|
|
1950
|
Using Arduino / Programming Questions / Re: When does -1 != -1 ?
|
on: December 22, 2011, 11:39:47 am
|
|
Much appreciated, guys. I'm definitely seeing different behavior, so will continue to look into it. Using Unos here, not sure what bearing that might have. There is one more PC I can try it on here.
|
|
|
|
|