Jump to content
PLC Forum


Sign in to follow this  
dott.cicala

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

Recommended Posts

dott.cicala

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?

 

 

Share this post


Link to post
Share on other sites

giacomo56

Togli i ';' nella definizione dei pins.

 

Ciao

Share this post


Link to post
Share on other sites
dott.cicala

Grande! L'ho riguardato centinaia di volte e non me ne sono mai accorto! :wallbash:

 

01ac84a3084f324a5d0d939c5b1345f0.JPG

 

....perché sbagliavo proprio!

 

Grazie :thumb_yello:

Share this post


Link to post
Share on other sites
GiRock
#define _XTAL_FREQ 800000 // manca uno zero per gli 8MHz!!!

 

Share this post


Link to post
Share on other sites
GiRock

Ho provato a compilarlo al volo e non mi ha dato errori di nessun genere anche senza la modifica suggerita...

Share this post


Link to post
Share on other sites
dott.cicala

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...