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

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

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

Добавлен: 12.06.2025

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

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

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

© MCS Electronics, 1995-2007

GETRC

Action

Retrieves the value of a resistor or a capacitor.

Syntax

var = GETRC( pin , number )

Remarks

Var

The word variable that is assigned with the value.

Pin

The PIN name for the R/C is connection.

Number

The port pin for the R/C is connection.

The name of the input port (PIND for example) must be passed even when allthe other pins are configured for output. The pin number must also be passed. This may be a constant or a variable.

A circuit is shown below:

The capacitor is charged and the time it takes to discharge it is measured and stored in the variable. Now when you vary either the resistor or the capacitor, different values will be returned. This function is intended to return a relative position of a resistor wiper, not to return the value of the resistor. But with some calculations it can be retrieved.

See also

NONE

Example

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

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

: getrc.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: demonstrates how to get the value of a resistor

'micro

: AT90S8535

'suited for demo

: yes

'commercial addon needed

: no

'The library also shows how to pass a variable for use with individual port

'pins. This is only possible in the AVR architecture and not in the 8051

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

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

page -510-


© MCS Electronics, 1995-2007

$regfile = "8535def.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

'The function works by charging a capacitor and uncharge it little by little 'A word counter counts until the capacitor is uncharged.

'So the result is an indication of the position of a pot meter not the actual 'resistor value

'This example used the 8535 and a 10K ohm variable resistor connected to PIND.4

'The other side of the resistor is connected to a capacitor of 100nF. 'The other side of the capacitor is connected to ground.

'This is different than BASCOM-8051 GETRC! This because the architecture is different.

'The result of getrc() is a word so DIM one

Dim W As Word

Do

'the first parameter is the PIN register.

'the second parameter is the pin number the resistor/capacitor is connected to

'it could also be a variable! W = Getrc(pind , 4)

Print W

Wait 1

Loop

GETRC5

Action

Retrieves the RC5 remote code from a IR transmitter.

Syntax

GETRC5( address, command )

Uses

TIMER0

Remarks

address

The RC5 address

command

The RC5 command.

This statement is based on the AVR 410 application note. Since a timer is needed for accurate delays and background processing TIMER0 is used by this statement.

page -511-


© MCS Electronics, 1995-2007

Also the interrupt of TIMER0 is used by this statement.

TIMER0 can be used by your application since the values are preserved by the statement but a delay can occur. The interrupt can not be reused.

GETRC5 supports extended RC5 code reception.

The SFH506-36 is used from Siemens. Other types can be used as well. The TSOP1736 has been tested with success.

For a good operation use the following values for the filter.

Most audio and video systems are equipped with an infra-red remote control.

The RC5 code is a 14-bit word bi-phase coded signal.

The two first bits are start bits, always having the value 1.

The next bit is a control bit or toggle bit, which is inverted every time a button is pressed on the remote control transmitter.

Five system bits hold the system address so that only the right system responds to the code.

Usually, TV sets have the system address 0, VCRs the address 5 and so on. The command sequence is six bits long, allowing up to 64 different commands per address.

The bits are transmitted in bi-phase code (also known as Manchester code).

page -512-

© MCS Electronics, 1995-2007

For extended RC5 code, the extended bit is bit 6 of the command.

The toggle bit is stored in bit 7 of the command.

See also

CONFIG RC5 , RC5SEND, RC6SEND

Example

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

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

: rc5.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: based on Atmel AVR410 application note

'micro

: 90S2313

'suited for demo

: yes

'commercial addon needed

: no

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

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

$regfile = "2313def.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

'use byte library for smaller code $lib "mcsbyte.lbx"

'This example shows how to decode RC5 remote control signals 'with a SFH506-35 IR receiver.

'Connect to input to PIND.2 for this example

'The GETRC5 function uses TIMER0 and the TIMER0 interrupt.

'The TIMER0 settings are restored however so only the interrupt can not 'be used anymore for other tasks

'tell the compiler which pin we want to use for the receiver input

Config Rc5 = Pind.2

'the interrupt routine is inserted automatic but we need to make it occur 'so enable the interrupts

Enable Interrupts

'reserve space for variables

Dim Address As Byte , Command As Byte Print "Waiting for RC5..."

Do

'now check if a key on the remote is pressed 'Note that at startup all pins are set for INPUT 'so we dont set the direction here

'If the pins is used for other input just unremark the next line

page -513-


© MCS Electronics, 1995-2007

'Config Pind.2 = Input

Getrc5(address , Command)

'we check for the TV address and that is 0 If Address = 0 Then

'clear the toggle bit

'the toggle bit toggles on each new received command 'toggle bit is bit 7. Extended RC5 bit is in bit 6 Command = Command And &B01111111

Print Address ; " " ; Command

End If Loop End

GETTCPREGS

Action

Read a register value from the W3100A

Syntax

var = GETTCPREGS(address, bytes)

Remarks

Address

The address of the W3100A register.

bytes

The number of bytes to read.

Most W3100A options are implemented with BASCOM statements or functions. When there is a need to read from the W3100A register you can use the GETTCPREGS function. It can read multiple bytes. It is important that you specify the highest address. This because the registers must be read starting with the higest address.

See also

SETTCPREGS

ASM

NONE

Example

See SETTCPREGS

GETSOCKET

Action

Creates a socket for TCP/IP communication.

Syntax

page -514-

© MCS Electronics, 1995-2007

Result = GETSOCKET(socket, mode, port, param)

Remarks

Result

A byte that is assigned with the socket number you requested. When the

operation fails, it will return 255.

Mode

Port

Param

The socket mode. Use sock_stream(1), sock_dgrm(2), sock_ipl_raw(3), sock) or macl_raw(4). The modes are defined with constants.

For TCP/IP communication you need to specify sock_streamor the equivalent value 1.

For UDP communication you need to specify sock_dgrm or the equivalent value 2.

This is the local port that will be used for the communication. You may specify any value you like but each socket must have it’s own local port number.

When you use 0, the value of LOCAL_PORT will be used.

LOCAL_PORT is assigned with CONFIG TCPIP.

After the assignment, LOCAL_PORT will be increased by 1. So the simplest way is to setup a local port with CONFIG TCPIP, and then use 0 for port.

Optional parameter. Use 0 for default.

128 : send/receive broadcast message in UDP

64 : use register value with designated timeout value

32 : when not using no delayed ack

16: when not using silly window syndrome

Consult the W3100A documentation for more information.

After the socket has been initialized you can use SocketConnect to connect to a client, or SocketListen to act as a server.

See also

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

Partial Example

I = Getsocket(0 , Sock_stream , 5000 , 0)' get a new socket

GLCDCMD

Action

Sends a command byte to the SED graphical LCD display.

Syntax

page -515-