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

© MCS Electronics, 1995-2007

Action

Overrides the RC5 pin assignment from the Option Compiler Settings.

Syntax

CONFIG RC5 = pin [,TIMER=2]

Remarks

Pin

The port pin to which the RC5 receiver is connected.

TIMER

Must be 2. The micro must have a timer2 when you want to

 

use this option. This additional parameter will cause that

 

TIMER2 will be used instead of the default TIMER0.

 

 

When you use different pins in different projects, you can use this statement to override the Options Compiler setting for the RC5 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. In BASCOM-AVR the settings are also stored in the project.CFG file.

See also

GETRC5

Example

CONFIG RC5 = PIND.5 'PORTD.5 is the RC5 input line

CONFIG SDA

Action

Overrides the SDA pin assignment from the Option Compiler 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. In BASCOM-AVR the settings are also stored in the project.CFG file.

See also

CONFIG SCL , CONFIG I2CDELAY

Example

CONFIG SDA = PORTB.7 'PORTB.7 is the SDA line

page -371-

© MCS Electronics, 1995-2007

CONFIG SCL

Action

Overrides the SCL pin assignment from the Option Compiler 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. Of course BASCOM-AVR also stores the settings in a project.CFG file.

See also

CONFIG SDA , CONFIG I2CDELAY

Example

CONFIG SCL = PORTB.5 'PORTB.5 is the SCL line

CONFIG SERIALIN

Action

Configures the hardware UART to use a buffer for input

Syntax

CONFIG SERIALIN = BUFFERED , SIZE = size [, BYTEMATCH=ALL|BYTE] [,CTS=pin, RTS=pin , Threshold_full=num , Threshold_empty=num ]

Remarks

size

A numeric constant that specifies how large the input buffer should

 

be. The space is taken from the SRAM.

bytematch

The ASCII value of the byte that will result in calling the user label.

 

When you specify ALL, the user label will be called for every byte that

 

is received.

CTS

The pin used for the CTS.(Clear to send). For example PIND.6

RTS

The pin used for RTS. (Ready to send). For example PIND.7

Threshold_full

The number of bytes that will cause RTS to be set to '1'. This is an

 

indication to the sender, that the buffer is full.

 

 

page -372-

 

© MCS Electronics, 1995-2007

 

 

 

Threshold_empt

The number of free bytes that must be in the buffer before CTS may

 

y

be made '0' again.

 

The following internal variables will be generated : _RS_HEAD_PTR0 , a byte counter that stores the head of the buffer _RS_TAIL_PTR0 , a byte counter that stores the tail of the buffer.

_RS232INBUF0 , an array of bytes that serves as a ring buffer for the received characters. _RS_BUFCOUNTR0, a byte that holds the number of bytes that are in the buffer.

The optional BYTEMATCH can be used to monitor the incoming bytes and call a label when the specified label is found.

This way you can determine the start of a serial stream.

While bytematch allows you to trap the incoming bytes, take care that you do not delay the program execution too much. After all the serial input interrupt is used in order not to miss incoming data. When you add delays or code that will delay execution too much you will loose incoming data.

To clear the buffer, use CLEAR SERIALIN. Do not read and write the internal buffer variables yourself.

CTS-RTS is hardware flow control. Both the sender and receiver need to use CTS-RTS when CTS-RTS is used. When on of the partie's does not use CTS-RTS, no communication will be possible.

CTS-RTS use two extra lines. The receiver must check the CTS pin to see if it may send. The CTS pin is a input pin as the receiver looks at the level that the sender can change.

The receiver can set the RTS pin to indicate to the sender that it can accept data.

In the start condition, RTS is made '0' by the receiver. The sender will then check this logic level with it's cts pin, and will start to send data. The receiver will store the data into the buffer and when the buffer is almost full, or better said, when the Threshold_ful is the same as the number of bytes in the receive buffer, the receiver will make RTS '1' to signal to the sender, that the buffer is full. The sender will stop sending data. And will continue when the RTS is made '0' again.

The receiver can send data to the sender and it will check the CTS pin to see if it may send data.

In order to work with CTS-RTS, you need both a serial input buffer, and a serialoutput buffer. So use both CONFIG SERIALIN and CONFIG SERIALOUT to specify the buffers. The CTS-RTS can only be configured with the CONFIG SERIALIN statement.

The thresholds are needed for high baud rates where it will take some time to react on a CTS-RTS.

You need to experiment with the thresholds but good start values are 80%full, and 20% empty.

ASM

Routines called from MCS.LIB :

_GotChar. This is an ISR that gets called when ever a character is received. When there is no room for the data it will not be stored.

So the buffer must be emptied periodic by reading from the serial port using the normal statements like INKEY() and INPUT.

page -373-

© MCS Electronics, 1995-2007

Since URXC interrupt is used by _GotChar, you can not use this interrupt anymore. Unless you modify the _gotchar routine of course.

See also

CONFIG SERIALOUT , ISCHARWAITING , CLEAR

Example

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

 

------------

: rs232buffer.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: example shows the difference between normal and

buffered

serial INPUT

'

'micro

: Mega161

'suited for demo

: yes

'commercial addon needed

: no

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

 

------------

 

$regfile = "m161def.dat"

' specify the used

micro

' used crystal

$crystal = 4000000

frequency

' use baud rate

$baud = 9600

$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

 

'first compile and run this program with the line below remarked Config Serialin = Buffered , Size = 20

Dim Na As String * 10

'the enabling of interrupts is not needed for the normal serial mode 'So the line below must be remarked to for the first test

Enable Interrupts

Print "Start"

Do

'get a char from the UART

 

If Ischarwaiting() = 1 Then

'was there a char?

Input Na$

'print it

Print Na

End If

 

Wait 1

'wait 1 second

Loop

 

'You will see that when you slowly enter characters in the terminal emulator 'they will be received/displayed.

'When you enter them fast you will see that you loose some chars

'NOW remove the remarks from line 11 and 18 'and compile and program and run again

'This time the chars are received by an interrupt routine and are

page -374-