update terbaru haya di barliannet.com

Sabtu, 25 April 2015

memahami perintah goto pada bascom 8535

pada kesempatan ini saya akan mencoba memahami perintah goto pada bascom
 Perintah ini untuk melakukan lompatan ke label kemudian melakukan serangkaian instruksi
tanpa harus kembali lagi, sehingga tidak perlu RETURN. Contoh
sintaknya sbb:
GOTO <label> sebuah label diakhiri dengan : ( titik dua )
goto perintah1 lebelnya perintah1:

contoh aplikasi dengan bascom
=============================================================


   '  barlianno pemahaman if then else dan goto
  
$regfile = "m8535.dat"
$crystal = 1000000
Buz
Alias Portd.4
Config Portc = Output                                       'dipasang seven segmen comon anoda
Config Portb = Output                                       'dipasang led
Config Porta = Input                                        'di pasang tombol
Ddrd.4 = 1                                                  'di pasang buzer
 
Portb = 0
Portc = 0
Porta = &HFF                                                'heksa ff=11111111

Do
If Pina = &B11111110 Then
   
Goto Perintah1                                          'untuk meloncat keperintah1

Elseif Pina = &B11111101 Then
 
Goto Perintah2                                            'untuk meloncat keperintah2

Elseif Pina = &B11111011 Then
Goto Perintah3                                              'untuk meloncat keperintah3

Elseif Pina = &B11110111 Then
 
Goto Perintah4                                            'untuk meloncat keperintah4

Elseif Pina = &B11101111 Then
 
Goto Perintah5                                            'untuk meloncat keperintah5

Elseif Pina = &B11011111 Then
   Buz
= 1
  
Portc = &H82                                             'heksa82= 10000010 muncul angka 6
  
Portb = &B00111111
  
Bitwait Pina.5 , Set
Elseif Pina = &B10111111 Then

   Buz
= 1
  
Portc = &HF8                                             'heksaf8= 11111000 muncul angka 7
  
Portb = &B01111111
  
Bitwait Pina.6 , Set
Elseif Pina = &B01111111 Then
   Buz
= 1                                                  'heksa 80=10000000 muncul angka 8
  
Portc = &H80
  
Portb = &B11111111
  
Bitwait Pina.7 , Set
Else
Utama
:
   Buz
= 0                                                  'buzer tidak buyi
  
Portc = &HFF                                             'seven segmen mati
  
Portb = &B00000000                                       'led mati
   
Waitms 100

   
Portc = &HF9                                            'angka1 sevensegment
   
Portb = &B00000001                                      'led 1 yala
     
Waitms 100

  
Portc = &HA4                                             'angka2 seven segment
  
Portb = &B00000010                                       'led 2 yala
    
Waitms 100

   
Portc = &HB0                                            'angka 3 seven segment
  
Portb = &B00000100                                       'led 3 yala
         
Waitms 100

  
Portc = &H99                                             'angka 4 seven segment
  
Portb = &B00001000                                       'led 4 yala
  
Waitms 100

  
Portc = &H92                                             'angka 5 seven segment
  
Portb = &B00010000                                       'led 5 yala
  
Waitms 100

   
Portc = &H82                                            'angka 6 seven segment
  
Portb = &B00100000                                       'led 6 yala
  
Waitms 100

 
Portc = &HF8                                              'angka 7 seven segment
  
Portb = &B01000000                                       'led 7 yala
  
Waitms 100

  
Portc = &H80                                             'angka 8 seven segment
  
Portb = &B10000000                                       'led 8 yala
  
Waitms 100
End If


Loop

Perintah1
:
Portc = &HF9                                                'muncul anka 1
  
Portb = &B00000000                                       'led mati
   
Waitms 1000
  
Portb = &B10000000                                       'led 1 yala
     
Waitms 1000
  
Portb = &B01000000                                       'led 2 yala
    
Waitms 1000
  
Portb = &B00100000                                       'led 3 yala
    
Waitms 1000
  
Portb = &B00010000                                       'led 4 yala
  
Waitms 1000
  
Portb = &B00001000                                       'led 5 yala
  
Waitms 1000
  
Portb = &B00000100                                       'led 6 yala
  
Waitms 1000
  
Portb = &B00000010                                       'led 7 yala
  
Waitms 1000
  
Portb = &B00000001                                       'led 8 yala
  
Waitms 1000
  
Goto Utama

  Perintah2
:
    
Portc = &HA4                                           'angka2 seven segment
   
Portb = &B11000000                                      'led meyala 2
   
Waitms 1000
  
Portb = &B01100000
     
Waitms 1000
  
Portb = &B00110000
    
Waitms 1000
  
Portb = &B00011000
    
Waitms 1000
  
Portb = &B00001100
  
Waitms 1000
  
Portb = &B00000110
  
Waitms 1000
  
Portb = &B00000011
  
Waitms 1000
  
Goto Utama                                               'perintah untuk kembali ke utama

  Perintah3
:
  
Portc = &HB0                                             'angka3 seven segment
   
Portb = &B11100000                                      'led meyala 3
   
Waitms 1000
  
Portb = &B01110000
     
Waitms 1000
  
Portb = &B00111000
    
Waitms 1000
  
Portb = &B00011100
    
Waitms 1000
  
Portb = &B00001110
  
Waitms 1000
  
Portb = &B00000111
  
Waitms 1000
  
Portb = &B00000011
  
Waitms 1000
  
Goto Utama                                               'perintah untuk kembali ke utama

    Perintah4
:
  
Portc = &H99                                             'angka 4 seven segment
   
Portb = &B11110000                                      'led meyala 4
   
Waitms 1000
  
Portb = &B01111000
     
Waitms 1000
  
Portb = &B00111100
    
Waitms 1000
  
Portb = &B00011110
    
Waitms 1000
  
Portb = &B00001111
  
Waitms 1000
  
Portb = &B00000111
  
Waitms 1000
  
Portb = &B00000011
  
Waitms 1000
  
Goto Utama                                               ' perintah untuk kembali ke utama

    Perintah5
:
  
Portc = &H92                                             'angka 5 seven segment
   
Portb = &B11111000                                      'led meyala 5
   
Waitms 1000
  
Portb = &B01111100
     
Waitms 1000
  
Portb = &B00111110
    
Waitms 1000
  
Portb = &B00011111
    
Waitms 1000
  
Portb = &B00001111
  
Waitms 1000
  
Portb = &B00000111
  
Waitms 1000
  
Portb = &B00000011
  
Waitms 1000
  
Goto Utama                                               'perintah untuk kembali ke utama
  
End
======================================================================================
  
'GOTO <label> Perintah ini untuk melakukan lompatan ke label kemudian melakukan serangkaian instruksi
'tanpa harus kembali lagi, sehingga tidak perlu RETURN. Contoh:
'Goto Perintah1   maka akan langsung menjalan kan ( perintah 1:)

  di proteus buat sekema seperti di bawah ini


cara keraja program bila tombol tombol 1,2,3,4,5 bila salah satu di tekan maka akan menjalan kar perintah goto

contoh kita tekan tombol 1 
 
 If Pina = &B11111110 Then
   
Goto Perintah1                                          'untuk meloncat keperintah1

maka akan men jalankan program 

Perintah1:
Portc = &HF9                                                'muncul anka 1
  
Portb = &B00000000                                       'led mati
   
Waitms 1000
  
Portb = &B10000000                                       'led 1 yala
     
Waitms 1000
  
Portb = &B01000000                                       'led 2 yala
    
Waitms 1000
  
Portb = &B00100000                                       'led 3 yala
    
Waitms 1000
  
Portb = &B00010000                                       'led 4 yala
  
Waitms 1000
  
Portb = &B00001000                                       'led 5 yala
  
Waitms 1000
  
Portb = &B00000100                                       'led 6 yala
  
Waitms 1000
  
Portb = &B00000010                                       'led 7 yala
  
Waitms 1000
  
Portb = &B00000001                                       'led 8 yala
  
Waitms 1000
  
Goto Utama


semoga bermanpaat telah di uji coba di lab barlianno