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

© MCS Electronics, 1995-2007

Action

Configures how much servo’s will be controlled.

Syntax

CONFIG SERVOS = X , Servo1 = Portb.0 , Servo2 = Portb.1 , Reload = rl

Remarks

Servo’s need a variable pulse in order to operate. The CONFIG SERVOS directive will set up a byte array with the servo pulse width values and will initialize an ISR that uses TIMER0.

XThe number of servo’s you want to control. Each used servo will use one byte of SRAM.

PORT

The port pin the servo is attached too.

RL

The reload value for the ISR in uS.

When you use for example :

Config Servos = 2 , Servo1 = Portb.0 , Servo2 = Portb.1 , Reload = 10 The internal ISR will execute every 10 uS.

An arrays named SERVO() will be created and it can hold 2 bytes : servo(1) and servo(2).

By setting the value of the servo() array you control how long the positive pulse will last. After it has reached this value it will be reset to 0.

The reload value should be set to 10. After 20 mS, a new pulse wil be generated.

You can use other reload values but it will also mean that the repeat value will change.

The PORT pins specified must be set to work as an output pin by the user. CONFIG PINB.0 = OUTPUT

Will set a pin to output mode.

Resources used

TIMER0 is used to create the ISR.

ASM

NONE

Example

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

 

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

: servos.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: demonstrates the SERVO option

'micro

: 90S2313

'suited for demo

: yes

'commercial addon needed

: no

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

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

$regfile = "2313def.dat"

' specify the used

micro

' used crystal

$crystal = 4000000

page -384-

 

© MCS Electronics, 1995-2007

frequency

' use baud rate

$baud = 19200

$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

 

'Servo's need a pulse in order to operate

'with the config statement CONFIG SERVOS we can specify how many servo's we 'will use and which port pins are used

'A maximum of 14 servos might be used

'The SERVO statements use one byte for an interrupt counter and the TIMER0 'This means that you can not use TIMER0 anymore

'The reload value specifies the interval of the timer in uS

'Config Servos = 2 , Servo1 = Portb.0 , Servo2 = Portb.1 , Reload = 10

Config Servos = 1 , Servo1 = Portb.0 , Reload = 10 'as an option you can use TIMER1

'Config Servos = 2 , Servo1 = Portb.0 , Servo2 = Portb.1 , Reload = 10 , Timer = Timer1

'we use 2 servos with 10 uS resolution(steps)

'we must configure the port pins used to act as output

Config Portb = Output

'finally we must turn on the global interrupt

Enable Interrupts

'the servo() array is created automatic. You can used it to set the

'time the servo must be on

'10 times 10 = 100

Servo(1) = 10

uS on

'20 times 10 =

'Servo(2) = 20

200 uS on

 

Do

 

Loop

 

Dim I As Byte

 

Do

 

For I = 0 To 100

 

Servo(1) = I

 

Waitms 1000

 

Next

 

For I = 100 To 0 Step -1

 

' Servo(1) = I

 

Waitms 1000

 

Next

 

Loop

 

End

 

CONFIG TCPIP

Action

Configures the TCP/IP W3100A chip.

Syntax

page -385-

© MCS Electronics, 1995-2007

CONFIG TCPIP = int , MAC = mac , IP = ip, SUBMASK = mask, GATEWAY = gateway, LOCALPORT= port, TX= tx, RX= rx , NOINIT= 0|1 , TWI=address , Clock =speed [, baseaddress = address]

Remarks

Int

The interrupt to use such as INT0 or INT1.

 

For the Easy TCP/IP PCB, use INT0.

MAC

The MAC address you want to assign to the W3100A.

 

The MAC address is a unique number that identifies your chip. You must

 

use a different address for every W3100A chip in your network.

 

Example : 123.00.12.34.56.78

 

You need to specify 6 bytes that must be separated by dots. The bytes

 

must be specified in decimal notation.

IP

The IP address you want to assign to the W3100A.

 

The IP address must be unique for every W3100A in your network. When

 

you have a LAN, 192.168.0.10 can be used. 192.168.0.x is used for LAN’s

 

since the address is not an assigned internet address.

SUBMASK

The submask you want to assign to the W3100A.

 

The submask is in most cases 255.255.255.0

GATEWAY

This is the gateway address of the W3100A.

 

The gateway address you can determine with the IPCONFIG command at

 

the command prompt :

 

C:\>ipconfig

 

Windows 2000 IP Configuration

 

Ethernet adapter Local Area Connection 2:

 

Connection-specific DNS Suffix . :

 

IP Address. . . . . . . . . . . . : 192.168.0.3

 

Subnet Mask . . . . . . . . . . . : 255.255.255.0

 

Default Gateway . . . . . . . . . : 192.168.0.1

 

Use 192.168.0.1 in this case.

LOCALPORT

A word value that is assigned to the LOCAL_PORT internal variable. See

 

also Getsocket.

 

As a default you can assign a value of 5000.

TX

A byte which specifies the transmit buffer size of the W3100A. The

 

W3100A has 4 sockets.

 

A value of 00 will assign 1024 bytes, a value of 01 will assign 2048 bytes.

 

A value of 10 will assign 4096 bytes and a value of 11 will assign 8192

 

bytes.

 

This is binary notation. And the Msbits specify the size of socket 3.

 

For example, you want to assign 2048 bytes to each socket for

 

transmission : TX = &B01010101

 

 

page -386-

© MCS Electronics, 1995-2007

RX

Noinit

Since the transmission buffer size may be 8KB in total, you can split them up in 4 parts of 2048 bytes : 01.

When you want to use 1 socket with 8KB size, you would use : TX = &B11. You can use only 1 socket in that case : socket 0.

A byte which specifies the receive buffer size of the W3100A. The W3100A has 4 sockets.

A value of 00 will assign 1024 bytes, a value of 01 will assign 2048 bytes. A value of 10 will assign 4096 bytes and a value of 11 will assign 8192 bytes.

This is binary notation. And the Msbits specify the size of socket 3.

For example, you want to assign 2048 bytes to each socket for reception : RX = &B01010101

Since the receive buffer size may be 8KB in total, you can split them up in 4 parts of 2048 bytes : 01.

When you want to use 1 socket with 8KB size, you would use : RX = &B11. You can use only 1 socket in that case : socket 0.

Consult the W3100A pdf for more info.

Make this 1 when you want to configure the TCP, MAC, Subnetmask and GateWay dymanic. Noinit will only make some important settings and you need to use SETTCP in order to finish the setup.

TWI

The slave address of the W3100A/NM7010. When you specify TWI, your

 

micro must have a TWI interface such as Mega128, Mega88, Mega32.

Clock

The clock frequency to use with the TWI interface

Baseaddress An optional value for the chip select of the W3100A. This is default &H8000 when not specified. When you create your own board, you can override it.

The CONFIG TCPIP statement may be used only once.

Interrupts must be enabled before you use CONFIG TCPIP.

Configuring the W3100A will init the chip.

After the CONFIG TCPIP, you can already PING the chip!

The TWI mode works only when your micro support the TWI mode. You need to have 4k7 pull up resistors.

MCS Electronics has a small adapter PCB and KIT available that can be connected easily to your microprocessor.

The new TWI mode makes your PCB design much simpler. TWI is not as fast as bus mode. While you can use every supported TCP/IP function, it will run at a lower speed.

See also

GETSOCKET , SOCKETCONNECT, SOCKETSTAT , TCPWRITE, TCPWRITESTR, TCPREAD, CLOSESOCKET , SOCKETLISTEN

Syntax Example

Config Tcpip = Int0 , Mac = 00.00.12.34.56.78 , Ip = 192.168.0.8 , Submask = 255.255.255.0 , Gateway = 192.168.0.1 , Localport = 1000 , Tx = $55 , Rx = $55

page -387-