14.11.2012 Views

Guide to adding PIC micro-controllers to Flowcode - Matrix ...

Guide to adding PIC micro-controllers to Flowcode - Matrix ...

Guide to adding PIC micro-controllers to Flowcode - Matrix ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Guide</strong> <strong>to</strong> <strong>adding</strong> <strong>PIC</strong> <strong>micro</strong>-<strong>controllers</strong> <strong>to</strong> <strong>Flowcode</strong>.<br />

Contents<br />

1. Introduction<br />

2. Description of the FCD Sections<br />

a. [Device]<br />

b. [Config]<br />

c. [Pins]<br />

d. [Ports]<br />

e. [PortMasks]<br />

f. [ADCPins]<br />

g. [Code]<br />

h. [Defines]<br />

i. [Interrupts]<br />

3. Example FCD conversion 16F84 <strong>to</strong> a 16C711<br />

1. Introduction<br />

<strong>Flowcode</strong> collects its list of <strong>micro</strong>-<strong>controllers</strong> from the FCD files located inside the <strong>Flowcode</strong> V3/FCD/<br />

direc<strong>to</strong>ry.<br />

FCD stands for <strong>Flowcode</strong> definition file.<br />

Therefore <strong>adding</strong> a new <strong>PIC</strong> <strong>micro</strong>-controller <strong>to</strong> <strong>Flowcode</strong> is simply a case of creating a FCD file for<br />

the <strong>micro</strong>controller.<br />

The easiest way <strong>to</strong> get started is <strong>to</strong> find a <strong>micro</strong>-controller that is as similar as possible <strong>to</strong> the device<br />

you wish <strong>to</strong> implement. You can then copy the similar device’s FCD file and then edit any parts that<br />

are not similar.<br />

The definition file is broken down in<strong>to</strong> the following sections.<br />

[Device]<br />

[Config] (optional)<br />

[Pins]<br />

[Ports]<br />

[PortMasks]<br />

[ADCPins]<br />

[Code]<br />

[Defines]<br />

[Interrupts]<br />

2. Description of the FCD Sections<br />

a. [Device]<br />

Contains information about the <strong>micro</strong>-controller such as the number of pins, the number of ports, ADC<br />

inputs, Maximum clock speed settings etc.<br />

Optional extras that can be added <strong>to</strong> the device section<br />

ChipName=16C711 – Specifies the target name of the <strong>micro</strong>-controller if the FCD name is different <strong>to</strong><br />

the target name.<br />

ConfigOverride=1 – Specifies a fixed configuration word<br />

Specifying a fixed configuration requires the configuration data <strong>to</strong> be given in a Config section.


. [Config]<br />

This optional section forces the chip <strong>to</strong> compile with a certain set of configuration data. All 14 entries<br />

(0 <strong>to</strong> 13) need <strong>to</strong> be entered, even if the chip has only 1 or 2 configuration words.<br />

16F Example:<br />

[Config]<br />

0=0x3F2A<br />

1=0xFFFF<br />

2=0xFFFF<br />

3=0xFFFF<br />

4=0xFFFF<br />

5=0xFFFF<br />

6=0xFFFF<br />

7=0xFFFF<br />

8=0xFFFF<br />

9=0xFFFF<br />

10=0xFFFF<br />

11=0xFFFF<br />

12=0xFFFF<br />

13=0xFFFF<br />

18F Example:<br />

[Config]<br />

0=0x20<br />

1=0x0E<br />

2=0x3E<br />

3=0x1E<br />

4=0x00<br />

5=0x81<br />

6=0x81<br />

7=0x00<br />

8=0x0F<br />

9=0xC0<br />

10=0x0F<br />

11=0xA0<br />

12=0x0F<br />

13=0x40<br />

c. [Pins]<br />

Used by the real time “Chip” diagram in <strong>Flowcode</strong>, Assigns string names <strong>to</strong> the pins.<br />

Pin1="RA2/AN2"<br />

Pin2="RA3/AN3"<br />

d. [Ports]<br />

Used <strong>to</strong> configure where the I/O is on the real time “Chip” diagram. Pins that are assigned <strong>to</strong> I/O<br />

should be listed with their port and pin information.<br />

Examples<br />

PortPin1=0x0002 – Means that pin 1 of the <strong>micro</strong>-controller is RA2<br />

PortPin5=0x0007 – Means that pin 5 of the <strong>micro</strong>-controller is RA7<br />

PortPin8=0x0102 – Means that pin 8 of the <strong>micro</strong>-controller is RB2<br />

PortPin21=0x0107 – Means that pin 21 of the <strong>micro</strong>-controller is RB7<br />

PortPin25=0x0302 – Means that pin 25 of the <strong>micro</strong>-controller is RD2


e. [PortMasks]<br />

Used <strong>to</strong> configure which I/O lines are available on a port.<br />

Example of an incomplete port<br />

PortMask0=0x1F – Means that PortA has only 5 pins<br />

PortMask4=0x07 – Means that PortE has only 3 pins<br />

Example of a complete port<br />

PortMask1=0xFF – Means that PortB has all 8 pins<br />

f. [ADCPins]<br />

Configures which pins have analogue capabilities. The ADC# is the (AN) channel of the pin and the<br />

number being assigned <strong>to</strong> it is the pin number itself.<br />

ADC0=17<br />

ADC1=18<br />

ADC2=1<br />

ADC3=2<br />

g. [Code]<br />

Most of the code section can be copied as is. A few things <strong>to</strong> look out for are.<br />

Initialise – Used <strong>to</strong> configure the <strong>PIC</strong><strong>micro</strong> <strong>to</strong> use all I/O as digital<br />

ADCCapture – Used <strong>to</strong> capture an analogue signal from channel %a<br />

h. [Defines]<br />

This section details the peripherals of the <strong>micro</strong>-controller. The easiest way <strong>to</strong> complete this section is<br />

<strong>to</strong> find other devices with the same hardware configuration and use their peripheral list. You must<br />

make sure that the ports and pins of the devices match correctly.<br />

i. [Interrupts]<br />

This section details the common interrupts that are available <strong>to</strong> the <strong>micro</strong>-controller. This section can<br />

be left as is. If there are interrupts you wish <strong>to</strong> use that are not the typical common ones then you can<br />

simply use the cus<strong>to</strong>m Interrupt function that is available within <strong>Flowcode</strong>.<br />

Implementing your own Interrupt – This will perform an interrupt when the ADC has finished<br />

sampling. Note that register names are lower case where as bit names are upper case.


3. Example FCD conversion 16F84 <strong>to</strong> a 16C711<br />

Creating a FCD file for a <strong>PIC</strong>16C711.<br />

The <strong>PIC</strong>16C711 is very similar <strong>to</strong> the <strong>PIC</strong>16F84. The only major differences being that the 16C711 has<br />

four analogue input pins and a larger EEPROM memory.<br />

So <strong>to</strong> begin we can take a copy of the 16F84.FCD and rename it 16C711.FCD.<br />

Remember that all of the information you require is contained in the <strong>PIC</strong><strong>micro</strong> datasheet. It may take a<br />

while <strong>to</strong> track down exactly what you are looking for but everything you require will be there.<br />

Below is a copy of the 16F84 FCD file with items that need removing highlighted in red. The 16C711<br />

modifications are highlighted in green.<br />

[Device]<br />

Pins=18<br />

Ports=2<br />

ADCPins=0 ADCPins=4<br />

ADCBits=0ADCBits=8<br />

MaxClock=10000000MaxClock=10000000<br />

PrescalerBits=3<br />

ClockDivider=4<br />

TimerOverflow=256<br />

ConfigAddress=0x2007<br />

ConfigCount=1<br />

PWMCount=0<br />

EepromSize=64EepromSize=1024<br />

HasAltPWM=0<br />

Pwm2IsD4=0<br />

ChipName=16C711<br />

[Pins]<br />

Pin1="RA2"Pin1="RA2/AN2"<br />

Pin2="RA3"Pin2="RA3/AN3/Vref"<br />

Pin3="RA4/T0CKI"<br />

Pin4="MCLR"<br />

Pin5="Vss"<br />

Pin6="RB0/INT"<br />

Pin7="RB1"<br />

Pin8="RB2"<br />

Pin9="RB3"<br />

Pin10="RB4"<br />

Pin11="RB5"<br />

Pin12="RB6"<br />

Pin13="RB7"<br />

Pin14="Vdd"<br />

Pin15="OSC2/CLKOUT"<br />

Pin16="OSC1/CLKIN"<br />

Pin17="RA0"Pin17="RA0/AN0"<br />

Pin18="RA1"Pin18="RA1/AN1"<br />

[Ports]<br />

PortPin1=0x0002<br />

PortPin2=0x0003<br />

PortPin3=0x0004<br />

PortPin6=0x0100<br />

PortPin7=0x0101<br />

PortPin8=0x0102<br />

PortPin9=0x0103<br />

PortPin10=0x0104<br />

PortPin11=0x0105<br />

PortPin12=0x0106<br />

PortPin13=0x0107<br />

PortPin17=0x0000<br />

PortPin18=0x0001<br />

[PortMasks]<br />

PortMask0=0x1F<br />

PortMask1=0xFF


[ADCPins]<br />

ADC0=17<br />

ADC1=18<br />

ADC2=1<br />

ADC3=2<br />

[Code]<br />

;Substitute macros<br />

;%c Clock Speed<br />

;%o Operand<br />

;%s Prescaler<br />

;%p PortID<br />

;%m MaskBits<br />

;%i Inverse Mask<br />

;%a ADC channel<br />

;%a Config Address<br />

;%v Config Value<br />

;%r Interrupt Flag Register<br />

;%b Interrupt Flag Bit<br />

;%n Interrupt Macro Name<br />

Directives="#include \n#pragma CLOCK_FREQ %c\n"<br />

MainStart="void main()\n{\n"<br />

MainEnd="\tmainendloop: go<strong>to</strong> mainendloop;\n}\n\n"<br />

IntStart="void interrupt(void)\n{\n"<br />

IntEnd="}\n\n"<br />

Initialise=""Initialise="adcon1 = 0x03;\n"<br />

IntInit="option_reg = 0xC0;\n\n"<br />

InputCmdFull="tris%p = tris%p | %m;\n%o = port%p;\n"<br />

InputCmdOneBit="tris%p = tris%p | %m;\n%o = ((port%p & %m) == %m);\n"<br />

InputCmdMask="tris%p = tris%p | %m;\n%o = port%p & %m;\n"<br />

OutputCmdFull="tris%p = 0x00;\nport%p = %o;\n"<br />

OutputCmdOneBit="tris%p = tris%p & %i;\nif (%o)\n\tport%p = (port%p & %i) | %m;\nelse\n\tport%p = port%p & %i;\n"<br />

OutputCmdMask="tris%p = tris%p & %i;\nport%p = (port%p & %i) | (%o & %m);\n"<br />

DelayCmdS="delay_s(%o);\n"<br />

DelayCmdMs="delay_ms(%o);\n"<br />

ADCCapture="char ta, cnt;\nadcon1 = 0x00;\nta = trisa;\ntrisa = trisa | 0x2F;\nadcon0 = 0xC1 | (%a

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!