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

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