modul 1 mengenal dan belajar pemograman bascom

16
 ENGENAL DAN BELAJAR PE OGRA AN DENGAN INSTRUKSI BASIC BASCO -8051 PENGANTAR PROGRAM UNTUK MENGHITUNG FREKUENSI DETAK JANTUNG $regfile = "8052.dat" $crystal = 12000000 Config Lcd = 40 * 2 Sw Alias 0.0 Dim A As Long , B  _ As Byte , Jmld_jantung As Byte , D As Byte '-------------------------------------------------------- Do Mulai_1: B_ = 0 Jmld_jantung = 0 A = 0 If 0!1 = 1 "#en  Lo$ate 1 , %  L$d &ALA" D"()I JA*"+* BL+M A("I&  lseif 0!1 = 0 "#en  .ls  Lo$ate 1 , %  L$d & *+(+/A* /(+*)I D"A( JA*"+* A("I &  osu Mulai  nd If Loo '-------------------------------------------------------- Mulai: 'jumla# a no2mal 3000 = 40 se$ond o2 A = 0 "o %00 'untu5 simulasi A = 300  Lo$ate 6 , 1  L$d A  If )7 = 0 And B_ = 0 "#en  In$2 B_  In$2 Jmld_jantung  Lo$ate 1 , 1  L$d Jmld_jantung

Upload: amir-si-keteng

Post on 14-Oct-2015

45 views

Category:

Documents


1 download

DESCRIPTION

test

TRANSCRIPT

  • 5/24/2018 Modul 1 Mengenal Dan Belajar Pemograman Bascom

    1/

    ENGENAL DAN BELAJAR PE OGRA ANDENGAN INSTRUKSI BASIC

    BASCO -8051PENGANTAR

    PROGRAM UNTUK MENGHITUNG FREKUENSI DETAK JANTUNG

    $regfile = "8052.dat"$crystal = 12000000Config Lcd = 40 * 2Sw Alias 0.0

    Dim A As Long , B_ As Byte , Jmld_jantungAs Byte , D As Byte

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

    DoMulai_1:

    B_ = 0Jmld_jantung = 0A = 0

    If 0!1= 1 "#en Lo$ate 1 , % L$d &ALA" D"()I JA*"+* BL+M A("I&

    lseif 0!1= 0 "#en .ls Lo$ate 1 , % L$d & *+(+/A* /(+*)I D"A( JA*"+* A("I& osu Mulai nd IfLoo

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

    Mulai:

    'jumla# a no2mal 3000 = 40 se$ondo2 A = 0 "o %00 'untu5 simulasi A = 300

    Lo$ate 6 , 1 L$d A If )7 = 0 And B_ = 0 "#en In$2 B_ In$2 Jmld_jantung Lo$ate 1 , 1 L$d Jmld_jantung

  • 5/24/2018 Modul 1 Mengenal Dan Belajar Pemograman Bascom

    2/

    lseif )7 = 1 And B_ = 1 "#en B_ = 0 lseif A = 300 "#en : osu .oma2e nd If 8aitms 6 *e9t A

    /etu2n'--------------------------------------------------------

    .oma2e: .ls If Jmld_jantung = ;< And Jmld_jantung = ;0 "#en Lo$ate1 , 1 L$d & (>*DI)I JA*"+* A*DA: & 'analisa 1 Lo$ate 1 , 1? L$d & DALAM (ADAA* *>/MAL&'=============================================

    lseif Jmld_jantung ?< "#en Lo$ate 1 , 1 L$d & (>*DI)I JA*"+* A*DA & 'analisa 6 Lo$ate 1 , 1? L$d & DALAM (ADAA* LMA@&

    lseifJml_jantung 11 "#en'============================================= Lo$ate 1 , 1 L$d & (>*DI)I JA*"+* :& Lo$ate 1 , 1? 'analisa 3 L$d & DALAM (ADAA* + *>/MAL "I*I &

    nd If 8aitms 1000'============================================= .ls

    oto Mulai_1

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

    MATERI

    MENGENAL INSTRUKSI BASCOM

    PEMOGRAMAN OUTPUT LED

  • 5/24/2018 Modul 1 Mengenal Dan Belajar Pemograman Bascom

    3/

    DATA INPUT / OUTPUT PORT

    OPERASI SHIFT T

    SHIFT LEF

    SHIFT RIGHT

    OPERASI COUNTER

    UP COUNTER

    DOWN COUNTER

    UP-DOWN COUNTER

    PEMOGRAMAN OUTPUT DIPSLAY

    OUTPUT 7 SEGMENT

    OUTPUT LCD

    MENGENAL INSTRUKSI BASCOM

    1WIRE

    1Wire routines allow you to communicate with Dallas 1wire chips.1WRESET, 1WREAD, 1WWRITE , 1WSEARCHFIRST, 1WSEARCHNEXT ,1WIRECOUNT

    Conditions

    Conditions execute a part of the program depending on the condition

    IF, ELSE, END IF, EXIT, DO, LOOP, SELECT, FOR, NEXT, TO, THEN,WHILE .. WEND

    Configuration

    Configuration command initialize the hardware to the desired state.CONFIG

    Conversion

    A conversion routine is a function that converts a number or string.ASC, BCD , CHR , FUSING , HEX , HEXVAL , HIGH , HIGHW ,MAKEDEC ,MAKEBCD, MAKEINT, STR, VAL

    Delay

    Delay routines delay the program for the specified time.DELAY, WAIT, WAITMS

  • 5/24/2018 Modul 1 Mengenal Dan Belajar Pemograman Bascom

    4/

    Directives

    Directives are special instructions for te co!piler" Te# can overri$e a

    settin% fro! te IDE"#IF , #ELSE , #ENDIF , $ASM - $END ASM ,$INCLUDE , $BAUD , $BGF ,$CRYSTAL , $DEFAULT XRAM , $IRAMSTART , $LARGE , $LCD , $MAP ,$NOBREAK , $NOINIT , $NONAN , $NONULL , $NORAMCLEAR , $NOSP ,$OBJ , $RAMSIE , $RAMSTART , $REGFILE , $ROMSTART ,$SERIALINPUT, $SERIALINPUT!LCD, $SERIALOUTPUT, $SIM

    Graphical LCD

    Graphical CD commands extend the normal text CD commands.!"#$% "&'W!(C

    I2C

    ()C commands allow you to communicate with ()C chips with the $W( hardwareor with emulated ()C hardware.()C*#C#(+#% ()C"#,D% ()C"$A*$% ()C"$'!% ()C*-$#% ()CW-$#

    Interrups

    (nterrupt related routines.', (nterrupt% #,A-#% D("A-#% !*('*($

    IO

    (/' commands are related to the (/' pins of the processor.A(A"% -($WA($% D#-'0,C#% "#$% *#"#$

    Mathath functions

    A-"%A+G% A2% (,% 'D

    Micro

    icro statements are highly related to the micro processor.-*#A3% !1%!4% (D#% #,D% !'W#*D'W,% "$A*$% "$'!% "$'! $(#*

    Meory

    Me!or# functions set or rea$ RAM & EE'ROM or flas !e!or#"

  • 5/24/2018 Modul 1 Mengenal Dan Belajar Pemograman Bascom

    5/

    C'EEK& ERASE& IN'& OUT& 'EEK& 'OKE& DIM& READ& RESTORE& DATA

    & (AR'TR

    Reote control

    *emote control statements send or receive (* commands for remote control.

    G#$*C5

    R!"2#2

    *"6)4) are serial routines that use the 0A*$ or emulate a 0A*$.

    WA($3# % !*(,$ % !*(,$-(, % !*(,$ % !0$ % '!#, %"!C % (,3# %(,!0$% (,!0$-(,% (,!0$% G#$% C'"#

    !$I

    "!( routines communicate according to the "!( protocol with either hardware "!(or software emulated "!(.

    "!((,% "!('0$% "!((,($

    !tring

    "tring routines are used to manipulate strings.

    (D% CA"#% (,"$*% #7$% #,% *(G&$% "$*(,G% *#!AC#% "!AC#%0CA"#

    %e&t LCD

    $ext CD routines wor8 with the normal text based CD displays.

    C"% C0*"'*% 7'0*$&(,#% &'#% CD% CD(,($% CD % 'CA$#% "&(7$CD % "&(7$C0*"'* %D("!A % 'W#*(,# % 0!!#*(,# %$&(*D(,#

    'arious

  • 5/24/2018 Modul 1 Mengenal Dan Belajar Pemograman Bascom

    6/

    $his section contains all statements that were hard to put into another group

    CA , C',"$ , C'0,$#* , D#C* , D#CA*# , D#7(,$ , D#7-($

    ,D#7-$# , D#7CDC&A* , D#7W'*D , G#$AD , G#$AD)951 ,

    G#$*C , , G'"0- , G'$' , (,C* , 'AD , ''30! , ''30!"$* ,

    'W , 'WW , ', +alue , *#ADAGCA*D , *# , *#$0*, , *,D ,*'$A$#, "&(7$, "&(7$(,, "&(7$'0$, "'0,D, "0-, "WA!

    $EMOGR(M() D(!(R *(!COM

    +O*"1

    1 DATA OUPUT PORT

    PROGRAM-1

    !"#$%&'( ) 1000000

    D*

    P0 ) 1

    P1 ) +

    P+ ) ,

    P ) 8

    P, ) 1.

    P5 ) +

    P. ) .,

    L**

    (L+A/A* ADA >/"

  • 5/24/2018 Modul 1 Mengenal Dan Belajar Pemograman Bascom

    7/

    Catatan

    Data yang akan dikeluarkan ke port langsung dapat diset

    PEMOGRAMAN DATA HE 2

    !"#$%&'( ) 1000000

    D*

    P0 ) 3H01

    P1 ) 3H0+

    P+ ) 3H0,

    P ) 3H08

    P, ) 3H10

    P5 ) 3H+0

    P. ) 3H,0

    L**

    KELUARAN PADA PORT

    Catatan

  • 5/24/2018 Modul 1 Mengenal Dan Belajar Pemograman Bascom

    8/1

    Data yang dikeluarkan ke port dalam hexa

    !erasi S#%& L'%&

    (!)(A s+ift left

    $crystal = 1000000,i- As /yte As /yte1 = 02 = 0 = 0

    ,o 0 = 3 %or = 0 &o 8 S+ift 0 Left 1 ait 1 et

    Loo

    @asil >utut

    rogra- !66& S#%& 7 ()#&

    !"#$%&'( ) 1000000D4 A% B$&6 7 N A% B$&6P1 ) 0P+ ) 0

  • 5/24/2018 Modul 1 Mengenal Dan Belajar Pemograman Bascom

    9/

    P ) 0D* P0 ) 3H80 F*# N ) 0 T* 8 S49& P0 7R4:& 7 1 F*# ) 1 T* 1000000 N6;& N6;&L**/

    PROGRAM UP-COUNTER

    !"#$%&'( ) 1000000

    D4 A% B$&6 N A% B$&6P1 ) 0

    D*

    P1 ) P1 < 1

    F*# N ) 0 T* 8

    N6;&

    L**

    P#*:#' U-C*=>&6# FOR- NET 2

    !"#$%&'( ) 1000000D4 A% B$&6 N A% B$&6

    P1 ) 0

    F*# N ) 1 T* ,0

    P1 ) N

    W'4& 1

    N6;&

    PROGRAM UP COUNTER WHILE-WEND 2

    !"#$%&'( ) 1000000D4 A% B$&6 7 N A% B$&6 7 A A% B$&6A ) 0W4(6 A ?) 10

  • 5/24/2018 Modul 1 Mengenal Dan Belajar Pemograman Bascom

    10

    P1 ) A I>"# A W'4& 1W6>@

    P#*:#' U-C*=>&6# 0 S/D ,0 2

    !"#$%&'( ) 1000000D4 A% B$&6 7 N A% B$&6P1 ) 0P+ ) 0P ) 0D* F*# N ) 1 T* ,0 P0 ) N F*# ) 1 T* 10 N6;& N6;&L**/

    PROGRRAM UP-COUNTER DENGAN IFTHEN!"#$%&'( ) 1000000

    D4 I A% B$&6 A A% B$&6

    A ) 0

    L'6(

    P0 ) A

    A ) A < 1

    I9 A ?) 10 T6>

    W'4& 1

    G*&* L'6( E>@ I9

    E>@

    PROGRAM DOWN -COUNTER

    !"#$%&'( ) 1000000

    D4 A% B$&6 N A% B$&6 A A% I>&6:6#

  • 5/24/2018 Modul 1 Mengenal Dan Belajar Pemograman Bascom

    11

    P1 ) 0

    P+ ) 0

    P ) 0

    D*

    A ) .0 F*# N ) 1 T* ,0

    P0 ) A

    F*# ) 1 T* 10

    N6;&

    A ) A - 1

    N6;&

    L**

    PENJELASAN INSTRUKSI

    DIDimension a variable.

    SyntaxDIMvar AS [XRAM/IRAM]type

    Remarks

    Var Any valid variable name such as b1, i or longname. var can also be an

    array : ar(10) for eample.

    !ype "it#"oolean, "yte, $ord, %nteger, &ong, 'ingle or 'tring

    A* 'pecify A* to store variable in eternal memory

    %A* 'pecify %A* to store variable in internal memory (default)

    A string variable needs an additional parameter that specifies the length of the string:

    Dim s As A* String * 10%n this case, the string can have a length of 10 characters.

    +ote that "%!' can only be stored in internal memory.

  • 5/24/2018 Modul 1 Mengenal Dan Belajar Pemograman Bascom

    12

    Difference with Q%n " you don-t need to dimension each variable before you use it. %n "A'/* you must

    dimension each variable before you use it. Also the A*#%A* options are not available in

    ".

    See A!s"/+'!, A'

    #xam$!e,""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

    , -c. 1//0"2 MC! Electronics

    ,""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

    , file3 DIM4*(!

    , deo3 DIM

    ,""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

    Di *1 (s *it ,5it can 5e or 1

    Di ( (s *yte ,5yte range fro "200

    Di C (s Integer ,integer range fro "#266 " 7#268

    Di L (s Long

    Di ! (s !ingle

    ,(ssign 5its

    *1 9 1 ,or

    !et *1 ,use set

    ,(ssign 5ytes

    ( 9 12

    ( 9 ( 7 1,(ssign integer

    C 9 "12

    C 9 C 7 1

    $rint C

    ,(ssign long

    L 9 12#:068

    $rint L

    ,(ssign single

    ! 9 12#:406

    $rint !

    End

    DO LOOP

  • 5/24/2018 Modul 1 Mengenal Dan Belajar Pemograman Bascom

    13

    Acti"nepeat a bloc of statements until condition is true.

    Syntax

    D%

    'tatements

    &%%' [ ()I&epression]

    Remarks2ou can eit a D/..&//3 4ith the %! D/statement.

    See a!s"%!, $5%& $+D, 6/, +!

    #xam$!eDimA AsByte

    Do 'start the loop

    A = A + 1 'increment A

    PrintA 'print it

    LoopUntilA = 10 'Repeat loop until A = 10

    PrintA 'A is still 10 here

    FOR NETActi"necute a bloc of statements a number of times.

    Syntax+%Rvar 7 start %/D%,)%end8S#'value9Remarks

    Var !he variable counter to use

    'tart !he starting value of the variable var

    nd !he ending value of the variable var

    Value !he value var is increased#decreased 4ith each time +! is encountered.

    -ar . yte Integer ,"r &"ng Sing!e

    start. yte Integer ,"r &"ng Sing!e 2"nstant

    en . yte Integer ,"r &"ng Sing!e 2"nstantste$ . yte Integer ,"r &"ng Sing!e 2"nstant

  • 5/24/2018 Modul 1 Mengenal Dan Belajar Pemograman Bascom

    14

    6or incremental loops you must use !/. 6or decremental loops you must use D/$+!/.2ou may use !/ for a decremental loop but in that case you must use a negative '!3 : 6or

    a 7 10 !o 1 '!3 31 2ou must end a 6/ structure 4ith the +! statement.!he use of '!3 is optional. "y default a value of 1 is used.

    See a!s")#X #XI +%R

    #xam$!e

    D4 Y A% B$&6 A A% B$&6; '% $&6

    $ ) 10 '6 $ 10

    F*# A ) 1 T* 10 @* &4% 10 &46%

    F*# ) Y T* 1 &4% *>6 '(%*

    P#4>& A #4>& &6 '(=6%

    N6;& >6;& ; "*=>& @*>2

    N6;& >6;& ' "*=>& =2

    D4 S A% S4>:(6

    F*# S ) 1 T* + S&6 01

    P#4>& S

    N6;&

    E>@

    WAIT SActi"n'uspends program eecution for a given time in m'.

    Syntax,AIMSm'

    Remarks

    m' !he number of milliseconds to 4ait. (1;

  • 5/24/2018 Modul 1 Mengenal Dan Belajar Pemograman Bascom

    15

    $A%!*' 10 -4ait for 10 m'3rint >?>

    SHIFTActi"n'hifts all bits one place to the left or right.

    SyntaxS4I+var , &6!#%@5! 8 , shifts9

    Remarks

    Var "yte, %nteger#$ord or &ong variable.

    'hifts !he number of shifts to perform.

    !he '5%6! statements shifts all bits to the left or right and so for a byte after

    shifts, the byte 4ill be Bero.

    See a!s"'5%6!%+, '5%6!/C! /!A!

    #xam$!eDim a as $ord

    a 7 1;'5%6! a, &6! , 1

    3rint a -;

  • 5/24/2018 Modul 1 Mengenal Dan Belajar Pemograman Bascom

    16

    See a!s"D/ .. &//3, 6/ .. +!

    #xam$!eDimA Asyte

    ,hi!eA