Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
BASCOM AVR, help reference (2007).PDF
Скачиваний:
281
Добавлен:
12.08.2013
Размер:
17.02 Mб
Скачать

 

© MCS Electronics, 1995-2007

 

 

 

CONFIG PS2EMU

NO

 

CONFIG SINGLE

NO

 

CONFIG SDA

NO

 

CONFIG SCL

NO

 

CONFIG SPI

NO

 

CONFIG TCPIP

NO

 

CONFIG TWI

YES

 

CONFIG TWISLAVE

NO

 

CONFIG TIMER0

YES

 

CONFIG TIMER1

YES

 

CONFIG TIMER2 and 3

YES

 

CONFIG WATCHDOG

YES

 

CONFIG WAITSUART

NO

 

CONFIG X10

NO

 

CONFIG XRAM

YES

 

Some CONFIG directives are intended to be used once. Others can be used multiple times. For example you can specify that a port must be set to input after you have specified that it is used as an input.

You cannot change the LCD pins during run time. In that case the last specification will be used or an error message will be displayed.

CONFIG 1WIRE

Action

Configure the pin to use for 1WIRE statements and override the compiler setting.

Syntax

CONFIG 1WIRE = pin

Remarks

Pin The port pin to use such as PORTB.0

The CONFIG 1WIRE statement, only overrides the compiler setting.

You can configure only one pin for the 1WIRE statements because the idea is that you can attach multiple 1WIRE devices to the 1WIRE bus.

You can however use multiple pins and thus multiple busses. All 1wire commands and functions need the port and pin in that case.

The 1wire commands and function will automatically set the DDR and PORT register bits to the proper state. You do not need to bring the pins into the right state yourself.

It is important that you use a pull up resistor of 4K7 ohm on the 1wire pin. The build in pull up resistor of the AVR is not sufficient.

Also notice that some 1wire chips also need +5V.

page -312-

© MCS Electronics, 1995-2007

See also

1WRESET , 1WREAD , 1WWRITE , 1WIRECOUNT , 1WRESET , 1WSEARCHFIRST , 1WSEARCHNEXT

Example

'-----------------------------------------------------------------------------

 

---

: 1wire.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: demonstrates 1wreset, 1wwrite and 1wread()

'micro

: Mega48

'suited for demo

: yes

'commercial addon needed

: no

' pull-up of 4K7 required to VCC from Portb.2

' DS2401 serial button connected to Portb.2

'-----------------------------------------------------------------------------

 

---

 

$regfile = "m48def.dat"

 

$crystal = 8000000

 

$hwstack = 32

' default use 32

for the hardware stack

'default use 10

$swstack = 10

for the SW stack

'default use 40

$framesize = 40

for the frame space

 

Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0

'when only bytes are used, use the following lib for smaller code $lib "mcsbyte.lib"

Config 1wire = Portb.0

'use this pin

'On the STK200 jumper B.0 must be inserted

 

Dim Ar(8) As Byte , A As Byte , I As Byte

 

Do

 

Wait 1

'reset the device

1wreset

Print Err

'print error 1 if

error

'read ROM command

1wwrite &H33

For I = 1 To 8

'place into array

Ar(i) = 1wread()

Next

 

'You could also read 8 bytes a time by unremarking the next line

'and by deleting the for next above

'read 8 bytes

'Ar(1) = 1wread(8)

For I = 1 To 8

'print output

Print Hex(ar(i));

Next

'linefeed

Print

Loop

 

'NOTE THAT WHEN YOU COMPILE THIS SAMPLE THE CODE WILL RUN TO THIS POINT

page -313-

© MCS Electronics, 1995-2007

 

'THIS because of the DO LOOP that is never terminated!!!

 

'New is the possibility to use more than one 1 wire bus

 

'The following syntax must be used:

 

For I = 1 To 8

'clear array to

Ar(i) = 0

see that it works

 

Next

 

1wreset Pinb , 2

'use this port and

pin for the second device

'note that now the

1wwrite &H33 , 1 , Pinb , 2

number of bytes must be specified!

 

'1wwrite Ar(1) , 5,pinb,2

 

'reading is also different

'read 8 bytes from

Ar(1) = 1wread(8 , Pinb , 2)

portB on pin 2

 

For I = 1 To 8

 

Print Hex(ar(i));

 

Next

 

'you could create a loop with a variable for the bit number !

For I = 0 To 3 'for pin 0-3 1wreset Pinb , I

1wwrite &H33 , 1 , Pinb , I Ar(1) = 1wread(8 , Pinb , I)

For A = 1 To 8 Print Hex(ar(a));

Next

Print Next

End

CONFIG ACI

Action

Configures the Analog Comparator.

Syntax

CONFIG ACI = ON|OFF, COMPARE = ON|OFF, TRIGGER=TOGGLE|RISING|FALLING

Remarks

ACI

Can be switched on or off

COMPARE

Can be on or off.

 

When switched ON, the TIMER1 in capture mode will trigger on ACI too.

TRIGGER

Specifies which comparator events trigger the analog comparator

 

interrupts.

 

 

See also

NONE

page -314-

© MCS Electronics, 1995-2007

Example

NONE

CONFIG ADC

Action

Configures the A/D converter.

Syntax

CONFIG ADC = single, PRESCALER = AUTO, REFERENCE = opt

Remarks

ADC

Running mode. May be SINGLE or FREE.

PRESCALER A numeric constant for the clock divider. Use AUTO to let the compiler generate the best value depending on the XTAL

REFERENCE Some chips like the M163 have additional reference options.

Value may be OFF , AVCC or INTERNAL. See the data sheets for the different modes.

Some newer micro's support also : INTERNAL_1.1

INTERNAL_2.56

INTERNALEXTCAP

See also

GETADC

ASM

The following ASM is generated(depending on the chip)

In _temp1,ADCSR ; get settings of ADC

Ori _temp1, XXX ; or with settings

Out ADCSR,_temp1 ; write back to ADC register

Example

'-----------------------------------------------------------------------------

 

---

: adc.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: demonstration of GETADC() function for 8535 or

M163 micro

: Mega163

'micro

'suited for demo

: yes

'commercial addon needed

: no

'use in simulator

: possible

' Getadc() will also work for other AVR chips that have an ADC converter '-----------------------------------------------------------------------------

page -315-