dott.cicala Inserito: 26 febbraio 2016 Segnala Inserito: 26 febbraio 2016 Salve a tutti. Sto cercando di migrare un progettino da MikroC a MPLAB X v3.25. Per rendere la cosa più facile, integro piccole parti e correggo eventuali errori. Non riesco però ad assegnare a qualsiasi ingresso o uscita una variabile. Se nel programma leggo/scrivo direttamente la porta, la compilazione va a buon fine /* * File: Battery_Saver.c * Author: Stefano T. * MCU: PIC12F1840 * * Created on 31 gennaio 2016 */ //****************************************************************************** // Registri configurazione //****************************************************************************** #include <xc.h> #include <stdlib.h> #include <stdio.h> // CONFIG1 #pragma config FOSC = INTOSC // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin) #pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled) #pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled) #pragma config MCLRE = OFF // MCLR Pin Function Select (MCLR/VPP pin function is digital input) #pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled) #pragma config CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled) #pragma config BOREN = OFF // Brown-out Reset Enable (Brown-out Reset disabled) #pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin) #pragma config IESO = ON // Internal/External Switchover (Internal/External Switchover mode is enabled) #pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled) // CONFIG2 #pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off) #pragma config PLLEN = ON // PLL Enable (4x PLL enabled) #pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset) #pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.) #pragma config LVP = ON // Low-Voltage Programming Enable (Low-voltage programming enabled) // Low-Voltage Programming Enable (Low-voltage programming enabled) // Low-Voltage Programming Enable (Low-voltage programming enabled) //****************************************************************************** // Configurazione Frequenza Clock //****************************************************************************** #define _XTAL_FREQ 800000 //****************************************************************************** //****** TAGs ****************************************************************** unsigned int Dc1, Dc2, Dc3; unsigned int AnVal1, AnVal2; float In_min, In_max, Out_min, Out_max, ActVolt, Reference; // Defining Voltage treholds float Ready =12.5; float Warning=12.; float Alarm =11.8; // PINs association #define Mos PORTAbits.RA2; // Nmos gate #define LedG PORTAbits.RA4; #define LedR PORTAbits.RA5; //****************************************************************************** void main(void) { //****************************************************************************** // Registri configurazione PORT[A] //****************************************************************************** WPUA = 0b00000000; // Resistenze Pull Up disattivate APFCON = 0b00000000; // Alternate Pin Function TRISA = 0b11001011; // RA2-RA4-RA5=OUT - RA0-RA1-RA3=INPUT LATA = 0b00000000; // PORT[A] Latch register ANSELA = 0b00000011; // Ingressi Anaogici RA0-RA1 //****************************************************************************** // Registri configurazione INTERRUPTS //****************************************************************************** INTCON = 0b00000000; // INTERRUPTS CTRL REGISTER PIE1 = 0b00000000; // PERIPHERAL INTERRUPT ENABLE REGISTER 1 PIE2 = 0b00000000; // PERIPHERAL INTERRUPT ENABLE REGISTER 2 PIR1 = 0b00000000; // PERIPHERAL INTERRUPT REQUEST REGISTER 1 PIR2 = 0b00000000; // PERIPHERAL INTERRUPT REQUEST REGISTER 2 IOCAP = 0b00000000; // INTERRUPT-ON-CHANGE PORT[A] POS.EDGE REGISTER IOCAN = 0b00000000; // INTERRUPT-ON-CHANGE PORT[A] NEG.EDGE REGISTER IOCAF = 0b00000000; // INTERRUPT-ON-CHANGE PORT[A] FLAG REGISTER //****************************************************************************** // REGISRTI AD //****************************************************************************** ADCON1 = 0b10010000; // Right Justfied - AD Clk = Fosc/32 = 1uS //****************************************************************************** In_min=0; In_max=1023; Out_min=0.; Out_max=5.; //****************************************************************************** while(1) { //****************************************************************************** // Lettura AN0 - RA0 //****************************************************************************** ADCON0bits.CHS0 =0; // BIT0 - AN SELECTOR | ADCON0bits.CHS1 =0; // BIT1 - AN SELECTOR | ADCON0bits.CHS2 =0; // BIT2 - AN SELECTOR |- RA0 SELEZIONATO ADCON0bits.CHS3 =0; // BIT3 - AN SELECTOR | ADCON0bits.CHS4 =0; // BIT4 - AN SELECTOR | ADCON0bits.ADON =1; // ATTIVO CONVERTITORE AD __delay_us(6); // ATTENDO 6us ADCON0bits.GO =1; // ATTIVO LA CONVERSIONE __delay_us(11); // ATTENDO 11us AnVal1 =ADRES; // TRASFERISCO VALORE AD SU VARIABILE ADCON0bits.GO =0; // DISATTIVO LA CONVERSIONE ADCON0bits.ADON =0; // DISATTIVO CONVERTITORE AD //****************************************************************************** // Lettura AN1 - RA1 //****************************************************************************** ADCON0bits.CHS0 =1; // BIT0 - AN SELECTOR | ADCON0bits.CHS1 =0; // BIT1 - AN SELECTOR | ADCON0bits.CHS2 =0; // BIT2 - AN SELECTOR |- RA1 SELEZIONATO ADCON0bits.CHS3 =0; // BIT3 - AN SELECTOR | ADCON0bits.CHS4 =0; // BIT4 - AN SELECTOR | ADCON0bits.ADON =1; // ATTIVO CONVERTITORE AD __delay_us(6); // ATTENDO 6us ADCON0bits.GO =1; // ATTIVO LA CONVERSIONE __delay_us(11); // ATTENDO 11us AnVal2 =ADRES; // TRASFERISCO VALORE AD SU VARIABILE ADCON0bits.GO =0; // DISATTIVO LA CONVERSIONE ADCON0bits.ADON =0; // DISATTIVO CONVERTITORE AD //****************************************************************************** // CTRL limiti //****************************************************************************** if(AnVal1<In_min)AnVal1=In_min; if(AnVal1>In_max)AnVal1=In_max; if(AnVal2<In_min)AnVal2=In_min; if(AnVal2>In_max)AnVal2=In_max; //****************************************************************************** // Floating Point Scaling - Conversione in Volt //****************************************************************************** ActVolt =(Out_min+(((AnVal1-In_min)/(In_max-In_min))*(Out_max-Out_min))); Reference=(Out_min+(((AnVal2-In_min)/(In_max-In_min))*(Out_max-Out_min))); //****************************************************************************** // Controllo tensione //****************************************************************************** PORTAbits.RA4=(ActVolt<=Reference); } } se invece sostituisco la porta con la sua dichiarazione associata ad una variabile, ottengo un errore di sintassi.... dove sbaglio?
giacomo56 Inserita: 26 febbraio 2016 Segnala Inserita: 26 febbraio 2016 Togli i ';' nella definizione dei pins. Ciao
dott.cicala Inserita: 26 febbraio 2016 Autore Segnala Inserita: 26 febbraio 2016 Grande! L'ho riguardato centinaia di volte e non me ne sono mai accorto! ....perché sbagliavo proprio! Grazie
GiRock Inserita: 26 febbraio 2016 Segnala Inserita: 26 febbraio 2016 #define _XTAL_FREQ 800000 // manca uno zero per gli 8MHz!!!
GiRock Inserita: 26 febbraio 2016 Segnala Inserita: 26 febbraio 2016 Ho provato a compilarlo al volo e non mi ha dato errori di nessun genere anche senza la modifica suggerita...
dott.cicala Inserita: 26 febbraio 2016 Autore Segnala Inserita: 26 febbraio 2016 A me col punto e virgola non lo compila....anzi...in proteus8.3 lo compila in mplab x invece no. Per lo zero.....hai ragione.....
Messaggi consigliati
Crea un account o accedi per commentare
Devi essere un utente per poter lasciare un commento
Crea un account
Registrati per un nuovo account nella nostra comunità. è facile!
Registra un nuovo accountAccedi
Hai già un account? Accedi qui.
Accedi ora