Cos'è ElectroYou | Login Iscriviti

ElectroYou - la comunità dei professionisti del mondo elettrico

Simulare l'alba e il tramonto

Raccolta di codici sorgenti

Moderatore: Foto UtentePaolino

0
voti

[101] Re: Simulare l'alba e il tramonto

Messaggioda Foto Utentecarlo87 » 4 gen 2013, 15:30

ti ringrazio.. Io ho sostemato ancora meglio il PIC diminuendo a pochissime micro piste
Avatar utente
Foto Utentecarlo87
23 6
Frequentatore
Frequentatore
 
Messaggi: 139
Iscritto il: 27 ott 2011, 20:05

1
voti

[102] Re: Simulare l'alba e il tramonto

Messaggioda Foto UtentePaolino » 4 gen 2013, 23:12

Allora, ecco qui una bozza:

Codice: Seleziona tutto
#include <xc.h>

/* Configuration bits */
#pragma config OSC = INTIO1, LVP = OFF, MCLRE = ON, WDT = OFF, IESO = OFF, PWRT = ON

/* Macros */
#define ON 1
#define OFF 0
#define TRUE 1
#define FALSE 0

#define GATE LATBbits.LATB1

/* Global variables */
int TrimmerValue;

/* Function prototypes */
void InitPic(void);
int ReadTrimmer (void);

void interrupt ISR (void)
{
    if (TMR1IF == ON)
    {
        TMR1H = 0x7F;
        GATE ^=1;
        TMR1IF = 0;
    }
}

void main (void)
{
    InitPic ();
    while(1)
    {
    }

}

void InitPic(void)
{
/* OSCILLATOR: internal oscillator at 8 MHz */
    OSCCON = 0xF0;

/* PORT I/O configuration */
    TRISA = 0xFF;
    TRISB = 0xFD;

/* A/D converter configuration */
    ADCON1 = 0xFE;
    ADCON0bits.ADON = ON;

/* Interrupts */
    RCONbits.IPEN = ON;
    INTCONbits.INT0IE = ON;
    PIE1bits.TMR1IE = ON;

    INTCONbits.GIEH = 1;
}


Per verificare questo codice dovrai avviare un progetto con MPLABX IDE e farlo compilare con XC8. A questo punto, una volta compilato e trasferito, su RB1 c'è un'onda quadra con periodo 1s. Lo devi verificare con il tester.

Prova.

Ciao.

Paolo.

P.S. Poi ci facciamo un articolo, ok? ;-)
"Houston, Tranquillity Base here. The Eagle has landed." - Neil A.Armstrong

-------------------------------------------------------------

PIC Experience - http://www.picexperience.it
Avatar utente
Foto UtentePaolino
32,6k 8 12 13
G.Master EY
G.Master EY
 
Messaggi: 4226
Iscritto il: 20 gen 2006, 11:42
Località: Vigevano (PV)

1
voti

[103] Re: Simulare l'alba e il tramonto

Messaggioda Foto UtentePaolino » 5 gen 2013, 9:56

Correggi la InitPic così:

Codice: Seleziona tutto
void InitPic(void)
{
/* OSCILLATOR: internal oscillator at 8 MHz */
    OSCCON = 0xF0;

/* PORT I/O configuration */
    TRISA = 0xFF;
    TRISB = 0xFD;

/* A/D converter configuration */
    ADCON1 = 0xFE;
    ADCON0bits.ADON = ON;

/* TIMER 1 setup */
    T1CON = 0x0F;
    TMR1H = 0x80;
    TMR1L = 0x00;
   
/* Interrupts */
    RCONbits.IPEN = ON;
    INTCONbits.INT0IE = ON;
    PIE1bits.TMR1IE = ON;

    INTCONbits.GIEH = ON;
}


Ciao.

Paolo.
"Houston, Tranquillity Base here. The Eagle has landed." - Neil A.Armstrong

-------------------------------------------------------------

PIC Experience - http://www.picexperience.it
Avatar utente
Foto UtentePaolino
32,6k 8 12 13
G.Master EY
G.Master EY
 
Messaggi: 4226
Iscritto il: 20 gen 2006, 11:42
Località: Vigevano (PV)

0
voti

[104] Re: Simulare l'alba e il tramonto

Messaggioda Foto Utentecarlo87 » 6 gen 2013, 22:40

Ciao paolino pure usando il programma da te indicato una volta creato il nuovo progetto, e durante la compilazione escono una serie di errori come mai:
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `C:/MPLABXProjects/alba-tramonto.X'
make -f nbproject/Makefile-default.mk dist/default/production/alba-tramonto.X.production.hex
make[2]: Entering directory `C:/MPLABXProjects/alba-tramonto.X'
"C:\Program Files\Microchip\xc8\v1.12\bin\xc8.exe" --pass1 --chip=18F1320 -Q -G --asmlist --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -obuild/default/production/_ext/43898991/alba-tramonto.p1 ../../alba-tramonto.c
../../alba-tramonto.c:4: error: undefined identifier "OSCCON"
../../alba-tramonto.c:7: error: undefined identifier "TRISA"
../../alba-tramonto.c:8: error: undefined identifier "TRISB"
../../alba-tramonto.c:11: error: undefined identifier "ADCON1"
../../alba-tramonto.c:12: error: undefined identifier "ADCON0bits"
../../alba-tramonto.c:12: error: struct/union required
../../alba-tramonto.c:12: error: undefined identifier "ON"
../../alba-tramonto.c:15: error: undefined identifier "T1CON"
../../alba-tramonto.c:16: error: undefined identifier "TMR1H"
../../alba-tramonto.c:17: error: undefined identifier "TMR1L"
../../alba-tramonto.c:20: error: undefined identifier "RCONbits"
../../alba-tramonto.c:20: error: struct/union required
../../alba-tramonto.c:21: error: undefined identifier "INTCONbits"
../../alba-tramonto.c:21: error: struct/union required
../../alba-tramonto.c:22: error: undefined identifier "PIE1bits"
../../alba-tramonto.c:22: error: struct/union required
../../alba-tramonto.c:24: error: struct/union required
make[2]: Leaving directory `C:/MPLABXProjects/alba-tramonto.X'
(908) exit status = 1
make[2]: *** [build/default/production/_ext/43898991/alba-tramonto.p1] Error 1
make[1]: Leaving directory `C:/MPLABXProjects/alba-tramonto.X'
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 3s)
Avatar utente
Foto Utentecarlo87
23 6
Frequentatore
Frequentatore
 
Messaggi: 139
Iscritto il: 27 ott 2011, 20:05

0
voti

[105] Re: Simulare l'alba e il tramonto

Messaggioda Foto Utentecarlo87 » 6 gen 2013, 22:46

paolino mi poi spiegare precisamente come fare a generare il file correttamente e poi caricarlo sul PIC??
Avatar utente
Foto Utentecarlo87
23 6
Frequentatore
Frequentatore
 
Messaggi: 139
Iscritto il: 27 ott 2011, 20:05

0
voti

[106] Re: Simulare l'alba e il tramonto

Messaggioda Foto Utentecarlo87 » 7 gen 2013, 20:34

Paolino mi poi spiegare precisamente come fare a generare il file correttamente e poi caricarlo sul PIC??" "Cortesemente, puoi indicarmi dove sta l'errore e come fare per generare correttamente il file .hex?"
Avatar utente
Foto Utentecarlo87
23 6
Frequentatore
Frequentatore
 
Messaggi: 139
Iscritto il: 27 ott 2011, 20:05

1
voti

[107] Re: Simulare l'alba e il tramonto

Messaggioda Foto UtentePaolino » 7 gen 2013, 22:13

Ma hai specificato che il progetto è per PIC18F1320?
"Houston, Tranquillity Base here. The Eagle has landed." - Neil A.Armstrong

-------------------------------------------------------------

PIC Experience - http://www.picexperience.it
Avatar utente
Foto UtentePaolino
32,6k 8 12 13
G.Master EY
G.Master EY
 
Messaggi: 4226
Iscritto il: 20 gen 2006, 11:42
Località: Vigevano (PV)

0
voti

[108] Re: Simulare l'alba e il tramonto

Messaggioda Foto Utentecarlo87 » 8 gen 2013, 13:22

si certo almeno questo so sicuro che lo fatto...
Avatar utente
Foto Utentecarlo87
23 6
Frequentatore
Frequentatore
 
Messaggi: 139
Iscritto il: 27 ott 2011, 20:05

1
voti

[109] Re: Simulare l'alba e il tramonto

Messaggioda Foto UtentePaolino » 8 gen 2013, 14:27

Sembra che ti manchi qualche parte nel codice...

Il codice sorgente lo devi copiare TUTTO dal questo post

Poi, la funzione InitPic() la modifichi come descritto qui

Ciao.

Paolo.
"Houston, Tranquillity Base here. The Eagle has landed." - Neil A.Armstrong

-------------------------------------------------------------

PIC Experience - http://www.picexperience.it
Avatar utente
Foto UtentePaolino
32,6k 8 12 13
G.Master EY
G.Master EY
 
Messaggi: 4226
Iscritto il: 20 gen 2006, 11:42
Località: Vigevano (PV)

0
voti

[110] Re: Simulare l'alba e il tramonto

Messaggioda Foto Utentecarlo87 » 8 gen 2013, 20:00

Paolino sto da oggi pomeriggio che mi sto scervellando ma escono sempre dei errori:

make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `C:/alba-tramonto.X'
make -f nbproject/Makefile-default.mk dist/default/production/alba-tramonto.X.production.hex
make[2]: Entering directory `C:/alba-tramonto.X'
"C:\Program Files\Microchip\xc8\v1.12\bin\xc8.exe" --pass1 --chip=18F1320 -Q -G --asmlist --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -obuild/default/production/nbproject/alba-tramonto.p1 nbproject/alba-tramonto.c
(908) exit status = 1
nbproject/alba-tramonto.c:43: error: attempt to reprogram configuration setting "PWRT" with OFF (is ON)
nbproject/alba-tramonto.c:61: error: conflicting declarations for variable "ISR" (nbproject/alba-tramonto.c:61)
make[2]: Leaving directory `C:/alba-tramonto.X'
make[1]: Leaving directory `C:/alba-tramonto.X'
make[2]: *** [build/default/production/nbproject/alba-tramonto.p1] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 2s)
Gli dici che hai provato anche MPLAB 8.x con XC8 e hai quest'altro errore:
Build C:\alba-tramonto for device 18F1320
Using driver C:\Program Files\Microchip\xc8\v1.12\bin\xc8.exe

Make: The target "C:\alba-tramonto.p1" is out of date.
Executing: "C:\Program Files\Microchip\xc8\v1.12\bin\xc8.exe" --pass1 C:\alba-tramonto.c -q --chip=18F1320 -P --runtime=default --opt=default -N-1 -D__DEBUG=1 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Error [1389] C:\alba-tramonto.c; 43.1 attempt to reprogram configuration setting "PWRT" with OFF (is ON)
Error [1098] C:\alba-tramonto.c; 61.1 conflicting declarations for variable "ISR" (C:\alba-tramonto.c:61)
(908) exit status = 1

********** Build failed! **********


Mica posso uilizzare MPLAB 8.x che è più semplice e lo conosco un po'???
Scusami se ti sto creando solo disturbo Paolino
Avatar utente
Foto Utentecarlo87
23 6
Frequentatore
Frequentatore
 
Messaggi: 139
Iscritto il: 27 ott 2011, 20:05

PrecedenteProssimo

Torna a Firmware e programmazione

Chi c’è in linea

Visitano il forum: Nessuno e 7 ospiti