CONFIG
Select one of the following topics to learn more about a specific config statement.
CONFIG TIMER0, TIMER1
CONFIG TIMER2 (for 8052 compatible chips)
CONFIG LCD
CONFIG LCDBUS
CONFIG LCDPIN
CONFIG BAUD
CONFIG 1WIRE
CONFIG SDA
CONFIG SCL
CONFIG DEBOUNCE

CONFIG WATCHDOG
CONFIG SPI
CONFIG I2CDELAY
CONFIG MICROWIRE
CONFIG SERVOS
CONFIG ADUC812
CONFIG GETRC
CONFIG PRINT
CONFIG GRAPHLCD

CONFIG TIMER0, TIMER1
Action

Configure TIMER0 or TIMER1.

Syntax

CONFIG TIMERx = COUNTER/TIMER , GATE=INTERNAL/EXTERNAL , MODE=0/3

Remarks

TIMERx TIMER0 or TIMER1.
COUNTER will configure TIMERx as a COUNTER and TIMER will configure TIMERx as a TIMER.
A TIMER has built in clock input and a COUNTER has external clock input.
GATE INTERNAL or EXTERNAL. Specify EXTERNAL to enable gate control with the INT input.
MODE Time/counter mode 0-3. See Hardware for more details.
So CONFIG TIMER0 = COUNTER, GATE = INTERNAL, MODE=2 will configure TIMER0 as a COUNTER with not external gatecontrol , in mode 2 (auto reload)

When the timer/counter is configured the timer/counter is stopped so you must start it afterwards with the START TIMERx statement.

See the additional statements for other microprocessors that use the CONFIG statement.

Example
CONFIG TIMER0=COUNTER, MODE=1, GATE=INTERNAL
COUNTER0 = 0 'reset counter 0

START COUNTER0 'enable the counter to run
DELAY 'wait a while
PRINT COUNTER0 'print it
END

 

TIMER2 in 8032 and compatibles
Some microprocessors have an additional timer on board : TIMER2.
This section describes the 8032 compatible TIMER2 and is not compatible with th TIMER2 found in the 80C535 and others.
TIMER2 is a 16-bit timer/counter which can operate as either an event timer or an event counter. TIMER2 has three main operating modes : capture, auto-reload(up or down counting) , and baud rate generator.

Capture mode
In the capture mode there are two options :

16-bit timer/counter which upon overflowing sets bit TF2, the TIMER2 overflow bit. This bit can be used to generate an interrupt.

Counter mode :
CONFIG TIMER2 = COUNTER, GATE = INTERNAL, MODE = 1

Timer mode:
CONFIG TIMER2=TIMER, GATE= INTERNAL,MODE =1

As above but with the added future that a 1 to 0 transition on at external input T2EX causes the current values in the TIMER2 registers TL2 and TH2 to be captured into the capture registers RCAP2L and RCAP2H.

Counter mode:
CONFIG TIMER2 = COUNTER, GATE = EXTERNAL, MODE = 1

Timer mode:
CONFIG TIMER2=TIMER,GATE=EXTERNAL,MODE=1

In addition the transition at T2EX causes bit EXF2 in T2CON to be set and EXF2 like TF2 can generate an interrupt.

The TIMER2 interrupt routine can interrogate TF2 and EXF2 to determine which event caused the interrupt.
(there is no reload value in this mode. Even when a capture event occurs from T2EX the counter keeps on counting T2EX pin transitions or osc/12 pulses)

Auto reload mode
In the 16-bit auto reload mode, TIMER2 can be configured as a timer or counter which can be programmed to count up or down. The counting direction is determined by bit DCEN.

TIMER2 will default to counting up to &HFFFF and sets the TF2 overflow flag bit upon overflow. This causes the TIMER2 registers to be reloaded with the 16-bit value in RCAP2L and RCAP2H.
The values in RCAP2L and RCAP2H are preset by software means.

Counter mode:
CONFIG TIMER2=COUNTER,GATE=INTERNAL,MODE=0

Timer mode:
CONFIG TIMER2=COUNTER,GATE=INTERNAL,MODE=0

If EXEN2=1 then a 16-bit reload can be triggered either by an overflow or by a 1 to 0 transition at input T2EX. This transition also sets the EXF2 bit. The TIMER2 interrupt, if enabled, can be generated when either TF2 or EXF2 are 1.

Counter mode:
CONFIG TIMER2=COUNTER,GATE=EXTERNAL,MODE=0

Timer mode:
CONFIG TIMER2=TIMER,GATE=EXTERNAL,MODE=0
TIMER2 can also count up or down. This mode allows pin T2EX to control the direction of count. When a logic 1 is applied at pin T2EX TIMER2 will count up. TIMER2 will overflow at &HFFFF and sets the TF2 flag, which can then generate an interrupt, if the interrupt is enabled. This timer overflow also causes the 16-bit value in RCAP2L en RCAP2H to be reloaded in to the timer registers TL2 and TH2.

Counter mode:
CONFIG TIMER2=COUNTER,GATE=INTERNAL/EXTERNAL,MODE=0,DIRECTION=UP

Timer mode:
CONFIG TIMER2=COUNTER,GATE=INTERNAL/EXTERNAL,MODE=0,DIRECTION=UP


A logic 0 applied at pin T2EX causes TIMER2 to count down. The timer will under flow when TL2 and TH2 become equal to the value stored in RCAP2L and RCAP2H. TIMER2 under flows sets the TF2 flag and causes &HFFFF to be reloaded into the timer registers TL2 and TH2.

Counter mode:
CONFIG TIMER2=COUNTER,GATE=INTERNAL/EXTERNAL,MODE=0,DIRECTION=DOWN

Timer mode:
CONFIG TIMER2=COUNTER,GATE=INTERNAL/EXTERNAL,MODE=0,DIRECTION=DOWN


The external flag TF2 toggles when TIMER2 under flows or overflows.
The EXF2 flag does not generate an interrupt in counter UP/DOWN mode.

Baud rate generator
This mode can be used to generate a baud rate for the serial port. TIMER1 can be used for an other task this way.
CONFIG TIMER2=TIMER,GATE=INTERNAL,MODE=2


Receive only
This mode can be used to generate the baud rate for the receiver only.

TIMER1 can be used for the transmission with an other baud rate.
CONFIG TIMER2=TIMER,GATE=INTERNAL,MODE=3

Note that TIMER1 must be setup from assembler this way.


Transmit only
This mode can be used to generate the baud rate for transmitter only.
TIMER1 can be used for the reception with an other baud rate.
CONFIG TIMER2=TIMER,GATE=INTERNAL,MODE=4

Note that TIMER1 must be setup from assembler this way.

Clock output
Some 8052 deviants have the ability to generate a 50% duty cycle clock on P1.0.

CONFIG TIMER2=TIMER,MODE=5

The output frequency = (fOSC / 4) / (65536-CAPTURE)

Use CAPTURE = value to set the capture register.

How to determine what caused the interrupt
You can test the bit T2CON.7 to see if an overflow caused the interrupt.
You can test bit T2CON.6 whether either a reload or capture is caused by a negative transition on T2EX.

Timer2_ISR:
If T2CON.7 = 1 Then
Print "Timer overflowed"
Else
If T2CON.6 = 1 Then

Print "External transition"
End if
End If
Return

 

CONFIG LCD
Action
Configure the LCD display.

Syntax
CONFIG LCD = LCDtype

Remarks

LCDtype The type of LCD display used. This can be :
40 * 4, 40 * 2, 16 * 1, 16 * 1a, 16 * 2, 16 * 4, 16 * 4, 20 * 2 or 20 * 4 or 40 * 4a
Default 16 * 2 is assumed.
The 16 * 1a LCD display is a special one. It is intended for the display that has the memory organized as 2 lines of 8 characters.

The 40 * 4a LCD display is also a special one. It has two ENABLE lines.
The CONFIG LCDPIN directive must be used to configure the second E line:

CONFIG LCDPIN = PIN , E1 = Pin, E2 = pin, etc.

To select between E1 and E2 you need to set the B register.
Mov b,#0 'selects E1
Mov b,#1 'selects E2

LCD with a constant will work and also with strings.
To call the low level routines :
Mov a,#2 ; code into acc
Mov B,#0 ; or use Mov b,#1
acall LCD_CONTROL ; call routine

To send data use the low level routine WRITE_LCD instead of LCD_CONTROL

Most LCD routines will work with the 40*4a display but some will fail. In that case you need to use the low level ASM routines as shown above.

Example
REM Sample for normal displays
CONFIG LCD = 40 * 4
LCD "Hello" 'display on LCD
FOURTHLINE 'select line 4
LCD "4" 'display 4
END

 

CONFIG LCDBUS
Action

Configures the LCD databus.

Syntax

CONFIG LCDBUS = constant

Remarks

constant 4 for 4-bit operation, 8 for 8-bit mode (default)
Use this statement together with the $LCD = address statement.
When you use the LCD display in the bus mode the default is to connect all the data lines. With the 4-bit mode you only have to connect data lines d7-d4.

See also
CONFIG LCD

Example
$LCD = &H8000 'address of enable signal
Config LCDBUS = 4 '4 bit mode
LCD "hello"

 

CONFIG LCDPIN
Action

Override the LCD-options to store the settings in your program.

Syntax

CONFIG LCDPIN = PIN, DB4= P1.1,DB5=P1.2,DB6=P1.3,DB7=P1.4,E=P1.5,RS=P1.6

Remarks

P1.1 etc. are just an example in the syntax.

See also

CONFIG LCD

Example

CONFIG LCDPIN = PIN ,DB4= P1.1,DB5=P1.2,DB6=P1.3,DB7=P1.4,E=P1.5,RS=P1.6

 

CONFIG BAUD
Action

Configure the uP to select the intern baud rate generator.

This baud rate generator is only available in the 80515, 80517, 80535, 80537 and compatible chips.

Syntax

CONFIG BAUD = baud rate

Remarks

Baud rate Baud rate to use : 4800 or 9600
Example
CONFIG BAUD = 9600 'use internal baud generator
Print "Hello"
End

CONFIG 1WIRE
Action
Configure the pin to use for 1WIRE statements.

Syntax
CONFIG 1WIRE = pin

Remarks

pin The port pin to use such as P1.0
See also
1WRESET , 1WREAD , 1WWRITE


Example
Config 1WIRE = P1.0 'P1.0 is used for the 1-wire bus
1WRESET 'reset the bus

 

CONFIG SDA
Action

Overrides the SDA pin assignment from the Option Settings.

Syntax

CONFIG SDA = pin

Remarks

pin The port pin to which the I2C-SDA line is connected.
When you use different pins in different projects, you can use this statement to override the Options Compiler setting for the SDA pin. This way you will remember which pin you used because it is in your code and you do not have to change the settings from the options.

See also
CONFIG SCL CONFIG I2CDELAY

Example
CONFIG SDA = P3.7 'P3.7 is the SDA line

 

CONFIG SCL
Action

Overrides the SCL pin assignment from the Option Settings.

Syntax

CONFIG SCL = pin

Remarks

pin The port pin to which the I2C-SCL line is connected.
When you use different pins in different projects, you can use this statement to override the Options Compiler setting for the SCL pin. This way you will remember which pin you used because it is in your code and you do not have to change the settings from the options.
This statement can not be used to change the pin dynamically during runtime.

See also

CONFIG SDA CONFIG I2CDELAY

Example
CONFIG SCL = P3.5 'P3.5 is the SCL line

 

CONFIG DEBOUNCE
Action

Configures the delay time for the DEBOUNCE statement.

Syntax

CONFIG DEBOUNCE = time

Remarks

time A numeric constant which specifies the delay time in mS.
When the debounce time is not configured, 25 mS will be used as a default.
Note that the delay time is based on a 12 MHz clock frequency.

See also
DEBOUNCE

Example
Config Debounce = 25 mS '25 mS is the default

 

CONFIG WATCHDOG
Action

Configures the watchdog timer from the AT89C8252

Syntax

CONFIG WATCHDOG = time

Remarks

time The interval constant in mS the watchdog timer will count to.
Possible settings:
16 , 32, 64 , 128 , 256 , 512 , 1024 and 2048.
When the WD is started, a reset will occur after the specified number of mS.
With 2048, a reset will occur after 2 seconds, so you need to reset the WD in your programs periodically.

See also
START WATCHDOG , STOP WATCHDOG , RESET WATCHDOG

Example
'-----------------------------------------------------
' (c) 1998 MCS Electronics
' WATCHD.BAS demonstrates the AT89S8252 watchdog timer
' select 89s8252.dat !!!

'-----------------------------------------------------
Config Watchdog = 2048 'reset after 2048 mSec
Start Watchdog 'start the watchdog timer
Dim I As Word
For I = 1 To 10000
Print I 'print value
' Reset Watchdog
'you will notice that the for next doesnt finish because of the reset
'when you unmark the RESET WATCHDOG statement it will finish because the
'wd-timer is reset before it reaches 2048 msec

Next
End

 

CONFIG SPI
Action

Configures the SPI related statements.

Syntax

CONFIG SPI = SOFT, DIN = PIN, DOUT = PIN , CS = PIN, CLK = PIN ,DATA ORDER = DO, NOCS =

Remarks

DIN Data input. Pin is the pin number to use such as p1.0
DOUT Data output. Pin is the pin number to use such as p1.1
CS Chip select. Pin is the pin number to use such as p1.2
CLK Clock. Pin is the pin number to use such as p1.3
NOCS Option without parameter. Use it to disable the resetting and setting of the CS pin.
DATA ORDER Use MSB or LSB. With MSB, MS bit will be sent first. LSB option will send the LS bit first.
When the NOCS option is used you must reset and set the CS pin yourself.
The option is intended when you want to do large transfers between the micro and the SPI device. With the little internal memory you can do that in steps but of course you don't want the CS pin to change after each use of the SPIIN or SPIOUT routine.

See also
SPIIN SPIOUT

Example
Config SPI = SOFT, DIN = P1.0 , DOUT = P1.1, CS = P1.2, CLK = P1.3
SPIOUT var , 1 'send 1 byte

 

CONFIG I2CDELAY
Action

Configures the delay for the I2C clock.

Syntax

CONFIG I2CDELAY = value

Remarks

value A numeric constant.
1 will generate the default clock.
0 will generate a higher clock and >=2 will generate a lower clock frequency.
By default the following delay routine is called with an ACALL :
Delay5:
Nop
Ret
For 12 MHz, there is a 1 MHz system clock. So not counting the other statement, the minimal delay is 4 * 2 = 8 cycles.

See also
CONFIG SCL CONFIG SDA

Example
CONFIG I2CDELAY = 0 'we need higher clock

 

CONFIG MICROWIRE
Action
Configures the microwire pins.

Syntax
Config Microwire = Pin , Cs = P1.1 , Din = P1.2 , Dout = P1.4 , Clock = P1.5 , Al = 7

Remarks

CS Chip select
DIN Data input
DOUT Data output
CLOCK Pin that generates the Clock
AL Address lines. See table below.
It depends if you work with bytes or words. In our example we will use the 93C46 and work with bytes. AL will be 7 in this case.
Chip 93C46 93C56 93C57 93C66
Data bits 8 16 8 16 8 16 8 16
AL 7 6 9 8 8 7 9 8
See also
MWINIT, MWWOPCODE , MWWRITE , MWREAD

 

CONFIG SERVOS
Action

Configures the number of servos and their pins.

Syntax

Config SERVOS = number , SERVO1 = P1.1 , SERVO2 = P1.2 , SERVO3 = P1.4 , SERVO4 = P1.5 , RELOAD = value

Remarks

number The number of servos you want to use.
When you specify 2, you must also add the SERVO1 and SERVO2 parameters.
servo1 The pin that is attached to servo 1.
servo2 The pin that is attached to servo 2.
servo3 The pin that is attached to servo 3.
servo4 The pin that is attached to servo 4.
RELOAD The reload value in uS. Default 100 uS
The CONFIG SERVOS compiler directive wil include an interrupt that will execute every 100 uS. TIMER0 int is enabled and also TIMER0 is started.
The number of bytes used by the use of SERVO's is 1 + number of servos.
So when you use 2 servo's , it will take 3 bytes of internal memory.
TIMER0 can not be used by your program anymore.
To change the pulse duration you assign the special reserved variables the number of 100 uS steps:
SERVO1 = 8 '800 uS pulse
SERVO2 = 12 '1200 uS duration

After 20 mS the pulses will be send again to the port pins.
The maximum number of servo's is 16. The example shows how to set it up for 4 servo's only.
When you specify RELOAD = 50 , 50 uS steps will be used!
When you have a lot of servo's the RELOAD must be higher than when you have less servos. When you have a reload of 10 uS for example it will be impossible for the 8051 to handle more than 1 servo without loosing time.
For 2 servo's 20 or 25 should be used for best results.

 

CONFIG ADUC812
Action
Configures the ADUC812 microprocessor.

Syntax for ADC
Config ADUC812 = ADCON , MODE = mode, CLOCK = clock , ACQUISITION = aq , TIMER2 = tm , EXTRIG
= value

Syntax for DAC
Config ADUC812 = DAC , MODE = mode, RANGE0 = r0 , RANGE1 = r1 , CLEAR0 = clr0 , CLEAR1 = clr1 , SYNC = sync, POWER0 = pwr0, POWER1 = pwr1

Remarks ADC

mode POWERDOWN, NORMAL, PDNE, STANDBY.
PDNE means POWERDOWN if not executing a conversion cycle.
clock This is a constant that specifies the clock division of the master clock. It may be 1,2,4 or 8.
An ADC conversion will require 16 ADC clocks in addition to the selected number of acquisition clocks.
aq This is a constant that specifies the time available for the input/track hold amplifier to acquire the input signal.
It may be in range from 1-4. 1 Acquisition clock is enough for an impedance up to 8K
tm2 The TIMER2 can be ENABLED or DISABLED. When enabled the timer2 overflow serves as a trigger for the AD conversion.
value The external trigger may be ENABLED or DISABLED. When enabled the external pin 23 (CONVST) can start the conversion while it is low.
Remarks DAC

mode The DAC can be in 8 bit mode or 12 bit mode. So the parameter may be 8 or 12. Both DACS are set with this parameter.
r0 The DAC0 range can be set to VDD or VREF. With VDD the range is from 0-VDD. For VREF it is 0-VREF.
r1 The DAC1 range can be set to VDD or VREF. With VDD the range is from 0-VDD. For VREF it is 0-VREF
clr0 This parameter when TRUE will clear the DAC0. This will set the output voltage to 0 V.
clr1 This parameter when TRUE will clear the DAC1. This will set the output voltage to 0 V
sync May be ENABLED or DISABLED. While enabled the DAC outputs as soon as the DACxL SFR's are written. The user can simultaneously update both DAC's by first updating the DACxL/H SFR's while SYNC is disabled. Both DACs will then update when the SYNC is enabled.
pwr0 This parameter when ON will power ON the DAC0. When OFF the DAC0 is powered OFF.
pwr1 This parameter when ON will power ON the DAC1. When OFF the DAC1 is powered OFF

 

CONFIG GETRC
Action
Configures the GETRC() charge time.

Syntax
Config GETRC = time

Remarks

time The time in milli seconds to charge the capacitor
See also
GETRC

 

CONFIG PRINT
Action

Configures the PRINT statement.

Syntax

Config PRINT = pin

Config PRINTMODE = mode

Remarks

pin The pin to use for the output control such as P3.0
mode The mode of the control pin. SET or RESET.
When you want to control a RS-485 device you need an additional pin to control the buffer. When the pin must be high during printing use SET. When it must be low during print use RESET.

See also
Config Print = P3.0 'this pin controls the buffer
Config mode = SET 'during PRINT this pin goes high.
Print "Hello"