Menu

Problem pins names

Help
Gigi
2020-04-09
2020-04-09
  • Gigi

    Gigi - 2020-04-09

    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.

    '****************************************************************
    #chip 16F877a,8    ' Clock
    #option explicit
    
    ' -- MPASM config
    #config OSC=HS, PWRTE=ON, BOREN=ON, LVP=OFF, WDTE=OFF, DEBUG=OFF
    
    '===========================================================================
    '*****  SETTAGGIO PORTE
    #define AN0     PORTA.0     ' A/D tensione Batt1
    #define AN1     PORTA.1     ' A/D tensione 2
    #define AN2     PORTA.2     ' A/D 3
    #define AN3     PORTA.3     ' A/D 4
    #define Buzz    PORTA.4     ' buzzer errore o avviso problema attivo LOW
    #define AN4     PORTA.5     ' A/D corrente linea
    '-------------------
    #define ADR0      PORTB.0    '
    #define ADR1      PORTB.1    '
    #define ADR2      PORTB.2    '
    #define B3        PORTB.3    '
    #define En        PORTB.4    ' LCD data LCD seriale
    #define Rs        PORTB.5    ' LCD clock
    #define Rxdb      PORTB.6    ' RX debug (PICKIT2 tx)
    #define Txdb      PORTB.7    ' TX debug (PICKIT2 rx)
    '-- PORTA C indirizzo=7
    #define Ds      PORTC.0      ' DS1820 temperatura ambiente
    #define Spk     PORTC.1      '
    #define Vent    PORTC.2      ' ventilazione ambiente
    #define Rele    PORTC.3      ' Disattivazione banco batteria
    #define C4      PORTC.4      '
    #define C5      PORTC.5      '
    #define tx485   PORTC.6     ' TX dati rs485 38400 Bps
    #define rx485   PORTC.7     ' RX dati rs485
    '-- PORTA D
    #define D0      PORTD.0      '
    #define D1      PORTD.1      '
    #define D2      PORTD.2      '
    #define D3      PORTD.3      '
    #define D4      PORTD.4      '
    #define D5      PORTD.5      '
    #define D6      PORTD.6     '
    #define D7      PORTD.7     '
    '-- PORTA E
    #define AN5      PORTE.0    ' A/D temperatura NTC
    #define AN6      PORTE.1
    #define AN7      PORTE.2
    
    #define USART_BAUD_RATE 38400  'Hser baud rate
    #define USART_TX_BLOCKING
    #define LowSpeed 0          'ADC
    
    ; -- LCD seriale I2C
    #define I2C_MODE Master
    #define I2C_DATA PORTb.4
    #define I2C_CLOCK PORTb.5
    #define LCD_I2C_Address_1     ;Address of I2C adapter  Default 0x4E
    
    #define I2C_DISABLE_INTERRUPTS ON
       '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
       #define LCD_IO 10   'TIPO di lcd
    'You may need to use SLOW or MEDIUM if your LCD is a slower device.
       #define LCD_SPEED FAST
       'You may need to invert these states. Dependent of LCD I2C adapter.
       #define LCD_Backlight_On_State  1
       #define LCD_Backlight_Off_State 0
    
    
    #include <DS18s20.h>
    #define   DQ DS ; change port configuration as required
    ' ----- Include library
    #include <SoftSerial.h>
    ; ----- Config Serial UART :
    #define SER1_BAUD 9600   ; baudrate must be defined
    #define SER1_DATABITS 8    ; databits optional (default = 8)
    #define SER1_STOPBITS 1    ; stopbits optional (default = 1)
    #define SER1_INVERT Off    ; inverted polarity optional (default = Off)
    ; Config I/O ports for transmitting:
    #define SER1_TXPORT PORTB  ; I/O port (without .bit) must be defined
    #define SER1_TXPIN 7       ; portbit  must be defined
    ; Config I/O ports for receiving:
    #define SER1_RXPORT PORTB  ; I/O port (without .bit) must be defined
    #define SER1_RXPIN 6       ; portbit  must be defined
    #define SER1_RXNOWAIT Off  ; don't wait for stopbit optional (default = Off)
    
    '--------------------------------------------------------------
    '--- VARIABILI PROGRAMMA PRINCIPALE  banco 0 - 96 BYTE max ----
    #define Ag_volt   54       ' variazione tollerata temperatura LITIO
    #define AG_amp    200      '
    
    ' --
    dim Tmp,Tmp1,Tmp2      as byte
    dim Tmpw,Tmpw1        as word
    dim Tmpl              as long
    
    
    ' ---
    dim Vbat(10)    as word   ' tensione elementi batteria
    dim I_inp       as Word   ' Corrente carica
    dim I_out       as word   ' Corrente scarica
    
    dim Tc_amb      as Byte     ' temperatura ambiente
    dim Tc_delta    as word     ' DELTA temperatura
    dim Vtot        as word     ' tensione totale banco
    
    '==== SETTAGGI DELLE PORTE DEL PIC I/O ecc. ======================
    
    ' --------  bit a bit controllo 0=output  1=input
    dir porta b'00101111'    ' legge impostazioni INP/OUT
    dir portb b'01001000'    ' delle porte
    dir portc b'10110000'
    dir portd b'10111111'
    dir porte b'10111111'
    
    '--------- ripristina porte ---------
    'epread    1,tmp        'ID del dispositivo
    'epread    2,control     '
    
    'start initialization process
    do
      ' legge ADC corrente temperatura
    
      ser1print  ReadAD10(an4)       ' corrente carica scarica
    ser1print " "
      ser1print ReadAD10(an5)      ' PORTE 0  delta temperatura
    ser1print " -- "
    
    
    wait 5 S
    loop
    
     
  • Anobium

    Anobium - 2020-04-09
    '===========================================================================
    '*****  SETTAGGIO PORTE
    #define AN0     PORTA.0     ' A/D tensione Batt1
    #define AN1     PORTA.1     ' A/D tensione 2
    #define AN2     PORTA.2     ' A/D 3
    #define AN3     PORTA.3     ' A/D 4
    #define Buzz    PORTA.4     ' buzzer errore o avviso problema attivo LOW
    #define AN4     PORTA.5     ' A/D corrente linea
    
    '-- PORTA E
    #define AN5      PORTE.0    ' A/D temperatura NTC
    #define AN6      PORTE.1
    #define AN7      PORTE.2
    

    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,

     
  • Gigi

    Gigi - 2020-04-09

    I thought that if there are double definitions, the compiler would report the error.

     
    • Anobium

      Anobium - 2020-04-09

      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

       
      • stan cartwright

        stan cartwright - 2020-04-09

        How is the mega328p include using port bits?

        #chip mega328p, 16
        
        'Startup routine
        #startup InitUno, 90
        
        'A/D speed
        'Need to slow down due to high clock speed
        #define ADSpeed LowSpeed
        
        'Analog inputs
        'Analog 0 to 5 = AN0 to AN5 in GCBASIC
        #define ANALOG_0 PORTC.0
        #define ANALOG_1 PORTC.1
        #define ANALOG_2 PORTC.2
        #define ANALOG_3 PORTC.3
        #define ANALOG_4 PORTC.4
        #define ANALOG_5 PORTC.5
        #define RESET portc.6
        
        'Digital pins
        #define DIGITAL_0 PORTD.0
        #define DIGITAL_1 PORTD.1
        #define DIGITAL_2 PORTD.2
        #define DIGITAL_3 PORTD.3
        #define DIGITAL_4 PORTD.4
        
        #define DIGITAL_5 PORTD.5
        #define DIGITAL_6 PORTD.6
        #define DIGITAL_7 PORTD.7
        #define DIGITAL_8 PORTB.0
        
        #define DIGITAL_9 PORTB.1
        #define DIGITAL_10 PORTB.2
        #define DIGITAL_11 PORTB.3
        #define DIGITAL_12 PORTB.4
        #define DIGITAL_13 PORTB.5
        
        'On-board devices
        #define LED PORTB.5
        #define BUTTON PORTC.6
        
        '''@hide
        Sub InitUno
          'Set UART pin directions
          Dir PORTD.0 In
          Dir PORTD.1 Out
        End Sub
        
         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.