PIC16LF1509 for schleife bricht nicht ab

Gast #5357416
Lesenswert?

Hallo Leute,

ich habe eine LED die eine bestimmt Anzahl blinken soll. Dafür habe ich 
den Code unten geschrieben. Das Problem ist, dass sie durchgehend blinkt 
und nicht nur zehn mal. Warum bricht das Programm nicht irgendwann ab?
1
#include <xc.h>
2

3

4
/***** CONFIGURATION *****/
5
//  ext reset, internal oscillator (no clock out), no watchdog timer
6
#pragma config MCLRE = ON, FOSC = INTOSC, CLKOUTEN = OFF, WDTE = OFF
7
//  brownout resets enabled, low brownout voltage, no low-power brownout reset
8
#pragma config BOREN = ON, BORV = LO, LPBOR = OFF
9
//  no power-up timer, no code protect, no write protection
10
#pragma config PWRTE = OFF, CP = OFF, WRT = OFF
11
//  stack resets on, high-voltage programming
12
#pragma config STVREN = ON, LVP = OFF
13

14
#define _XTAL_FREQ  500000      // oscillator frequency for _delay()
15

16

17
/***** MAIN PROGRAM *****/
18
void main()
19
{
20
    //*** Initialisation
21

22
    // configure port
23
    LATA = 0;
24
    TRISA = 0;
25

26
    // configure oscillator
27
    OSCCONbits.SCS1 = 1;        // select internal clock
28
    OSCCONbits.IRCF = 0b0111;   // internal oscillator = 500 kHz
29

30

31
    //*** Main loop
32
    for (int i=0;i<10;i++)
33
    {
34
        LATA^=0x20;
35
        __delay_ms(500);
36

37
    }
38
}

Grüße
Hans und Jürgen
Gast #5357494
Lesenswert?

Ich habe gelesen, dass man nicht genau sagen kann was der µc macht wenn 
man zum Programmende gekommen ist. Scheint wohl so, dass jeder Typ etwas 
anderes macht.

Also am besten den µc nicht zum Programmende kommen lassen?

Beste Grüße

H&J
Moderator (Firma: Titel) Persönliche Seite #5357560
Lesenswert?

Hans Jürgen schrieb:
> Ich habe gelesen, dass man nicht genau sagen kann was der µc macht wenn
> man zum Programmende gekommen ist.
Man kann es recht genau sagen, wenn man sich den Startup-Code ansieht.

> Also am besten den µc nicht zum Programmende kommen lassen?
Natürlich nicht. Was sollte er denn nach dem "Programmende" machen, wenn 
trotzdem noch Versorgungspannung an ihm und dem gesamten Drumherum 
anliegt?
#5358455
Lesenswert?

Hans Jürgen schrieb:
> Ich habe gelesen, dass man nicht genau sagen kann was der µc macht wenn
> man zum Programmende gekommen ist. Scheint wohl so, dass jeder Typ etwas
> anderes macht.

Kleine Erläuterung zu Lothars Ausführungen. Nicht der uC macht das im 
allgemeinen, sondern der Compiler. Also kannst du im User Guide von 
diesem nachschauen was da genau passiert.

################################################################
5.10 MAIN, RUNTIME STARTUP AND RESET
The identifier main is special. You must always have one, and only one, 
function called main() in your programs. This is the first function to 
execute in your program.
Code associated with main(); however, is not the first code to execute 
after Reset.
Additional code provided by the compiler, and known as the runtime 
startup code, is executed first and is responsible for transferring 
control to the main() function. The actions and control of this code is 
described in the following sections.
The compiler inserts special code at the end of main() which is executed 
if this function ends, i.e., a return statement inside main() is 
executed, or code execution reaches the main()’s terminating right 
brace. This special code causes execution to jump to address 0, the 
Reset vector for all 8-bit PIC devices. This essentially performs a 
software Reset. Note that the state of registers after a software Reset 
can be different
to that after a hardware Reset.
It is recommended that the main() function does not end. Add a loop 
construct (such as a while(1)) that will never terminate either around 
your code in main() or at the end of your code, so that execution of the 
function will never terminate. For example,

void main(void)
{
// your code goes here
// finished that, now just wait for interrupts
    while(1)
    continue;
}
################################################################

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren