Rabu, 15 Mei 2019

contoh program coding bascom untuk LM35


' Pemrograman Bascom AVR Termometer Digital Dengan LM35 Berbasis Mikrokontroler ATMega32
' program termometer digital
' http://goes-open.blogspot.com
' mirza dhanu sulistya
' tutorial

$regfile = "m8def.dat"
$crystal = 11059200
$baud = 9600


Config Adc = Single , Prescaler = Auto , Reference = Internal

Dim A As Word , Volt As Word , Volt_d As Byte , X As Byte
Dim Tempa As Byte , Digit4 As Byte , Digit3 As Byte , Digit2 As Byte , Digit1 As Byte

Start Adc                                                   ' memulai ADC

Config Portb = Output
Ser1 Alias Portb.1
Clocks Alias Portb.2
Latch Alias Portb.3

Do                                                          ' memulai program
For X = 1 To 100
A = Getadc(0)
Volt = A + Volt
Waitms 100
Next X



Volt = Volt / 100
Volt = Volt * 49
Volt = Volt / 100


Digit1 = Volt / 10
Digit2 = Volt Mod 10

Print "suhu" ; "=" ; Volt ; "," ; Volt_d;

Gosub Tampilkan






Loop


Tampilkan:
Latch = 0

Tempa = Digit2
Gosub Pilihangka
Tempa = Digit1
Gosub Pilihangka


Latch = 1
'Waitms 250

Return

Pilihangka:

Select Case Tempa
      Case 0 : Tempa = &B10000000
      Case 1 : Tempa = &B11100110
      Case 2 : Tempa = &B01000001
      Case 3 : Tempa = &B01000100
      Case 4 : Tempa = &B00100110
      Case 5 : Tempa = &B00010100
      Case 6 : Tempa = &B00010000
      Case 7 : Tempa = &B11000110
      Case 8 : Tempa = &B00000000
      Case 9 : Tempa = &B00000100
      Case 10 : Tempa = &B11110111
   End Select

   Ser1 = Tempa.7
   Gosub Clock_out
   Ser1 = Tempa.6
   Gosub Clock_out
   Ser1 = Tempa.5
   Gosub Clock_out
   Ser1 = Tempa.4
   Gosub Clock_out
   Ser1 = 0
   Gosub Clock_out
   Ser1 = Tempa.2
   Gosub Clock_out
   Ser1 = Tempa.1
   Gosub Clock_out
   Ser1 = Tempa.0
   Gosub Clock_out
Return

Clock_out:
   Clocks = 0
   Clocks = 1
   Return

Tidak ada komentar:

Posting Komentar