I report this problem again on the names of the pins that give big problems, I paste this test program that does not work the ADC inputs. If you change the name of the PIN AN0, AN1 etc. everything works well, I spent a lot of time to understand the reason.
'****************************************************************
#chip16F877a,8' Clock
#optionexplicit' -- MPASM config
#configOSC=HS, PWRTE=ON, BOREN=ON, LVP=OFF, WDTE=OFF, DEBUG=OFF'==========================================================================='***** SETTAGGIO PORTE
#defineAN0PORTA.0' A/D tensione Batt1
#defineAN1PORTA.1' A/D tensione 2
#defineAN2PORTA.2' A/D 3
#defineAN3PORTA.3' A/D 4
#defineBuzzPORTA.4' buzzer errore o avviso problema attivo LOW
#defineAN4PORTA.5' A/D corrente linea'-------------------
#defineADR0PORTB.0'
#defineADR1PORTB.1'
#defineADR2PORTB.2'
#defineB3PORTB.3'
#defineEnPORTB.4' LCD data LCD seriale
#defineRsPORTB.5' LCD clock
#defineRxdbPORTB.6' RX debug (PICKIT2 tx)
#defineTxdbPORTB.7' TX debug (PICKIT2 rx)'-- PORTA C indirizzo=7
#defineDsPORTC.0' DS1820 temperatura ambiente
#defineSpkPORTC.1'
#defineVentPORTC.2' ventilazione ambiente
#defineRelePORTC.3' Disattivazione banco batteria
#defineC4PORTC.4'
#defineC5PORTC.5'
#definetx485PORTC.6' TX dati rs485 38400 Bps
#definerx485PORTC.7' RX dati rs485'-- PORTA D
#defineD0PORTD.0'
#defineD1PORTD.1'
#defineD2PORTD.2'
#defineD3PORTD.3'
#defineD4PORTD.4'
#defineD5PORTD.5'
#defineD6PORTD.6'
#defineD7PORTD.7''-- PORTA E
#defineAN5PORTE.0' A/D temperatura NTC
#defineAN6PORTE.1
#defineAN7PORTE.2
#defineUSART_BAUD_RATE38400'Hser baud rate
#defineUSART_TX_BLOCKING
#defineLowSpeed0'ADC; -- LCD seriale I2C
#defineI2C_MODEMaster
#defineI2C_DATAPORTb.4
#defineI2C_CLOCKPORTb.5
#defineLCD_I2C_Address_1;Address of I2C adapter Default 0x4E
#defineI2C_DISABLE_INTERRUPTSON'Optionally, you can reduce the I2C timings.' #define I2C_BIT_DELAY 0 us' #define I2C_CLOCK_DELAY 1 us' #define I2C_END_DELAY 0 us'''Set up LCD
#defineLCD_IO10'TIPO di lcd'You may need to use SLOW or MEDIUM if your LCD is a slower device.
#defineLCD_SPEEDFAST'You may need to invert these states. Dependent of LCD I2C adapter.
#defineLCD_Backlight_On_State1
#defineLCD_Backlight_Off_State0
#include<DS18s20.h>
#defineDQDS; change port configuration as required' ----- Include library
#include<SoftSerial.h>; ----- Config Serial UART :
#defineSER1_BAUD9600; baudrate must be defined
#defineSER1_DATABITS8; databits optional (default = 8)
#defineSER1_STOPBITS1; stopbits optional (default = 1)
#defineSER1_INVERTOff; inverted polarity optional (default = Off); Config I/O ports for transmitting:
#defineSER1_TXPORTPORTB; I/O port (without .bit) must be defined
#defineSER1_TXPIN7; portbit must be defined; Config I/O ports for receiving:
#defineSER1_RXPORTPORTB; I/O port (without .bit) must be defined
#defineSER1_RXPIN6; portbit must be defined
#defineSER1_RXNOWAITOff; don't wait for stopbit optional (default = Off)'--------------------------------------------------------------'--- VARIABILI PROGRAMMA PRINCIPALE banco 0 - 96 BYTE max ----
#defineAg_volt54' variazione tollerata temperatura LITIO
#defineAG_amp200'' --dimTmp,Tmp1,Tmp2asbytedimTmpw,Tmpw1asworddimTmplaslong' ---dimVbat(10)asword' tensione elementi batteriadimI_inpasWord' Corrente caricadimI_outasword' Corrente scaricadimTc_ambasByte' temperatura ambientedimTc_deltaasword' DELTA temperaturadimVtotasword' tensione totale banco'==== SETTAGGI DELLE PORTE DEL PIC I/O ecc. ======================' -------- bit a bit controllo 0=output 1=inputdirportab'00101111'' legge impostazioni INP/OUTdirportbb'01001000'' delle portedirportcb'10110000'dirportdb'10111111'dirporteb'10111111''--------- ripristina porte ---------'epread 1,tmp 'IDdeldispositivo'epread 2,control ''start initialization processdo' legge ADC corrente temperaturaser1printReadAD10(an4)' corrente carica scaricaser1print""ser1printReadAD10(an5)' PORTE 0 delta temperaturaser1print" -- "wait5Sloop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
No. You can overwrite any constant in your user program. This is how much of Great Cow BASIC works.. a really good example is PWM. We set the Frequency and the Duty at 38 and 50% respectively... in your user program you just refined the same constants to overwrite the defaults.
Anyway. Please dont redefine as they are byte constants not port.bit
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I report this problem again on the names of the pins that give big problems, I paste this test program that does not work the ADC inputs. If you change the name of the PIN AN0, AN1 etc. everything works well, I spent a lot of time to understand the reason.
These are very wrong. PortA.0 is AN0 and etc. But, you do not create additional constants to the ANx. They are defined for you - check the datasheet,
I thought that if there are double definitions, the compiler would report the error.
No. You can overwrite any constant in your user program. This is how much of Great Cow BASIC works.. a really good example is PWM. We set the Frequency and the Duty at 38 and 50% respectively... in your user program you just refined the same constants to overwrite the defaults.
Anyway. Please dont redefine as they are byte constants not port.bit
How is the mega328p include using port bits?