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

© MCS Electronics, 1995-2007

Data 0 , 60 , 0 , 0 , 0 , 0 , 8 , 0 , 0 , 49 , 0 , 52 , 55 , 0 , 0 , 0

Data 48 , 44 , 50 , 53 , 54 , 56 , 0 , 0 , 0 , 43 , 51 , 45 , 42 , 57 , 0 , 0

'shifted keys UPPER case

Data 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0

Data 0 , 0 , 0 , 0 , 0 , 81 , 33 , 0 , 0 , 0 , 90 , 83 , 65 , 87 , 34 , 0 Data 0 , 67 , 88 , 68 , 69 , 0 , 35 , 0 , 0 , 32 , 86 , 70 , 84 , 82 , 37 , 0 Data 0 , 78 , 66 , 72 , 71 , 89 , 38 , 0 , 0 , 76 , 77 , 74 , 85 , 47 , 40 , 0 Data 0 , 59 , 75 , 73 , 79 , 61 , 41 , 0 , 0 , 58 , 95 , 76 , 48 , 80 , 63 , 0 Data 0 , 0 , 0 , 0 , 0 , 96 , 0 , 0 , 0 , 0 , 13 , 94 , 0 , 42 , 0 , 0

Data 0 , 62 , 0 , 0 , 0 , 8 , 0 , 0 , 49 , 0 , 52 , 55 , 0 , 0 , 0 , 0

Data 48 , 44 , 50 , 53 , 54 , 56 , 0 , 0 , 0 , 43 , 51 , 45 , 42 , 57 , 0 , 0

GETATKBDRAW

Action

Reads a key from a PC AT keyboard.

Syntax

var = GETATKBDRAW()

Remarks

var The variable that is assigned with the key read fromthe keyboard.

It may be a byte or a string variable.

When no key is pressed a 0 will be returned.

The GETATKBDRAW() function needs 2 input pins and a translation table for the keys. You can read more about this at the CONFIG KEYBOARD compiler directive.

The GetatkbdRAW function will return RAW data from a PS/2 keyboard or Mouse.

While GetatKBD is intended to wait for pressed keys, GetATkbdRAW just returns raw PS/2 data so you can use your own code to process the data.

See Also

GETATKBD , CONFIG KEYBOARD

Example

See GETATKBD.BAS

GETDSTIP

Action

Returns the IP address of the peer.

page -506-

© MCS Electronics, 1995-2007

Syntax

Result = GETDSTIP( socket)

Remarks

Result

A LONG variable that will be assigned with the IP address of the peer or

 

destination IP address.

Socket

The socket number (0-3)

 

 

When you are in server mode, it might be desirable to detect the IP address of the connecting client.

You can use this for logging, security, etc.

The IP number MSB, is stored in the LS byte of the variable.

See also

CONFIG TCPIP, GETSOCKET , SOCKETCONNECT, SOCKETSTAT , TCPWRITE, TCPWRITESTR, CLOSESOCKET , SOCKETLISTEN , GETDSTPORT

Partial Example

Dim L as Long

L = GetdstIP(i) ' store current IP number of socket i

GETDSTPORT

Action

Returns the port number of the peer.

Syntax

Result = GETDSTPort( socket)

Remarks

Result

A WORD variable that is assigned with the port number of the peer or

 

destination port number.

Socket

The socket number.

 

 

When you are in server mode, it might be desirable to detect the port number of the connecting client.

You can use this for logging, security, etc.

See also

CONFIG TCPIP, GETSOCKET , SOCKETCONNECT, SOCKETSTAT , TCPWRITE, TCPWRITESTR, CLOSESOCKET , SOCKETLISTEN , GETDSTIP

page -507-

© MCS Electronics, 1995-2007

Partial Example

Dim P as Word

P = GetdstPORT(i)' store current port number of socket i

GETKBD

Action

Scans a 4x4 matrix keyboard and return the value of the key pressed.

Syntax

var = GETKBD()

Remarks

Var

The numeric variable that is assigned with the value read

 

from the keyboard

 

 

The GETKBD() function can be attached to a port of the uP.

You can define the port with the CONFIG KBD statement.

A schematic for PORTB is shown below

Note that the port pins can be used for other tasks as well. But you might need to set the port direction of those pins after you have used getkbd(). For example the LCD pins are set to output at the start of your program. A call to getkbd() would set the pins to input.

By setting DDR.x register you can set the pins to the proper state again. As an alternative you can use CONFIG PIN or CONFIG PORT.

When no key is pressed 16 will be returned.

When using the 2 additional rows, 24 will be returned when no key is pressed.

On the STK200 this might not work since other hardware is connected too that nterferesi.

You can use the Lookup() function to convert the byte into another value. This because the GetKBD() function does not return the same value as the key pressed. It willdepend on which keyboard you use.

page -508-

© MCS Electronics, 1995-2007

Sometimes it can happen that it looks like a key is pressed while you do not press a key. This is caused by the scanning of the pins which happens at a very high frequency.

It will depend on the used keyboard. You can add series resistors with a value of 470-1K

The routine will wait for 100 mS by default after the code is retrieved. With CONFIG KBD you can set this delay.

See also

CONFIG KBD

Example

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

 

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

: getkbd.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: demo : GETKBD

'micro

: Mega48

'suited for demo

: yes

'commercial addon needed

: no

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

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

$regfile = "m48def.dat"

' specify the used

micro

' used crystal

$crystal = 4000000

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

 

'specify which port must be used 'all 8 pins of the port are used Config Kbd = Portb

'dimension a variable that receives the value of the pressed key

Dim B As Byte

'loop for ever

Do

B = Getkbd()

'look in the help file on how to connect the matrix keyboard

'when you simulate the getkbd() it is important that you press/click the keyboard button

' before running the getkbd() line !!!

Print B

'when no key is pressed 16 will be returned

'use the Lookup() function to translate the value to another one

' this because the returned value does not match the number on the keyboad

Loop

End

page -509-