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

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

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

Добавлен: 12.06.2025

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

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

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

© MCS Electronics, 1995-2007

'I have little knowledge about these cards and please dont contact me about magnectic readers

'It is important however that you pull the card from the right direction as I was doing it wrong for

'some time :-)

'On the DT006 remove all the jumpers that are connected to the LEDs

'[We use ALIAS to specify the pins and PIN register]

'all pins are

_mport Alias Pinb

connected to PINB

'data line (blue)

_mdata Alias 0

PORTB.0

'CS line (yellow)

_mcs Alias 1

PORTB.1

'clock line

_mclock Alias 2

(green) PORTB.2

Config Portb = Input

'we only need bit

0,1 and 2 for input

'make them high

Portb = 255

Do

'print a message

Print "Insert magnetic card"

Readmagcard Ar(1) , B , 5

'read the data

Print B ; " bytes received"

For A = 1 To B

'print the bytes

Print Ar(a);

Next

Print

Loop

'By sepcifying 7 instead of 5 you can read 7 bit data

REM

Action

Instruct the compiler that comment will follow.

Syntax

REM or '

Remarks

You can and should comment your program for clarity and your later sanity. You can use REM or ' followed by your comment.

All statements after REM or ' are treated as comments so you cannot use statements on the same line after a REM statement.

Block comments can be used too:

'( start block comment

print "This will not be compiled ') end block comment

page -612-


© MCS Electronics, 1995-2007

Example

Rem TEST.BAS version 1.00

Print A ' " this is comment : PRINT " Hello "

^ - - - This Will Not Be Executed!

RESET

Action

Reset a bit to zero.

Syntax

RESET bit

RESET var.x

Remarks

bit

Can be a SFR such as PORTB.x, or any bit variable where x=0-7.

var

Can be a byte, integer word or long variable.

xConstant of variable to reset.(0-7) for bytes and (0-15) for Integer/Word. For longs(0-31)

You can also use the constants from the definition file to set or reset a bit.

RESET PORTB.PB7 'will reset bin 7 of portB. This because PB7 is a constant in the def file.

See also

SET , TOGGLE

Example

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

---

: boolean.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: demo: AND, OR, XOR, NOT, BIT and MOD

'suited for demo

: yes

'commercial addon needed

: no

'use in simulator

: possible

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

---

' specify the used

$regfile = "m48def.dat"

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

page -613-


© MCS Electronics, 1995-2007

for the frame space

Dim A As Byte , B1 As Byte , C As Byte

Dim Aa As Bit , I As Integer

A = 5 : B1 = 3

' assign values

C = A And B1

' and a with b

Print "a AND c = " ; C

' print result

C = A Or

B1

'also for or

Print "a OR b1 = " ; C

C = A Xor B1

' and for xor

Print "a XOR b1 = " ; C

A = 1

'not

C = Not A

Print "c = NOT a " ; C

C = C Mod 10

Print "c MOD 10 = " ; C

If Portb.1 = 1 Then

Print "Bit set"

Else

Print "Bit not set"

End If

Aa = 1

'use this or ..

Set Aa

'use the set

statement

If Aa = 1 Then

Print "Bit set (aa=1)"

Else

Print "Bit not set(aa=0)"

End If

Aa = 0

'now try 0

Reset Aa

'or use reset

If Aa = 1 Then

Print "Bit set (aa=1)"

Else

Print "Bit not set(aa=0)"

End If

B1 = 255

'assign variable

Reset B1.0

'reset bit 0 of a

byte variable

'print it

Print B1

Set B1.0

'set it

Print B1

'print it

End

RESTORE

Action

Allows READ to reread values in specified DATA statements by setting data pointer to

page -614-


© MCS Electronics, 1995-2007

beginning of data statement.

Syntax

RESTORE label

Remarks

label The label of a DATA statement.

See also

DATA , READ , LOOKUP

Example

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

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

: readdata.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: demo : READ,RESTORE

'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 Integer , B1 As Byte , Count As Byte

Dim S As String * 15

Dim L As Long

'point to stored

Restore Dta1

data

'for number of

For Count = 1 To 3

data items

" ; B1

Read B1 : Print Count ; "

Next

Restore Dta2

'point to stored

data

'for number of

For Count = 1 To 2

data items

" ; A

Read A : Print Count ; "

Next

Restore Dta3

Read S : Print S

Read S : Print S

page -615-