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

© MCS Electronics, 1995-2007

DEBUG

Action

Instruct compiler to start or stop debugging, or print variable to serial port

Syntax

DEBUG ON | OFF | var

Remarks

ON

Enable debugging

OFF

Disable debugging

var

A variable which values must be printed to the serial port

 

 

During development of your program a common issue is that you need to know the value of a variable.

You can use PRINT to print the value but then it will be in the application as well. You can use conditional compilation such as :

CONST TEST=1 #IF TEST

print var #ENDIF

But that will result in a lot of typing work. The DEBUG option is a combination of conditional compilation and PRINT. Whenever you activate DEBUG with the ON parameter, all 'DEBUG var' statements will be compiled.

When you turn DEBUG OFF, all 'DEBUG var' statements will not be compiled.

You can not nest the ON and OFF. The last statements wins.

Typical you will have only one DEBUG ON statement. And you set it to OFF when your program is working.

An example showing nesting is NOT supported:

DEBUG ON

DEBUG ON ' it is still ON

DEBUG OFF' it is OFF now

An example showing multiple DEBUG:

DEBUG ON

DEBUG var ' this is printed

DEBUG var2 ' this is also printed

DEBUG OFF

DEBUG var3 'this is NOT printed

DEBUG var4 ' this is not printed

DEBUG ON ' turn DEBUG ON

If A = 2 Then

DEBUG A ' this is printed

End If

page -444-

© MCS Electronics, 1995-2007

See also

DBG

ASM

NONE

Example

DEBUG ON

Dim A As Byte

DEBUG A

End

DEBOUNCE

Action

Debounce a port pin connected to a switch.

Syntax

DEBOUNCE Px.y , state , label [ , SUB]

Remarks

Px.y

A port pin like PINB.0 , to examine.

State

0 for jumping when PINx.y is low , 1 for jumping when PINx.y is high

Label

The label to GOTO when the specified state is detected

SUB

The label to GOSUB when the specified state is detected

 

 

When you specify the optional parameter SUB, a GOSUB to label is performed instead of a GOTO.

The DEBOUNCE statement tests the condition of the specified pin and if true there willbe a delay for 25 mS and the condition will be checked again. (eliminating bounce of a switch)

When the condition is still true and there was no branch before, it branches to specified the label.

When the condition is not true, or the logic level on the pin is not of the specified evel, the code on the next line will be executed.

When DEBOUNCE is executed again, the state of the switch must have gone back in the original position before it can perform another branch. So if you are waiting for a pin to go low, and the pin goes low, the pin must change to high, before a new low level will result in another branch.

Each DEBOUNCE statement, which uses a different port, uses 1 BIT of the internal memory to hold its state. And as the bits are stored in SRAM, it means that even while you use only 1 pin/bit, a byte is used for storage of the bit.

DEBOUNCE will not wait for the input value to met the specified condition. You need to use BITWAIT if you want to wait until a bit will have a certain value.

page -445-

© MCS Electronics, 1995-2007

So DEBOUNCE will not halt your program while a BITWAIT can halt your program if the bit will never have the specified value. You can combine BITWAIT and DEBOUNCE statements by preceding a DEBOUNCE with a BITWAIT statement.

See also

CONFIG DEBOUNCE , BITWAIT

Example

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

 

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

: deboun.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: demonstrates DEBOUNCE

'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

 

Config Debounce = 30

'when the config

statement is not used a default of 25mS will be used but we override to use 30 mS

'Debounce Pind.0 , 1 , Pr 'try this for branching when high(1) Debounce Pind.0 , 0 , Pr , Sub

Debounce Pind.0 , 0 , Pr , Sub

'

 

^-----

label to branch to

'

^

^----------

Branch when P1.0 goes low(0)

'

 

Examine P1.0

'When Pind.0 goes low jump to subroutine Pr 'Pind.0 must go high again before it jumps again 'to the label Pr when Pind.0 is low

Debounce Pind.0 , 1 , Pr

'no branch

Debounce Pind.0 , 1 , Pr

'will result in a

return without gosub

 

End

 

Pr:

 

Print "PIND.0 was/is low"

 

Return

 

page -446-

© MCS Electronics, 1995-2007

DECR

Action

Decrements a variable by one.

Syntax

DECR var

Remarks

There are often situations where you want a number to be decreased by 1. It is simpler to write :

DECR var compared to : var = var - 1

See also

INCR

Example

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

 

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

: decr.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: demostrate decr

'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

 

Dim A As Byte , I As Integer

 

A = 5

'assign value to a

Decr A

'decrease (by one)

Print A

'print it

I = 1000

 

Decr I

 

Print I

 

End

 

page -447-