Analogue Input for PIC16F716

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
Rosenbaum
Flowcode V4 User
Posts: 25
Joined: Thu Feb 22, 2007 3:20 pm
Has thanked: 1 time
Been thanked: 5 times
Contact:

Analogue Input for PIC16F716

Post by Rosenbaum »

How can I realise an analogue input in Flowcode 3.1.0.31 for the PIC16F716. I tried it with an ADC and two component macros ( 1. Sample ADC 2. ReadAsByte) and the simulation was running very well, but when I tried to compile it I got the error message:


D:\Eigene Dateien\Flow\An In\An In.c(77:9): error: unknown identifier 'adresh'
D:\Eigene Dateien\Flow\An In\An In.c(77:2): error: error in expression
D:\Eigene Dateien\Flow\An In\An In.c(77:2): error: failed to generate expression
D:\Eigene Dateien\Flow\An In\An In.c(83:13): error: unknown identifier 'adresh'
D:\Eigene Dateien\Flow\An In\An In.c(83:13): error: invalid operand 'adresh'
D:\Eigene Dateien\Flow\An In\An In.c(83:20): error: failed to generate expression
D:\Eigene Dateien\Flow\An In\An In.c(83:20): error: invalid operand '<<'
D:\Eigene Dateien\Flow\An In\An In.c(83:10): error: failed to generate expression
D:\Eigene Dateien\Flow\An In\An In.c(84:14): error: unknown identifier 'adresl'
D:\Eigene Dateien\Flow\An In\An In.c(84:14): error: invalid operand 'adresl'
D:\Eigene Dateien\Flow\An In\An In.c(84:21): error: failed to generate expression
D:\Eigene Dateien\Flow\An In\An In.c(84:21): error: invalid operand '>>'
D:\Eigene Dateien\Flow\An In\An In.c(84:10): error: failed to generate expression

Can somebody help me to realise an analogue input wich I am able to simulate and also to compile.

User avatar
Steve
Matrix Staff
Posts: 3422
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Post by Steve »

Hello Rosenbaum,

The FCD file (Flowcode Chip Definition) for that device is wrong. I will fix it in the next release of Flowcode. In the meantime, you can change it yourself. Locate the 16F716.FCD file (in the FCD folder of the Flowcode folder) and replace the text with the following:


[Device]
Pins=18
Ports=2
ADCPins=4
ADCBits=8
MaxClock=20000000
PrescalerBits=3
ClockDivider=4
TimerOverflow=256
ConfigAddress=0x2007
ConfigCount=1
PWMCount=1

[Pins]
Pin1="RA2/AN2"
Pin2="RA3/AN3
Pin3="RA4/T0CKI"
Pin4="MCLR/VPP"
Pin5="VSS"
Pin6="RB0/INT"
Pin7="RB1/T1CKI"
Pin8="RB2/T1OSI"
Pin9="RB3/CCP1/P1A"
Pin10="RB4"
Pin11="RB5/P1B"
Pin12="RB6/P1C"
Pin13="RB7/P1D"
Pin14="VDD"
Pin15="OSC2/CLKOUT"
Pin16="OSC1/CLKIN"
Pin17="RA0/AN0"
Pin18="RA1/AN1"

[Ports]
PortPin1=0x0002
PortPin2=0x0003
PortPin3=0x0004
PortPin6=0x0100
PortPin7=0x0101
PortPin8=0x0102
PortPin9=0x0103
PortPin10=0x0104
PortPin11=0x0105
PortPin12=0x0106
PortPin13=0x0107
PortPin17=0x0000
PortPin18=0x0001

[PortMasks]
PortMask0=0x1F
PortMask1=0xFF

[ADCPins]
ADC0=17
ADC1=18
ADC2=1
ADC3=2

[Code]
;Substitute macros
;%c Clock Speed
;%o Operand
;%s Prescaler
;%p PortID
;%m MaskBits
;%i Inverse Mask
;%a ADC channel
;%a Config Address
;%v Config Value
;%r Interrupt Flag Register
;%b Interrupt Flag Bit
;%n Interrupt Macro Name
Directives="#include <system.h>\n#pragma CLOCK_FREQ %c\n"
MainStart="void main()\n{\n"
MainEnd="\tmainendloop: goto mainendloop;\n}\n\n"
IntStart="void interrupt(void)\n{\n"
IntEnd="}\n\n"
Initialise="adcon1 = 0x07;\n"
IntInit="option_reg = 0xC0;\n\n"
InputCmdFull="tris%p = tris%p | %m;\n%o = port%p;\n"
InputCmdOneBit="tris%p = tris%p | %m;\n%o = ((port%p & %m) == %m);\n"
InputCmdMask="tris%p = tris%p | %m;\n%o = port%p & %m;\n"
OutputCmdFull="tris%p = 0x00;\nport%p = %o;\n"
OutputCmdOneBit="tris%p = tris%p & %i;\nif (%o)\n\tport%p = (port%p & %i) | %m;\nelse\n\tport%p = port%p & %i;\n"
OutputCmdMask="tris%p = tris%p & %i;\nport%p = (port%p & %i) | %o;\n"
DelayCmdS="delay_s(%o);\n"
DelayCmdMs="delay_ms(%o);\n"
ADCCapture="char ta, cnt;\nta = trisa;\ntrisa = trisa | 0x0F;\nadcon1 = 0x00;\nadcon0 = 0x81 | (%a << 3);\ncnt =0;\nwhile (cnt <220) cnt++;\nadcon0 = adcon0 | 0x04;\nwhile (adcon0 & 0x04);\nadcon1 = 0x07;\nadcon0 = 0x80;\ntrisa = ta;\n"
ADCHigh="return 0;\n"
ADCLow="return adres;\n"
ADCFull="return adres;\n"
InitialPortLetter="a"
ConfigData="#pragma DATA %a, %v\n"
IntHandler="if (%r & (1 << %b))\n{\n\tFCM_%n();\n\tclear_bit(%r, %b);\n}\n"

[Defines]
Define1=#define P16F716
Define2=#define MX_PWM
Define3=#define MX_PWM_PORT portb
Define4=#define MX_PWM_TRIS trisb
Define5=#define MX_PWM_CNT 1
Define6=#define MX_PWM_1 3

[Interrupts]
;first 3 should always be 1=TMR0, 2=RB0INT, 3=PORTB
;any other interrupts need to also have this set: "intcon.PEIE=1;\n"
GeneralInit="intcon.GIE=1;\n"
Count=3
1=TMR0
2=RB0INT
3=PORTB

[TMR0]
;it is vital that this section remains exactly as-is (for all chips?)
Name=(this is retrieved from the resource file)
FlagReg=intcon
FlagBit=T0IF
EnReg=intcon
EnBit=T0IE
OptCnt=3
TmrOpt=3
Opt1="Clock Source Select"
Opt1Cnt=2
Opt1_1="Transition on T0CKI pin"
Opt1_1Val="option_reg.T0CS=1;\n"
Opt1_2="Internal clock (CLKO)"
Opt1_2Val="option_reg.T0CS=0;\n"
Opt2="Source Edge Select"
Opt2Cnt=2
Opt2_1="high-to-low transition on T0CKI"
Opt2_1Val="option_reg.T0SE=1;\n"
Opt2_2="low-to-high transition on T0CKI"
Opt2_2Val="option_reg.T0SE=0;\n"
Opt3="Prescaler Rate"
Opt3Cnt=9
Opt3_1="1:1"
Opt3_1Val="option_reg = (option_reg & 0xF0) | 0x08;\n"
Opt3_2="1:2"
Opt3_2Val="option_reg = (option_reg & 0xF0) | 0x00;\n"
Opt3_3="1:4"
Opt3_3Val="option_reg = (option_reg & 0xF0) | 0x01;\n"
Opt3_4="1:8"
Opt3_4Val="option_reg = (option_reg & 0xF0) | 0x02;\n"
Opt3_5="1:16"
Opt3_5Val="option_reg = (option_reg & 0xF0) | 0x03;\n"
Opt3_6="1:32"
Opt3_6Val="option_reg = (option_reg & 0xF0) | 0x04;\n"
Opt3_7="1:64"
Opt3_7Val="option_reg = (option_reg & 0xF0) | 0x05;\n"
Opt3_8="1:128"
Opt3_8Val="option_reg = (option_reg & 0xF0) | 0x06;\n"
Opt3_9="1:256"
Opt3_9Val="option_reg = (option_reg & 0xF0) | 0x07;\n"

[RB0INT]
Name=(this is retrieved from the resource file)
FlagReg=intcon
FlagBit=INTF
EnReg=intcon
EnBit=INTE
OptCnt=1
TmrOpt=0
Opt1="Interrupt Edge Select"
Opt1Cnt=2
Opt1_1="rising edge of RB0/INT"
Opt1_1Val="option_reg.INTEDG=1;\n"
Opt1_2="falling edge of RB0/INT"
Opt1_2Val="option_reg.INTEDG=0;\n"

[PORTB]
Name=(this is retrieved from the resource file)
FlagReg=intcon
FlagBit=RBIF
EnReg=intcon
EnBit=RBIE
OptCnt=0
TmrOpt=0

Post Reply