Vai al contenuto
PLC Forum


MPLAB X IDE v3.25: Dov'è l'errore?


dott.cicala

Messaggi consigliati

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....

94e07a0bc0baafa597ae63cc5db377cf.JPG

 

54438782b9378fe8ba5ca957f20eba69.JPG

 

dove sbaglio?

 

 

Link al commento
Condividi su altri siti


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 account

Accedi

Hai già un account? Accedi qui.

Accedi ora
×
×
  • Crea nuovo/a...