ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 12.06.2025

Просмотров: 8244

Скачиваний: 1

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

© MCS Electronics, 1995-2007

See also

CONFIG TCPIP, GETSOCKET , SOCKETCONNECT, SOCKETSTAT , TCPWRITE, TCPWRITESTR, TCPREAD, SOCKETLISTEN

Example

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

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

: clienttest.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: start the easytcp.exe program and listen to port

5000

: Mega161

'micro

'suited for demo

: no

'commercial addon needed

: yes

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

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

$regfile = "M161def.dat"

$crystal = 4000000

$baud = 19200

' default use 40

$hwstack = 40

for the hardware stack

' default use 40

$swstack = 40

for the SW stack

' default use64

$framesize = 64

for the frame space

Const Sock_stream = $01

' Tcp

Const Sock_dgram = $02

' Udp

Const Sock_ipl_raw = $03

' Ip Layer Raw

Sock

' Mac Layer Raw

Const Sock_macl_raw = $04

Sock

' Confirm Socket

Const Sel_control = 0

Status

' Confirm Tx Free

Const Sel_send = 1

Buffer Size

' Confirm Rx Data

Const Sel_recv = 2

Size

'socket status

' Status Of

Const Sock_closed = $00

Connection Closed

' Status Of Arp

Const Sock_arp = $01

Const Sock_listen = $02

' Status Of

Waiting For Tcp Connection Setup

' Status Of

Const Sock_synsent = $03

Setting Up Tcp Connection

' Status Of

Const Sock_synsent_ack = $04

Setting Up Tcp Connection

' Status Of

Const Sock_synrecv = $05

Setting Up Tcp Connection

' Status Of Tcp

Const Sock_established = $06

Connection Established

' Status Of

Const Sock_close_wait = $07

Closing Tcp Connection

' Status Of

Const Sock_last_ack = $08

Closing Tcp Connection

' Status Of

Const Sock_fin_wait1 = $09

Closing Tcp Connection

' Status Of

Const Sock_fin_wait2 = $0a

Closing Tcp Connection

' Status Of

Const Sock_closing = $0b

page -309-


© MCS Electronics, 1995-2007

Closing Tcp Connection

' Status Of

Const Sock_time_wait = $0c

Closing Tcp Connection

' Status Of

Const Sock_reset = $0d

Closing Tcp Connection

' Status Of Socket

Const Sock_init = $0e

Initialization

' Status Of Udp

Const Sock_udp = $0f

Const Sock_raw = $10

' Status of IP RAW

$lib "tcpip.lbx"

' specify the

tcpip library

' display a

Print "Init , set IP to 192.168.0.8"

message

' before we use

Enable Interrupts

config tcpip , we need to enable the interrupts

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

'Use the line below if you have a gate way

'Config Tcpip = Int0 , Mac = 12.128.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

Dim Bclient As Byte

' socket number

Dim Idx As Byte

' result

Dim Result As Word

Dim S As String * 80

For Idx = 0 To 3

' for all sockets

Bclient = Getsocket(idx , Sock_stream , 0 , 0)

' get socket for

client mode, specify port 0 so loal_port is used

' print local port

Print "Local port : " ; Local_port

that was used

Print "Socket " ; Idx ; " " ; Bclient

' connect to

Result = Socketconnect(idx , 192.168.0.3 , 5000)

easytcpip.exe server

Print "Result " ; Result

Next

Do

If Ischarwaiting() <> 0 Then

' is there a key

waiting in the uart?

' get the key

Bclient = Waitkey()

If Bclient = 27 Then

' send WHO , TIME

Input "Enter string to send " , S

or EXIT

For Idx = 0 To 3

Result = Tcpwritestr(idx , S , 255)

Next

End If

End If

For Idx = 0 To 3

' get status

Result = Socketstat(idx , 0)

Select Case Result

Case Sock_established

' get number of

Result = Socketstat(idx , Sel_recv)

bytes waiting

If Result > 0 Then

Do

Result = Tcpread(idx , S)

Print "Data from server: " ; Idx ; " " ; S

page -310-


© MCS Electronics, 1995-2007

Loop Until Result = 0

End If

Case Sock_close_wait

Print "close_wait"

Closesocket Idx

Case Sock_closed

'Print "closed"

End Select

Next

Loop

End

CONFIG

The CONFIG statement is used to configure the various hardware devices.

DIRECTIVE

RE-USABLE

CONFIG 1WIRE

NO

CONFIG ACI

YES

CONFIG ADC

NO

CONFIG ATEMU

NO

CONFIG BCCARD

NO

CONFIG CLOCK

NO

CONFIG CLOCKDIV

YES

CONFIG COM1

YES

CONFIG COM2 also COM3,

YES

COM4

CONFIG DATE

NO

CONFIG DCF77

NO

CONFIG DEBOUNCE

NO

CONFIG GRAPHLCD

NO

CONFIG I2CDELAY

NO

CONFIG I2CSLAVE

NO

CONFIG INPUT

NO

CONFIG INTx

YES

CONFIG KBD

NO

CONFIG KEYBOARD

NO

CONFIG LCD

NO

CONFIG LCDBUS

NO

CONFIG LCDMODE

NO

CONFIG LCDPIN

NO

CONFIG RC5

NO

CONFIG PORT

YES

CONFIG PRINT

NO

CONFIG PRINTBIN

NO

CONFIG SERIALIN

NO

CONFIG SERIALIN1

NO

CONFIG SERIALOUT

NO

CONFIG SERIALOUT1

NO

CONFIG SERVOS

NO

page -311-


© 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-