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

© MCS Electronics, 1995-2007

 

Wait 2

 

For X = 1 To 10

' show circle

Circle(20 , 20) , X , 255

Waitms 200

 

Next

 

Wait 2

 

'Now it is time to show a picture

 

'SHOWPIC X,Y,label

 

'The label points to a label that holds the image data

 

Test:

 

Showpic 0 , 0 , Plaatje

' show 2 since we

Showpic 0 , 64 , Plaatje

have a big display

 

Wait 2

' clear the text

Cls Text

End

 

'This label holds the mage data Plaatje:

'$BGF will put the bitmap into the program at this location $bgf "mcs.bgf"

'You could insert other picture data here

CONFIG KBD

Action

Configure the GETKBD() function and tell which port to use.

Syntax

CONFIG KBD = PORTx , DEBOUNCE = value [, DELAY = value]

Remarks

PORTx

The name of the PORT to use such as PORTB or PORTD.

DEBOUNCE By default the debounce value is 20. A higher value might be needed. The maximum is 255.

Delay

An optional parameter that will cause Getkbd() to wait the specified amount of time after the key is detected. This parameter might be added when you call GetKbd() repeatedly in a loop. Because of noise and static electricity, wrong values can be returned. A delau of say 100 mS, can eliminate this problem.

The GETKBD() function can be used to read the pressed key from a matrix keypad attached to a port of the uP.

You can define the port with the CONFIG KBD statement.

In addition to the default behavior you can configure the keyboard to have 6 rows instead of 4 rows.

CONFIG KBD = PORTx , DEBOUNCE = value , rows=6, row5=pinD.6, row6=pind.7

page -351-

© MCS Electronics, 1995-2007

This would specify that row5 is connected to pind.6 and row7 to pind.7 Note that you can only use rows=6. Other values will not work.

See also

GETKBD

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

CONFIG KEYBOARD

Action

Configure the GETATKBD() function and tell which port pins to use.

page -352-

© MCS Electronics, 1995-2007

Syntax

CONFIG KEYBOARD = PINX.y , DATA = PINX.y , KEYDATA = table

Remarks

KEYBOARD

The PIN that serves as the CLOCK input.

DATA

The PIN that serves as the DATA input.

KEYDATA

The label where the key translation can be found.

 

The AT keyboard returns scan codes instead of normal ASCII codes. So a

 

translation table s needed to convert the keys.

 

BASCOM allows the use of shifted keys too. Special keys like function

 

keys are not supported.

 

 

The AT keyboard can be connected with only 4 wires: clock,data, gnd and vcc. Some info is displayed below. This is copied from an Atmel data sheet.

The INT0 or INT1 shown can be in fact any pin that can serve as an INPUT pin.

The application note from Atmel works in interrupt mode. For BASCOM we rewrote the code so that no interrupt is needed/used.

See also

GETATKBD

Example

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

page -353-

 

© MCS Electronics, 1995-2007

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

: getatkbd.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: PC AT-KEYBOARD Sample

'micro

: Mega48

'suited for demo

: yes

'commercial addon needed

: no

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

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

$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

 

'For this example :

'connect PC AT keyboard clock to PIND.2 on the 8535 'connect PC AT keyboard data to PIND.4 on the 8535

'The GetATKBD() function does not use an interrupt. 'But it waits until a key was pressed!

'configure the pins to use for the clock and data 'can be any pin that can serve as an input 'Keydata is the label of the key translation table

Config Keyboard = Pind.2 , Data = Pind.4 , Keydata = Keydata

'Dim some used variables

Dim S As String * 12 Dim B As Byte

'In this example we use SERIAL(COM) INPUT redirection $serialinput = Kbdinput

'Show the program is running Print "hello"

Do

'The following code is remarked but show how to use the GetATKBD() function ' B = Getatkbd() 'get a byte and store it into byte variable

'When no real key is pressed the result is 0 'So test if the result was > 0

'If B > 0 Then

'Print B ; Chr(b)

'End If

'The purpose of this sample was how to use a PC AT keyboard

'The input that normally comes from the serial port is redirected to the 'external keyboard so you use it to type

Input "Name " , S 'and show the result

Print S

'now wait for the F1 key , we defined the number 200 for F1 in the table

Do

B = Getatkbd() Loop Until B <> 0 Print B

Loop

page -354-