PDA

View Full Version : 16F1786 issue with simple program.



luxornet
- 23rd January 2016, 13:12
I try to compile this with PicBasic 3.0.7:


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

HenrikOlsson
- 23rd January 2016, 15:19
Hi,
The 16F1786 has more than one config register while the 16F690 (and probably the "others" you've tried) doesn't.

#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:

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

midali
- 23rd January 2016, 15:28
Try this:


#CONFIG
__MCLRE_OFF
#ENDCONFIG

Heckler
- 23rd January 2016, 17:20
Here is one way to handle configs for multiple processsors...


#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

luxornet
- 24th January 2016, 06:17
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.

luxornet
- 24th January 2016, 13:07
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:


'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