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

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

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

Добавлен: 12.06.2025

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

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

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

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


© MCS Electronics, 1995-2007

End

'Since we do a redirection we call the routine from the redirection routine

'

Kbdinput:

'we come here when input is required from the COM port 'So we pass the key into R24 with the GetATkbd function

' We need some ASM code to save the registers used by the function $asm

push r16 ; save used register push r25

push r26 push r27

Kbdinput1:

; call the function

rCall _getatkbd

tst r24

; check for zero

breq Kbdinput1

; yes so try again

pop r27

; we got a valid key so restore registers

pop r26

pop r25

pop r16

$end Asm

'just return

Return

'The tricky part is that you MUST include a normal call to the routine 'otherwise you get an error

'This is no clean solution and will be changed B = Getatkbd()

'This is the key translation table

Keydata:

'normal keys lower case

Data 0 , 0 , 0 , 0 , 0 , 200 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , &H5E , 0

Data 0 , 0 , 0 , 0 , 0 , 113 , 49 , 0 , 0 , 0 , 122 , 115 , 97 , 119 , 50 , 0 Data 0 , 99 , 120 , 100 , 101 , 52 , 51 , 0 , 0 , 32 , 118 , 102 , 116 , 114 , 53 , 0

Data 0 , 110 , 98 , 104 , 103 , 121 , 54 , 7 , 8 , 44 , 109 , 106 , 117 , 55 , 56 , 0

Data 0 , 44 , 107 , 105 , 111 , 48 , 57 , 0 , 0 , 46 , 45 , 108 , 48 , 112 , 43 , 0

Data 0 , 0 , 0 , 0 , 0 , 92 , 0 , 0 , 0 , 0 , 13 , 0 , 0 , 92 , 0 , 0 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

CONFIG LCD

Action

Configure the LCD display and override the compiler setting.

page -355-


© MCS Electronics, 1995-2007

Syntax

CONFIG LCD = LCDtype , CHIPSET=KS077 | Dogm163v5 | DOG163V3 | DOG162V5 | DOG162V3 [,CONTRAST=value]

Remarks

LCDtype

Chipset

KS077

CHIPSET

DOGM

The type of LCD display used. This can be :

40 * 4,16 * 1, 16 * 2, 16 * 4, 16 * 4, 20 * 2 or 20 * 4 or 16 * 1a or 20*4A.

Default 16 * 2 is assumed.

Most text based LCD displays use the same chip from Hitachi. But some use the KS077 which is highly compatible but needs an additional function register to be set. This parameter will cause that this register is set when you initialize the display.

The DOGM chip set uses a special function register that need to be set. The 16 x 2 LCD displays need DOG162V3 for 3V operation or DOG162V5 for 5V operation.

The 16 x 3 LCD displays need DOG163V3 for 3V operation or Dogm163v5 for 5V operation

CONTRAST The optional contrast parameter is only supported for the EADOG displays. By default a value from the manufacture is used. But you might want to override this value with a custom setting.

When you have a 16 * 2 display, you don't have to use this statement.

The 16 * 1a is special. It is used for 2 * 8 displays that have the address of line 2, starting at location &H8.

The 20*4A is also special. It uses the addresses &H00, &H20, &H40 and &H60 for the 4 lines. It will also set a special function register.

See Also

CONFIG LCDPIN , CONFIG LCDBUS

Example1

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

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

: lcd.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: demo: LCD, CLS, LOWERLINE, SHIFTLCD, SHIFTCURSOR,

HOME

CURSOR, DISPLAY

'

'micro

: Mega8515

'suited for demo

: yes

'commercial addon needed

: no

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

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

$regfile = "m8515.dat"

' specify the used

micro

' used crystal

$crystal = 4000000

frequency

' use baud rate

$baud = 19200

$hwstack = 32

' default use 32

for the hardware stack

page -356-