• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Atmega328p and Arduino Nano

I know nothing about the Atmega328p, and little about anything else. So in desperation to program an Arduino Nano which uses the 328p i tried this very basic code to get the built-in LED to flash. The nano would be programmed via XLoader which adapts the Arduino to a hex file. Needless to say it doesn't work. Although the program seems to upload (Nano LEDs active) the LED remains off. Can anyone help by telling me why this doesn't work, and offer a correction? I understand the internal LED is connected to PD7 (pin13).

PD.7 = 0
Loop:
PD.7 = 1
Waitms 500
PD7 = 0
Waitms 500
GoTo Loop
 

alec_t

Well-Known Member
Most Helpful Member
Welcome to ETO!
I'm no programmer, but have you actually configured PD.7 as a digital output as part of an initialisation routine?
 

Nigel Goodwin

Super Moderator
Most Helpful Member
Use the Arduino IDE, which makes it VERY simple to use, and the 'default' program flashes an LED in that way - except it doesn't use the horrible 'Goto' :banghead:

C++:
// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}
 
Welcome to ETO!
I'm no programmer, but have you actually configured PD.7 as a digital output as part of an initialisation routine?
I haven't so far found a way of initialising the atmega328p. I know the PIC micros use the ALL Digital command,,but can't find an equivalent for Atmegas in in the AVR Simulator IDE. references. Maybe it's there somewhere in the examples, but I'm unable to follow the complexities of these. Pity Vladmir didn't provide a simple Blink example for raw beginners like me!
 
I haven't so far found a way of initialising the atmega328p. I know the PIC micros use the ALL Digital command,,but can't find an equivalent for Atmegas in in the AVR Simulator IDE. references. Maybe it's there somewhere in the examples, but I'm unable to follow the complexities of these. Pity Vladmir didn't provide a simple Blink example for raw beginners like me!

Wow, seem to have screwed up something here. Sorry!.
 

sagor1

Active Member
There is also Great Cow Basic, which supports atmega chips, as well as PICs. While I use Oshonsoft PIC IDE 90% of the time, I find it not too hard to convert to GCB if the code is not too complex.
Low level stuff like certain interrupts, seems easier for me with Oshonsoft however.
 

atferrari

Well-Known Member
I know the PIC micros use the ALL Digital command,,but can't find an equivalent for Atmegas in in the AVR Simulator IDE.
What is it? I have never used that. :oops:
 

sagor1

Active Member
"AllDigital" is an Oshonsoft compiler command that clears any A/D and comparators, thus setting all IO lines as digital only. The user still has to define input or output. It is not a PIC instruction, but a software instruction....
The AllDigital command is not available in the Oshonsoft AVR compiler from what I see. The Atmega has to have each of its lines defined I guess...
 
Last edited:
Was addressing the wrong pin; should have been PB.5. Worked fine after that without any initial configuring, although i realise that leaving that stuff out is probably bad practice. Seems AVR's rough equavalent to PIC's AllDigital command is DDRB/C /D. set to 1 or 0. Didn't need to use that though. Thanks for all your comments.
 

atferrari

Well-Known Member
"AllDigital" is an Oshonsoft compiler command that clears any A/D and comparators, thus setting all IO lines as digital only. The user still has to define input or output. It is not a PIC instruction, but a software instruction....
The AllDigital command is not available in the Oshonsoft AVR compiler from what I see. The Atmega has to have each of its lines defined I guess...
Failed to notice Oshonsoft. Sorry.
 

Mickster

Well-Known Member
Most Helpful Member
Failed to notice Oshonsoft. Sorry.
I did the same.
Guess that's maybe a result of scrolling down to the "Latest Posts" section, rather than going into the sub-sections.
I don't think we are alone..
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
I did the same.
Guess that's maybe a result of scrolling down to the "Latest Posts" section, rather than going into the sub-sections.
I don't think we are alone..
Yeah Mick!!! What you doing in our forum... This is Vladimir's place.. LOL...
 
Use the Arduino IDE, which makes it VERY simple to use, and the 'default' program flashes an LED in that way - except it doesn't use the horrible 'Goto' :banghead:
Just reviewing this thread. I've come across this criticism of "GoTo" before and Just wondering what's wrong with it, and isn't the closing bracket of the Arduino sketch loop function equivalent to the "GoTo" statement?
 
Last edited by a moderator:

Nigel Goodwin

Super Moderator
Most Helpful Member
GOTO is seriously hated in high level languages, making code much more unreadable, and any reasonably 'modern' language has much better structures that don't require it's use.

Probably the only language that ever did was very early BASIC's?, the ones where you still needed line numbers.

The 'better' the language the less reason to use GOTO, and with ones like Pascal it's hard to find any examples which actually use it - I rewrote a Visual BASIC program in Delphi (Pascal for Windows) and while I got rid of most of them I was unable to remove a couple (without an even more massive rewrite). In order to do so I had to look it up, as in all my years of Pascal/Delphi I'd never used it, and had no idea of how to do so.
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
Just reviewing this thread. I've come across this criticism of "GoTo" before and Just wondering what's wrong with it, and isn't the closing bracket of the Arduino sketch loop function equivalent to the "GoTo" statement?
Goto in high level languages can be used, but stay local... Not even just local, you need to be in the same scope.. A goto can go virtually anywhere... Not so important with Vladimirs compiler as he uses hardware stack... But in C or Pascal or other basics, it causes a stack underflow if you goto somewhere outside the scope of the current position..

Most high level compilers use a software stack ( why you get many nested scopes ) Scopes are between the {} braces.. Much more used in C++, but all compilers compile to assembly then to native.. I'm not sure about basic compilers, as I don't think the code has scopes..

I'm sorry if this is above your head....... Imagine in assembly you place "jmp" passed the local pointers range... 256 bytes on 8 bit chips... well.. "It don't run to good" As the good doctor said.. So the same at high level.... Don't use GOTO unless you are familiar... VERY familar, with your compiler..
 

Latest threads

EE World Online Articles

Loading

 
Top