16F1786 issue with simple program.


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2010
    Posts
    37

    Default 16F1786 issue with simple program.

    I try to compile this with PicBasic 3.0.7:
    Code:
    'PIC16F1786
    #CONFIG
        __config _MCLRE_OFF
    #ENDCONFIG
    for PIC16F176 but I got an error:
    [ASM ERROR] CODE_1.ASM (33) : Argument out of range (not a valid register address)
    If I compile for PIC16F690 or other, the error doesn't occur.
    I have no idea what happened.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,520


    Did you find this post helpful? Yes | No

    Default Re: 16F1786 issue with simple program.

    Hi,
    The 16F1786 has more than one config register while the 16F690 (and probably the "others" you've tried) doesn't.
    Code:
    #CONFIG
        __config _CONFIG1, _MCLRE_OFF
    #ENDCONFIG
    Just remember that when you include a #CONFIG/#ENDCONFIG as above it replaces ALL of the PBP default ones, reverts to the devices specific HARDWARE defaults and THEN sets the bits you include in your block. I usually copy the default PBP ones and the changed/add what I need.

    For the 16F1786 the PBP defaults are:
    Code:
      #CONFIG
            __config _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_ON &  _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF
            __config _CONFIG2, _PLLEN_OFF & _LVP_OFF & _VCAPEN_OFF
      #ENDCONFIG
    /Henrik.

  3. #3
    Join Date
    Jan 2014
    Posts
    84


    Did you find this post helpful? Yes | No

    Default Re: 16F1786 issue with simple program.

    Try this:

    Code:
    #CONFIG
             __MCLRE_OFF  
    #ENDCONFIG

  4. #4
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: 16F1786 issue with simple program.

    Here is one way to handle configs for multiple processsors...

    Code:
        #IF __PROCESSOR__ = "16F1828"
            #CONFIG
            __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
            __CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_25 & _LVP_OFF
            #endconfig
        #ELSE
            #IF __PROCESSOR__ = "16F690"
                #CONFIG
                __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _IESO_OFF & _FCMEN_OFF
                #endconfig
            #ELSE
                #ERROR "Program does not support " + __PROCESSOR__
            #ENDIF
        #ENDIF
    
        #msg "compiling for target " + __PROCESSOR__
    it dosen't paste in a code window very well (due to line wrap) but you should get the idea.
    try and copy/paste it into your IDE
    Last edited by Heckler; - 23rd January 2016 at 17:22.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  5. #5
    Join Date
    Jan 2010
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: 16F1786 issue with simple program.

    Thank you very much HenrikOlsson and Heckler.
    I can compile now my PIC16F1786. Because you provide me a lot of information about this micro, I decided to read (finally) some information provided in PicBasic\DEVICE folder.
    Thank you again.
    Last edited by luxornet; - 24th January 2016 at 06:31.

  6. #6
    Join Date
    Jan 2010
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: 16F1786 issue with simple program.

    I figure a HelloWorld program and works fine in Proteus Simulator.
    But I stuck when I try to read AN0 analog port.
    The PicBasic ADCIN 0, something return "0".
    No better luck when I try to explicitly read AN0, like bellow:
    Code:
    'PIC16F1786
        #CONFIG
            __config _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_ON &  _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF
            __config _CONFIG2, _PLLEN_OFF & _LVP_OFF & _VCAPEN_OFF
        #ENDCONFIG
        
        include "MODEDEFS.BAS"
        
        DEFINE OSC 8
        OSCCON.6 = 1
        OSCCON.5 = 1
        OSCCON.4 = 1
        OSCCON.3 = 0
        OSCCON.1 = 1
    
        TRISA = %00001001    'AN0 is Analog
        TRISB = %11000000
        TRISC = %00000000
    
        
        ANSELA = %00001001 'digital; AN0 is analog
        ANSELB = %00001001
    
        'Configure VREF:
    '    ADCON1.1 = 0
    '    ADCON1.0 = 1 'VREF+ is connected to VREF+ pin
        ADCON1.1 = 0
        ADCON1.0 = 0 'VREF+ is connected to VDD
    
        ADCON1.2 = 0 ' VREF- is connected to VSS
        
        'ADC result
        ADCON0.7 = 1 ' 10 bits result
        ADCON0.0 = 1 ' ADC is enabled   
        
        ADCON1.6 = 1 'FOSC/64
        ADCON1.5 = 1
        ADCON1.4 = 0
        
        CM1CON0.7 = 0'comparator is disabled
        CM2CON0.7 = 0'comparator is disabled
        
        DACCON0.7 = 0 'DAC is disabled
        
        'disable intrerupt:
        INTCON = 0'intrerupt is disabled
        
        DEFINE ADC_BITS 10       ' Set number of bits in result
        DEFINE ADC_CLOCK 3     ' Set clock source (rc = 3)
        DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds 
    
    
    '-[The connection between the LCD display and the microcontroller is as follows:]-
        ' Define LCD pins
        DEFINE LCD_DREG PORTC 'LCD data port 
        DEFINE LCD_DBIT 0 'LCD data starting bit 0 or 4 
        DEFINE LCD_RSREG PORTA 'LCD register select port 
        DEFINE LCD_RSBIT 2 'LCD register select bit       - pinul RS
        DEFINE LCD_EREG PORTA 'LCD enable port 
        DEFINE LCD_EBIT 7 'LCD enable bit                 - pinul E
    '    DEFINE LCD_RWREG PORTC 'LCD read/write port 
    '    DEFINE LCD_RWBIT 6 'LCD read/write bit 
        DEFINE LCD_BITS 4 'LCD bus size 4 or 8 
        DEFINE LCD_LINES 2 'Number lines on LCD 
        DEFINE LCD_COMMANDUS 2000 'Command delay time in us 
        DEFINE LCD_DATAUS 50 'Data delay time in us 
    
    ;-----[Variables]----------------------------------------------------
        Thermocouple  var word
        adval	      var	word    
    ;----[Initialization]-----------------------------------------------------------
    
    '---[Hello World]---------------------------------------------------------------
    Afisaj:
        LCDOUT $FE,1 ' Clear LCD
        LCDOUT $FE,2 ' Home cursor
        'Display initial screen
        lcdout $FE,2,"PIC16F1786",$fe, $C0,"Luxornet@2016"    
        pause 1000
        LCDOUT $FE,1 ' Clear LCD
        LCDOUT $FE,2 ' Home cursor
    
    ;----[Main program loop]--------------------------------------------------------
    Main:
        'ADCIN 0, Thermocouple
    
    '  	ADCON0 = %10000001	' Configure and turn on A/D Module
    
      	ADCON0.7 = 1 '10 bits result
    	pause 10
        ADCON0.2 = 0	' use channel 0
        ADCON0.3 = 0
        ADCON0.4 = 0
        ADCON0.5 = 0
        ADCON0.6 = 0
        
        ADCON0.0 = 1 'ADC is enabled 
        
        ADCON0.1 = 1    ' Start Conversion   'Bit GO/DONE  
    
    Voltmeter1:
        Pause 100
    	If ADCON0.1 = 1 Then Voltmeter1	' Wait for low on bit-1 of ADCON0, conversion finished
    
    	adval.highbyte = ADRESH	' Move HIGH byte of result to adval
    	adval.lowbyte = ADRESL	' Move LOW byte of result to adval
    
        lcdout $FE,2,"Thermocouple: ",dec adval,"   "
        pause 500
       
    GOTO Main
    Last edited by luxornet; - 24th January 2016 at 13:10.

Similar Threads

  1. 18F4550 issue with simple program.
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 20th January 2016, 11:48
  2. Program Configuration check mark issue... maybe.
    By Szczepaniec in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 8th November 2012, 18:17
  3. Simple LED driving issue - setup?
    By George in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th March 2011, 01:54
  4. Code issue with a flashing light(simple question)
    By IAmTheAnswer in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 8th May 2010, 11:46
  5. Help with simple program
    By mykewl in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 31st July 2008, 08:58

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts