Forum Sains Indonesia

Ilmu Terapan => Teknik Elektro => Ilmu Teknik => Mikrokontroler dan Robotika => Topik dimulai oleh: caturpermadi pada April 06, 2013, 07:35:45 PM

Judul: cara bikin program counter dengan bascom-AVR?
Ditulis oleh: caturpermadi pada April 06, 2013, 07:35:45 PM
saya mau tanya kalo bikin program counter dengan supply counter eksternal gimana caranya ya?
saya pakai bahasa bascom-AVR trus menggunakan mikrokontroller atmega8, terakhir coba berhasil tapi pas di download n d coba di alat gagal  ???
trus pas saya simulasiin lg malah jadi gagal.
kira2 ada solusinya ga?

ni listing program saya :

$regfile = "m8def.dat"
$crystal = 4000000

Config Lcdpin = Pin , E = Portc.1 , Rs = Portc.0 ,
Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5,
Config Lcd = 16 * 2

Config Timer1 = Counter , Edge = Falling
Enable Interrupts
Enable Ovf1
On Ovf1 Int_counter1

Dim Rpm As Integer
Dim Kontrol As Byte
Dim Nyala As Byte

Config Portb.5 = Output

Ddrd.5 = 0
Portd.5 = 1

Ddrd.6 = 0
Portd.6 = 1

Ddrd.7 = 0
Portd.7 = 1

Cursor Off
Kontrol = 0
Nyala = 0

Cls
Locate 1 , 1
Lcd "Please Wait"
Waitms 100
Locate 1 , 12
Lcd "."
Waitms 30
Locate 1 , 13
Lcd "."
Waitms 30
Locate 1 , 14
Lcd "."
Waitms 30
Locate 1 , 15
Lcd "."
Waitms 30
Locate 1 , 16
Lcd "."
Waitms 30
Cls

Do
'--------------------------pilih
If Pind.7 = 0 Then
Nyala = Nyala + 1
End If

If Nyala = 1 Then
Portb.5 = 1
End If

If Kontrol = 0 Then
Gosub Awal
End If

If Kontrol = 1 Then
Gosub Penghitungan
End If

If Kontrol = 2 Then
Goto Shutdown
End If

If Pind.6 = 0 Then
Kontrol = Kontrol + 1
End If
Waitms 50

Loop

Awal:
Locate 1 , 1
Lcd "Tekan 'START'"
Waitms 150
Locate 2 , 1
Lcd "untuk memulai"
Waitms 150
Return

Penghitungan:
   Counter1 = 0
   Rpm = 0
   Start Timer1
    Wait 5
   Stop Timer1
    Rpm = Rpm + Counter1
    Rpm = Rpm * 3

   Locate 1 , 1
   Lcd "Respiratory Rate"
   Locate 2 , 1
   Lcd "Hasil="
   Locate 2 , 7
   Lcd "    "
   Locate 2 , 7
   Lcd Rpm
   Locate 2 , 10
   Lcd "/menit"
   Wait 2
Return

Shutdown:
   Cls
   Locate 1 , 1
   Lcd "Thank you"
   Waitms 150
   Cls
   Locate 1 , 1
   Lcd "This device is"
   Locate 2 , 1
   Lcd "powering down..."
   Wait 2
   Portb.5 = 0
   Wait 1

Int_counter1:
  Rpm = Rpm + 65535
Return