SMK Binawiyata Sragen

  • This is default featured slide 1 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

  • This is default featured slide 2 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

  • This is default featured slide 3 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

  • This is default featured slide 4 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

  • This is default featured slide 5 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

Tampilkan postingan dengan label Bascom AVR. Tampilkan semua postingan
Tampilkan postingan dengan label Bascom AVR. Tampilkan semua postingan

Program Animasi LED 24x24 Dot Matrik

Kode program : dengan Bascom AVR
$regfile = "m32def.dat"
$crystal = 8000000
$hwstack = 32
$swstack = 32
$framesize = 24

'---- this section from Gif Properties
Const Total_frame = 8
Const Width = 24
Const Height = 24
'---- end of Gif Properties

Const Number_of_matrix_in_row = Width / 8
Const Byte_in_col = Height / 8
Const Frame_size = Width * Byte_in_col
Const Number_of_byte_in_8_col = Byte_in_col * 8

Declare Sub Readframe(byval Frame_number As Word)
' Port A for COL refresh
Config Porta = Output
' Port D for 74595 register
Config Portd = Output
Config Timer0 = Timer , Prescale = 64                       'Clock value: 15.625 kHz
On Ovf0 Refresh
Enable Timer0                                               ' enable the timer interrupt
Enable Interrupts
Sh_cp Alias Portd.3
Ds Alias Portd.4
St_cp Alias Portd.5
Mr Alias Portd.6
Oe Alias Portd.7
Col_port Alias Porta
Dim Col As Byte
Dim Buf(frame_size) As Byte
Dim I As Byte
Dim Matrix_counter As Word
Dim Buf_idx As Word
Dim Col_number_in_buf As Byte
Dim Frame_count As Word

Reset Mr
Set Mr
Reset Oe
Do
For Frame_count = 1 To Total_frame
 Readframe Frame_count
 Waitms 200
Next Frame_count
Loop
End                                                         'end program

Sub Readframe(byval Frame_number As Word)
 Local Idx As Word
 Local Lookup_idx As Word
 Disable Timer0
 Decr Frame_number
 'Start of Frame in lookup table
 Lookup_idx = Frame_number * Frame_size
 For Idx = 0 To Frame_size
  Buf(idx) = Lookup(lookup_idx , Ani )
  Incr Lookup_idx
 Next Idx
 Enable Timer0
End Sub

Refresh:
 Reset Mr
 Set Mr
 Col_port = &H00
 Set Oe
 Col_port = 2 ^ Col
 For Matrix_counter = 1 To Number_of_matrix_in_row
  Col_number_in_buf = Number_of_matrix_in_row - Matrix_counter
  Col_number_in_buf = Col_number_in_buf * Number_of_byte_in_8_col
  Buf_idx = Col * Byte_in_col
  Buf_idx = Buf_idx + Col_number_in_buf
  For I = 1 To Byte_in_col
   Shiftout Ds , Sh_cp , Buf(buf_idx) , 1 , 8
   Incr Buf_idx
  Next I
 Next Matrix_counter
 Reset St_cp
Set St_cp
Reset Oe
If Col < 7 Then
 Incr Col
Else
 Col = 0
End If
Return

'---- this delay table from Frame Properties
Delay:
'Frame 1
Data 200%
'Frame 2
Data 100%
'Frame 3
Data 100%
'Frame 4
Data 100%
'Frame 5
Data 100%
'Frame 6
Data 100%
'Frame 7
Data 100%
'Frame 8
Data 100%

Ani:
Data &H18, &H00, &H18 '...##..............##...
Data &H30, &H00, &H0C '..##................##..
Data &H6F, &HF7, &HE6 '.##.########.######..##.
Data &HDF, &HFC, &H23 '##.###########....#...##
Data &HBF, &HFE, &H21 '#.#############...#....#
Data &H00, &H7F, &H20 '.........#######..#.....
Data &H00, &HFF, &HA0 '........#########.#.....
Data &H3F, &HEF, &HE0 '..#########.#######.....
Data &H3F, &HDB, &HE0 '..########.##.#####.....
Data &H37, &H91, &HDE '..##.####..#...###.####.
Data &H00, &H17, &HBF '...........#.####.######
Data &H00, &H3C, &H3F '..........####....######
Data &H30, &HE0, &H3F '..##....###.......######
Data &H38, &H40, &H3F '..###....#........######
Data &H3C, &H80, &H1E '..####..#..........####.
Data &H3E, &H80, &H00 '..#####.#...............
Data &H3F, &H00, &H00 '..######................
Data &H3D, &H00, &H00 '..####.#................
Data &H3A, &H00, &H00 '..###.#.................
Data &HB6, &H00, &H01 '#.##.##................#
Data &HC6, &H00, &H03 '##...##...............##
Data &H6C, &H00, &H06 '.##.##...............##.
Data &H3C, &H00, &H0C '..####..............##..
Data &H18, &H00, &H18 '...##..............##...

' Frame 2
' Delay : 100ms
Data &H18, &H10, &H18 '...##......#.......##...
Data &H30, &H0F, &HEC '..##........#######.##..
Data &H6F, &HFC, &H26 '.##.##########....#..##.
Data &HDF, &HFF, &H23 '##.#############..#...##
Data &HBF, &HFF, &H21 '#.##############..#....#
Data &H00, &H7F, &HA0 '.........########.#.....
Data &H00, &HFF, &HE0 '........###########.....
Data &H3F, &HEB, &HE0 '..#########.#.#####.....
Data &H3F, &HC9, &HE0 '..########..#..####.....
Data &H37, &H90, &HDE '..##.####..#....##.####.
Data &H00, &H3F, &HBF '..........#######.######
Data &H00, &H10, &H3F '...........#......######
Data &H30, &H20, &H3F '..##......#.......######
Data &H38, &H20, &H3F '..###.....#.......######
Data &H3C, &H20, &H1E '..####....#........####.
Data &H3E, &H40, &H00 '..#####..#..............
Data &H3E, &H40, &H00 '..#####..#..............
Data &H3C, &H40, &H00 '..####...#..............
Data &H38, &HC0, &H00 '..###...##..............
Data &HB1, &H80, &H01 '#.##...##..............#
Data &HC1, &H80, &H03 '##.....##.............##
Data &H61, &H80, &H06 '.##....##............##.
Data &H31, &H80, &H0C '..##...##...........##..
Data &H18, &H80, &H18 '...##...#..........##...

' Frame 3
' Delay : 100ms
Data &H18, &H10, &H18 '...##......#.......##...
Data &H30, &H0F, &HEC '..##........#######.##..
Data &H6F, &HFC, &H26 '.##.##########....#..##.
Data &HDF, &HFF, &H23 '##.#############..#...##
Data &HBF, &HFF, &H21 '#.##############..#....#
Data &H00, &H7F, &HA0 '.........########.#.....
Data &H00, &HFF, &HE0 '........###########.....
Data &H3F, &HEB, &HE0 '..#########.#.#####.....
Data &H3F, &HC9, &HE0 '..########..#..####.....
Data &H37, &H88, &HDE '..##.####...#...##.####.
Data &H00, &H1F, &HBF '...........######.######
Data &H00, &H08, &H3F '............#.....######
Data &H30, &H08, &H3F '..##........#.....######
Data &H38, &H08, &H3F '..###.......#.....######
Data &H3C, &H08, &H1E '..####......#......####.
Data &H3E, &H08, &H00 '..#####.....#...........
Data &H3E, &H18, &H00 '..#####....##...........
Data &H3C, &H18, &H00 '..####.....##...........
Data &H38, &H18, &H00 '..###......##...........
Data &HB0, &H18, &H01 '#.##.......##..........#
Data &HC0, &H18, &H03 '##.........##.........##
Data &H60, &H08, &H06 '.##.........#........##.
Data &H30, &H00, &H0C '..##................##..
Data &H18, &H00, &H18 '...##..............##...

' Frame 4
' Delay : 100ms
Data &H18, &H10, &H18 '...##......#.......##...
Data &H30, &H0F, &HEC '..##........#######.##..
Data &H6F, &HFC, &H26 '.##.##########....#..##.
Data &HDF, &HFF, &H23 '##.#############..#...##
Data &HBF, &HFF, &H21 '#.##############..#....#
Data &H00, &H7F, &HA0 '.........########.#.....
Data &H00, &HFF, &HE0 '........###########.....
Data &H3F, &HEB, &HE0 '..#########.#.#####.....
Data &H3F, &HC9, &HE0 '..########..#..####.....
Data &H37, &H88, &HDE '..##.####...#...##.####.
Data &H00, &H1F, &HBF '...........######.######
Data &H00, &H08, &H3F '............#.....######
Data &H30, &H08, &H3F '..##........#.....######
Data &H38, &H08, &H3F '..###.......#.....######
Data &H3C, &H08, &H1E '..####......#......####.
Data &H3E, &H08, &H00 '..#####.....#...........
Data &H3E, &H1C, &H00 '..#####....###..........
Data &H3C, &H1C, &H00 '..####.....###..........
Data &H38, &H1C, &H00 '..###......###..........
Data &HB0, &HDC, &H01 '#.##....##.###.........#
Data &HC0, &H1C, &H03 '##.........###........##
Data &H61, &HA8, &H06 '.##....##.#.#........##.
Data &H30, &H20, &H0C '..##......#.........##..
Data &H18, &H00, &H18 '...##..............##...

' Frame 5
' Delay : 100ms
Data &H18, &H10, &H18 '...##......#.......##...
Data &H30, &H0F, &HEC '..##........#######.##..
Data &H6F, &HFC, &H26 '.##.##########....#..##.
Data &HDF, &HFF, &H23 '##.#############..#...##
Data &HBF, &HFF, &H21 '#.##############..#....#
Data &H00, &H7F, &HA0 '.........########.#.....
Data &H00, &HFF, &HE0 '........###########.....
Data &H3F, &HEB, &HE0 '..#########.#.#####.....
Data &H3F, &HC9, &HE0 '..########..#..####.....
Data &H37, &H88, &HDE '..##.####...#...##.####.
Data &H00, &H1F, &HBF '...........######.######
Data &H00, &H08, &H3F '............#.....######
Data &H30, &H08, &H3F '..##........#.....######
Data &H38, &H08, &H3F '..###.......#.....######
Data &H3C, &H08, &H1E '..####......#......####.
Data &H3E, &H08, &H00 '..#####.....#...........
Data &H3E, &H1C, &H00 '..#####....###..........
Data &H3C, &H1C, &H00 '..####.....###..........
Data &H38, &H1C, &H00 '..###......###..........
Data &HB1, &H9C, &H01 '#.##...##..###.........#
Data &HC0, &H1C, &H03 '##.........###........##
Data &H63, &H48, &H06 '.##...##.#..#........##.
Data &H30, &H40, &H0C '..##.....#..........##..
Data &H18, &H00, &H18 '...##..............##...

' Frame 6
' Delay : 100ms
Data &H18, &H10, &H18 '...##......#.......##...
Data &H30, &H0F, &HEC '..##........#######.##..
Data &H6F, &HFC, &H26 '.##.##########....#..##.
Data &HDF, &HFF, &H23 '##.#############..#...##
Data &HBF, &HFF, &H21 '#.##############..#....#
Data &H00, &H7F, &HA0 '.........########.#.....
Data &H00, &HFF, &HE0 '........###########.....
Data &H3F, &HEB, &HE0 '..#########.#.#####.....
Data &H3F, &HC9, &HE0 '..########..#..####.....
Data &H37, &H88, &HDE '..##.####...#...##.####.
Data &H00, &H1F, &HBF '...........######.######
Data &H00, &H08, &H3F '............#.....######
Data &H30, &H08, &H3F '..##........#.....######
Data &H38, &H08, &H3F '..###.......#.....######
Data &H3C, &H08, &H1E '..####......#......####.
Data &H3E, &H08, &H00 '..#####.....#...........
Data &H3E, &H3E, &H00 '..#####...#####.........
Data &H3C, &H3E, &H00 '..####....#####.........
Data &H38, &H3E, &H00 '..###.....#####.........
Data &HB3, &H3E, &H01 '#.##..##..#####........#
Data &HC0, &H1C, &H03 '##.........###........##
Data &H66, &HC8, &H06 '.##..##.##..#........##.
Data &H30, &HC0, &H0C '..##....##..........##..
Data &H18, &H00, &H18 '...##..............##...

' Frame 7
' Delay : 100ms
Data &H18, &H10, &H18 '...##......#.......##...
Data &H30, &H0F, &HEC '..##........#######.##..
Data &H6F, &HFC, &H26 '.##.##########....#..##.
Data &HDF, &HFF, &H23 '##.#############..#...##
Data &HBF, &HFF, &H21 '#.##############..#....#
Data &H00, &H7F, &HA0 '.........########.#.....
Data &H00, &HFF, &HE0 '........###########.....
Data &H3F, &HEB, &HE0 '..#########.#.#####.....
Data &H3F, &HC9, &HE0 '..########..#..####.....
Data &H37, &H88, &HDE '..##.####...#...##.####.
Data &H00, &H1F, &HBF '...........######.######
Data &H00, &H08, &H3F '............#.....######
Data &H30, &H08, &H3F '..##........#.....######
Data &H38, &H08, &H3F '..###.......#.....######
Data &H3C, &H08, &H1E '..####......#......####.
Data &H3E, &H08, &H00 '..#####.....#...........
Data &H3E, &H3E, &H00 '..#####...#####.........
Data &H3C, &H3E, &H00 '..####....#####.........
Data &H38, &H3E, &H00 '..###.....#####.........
Data &HBC, &H3E, &H01 '#.####....#####........#
Data &HC0, &H1C, &H03 '##.........###........##
Data &H7B, &H08, &H06 '.####.##....#........##.
Data &H33, &H00, &H0C '..##..##............##..
Data &H18, &H00, &H18 '...##..............##...

' Frame 8
' Delay : 100ms
Data &H18, &H10, &H18 '...##......#.......##...
Data &H30, &H0F, &HEC '..##........#######.##..
Data &H6F, &HFC, &H26 '.##.##########....#..##.
Data &HDF, &HFF, &H23 '##.#############..#...##
Data &HBF, &HFF, &H21 '#.##############..#....#
Data &H00, &H7F, &HA0 '.........########.#.....
Data &H00, &HFF, &HE0 '........###########.....
Data &H3F, &HEB, &HE0 '..#########.#.#####.....
Data &H3F, &HC9, &HE0 '..########..#..####.....
Data &H37, &H88, &HDE '..##.####...#...##.####.
Data &H00, &H1F, &HBF '...........######.######
Data &H00, &H08, &H3F '............#.....######
Data &H30, &H08, &H3F '..##........#.....######
Data &H38, &H08, &H3F '..###.......#.....######
Data &H3C, &H08, &H1E '..####......#......####.
Data &H3E, &H08, &H00 '..#####.....#...........
Data &H3E, &H3E, &H00 '..#####...#####.........
Data &H3C, &H3E, &H00 '..####....#####.........
Data &H38, &H3E, &H00 '..###.....#####.........
Data &HB0, &H3E, &H01 '#.##......#####........#
Data &HF0, &H1C, &H03 '####.......###........##
Data &H70, &H08, &H06 '.###........#........##.
Data &H30, &H00, &H0C '..##................##..
Data &H18, &H00, &H18 '...##..............##...
Share:

Pengendali Lampu lalulintas 4 jalur

 Traficlight seperti kita ketahui digunakan untuk mengatur lalu lintas pada persimpangan jalan baik pertigaan atau perempatan bahkan simpang lima. Traficlight digunakan untuk menggantikan tugas pak polisi supaya kerjanya lebih ringan dan he he he tinggal tilang aja klo ada yang gak nurut.. cukup sekian basa basinya langsung saja ke konfigurasi hardwarenya. trafic ini terdiri dari tiga buah komponen utama yaitu:
1. Controler
2. Counter display 7 segment
3. Led merah, kuning dan hijau
Controler pada trafic ini menggunakan atmega16
Counter display menggunakan 7 segment dengan shift register sebagai perantara pengiriman data dari controler Led merah, kuning dan hijau digunakan mengatur lalulintas merah artinya stop, hijau artinya jalan dan kuning artinya jalan ngebut (keburu lampu merahnya nyala)

Gambar Rangkaian dengan simulator Proteus :

Pada prinsipnya kerja traficlight adalah menyalakan lampu hijau dan lampu kuning secara bergantian, misalnya pada trafic light 4 jalur ini. Pada traficlight ini nyala lampu hijau dan kuning dibuat sama untuk 4 jalurnya yaitu 8 detik untuk lampu hijau dan 2 detik untuk lampu kuning jadi totalnya adalah 11 detik. sedangkan untuk nyala lampu merahnya adalah 3 kali lipat nyala lampu hijau + Kuning, jadi untuk nyala lampu merahnya adalah 11+11+11 = 35. lho kog 35 bukannya 33? eit jangan salah dalam trafic light counter downnya menghitung atau mencacah sampai angka nol (0) bukan 1 untuk lebih jelasnya berikut adalah timeline nya

keterangan
garis hijau = lama nyala lampu hijau
garis kuning = lama nyala lampu kuning
garis merah = lama nyala lampu merah
setelah mengetahui konsepnya maka dapat langsung diimplementasikan pada programnya. disini bahasa pemrogramannya menggunakan Bascomavr. Berikut merupakan inti dari program traficlight diatas:

Souce Code :
$regfile = "m16def.dat"
$crystal = 12000000

Config Portb.0 = Output
Config Portb.1 = Output
Config Portb.2 = Output
Config Portb.5 = Output
Config Portb.6 = Output
Config Portb.7 = Output
Config Portd.0 = Output
Config Portd.1 = Output
Config Portd.2 = Output
Config Portd.5 = Output
Config Portd.6 = Output
Config Portd.7 = Output
Config Porta.0 = Output
Config Porta.1 = Output
Config Porta.2 = Output
Config Porta.5 = Output
Config Porta.6 = Output
Config Porta.7 = Output
Config Portc.0 = Output
Config Portc.1 = Output
Config Portc.2 = Output
Config Portc.5 = Output
Config Portc.6 = Output
Config Portc.7 = Output
'trafic 1
Data1 Alias Portb.0
Clock1 Alias Portb.1
Oe1 Alias Portb.2

Merah1 Alias Portb.5
Kuning1 Alias Portb.6
Hijau1 Alias Portb.7

'trafic 2
Data2 Alias Portd.7
Clock2 Alias Portd.6
Oe2 Alias Portd.5

Merah2 Alias Portd.0
Kuning2 Alias Portd.1
Hijau2 Alias Portd.2

'trafic3
Data3 Alias Porta.2
Clock3 Alias Porta.1
Oe3 Alias Porta.0

Merah3 Alias Porta.7
Kuning3 Alias Porta.6
Hijau3 Alias Porta.5

'trafic4
Data4 Alias Portc.0
Clock4 Alias Portc.1
Oe4 Alias Portc.2

Merah4 Alias Portc.5
Kuning4 Alias Portc.6
Hijau4 Alias Portc.7


Dim Kodesat1 As Byte , Npul1 As Integer , Nsat1 As Integer , Kodepul1 As Byte
Dim Sat1 As Byte , Pul1 As Byte , Flaghijau1 As Bit , Flagkuning1 As Bit , Flag1put As Bit
Dim A1 As Bit , B1 As Bit

Dim Kodesat2 As Byte , Npul2 As Integer , Nsat2 As Integer , Kodepul2 As Byte
Dim Sat2 As Byte , Pul2 As Byte , Flaghijau2 As Bit , Flagkuning2 As Bit
Dim A2 As Bit , B2 As Bit

Dim Kodesat3 As Byte , Npul3 As Integer , Nsat3 As Integer , Kodepul3 As Byte
Dim Sat3 As Byte , Pul3 As Byte , Flaghijau3 As Bit , Flagkuning3 As Bit
Dim A3 As Bit , B3 As Bit

Dim Kodesat4 As Byte , Npul4 As Integer , Nsat4 As Integer , Kodepul4 As Byte
Dim Sat4 As Byte , Pul4 As Byte , Flaghijau4 As Bit , Flagkuning4 As Bit
Dim A4 As Bit , B4 As Bit

Mulai:

A1 = 0
B1 = 0

A2 = 0
B2 = 0

A3 = 0
B3 = 0

A4 = 0
B4 = 0

Flaghijau1 = 0
Flagkuning1 = 0

Flaghijau2 = 0
Flagkuning2 = 0

Flaghijau3 = 0
Flagkuning3 = 0

Flaghijau4 = 0
Flagkuning4 = 0

Sat1 = 8
Pul1 = 0

Sat2 = 1
Pul2 = 1

Sat3 = 3
Pul3 = 2

Sat4 = 5
Pul4 = 3


Do

Gosub Tampil1
Gosub Tampil2
Gosub Tampil3
Gosub Tampil4

Gosub Trafic1
Gosub Trafic2
Gosub Trafic3
Gosub Trafic4

Decr Sat1
Decr Sat2
Decr Sat3
Decr Sat4

Loop

Trafic1:
'lampu
   If A1 = 0 And B1 = 0 Then
     Merah1 = 0
     Kuning1 = 0
     Hijau1 = 1
   End If

   If A1 = 0 And B1 = 1 Then
     Merah1 = 1
     Kuning1 = 0
     Hijau1 = 0
   End If

   If A1 = 1 And B1 = 0 Then
     Merah1 = 0
     Kuning1 = 1
     Hijau1 = 0
   End If

'counter

   If Sat1 = 0 And Pul1 = 0 And Flaghijau1 = 0 And Flagkuning1 = 0 Then
   Sat1 = 3
   Pul1 = 0
   Flaghijau1 = 1
   A1 = 1
   B1 = 0
   End If

   If Sat1 = 0 And Pul1 = 0 And Flaghijau1 = 1 And Flagkuning1 = 0 Then
   Sat1 = 6
   Pul1 = 3
   Flagkuning1 = 1
   A1 = 0
   B1 = 1
   End If

   If Sat1 = 0 And Pul1 = 0 And Flaghijau1 = 1 And Flagkuning1 = 1 Then
   A1 = 0
   B1 = 0
   Flaghijau1 = 0
   Flagkuning1 = 0
   End If

   If Sat1 = 0 And Pul1 = 3 Then
   Decr Pul1
   Sat1 = 10
   End If

   If Sat1 = 0 And Pul1 = 2 Then
   Decr Pul1
   Sat1 = 10
   End If

   If Sat1 = 0 And Pul1 = 1 Then
   Decr Pul1
   Sat1 = 10
   End If

Return


Tampil1:
Reset Oe1
Kodesat1 = Lookup(sat1 , Kode)
Kodepul1 = Lookup(pul1 , Kode)
Shiftout Data1 , Clock1 , Kodesat1 , 1
Shiftout Data1 , Clock1 , Kodepul1 , 1
Waitms 200
Set Oe1
Return

Trafic2:
'lampu
   If A2 = 0 And B2 = 1 Then
      Merah2 = 0
      Kuning2 = 0
      Hijau2 = 1
   End If

   If A2 = 1 And B2 = 0 Then
      Merah2 = 0
      Kuning2 = 1
      Hijau2 = 0
   End If

   If A2 = 0 And B2 = 0 Then
      Merah2 = 1
      Kuning2 = 0
      Hijau2 = 0
   End If

'counter
   If Sat2 = 0 And Pul2 = 0 And Flaghijau2 = 0 And Flagkuning2 = 0 Then
      Sat2 = 9
      Pul2 = 0
      Flaghijau2 = 1
      A2 = 0
      B2 = 1
   End If

   If Sat2 = 0 And Pul2 = 0 And Flaghijau2 = 1 Then
      Sat2 = 3
      Pul2 = 0
      Flagkuning2 = 1
      Flaghijau2 = 0
      A2 = 1
      B2 = 0
   End If

   If Sat2 = 0 And Pul2 = 0 And Flagkuning2 = 1 Then
      Sat2 = 6
      Pul2 = 3
      Flagkuning2 = 0
      Flaghijau2 = 1
      A2 = 0
      B2 = 0
   End If

   If Sat2 = 0 And Pul2 = 3 Then
   Decr Pul2
   Sat2 = 10
   End If

   If Sat2 = 0 And Pul2 = 2 Then
   Decr Pul2
   Sat2 = 10
   End If

   If Sat2 = 0 And Pul2 = 1 Then
   Decr Pul2
   Sat2 = 10
   End If

Return


Tampil2:
Reset Oe2
Kodesat2 = Lookup(sat2 , Kode)
Kodepul2 = Lookup(pul2 , Kode)
Shiftout Data2 , Clock2 , Kodesat2 , 1
Shiftout Data2 , Clock2 , Kodepul2 , 1
Waitms 200
Set Oe2
Return

Trafic3:
'lampu
   If A3 = 0 And B3 = 1 Then
      Merah3 = 0
      Kuning3 = 0
      Hijau3 = 1
   End If

   If A3 = 1 And B3 = 0 Then
      Merah3 = 0
      Kuning3 = 1
      Hijau3 = 0
   End If

   If A3 = 0 And B3 = 0 Then
      Merah3 = 1
      Kuning3 = 0
      Hijau3 = 0
   End If

'counter
   If Sat3 = 0 And Pul3 = 0 And Flaghijau3 = 0 And Flagkuning3 = 0 Then
      Sat3 = 9
      Pul3 = 0
      Flaghijau3 = 1
      A3 = 0
      B3 = 1
   End If

   If Sat3 = 0 And Pul3 = 0 And Flaghijau3 = 1 And Flagkuning3 = 0 Then
      Sat3 = 3
      Pul3 = 0
      Flaghijau3 = 0
      Flagkuning3 = 1
      A3 = 1
      B3 = 0
   End If

   If Sat3 = 0 And Pul3 = 0 And Flagkuning3 = 1 And Flagkuning3 = 1 Then
      Sat3 = 6
      Pul3 = 3
      Flagkuning3 = 0
      A3 = 0
      B3 = 0
   End If

   If Sat3 = 0 And Pul3 = 3 Then
   Decr Pul3
   Sat3 = 10
   End If

   If Sat3 = 0 And Pul3 = 2 Then
   Decr Pul3
   Sat3 = 10
   End If

   If Sat3 = 0 And Pul3 = 1 Then
   Decr Pul3
   Sat3 = 10
   End If

Return


Tampil3:
Reset Oe3
Kodesat3 = Lookup(sat3 , Kode)
Kodepul3 = Lookup(pul3 , Kode)
Shiftout Data3 , Clock3 , Kodesat3 , 1
Shiftout Data3 , Clock3 , Kodepul3 , 1
Waitms 200
Set Oe3
Return

Trafic4:
'lampu

   'If Flag1put = 1 Then
   '   Goto Mulai
   'End If

   If A4 = 0 And B4 = 1 Then
      Merah4 = 0
      Kuning4 = 0
      Hijau4 = 1
   End If

   If A4 = 1 And B4 = 0 Then
      Merah4 = 0
      Kuning4 = 1
      Hijau4 = 0
   End If

   If A4 = 0 And B4 = 0 Then
      Merah4 = 1
      Kuning4 = 0
      Hijau4 = 0
   End If

'counter
   If Sat4 = 0 And Pul4 = 0 And Flaghijau4 = 0 And Flagkuning4 = 0 Then
      Sat4 = 9
      Pul4 = 0
      Flaghijau4 = 1
      A4 = 0
      B4 = 1
   End If

   If Sat4 = 0 And Pul4 = 0 And Flaghijau4 = 1 And Flagkuning4 = 0 Then
      Sat4 = 3
      Pul4 = 0
      Flagkuning4 = 1
      A4 = 1
      B4 = 0
   End If

   If Sat4 = 0 And Pul4 = 0 And Flaghijau4 = 1 And Flagkuning4 = 1 Then
      'Flag1put = 1
      Goto Mulai
   End If

   If Sat4 = 0 And Pul4 = 3 Then
   Decr Pul4
   Sat4 = 10
   End If

   If Sat4 = 0 And Pul4 = 2 Then
   Decr Pul4
   Sat4 = 10
   End If

   If Sat4 = 0 And Pul4 = 1 Then
   Decr Pul4
   Sat4 = 10
   End If

Return


Tampil4:
Reset Oe4
Kodesat4 = Lookup(sat4 , Kode)
Kodepul4 = Lookup(pul4 , Kode)
Shiftout Data4 , Clock4 , Kodesat4 , 1
Shiftout Data4 , Clock4 , Kodepul4 , 1
Waitms 200
Set Oe4
Return

Kode:
Data &HC0 , &HF9 , &HA4 , &HB0 , &H99 , &H92 , &H82 , &HF8 , &H80 , &H90
Share:

Membuat Control Relay dengan Atmega8

Rangkaian Kontrol Relay :

Code List :
$regfile = "m8def.dat"
$crystal = 1000000
$hwstack = 64
$swstack = 64
$framesize = 64
Config Kbd = Portb , Debounce = 150 , Delay = 200
Config Portb = Input
Config Portc = Output
Config Portd = Output
Dim A As Byte
Speaker Alias Pinc.0

Main:
Wait 1
Sound Speaker , 120 , 100
Sound Speaker , 120 , 80

Do
A = Getkbd()
A = Lookup(a , Read_key)
If A < 12 Then
Select Case A

Case 0:
Sound Speaker , 120 , 20
Goto Main0


Case 1:
Sound Speaker , 120 , 20
Goto Main1


Case 2:
Sound Speaker , 120 , 20
Goto Main2


Case 3:
Sound Speaker , 120 , 20
Goto Main3


Case 4:
Sound Speaker , 120 , 20
Goto Main4


Case 5:
Sound Speaker , 120 , 20
Goto Main5


Case 6:
Sound Speaker , 120 , 20
Goto Main6


Case 7:
Sound Speaker , 120 , 20
Goto Main7


Case 8:
Sound Speaker , 120 , 20
Goto Main8


Case 9:
Sound Speaker , 120 , 20
Goto Main9

Case 11:
Sound Speaker , 120 , 20
Goto Main11

Case 10:
Sound Speaker , 120 , 20
Goto Main10
End Select
End If
Loop
End
'_______________________________________________________________________________
Read_key:
Data 1 , 4 , 7 , 11 , 2 , 5 , 8 , 0 , 3 , 6 , 9 , 10
'_______________________________________________________________________________
Main0:
A = Getkbd()
A = Lookup(a , Read_key)
If A < 12 Then
Select Case A
Case 0 To 9:
Sound Speaker , 120 , 500
Case 11:
Portc.5 = 1
Sound Speaker , 120 , 100
Sound Speaker , 120 , 80
Sound Speaker , 120 , 60
Goto Main
Case 10:
Portc.5 = 0
Sound Speaker , 120 , 60
Sound Speaker , 120 , 80
Sound Speaker , 120 , 100
Goto Main
End Select
End If
jmp main0

Main1:
A = Getkbd()
A = Lookup(a , Read_key)
If A < 12 Then
Select Case A
Case 0 To 9:
Sound Speaker , 120 , 500
Case 11:
Portc.4 = 1
Sound Speaker , 120 , 100
Sound Speaker , 120 , 80
Sound Speaker , 120 , 60
Goto Main
Case 10:
Portc.4 = 0
Sound Speaker , 120 , 60
Sound Speaker , 120 , 80
Sound Speaker , 120 , 100
Goto Main
End Select
End If
jmp main1

Main2:
A = Getkbd()
A = Lookup(a , Read_key)
If A < 12 Then
Select Case A
Case 0 To 9:
Sound Speaker , 120 , 500
Case 11:
Portc.3 = 1
Sound Speaker , 120 , 100
Sound Speaker , 120 , 80
Sound Speaker , 120 , 60
Goto Main
Case 10:
Portc.3 = 0
Sound Speaker , 120 , 60
Sound Speaker , 120 , 80
Sound Speaker , 120 , 100
Goto Main
End Select
End If
jmp main2

Main3:
A = Getkbd()
A = Lookup(a , Read_key)
If A < 12 Then
Select Case A
Case 0 To 9:
Sound Speaker , 120 , 500
Case 11:
Portc.2 = 1
Sound Speaker , 120 , 100
Sound Speaker , 120 , 80
Sound Speaker , 120 , 60
Goto Main
Case 10:
Portc.2 = 0
Sound Speaker , 120 , 60
Sound Speaker , 120 , 80
Sound Speaker , 120 , 100
Goto Main
End Select
End If
jmp main3

Main4:
A = Getkbd()
A = Lookup(a , Read_key)
If A < 12 Then
Select Case A
Case 0 To 9:
Sound Speaker , 120 , 500
Case 11:
Portc.1 = 1
Sound Speaker , 120 , 100
Sound Speaker , 120 , 80
Sound Speaker , 120 , 60
Goto Main
Case 10:
Portc.1 = 0
Sound Speaker , 120 , 60
Sound Speaker , 120 , 80
Sound Speaker , 120 , 100
Goto Main
End Select
End If
jmp main4

Main5:
A = Getkbd()
A = Lookup(a , Read_key)
If A < 12 Then
Select Case A
Case 0 To 9:
Sound Speaker , 120 , 500
Case 11:
Portd.0 = 1
Sound Speaker , 120 , 100
Sound Speaker , 120 , 80
Sound Speaker , 120 , 60
Goto Main
Case 10:
Portd.0 = 0
Sound Speaker , 120 , 60
Sound Speaker , 120 , 80
Sound Speaker , 120 , 100
Goto Main
End Select
End If
jmp main5
'www.bargh20.com
Main6:
A = Getkbd()
A = Lookup(a , Read_key)
If A < 12 Then
Select Case A
Case 0 To 9:
Sound Speaker , 120 , 500
Case 11:
Portd.1 = 1
Sound Speaker , 120 , 100
Sound Speaker , 120 , 80
Sound Speaker , 120 , 60
Goto Main
Case 10:
Portd.1 = 0
Sound Speaker , 120 , 60
Sound Speaker , 120 , 80
Sound Speaker , 120 , 100
Goto Main
End Select
End If
jmp main6

Main7:
A = Getkbd()
A = Lookup(a , Read_key)
If A < 12 Then
Select Case A
Case 0 To 9:
Sound Speaker , 120 , 500
Case 11:
Portd.2 = 1
Sound Speaker , 120 , 100
Sound Speaker , 120 , 80
Sound Speaker , 120 , 60
Goto Main
Case 10:
Portd.2 = 0
Sound Speaker , 120 , 60
Sound Speaker , 120 , 80
Sound Speaker , 120 , 100
Goto Main
End Select
End If
jmp main7

Main8:
A = Getkbd()
A = Lookup(a , Read_key)
If A < 12 Then
Select Case A
Case 0 To 9:
Sound Speaker , 120 , 500
Case 11:
Portd.3 = 1
Sound Speaker , 120 , 100
Sound Speaker , 120 , 80
Sound Speaker , 120 , 60
Goto Main
Case 10:
Portd.3 = 0
Sound Speaker , 120 , 60
Sound Speaker , 120 , 80
Sound Speaker , 120 , 100
Goto Main
End Select
End If
jmp main8

Main9:
A = Getkbd()
A = Lookup(a , Read_key)
If A < 12 Then
Select Case A
Case 0 To 9:
Sound Speaker , 120 , 500
Case 11:
Portd.4 = 1
Sound Speaker , 120 , 100
Sound Speaker , 120 , 80
Sound Speaker , 120 , 60
Goto Main
Case 10:
Portd.4 = 0
Sound Speaker , 120 , 60
Sound Speaker , 120 , 80
Sound Speaker , 120 , 100
Goto Main
End Select
End If
jmp main9

Main11:
Wait 3
A = Getkbd()
A = Lookup(a , Read_key)
If A = 11 Then
Sound Speaker , 120 , 100
Sound Speaker , 120 , 80
Sound Speaker , 120 , 60
Portc.5 = 1
Portc.4 = 1
Portc.3 = 1
Portc.2 = 1
Portc.1 = 1
Portd.0 = 1
Portd.1 = 1
Portd.2 = 1
Portd.3 = 1
Portd.4 = 1
Goto Main
Else
Goto Main
End If

Main10:
Wait 3
A = Getkbd()
A = Lookup(a , Read_key)
If A = 10 Then
Sound Speaker , 120 , 60
Sound Speaker , 120 , 80
Sound Speaker , 120 , 100
Portc.5 = 0
Portc.4 = 0
Portc.3 = 0
Portc.2 = 0
Portc.1 = 0
Portd.0 = 0
Portd.1 = 0
Portd.2 = 0
Portd.3 = 0
Portd.4 = 0
Goto Main
Else
Goto Main
End If
Share:

Stop Watch dengan Atmega32

Rangkaian :
Code List :
'Program Stopwatch
$regfile = "m32def.dat"
$crystal = 12000000

'deklarasi LCD
Config Lcdpin = Pin , Db4 = Portc.5 , Db5 = Portc.4 , Db6 = Portc.3 , Db7 = Portc.2 , E = Portc.6 , Rs = Portc.7
Config Lcd = 16 * 2
Cursor Off
Cls

'Deklarasi variabel
Dim Pengali As Word
Dim Detik_1 As Byte
Dim Detik As Byte
Dim Menit As Byte
Dim Jam As Word
Dim Status As Byte
Dim Status2 As Byte
Dim Status3 As Byte

'konfigurasi timer
Config Timer0 = Timer , Prescale = 256
Config Debounce = 30
'setting porta
Ddra = 0
Porta = 255

'pengaktifan interupsi timer
On Ovf0 Int_timer0

'penggantian nama variabel
Pin_reset Alias Pina.2
Pin_on_off Alias Pina.1
Pin_capture Alias Pina.0

'setting nilai awal variabel
'Pin_reset = 1
'Pin_on_off = 1
'Pin_capture = 1
Status = 0
Status2 = 1


'pengaktifan timer0
Enable Timer0

Do
 If Pin_capture = 0 Then
   Bitwait Pin_capture , Set
   Incr Status2
   Cls
   Locate 1 , 1
   Lcd "BINA ELEKTRONIK"
   Locate 2 , 1
   Lcd Jam ;
   Locate 2 , 3
   Lcd ":" ;
   Locate 2 , 4
   Lcd Menit ;
   Locate 2 , 6
   Lcd ":" ;
   Locate 2 , 7
   Lcd Detik ;
   Locate 2 , 9
   Lcd ":" ;
   Locate 2 , 10
   Lcd Detik_1 ;
   Locate 2 , 12
   Lcd Capture1
 End If
 If Status2 = 2 Then
   Locate 2 , 13
   Lcd "SLIP"
   End If
If Status2 = 2 Then
   Locate 2 , 11
   Lcd "       "
   End If
 If Pin_on_off = 0 Then
   Bitwait Pin_on_off , Set
   Incr Status

 End If

 If Pin_reset = 0 Then
      Pengali = 0
      Detik_1 = 00
      Locate 2 , 1
      Lcd "00"
      Locate 2 , 4
      Lcd "00"
      Locate 2 , 7
      Lcd "00"
      Locate 2 , 10
      Lcd "00"
      Detik = 00
      Menit = 00
      Jam = 00
 End If


 If Status > 2 Then
   Status = 1
 End If

 If Status2 > 2 Then
   Status2 = 1
   Cls
 End If

 If Status = 1 Then Enable Interrupts
 If Status = 2 Then Disable Interrupts

 If Status2 < 2 Then
   Locate 1 , 1
   Lcd "STOPWATCH"
   Locate 2 , 1
   Lcd Jam ;
   Locate 2 , 3
   Lcd ":" ;
   Locate 2 , 4
   Lcd Menit ;
   Locate 2 , 6
   Lcd ":" ;
   Locate 2 , 7
   Lcd Detik ;
   Locate 2 , 9
   Lcd ":" ;
   Locate 2 , 10
   Lcd Detik_1 ;
   End If
 If Status = 2 Then                                         ' tambahan
   Locate 2 , 13                                            ' tambahan
   Lcd "STOP"                                               ' tambahan
   End If                                                   ' tambahan
 If Status = 1 Then                                         ' tambahan
   Locate 2 , 13                                            ' tambahan
   Lcd ">>>>"                                               ' tambahan
 End If



Loop

Int_timer0:
   Incr Pengali
   If Pengali > 0 Then
      Pengali = 0
      Incr Detik_1
   End If
   If Detik_1 > 99 Then
      Detik_1 = 0
      Incr Detik
   End If
   If Detik > 59 Then
      Detik = 0
      Incr Menit
   End If
   If Menit > 59 Then
      Menit = 0
      Incr Jam
   End If
   Return
Share:

Pengendali motor stepper dengan keypad

Rangkaian ;

Code List :

$regfile = "m16def.dat"
$crystal = 1000000

Config Kbd = Portb
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 ,Rs = Portc.0 , E = Portc.1
Config Portd = Output
Config Porta = Input

Dim A As Byte , B As Byte , Key As Byte , C As Byte , D As Byte , E As Byte

Cls
Cursor Off

B = 0
D = 1

Q:
Locate 1 , 1
Lcd "Putaran :"
Locate 2 , 1
Lcd "Kecept  :"
Do
'************Read Keyboard
A = Getkbd()
If A > 15 Then
   Goto Q
Else
   Key = Lookup(a , Dta)
     If Key <= 9 Then
           B = B * 10
           B = B + Key
'*************Direction
          If D = 0 Then Lcd B
                   Waitms 270
               Elseif Key = 10 Then
                   Locate 1 , 11
                   Lcd "Kiri"
                   C = 1
                   D = 0
                   B = 0

               Elseif Key = 11 Then
                  Locate 1 , 11
                  Lcd "Kanan"
                  C = 2
                  D = 0
                  B = 0
'****************reset
               Elseif Key = 13 Then
                  Cls
                  D = 1
                  B = 0
                  Portd.0 = 0
                  Portd.1 = 0
                  Waitms 50
                  Goto Q
'****************Enter key
               Elseif Key = 14 Then
                   If D = 0 Then
                       Select Case C
                          Case 1 : Gosub R
                          Case 2 : Gosub T
                       End Select

                   End If
         End If

End If

Wait 1

Loop

End

Dta:
Data 7 , 8 , 9 , 10 , 4 , 5 , 6 , 11 , 1 , 2 , 3 , 12 , 13 , 0 , 14 , 15

R:
Do
Portd = &B00000001 : Waitms B
Portd = &B00000011 : Waitms B
Portd = &B00000010 : Waitms B
Portd = &B00000110 : Waitms B
Portd = &B00000100 : Waitms B
Portd = &B00001100 : Waitms B
Portd = &B00001000 : Waitms B
Portd = &B00001001 : Waitms B
  If Pina.0 = 1 Then
      Locate 2 , 1
      Lcd "Kecept:"
      B = 0
      Lcd B ; "          "
      Return
  End If

Loop

T:
Do
Portd = &B00001001 : Waitms B
Portd = &B00001000 : Waitms B
Portd = &B00001100 : Waitms B
Portd = &B00000100 : Waitms B
Portd = &B00000110 : Waitms B
Portd = &B00000010 : Waitms B
Portd = &B00000011 : Waitms B
Portd = &B00000001 : Waitms B
   If Pina.0 = 1 Then
       Locate 2 , 1
       Lcd "Kecept:"
       B = 0
       Lcd B ; "          "
       Return
   End If

Loop
Share:

Pengaturan Kecepatan Motor DC Dengan Mikrokontroler dengan BASCOM AVR

Penggunaan motor DC dewasa ini sudah sangatlah umum, salah satu kelebihan motor DC adalah relatif gampang didapat dan mudah diatur kecepatan putarnya. Secara umum pengaturan kecepatan motor DC adalah dengan menggunakan cara analog. Pada artikel kali ini akan dibahas contoh cara mengatur kecepatan motor DC dengan menggunakan mikrokontroller.
Mikrokontroler yang digunakan adalah Tipe AVR dari Atmel seperti mikrokontroler Atmega 8535, 16, 32. Informasi kecepatan motor akan ditampilkan pada modul LCD HD4480. Sedangkan sebagai driver motor menggunakan modul driver motor IC L298.
Cara pengaturan kecepatan yang digunakan adalah dengan menggunakan teknik PWM (Pulse Width Modulation), salah satu teknik untuk mengatur kecepatan motor DC yang umum digunakan. Dengan menggunakan PWM kita dapat mengatur kecepatan yang diinginkan dengan mudah. Teknik PWM untuk pengaturan kecepatan motor adalah, pengaturan kecepatan motor dengan cara merubah-rubah besarnya duty cycle pulsa. Pulsa yang yang berubah ubah duty cycle-nya inilah yang menentukan kecepatan motor. Besarnya amplitudo dan frekuensi pulsa adalah tetap, sedangkan besarnya duty cycle berubah-ubah sesuai dengan kecepatan yang diinginkan, semakin besar duty cylce maka semakin cepat pula kecepatan motor, dan sebaliknya semakin kecil duty cycle maka semakin pelan pula kecepatan motor. Sebagai contoh bentuk pulsa yang dikirimkan adalah seperti pada gambar 1, pulsa kotak dengan duty cycle pulsa 50%. Sedangkan sebagai contoh bentuk pulsa PWM adalah seperti pada gambar 2.
Seperti pada gambar 1, semakin besar duty cycle pulsa kotak, maka semakin lama pula posisi logika high. Jika motor diatur agar berjalan ketika diberi logika high, maka jika memberi pulsa seperti pada gambar 1 diatas, maka motor akan berada pada kondisi “nyala-mati-nyala-mati” sesuai dengan bentuk pulsa tersesebut. Semakin lama motor berada pada kondisi “nyala” maka semakin cepat pula kecepatan motor tersebut. Motor akan berputar dengan kecepatan maksimum jika mendapat pulsa dengan duty cycle 100%. Dengan kata lain motor mendapat logika high terus menerus.
Dengan mengatur besarnya duty cycle pulsa kotak yang dikirimkan, kita dapat mengatur banyaknya logika high yang diberikan pada motor, dengan kata lain mengatur lamanya waktu motor untuk berputar dalam satu periode pulsa. Jika lamanya waktu motor untuk berputar dalam satu periode pulsa ini berubah maka kecepatan purtaran motor juga akan berubah, sesuai dengan duty cycle atau waktu motor untuk berputar dalam satu periode pulsa.
===============================================================
PENGATURAN KECEPATAN MOTOR DC Berbasis Atmega8535
Skema dengan proteus:

Hasil simulasi dengan proteus:

Program Pengaturan Kecepatan Motor DC dengan Bascom AVR

1 $regfile = “m8535.dat”   ’menggunakan Atmega8535 sebagai preprosesor
  2 $crystal = 12000000      ’menggunakan crystal clock 12 MHz
  3 $eeprom                  'menggunakan fasilitas eeprom Atmega8535
  4
  5 ‘—————————inisialisasi lcd————————————
  6
  7 Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E = Portc.2 , Rs = Portc.0
  8 Config Lcd = 16 * 2 : Cursor Off
  9
 10 ‘—————————inisialisasi pwm———————————–
 11
 12 Config Timer1 = Pwm , Pwm = 10 , Prescale = 64 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Up       ‘pwm dengan settingan fast pwm 10 bit
 13
 14 ‘—————————inisialisasi port——————————–
 15
 16 ‘inisialisasi tombol
 17 Config Portb = Input
 18
 19 ‘—————————pull up internal——————————–
 20
 21 Portb.0 = 1
 22 Portb.1 = 1
 23 Portb.2 = 1
 24 Portb.3 = 1
 25 Config Portd = Output
 26alias logika motor
 27 M1a Alias Portd.0
 28 M1b Alias Portd.1
 29 M2a Alias Portd.2
 30 M2b Alias Portd.3
 31
 32 ‘——————————alias——————————————–
 33
 34alias tombol
 35 Sw_ok Alias Pinb.3
 36 Sw_cancel Alias Pinb.2
 37 Sw_down Alias Pinb.1
 38 Sw_up Alias Pinb.0
 39
 40 ‘——————————————————————————-
 41
 42 Dim Pwm As Integer
 43 Dim Pwm_eprom As Eram Integer
 44 Home
 45 Lcd “Fahmizal_dte2006″
 46 Lowerline
 47 Lcd “Cek fungsi PWM”
 48 Wait 1
 49
 50 Do
 51 Pwm = Pwm_eprom
 52 If Sw_up = 0 Then : Incr Pwm : Waitms 10
 53 End If
 54 If Sw_down = 0 Then : Decr Pwm : Waitms 10
 55 End If
 56 If Pwm > 1023 Then : Pwm = 0 : Waitms 10
 57 End If
 58 If Pwm < 0 Then : Pwm = 1023 : Waitms 10
 59 End If
 60 Pwm_eprom = Pwm
 61 Cls
 62
 63 Home
 64 Lcd “tes uji pwm”
 65 Lowerline
 66 Reset M1a
 67 Reset M2a
 68 Set M1b
 69 Set M2b
 70 Pwm1a = Pwm
 71 Pwm1b = Pwm
 72 Lcd “nilai pwm:” ; Pwm1a : Waitms 100
 73 Loop
 74 End
Share:

Jam Digital dengan Mode 12/24

Rangkaian :

Source Code : Bascom AVR
$regfile = "m8def.dat"
$crystal = 1000000
'------------------------  lcd -----------------------------------------------
Config Lcd = 16 * 2
Config Lcdpin = Pin , Rs = Pind.0 , E = Pind.1 , Db4 = Pind.2 , Db5 = Pind.3 , Db6 = Pind.4 , Db7 = Pind.5
Cls

'---------------------------  ds 1307 -----------------------------------------
$lib "ds1307clock.lib"
'configure the scl and sda pins
Config Sda = Portd.7
Config Scl = Portd.6
'address of ds1307
Const Ds1307w = &HD0                                        ' Addresses of Ds1307 clock
Const Ds1307r = &HD1
'------------------------------ key --------------------------------------------
Config Pinc.1 = Input
Config Pinc.2 = Input
Config Pinc.3 = Input
Config Pinc.4 = Input
'------------------------------------------------------------------------------
Config Debounce = 30

Dim A As Byte , B As Byte , Data1 As Byte , C As Byte

Dim Seco As Byte , Mine As Byte , Hour As Byte

'----------------------------------------------------------------------------
Cursor Off
'-----------------------------
Cls
Locate 1 , 6
Lcd "Hello"
Locate 2 , 1
Lcd "WWW.elec4u.ir"
Wait 2

For A = 1 To 15
 Shiftlcd Left
Waitms 300
Next

Cls
'-------------------------------------------------------------------------------
Main:
Do
         Gosub Ds1307
         Gosub 24_12
         Gosub Chekkey

Loop
'-------------------------------------------------------------------------------
Ds1307:
        I2cstart                                            ' Generate start code
        I2cwbyte Ds1307w                                    ' send address
        I2cwbyte 0                                          ' start address in 1307
        I2cstart                                            ' Generate start code
        I2cwbyte Ds1307r                                    ' send address
        I2crbyte Seco , Ack                                 'sec
        I2crbyte Mine , Ack                                 ' MINUTES
        I2crbyte Hour , Nack                                ' Hours
        I2cstop

        Seco = Makedec(seco) : Mine = Makedec(mine) : Hour = Makedec(hour)

        If Seco > 59 Then Seco = 0
        If Mine > 59 Then Mine = 0
        If Hour > 23 Then
        Hour = 0
        Gosub Seco
        End If

Return
'-------------------------------------------------------------------------------
 24_12:
 If Pinc.4 = 1 Then Gosub Disply_24
 If Pinc.4 = 0 Then Gosub Disply_12
 Return
'-------------------------------------------------------------------------------
Disply_24:

         Locate 1 , 1
         Lcd "Time = " ; Hour ; ":" ; Mine ; ":" ; Seco ; "      "
         Locate 2 , 6
         Lcd "(24)"
Return

'-------------------------------------------------------------------------------
Disply_12:

         If Hour = 0 Then Hour = 12
         If Hour > 12 Then Hour = Hour - 12

         Locate 1 , 1
         Lcd "Time = " ; Hour ; ":" ; Mine ; ":" ; Seco ; "      "
         Locate 2 , 6
         Lcd "(12)"
Return
'-------------------------------------------------------------------------------
Chekkey:

         Debounce Pinc.1 , 0 , Seco , Sub
         Debounce Pinc.2 , 0 , Mine , Sub
         Debounce Pinc.3 , 0 , Hour , Sub

Return
'---------------------------------------------
Seco:
         Incr Seco
         If Seco > 59 Then Seco = 0
         Seco = Makebcd(seco)
         I2cstart                                           ' Generate start code
         I2cwbyte Ds1307w                                   ' send address
         I2cwbyte 0                                         ' starting address in 1307
         I2cwbyte Seco
         I2cstop
Return

'-------------------------------------
Mine:
         Incr Mine
         If Mine > 59 Then Mine = 0
         Mine = Makebcd(mine)
         I2cstart                                           ' Generate start code
         I2cwbyte Ds1307w                                   ' send address
         I2cwbyte 1                                         ' starting address in 1307
         I2cwbyte Mine
         I2cstop
Return
'-------------------------------------

Hour:
         Incr Hour
         If Hour > 23 Then Hour = 0
         Hour = Makebcd(hour)
         I2cstart                                           ' Generate start code
         I2cwbyte Ds1307w                                   ' send address
         I2cwbyte 2                                         ' starting address in 1307
         I2cwbyte Hour
         I2cstop

Return
'-------------------------------------

End
Share:

Jam Digital menggunakan Mikro ATMega8 dan Bahasa BASCOM-AVR

Belajar menggunakan LCD dengan ATMega8535 tidaklah sulit, dengan menggunakan bahasa Bascom AVR hal ini menjadi mudah dilakukan terutama bagi pemula. Berikut adalah rangkaian konfigurasi pin pada mikro ATMega8535 dan contoh program yang dapat dicoba. Selamat Mencoba.

Gambar Rangkaian :

Rangkaian Tampilan LCD.
Kode Bascom AVR


1 $regfile = "m8def.dat"
2 $crystal = 1000000
3 '------------------------  lcd -----------------------------------------------
4 Config Lcd = 16 * 2
5 Config Lcdpin = Pin , Rs = Pind.0 , E = Pind.1 , Db4 = Pind.2 , Db5 = Pind.3 , Db6 = Pind.4 , Db7 = Pind.5
6 Cls
7 
8 '---------------------------  ds 1307 -----------------------------------------
9 $lib "ds1307clock.lib"
10 'configure the scl and sda pins
11 Config Sda = Portd.7
12 Config Scl = Portd.6
13 'address of ds1307
14 Const Ds1307w = &HD0                                        ' Addresses of Ds1307 clock
15 Const Ds1307r = &HD1
16 '------------------------------ key --------------------------------------------
17 Config Pinc.1 = Input
18 Config Pinc.2 = Input
19 Config Pinc.3 = Input
20 Config Pinc.4 = Input
21 '------------------------------------------------------------------------------
22 Config Debounce = 30
23 
24 Dim A As Byte , B As Byte , Data1 As Byte , C As Byte
25 
26 Dim Seco As Byte , Mine As Byte , Hour As Byte
27 
28 '----------------------------------------------------------------------------
29 Cursor Off
30 '-----------------------------
31 Cls
32 Locate 1 , 1
33 Lcd "Jam Digital LCD"
34 Locate 2 , 1
35 Lcd "Bina Project"
36 Wait 2 

37 
38 For A = 1 To 15
39  Shiftlcd Left
40 Waitms 30
41 Next
42 
43 Cls
44 '-------------------------------------------------------------------------------
45 Main:
46 Do
47          Gosub Ds1307
48          Gosub 24_12
49          Gosub Chekkey
50 
51 Loop
52 '-------------------------------------------------------------------------------
53 Ds1307:
54         I2cstart                                            ' Generate start code
55         I2cwbyte Ds1307w                                    ' send address
56         I2cwbyte 0                                          ' start address in 1307
57         I2cstart                                            ' Generate start code
58         I2cwbyte Ds1307r                                    ' send address
59         I2crbyte Seco , Ack                                 'sec
60         I2crbyte Mine , Ack                                 ' MINUTES
61         I2crbyte Hour , Nack                                ' Hours
62         I2cstop
63 
64         Seco = Makedec(seco) : Mine = Makedec(mine) : Hour = Makedec(hour)
65 
66         If Seco > 59 Then Seco = 0
67         If Mine > 59 Then Mine = 0
68         If Hour > 23 Then
69         Hour = 0
70         Gosub Seco
71         End If 

72 
73 Return
74 '-------------------------------------------------------------------------------
75  24_12:
76  If Pinc.4 = 1 Then Gosub Disply_24
77  If Pinc.4 = 0 Then Gosub Disply_12
78  Return
79 '-------------------------------------------------------------------------------
80 Disply_24:
81 
82          Locate 1 , 1
83          Lcd "Jam = " ; Hour ; ":" ;
84          If Mine < 10 Then
85             Lcd "0" ; Mine ; ":" ;
86          Else
87             Lcd Mine ; ":" ;
88          End If
89 
90          If Seco < 10 Then
91             Lcd "0" ; Seco
92          Else 

93             Lcd Seco
94          End If
95 
96          Locate 2 , 6
97          Lcd "(24 Jam)"
98 
99 Return
100 
101 '-------------------------------------------------------------------------------
102 Disply_12:
103 
104          If Hour = 0 Then Hour = 12
105          If Hour > 12 Then Hour = Hour - 12
106
107          Locate 1 , 1
108          Lcd "Jam = " ; Hour ; ":" ;
109          If Mine < 10 Then
110             Lcd "0" ; Mine ; ":" ;

111          Else
112             Lcd Mine ; ":" ;
113          End If
114
115          If Seco < 10 Then
116             Lcd "0" ; Seco
117          Else
118             Lcd Seco
119          End If
120
121          Locate 2 , 6
122          Lcd "(12 Jam)"
123 Return
124 '-------------------------------------------------------------------------------
125 Chekkey:
126
127          Debounce Pinc.1 , 0 , Seco , Sub
128          Debounce Pinc.2 , 0 , Mine , Sub
129          Debounce Pinc.3 , 0 , Hour , Sub
130 
131 

132 Return
133 '---------------------------------------------
134 Seco:
135          Incr Seco
136          If Seco > 59 Then Seco = 0

137          Seco = Makebcd(seco)
138          I2cstart                                           ' Generate start code
139          I2cwbyte Ds1307w                                   ' send address
140          I2cwbyte 0                                         ' starting address in 1307
141          I2cwbyte Seco
142          I2cstop
143 Return
144
145 '-------------------------------------
146 Mine:

147          Incr Mine
148          If Mine > 59 Then Mine = 0
149          Mine = Makebcd(mine)
150          I2cstart                                           ' Generate start code
151          I2cwbyte Ds1307w                                   ' send address
152          I2cwbyte 1                                         ' starting address in 1307
153          I2cwbyte Mine
154          I2cstop
155 Return
Share:

Feature AVR Mikrokontroler

AVR chip merupakan salah satu dari beberapa tipe chip yang banyak digunakan. selain sudah familiar dan penggunaan yang mudah chip ini juga banyak tersedia di toko elektronik di indonesia . selain itu banyak feature yang bisa mempermudah pekerjaan programmer, umumnya tipe ini dilengkapi dengan ADC, Timer, Interrupt, dll. salah satu tipe AVR “Kesayangan” saya,, yaitu : ATMega Family…

DIP 40 ini sangat menunjang beberapa pekerjaan saya selama ini,,
fetaturenya:
  1. High-performance, Low-power AVR® 8-bit Microcontroller
  2. Advanced RISC Architecture
    • 130 Powerful Instructions – Most Single Clock Cycle Execution
    • 32 x 8 General Purpose Working Registers
    • Fully Static Operation
    • Up to 16 MIPS Throughput at 16 MHz
    • On-chip 2-cycle Multiplier
  3. Nonvolatile Program and Data Memories
    • 8K Bytes of In-System Self-Programmable Flash
    • Endurance: 10,000 Write/Erase Cycles
    • Optional Boot Code Section with Independent Lock Bits
    • In-System Programming by On-chip Boot Program
    • True Read-While-Write Operation
    • 512 Bytes EEPROM
    • Endurance: 100,000 Write/Erase Cycles
    • 512 Bytes Internal SRAM
    • Programming Lock for Software Security
  4. Peripheral Features
    • Two 8-bit Timer/Counters with Separate Prescalers and Compare Modes
    • One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture
  5. Mode
    • Real Time Counter with Separate Oscillator
    • Four PWM Channels
    • 8-channel, 10-bit ADC
    • 8 Single-ended Channels
    • 7 Differential Channels for TQFP Package Only
    • 2 Differential Channels with Programmable Gain at 1x, 10x, or 200x for TQFP
  6. Package Only
    • Byte-oriented Two-wire Serial Interface
    • Programmable Serial USART
    • Master/Slave SPI Serial Interface
    • Programmable Watchdog Timer with Separate On-chip Oscillator
    • On-chip Analog Comparator
  7. Special Microcontroller Features
    • Power-on Reset and Programmable Brown-out Detection
    • Internal Calibrated RC Oscillator
    • External and Internal Interrupt Sources
    • Six Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down, Standby
      and Extended Standby
  8. I/O and Packages
    • 32 Programmable I/O Lines
    • 40-pin PDIP, 44-lead TQFP, 44-lead PLCC, and 44-pad MLF
  9. Operating Voltages
    • 2.7 – 5.5V for ATmega8535L
    • 4.5 – 5.5V for ATmega8535
  10. Speed Grades
    • 0 – 8 MHz for ATmega8535L
    • 0 – 16 MHz for ATmega8535
Share:

Aplikasi Tombol pada ATMega8535 Menggunakan Bahasa BASCOM AVR

Pada aplikasi ini saya menggunakan 2 jenis tombol yang berbeda. Pertama menggunakan Tombol Push Button, sedangkan yang kedua menggunakan Tombol Toggle. Maka disini saya membuat 2 buah contoh program untuk masing-masing jenis tombol.
Tombol Push Button.
Pada program pertama, saya menggunakan tombol push button sebagai masukan melalui PortC, dengan indikator yang ditunjukan pada 7Segment di PortA. Jika tombol tidak ditekan, maka data akan terbaca sebagai Low (0), Jika tombol ditekan maka data akan terbaca High (1). Maka untuk dapat membedakan pembacaan tombol pada saat ditekan atau tidak, saya menghubungkan tombol push button dengan Vcc +5 Volt DC. 
Gambar Rangkaian Aplikasi Tombol
Contoh Program 1
’Program Baca Masukan Tombol Push Button
  1 $regfile = "m8535.dat"
  2 $crystal = 4000000
  3 Config Porta = Output
  4 Config Portd = Output
  5 Config Portb = Input
  6 Config Portc = Input
  7 
  8 Do
  9 Select Case Pinc
 10 Case 1 : Porta = 1
 11 Case 2 : Porta = 2
 12 Case 4 : Porta = 3
 13 Case 8 : Porta = 4
 14 Case 16 : Porta = 5
 15 Case 32 : Porta = 6
 16 Case 64 : Porta = 7
 17 Case 128 : Porta = 8
 18 
 19 'Case Else : Porta = 0
 20 End Select
 21 Waitms 1
 22 Loop
 23 End 
Tombol Toggle.
Pada program kedua, saya menggunakan tombol toggle (On/Off) sebagai masukan melalui PortB dan menggunakan indikator keluaran LED melalui PortD. Program yang digunakan sangat sederhana seperti contoh program dibawah ini.
Contoh Program 2 ’Program Baca Masukan Tombol Toggle
  1 $regfile = "m8535.dat"
  2 $crystal = 4000000
  3 Config PortD = Output
  4 Config PortB = Input
  5 
  6 Do
  7 PortD=PinB
  8 Loop
  9 End 
Share:

Membuat Jam Digital yang dilengkapai dengan Setting Atmega Bascom AVR

Membuat program Jam digital dengan Mikrokontroler Bahasa Bascom ternyata tidak sulit. Bagi temen temen Elektromania ini mungkin bermanfaan bagi anda, ada contoh sederhana memebuat jam digital dengan dilengkapi setting jam dan tanggal

Gambar rangkaian :

Gambar rangkaian dengan Simulator Proteus
Kode Program dengan Bascom (Bas)
  1 
  2 $regfile = "m8def.dat"
  3 $crystal = 1000000
  4 $hwstack = 40
  5 $swstack = 20
  6 $framesize = 32
  7 
  8 Declare Sub Actual()
  9 
 10 Config Lcd = 16 * 4
 11 Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7 , E = Portd.0 , Rs = Portd.1
 12 Config Lcdbus = 4
 13 Deflcdchar Print , 14 , 32 , 17 , 25 , 21 , 19 , 17 , 17
 14 Config Date = Dmy , Separator = /
 15 Config Clock = Soft
 16 Enable Interrupts
 17 
 18 Dim Minuto As Byte
 19 
 20 
 21 Ddrd.2 = 1 : Portd.2 = 0
 22 Ddrc.0 = 0 : Portc.0 = 1
 23 Ddrc.1 = 0 : Portc.1 = 1
 24 
 25 Tombol_select Alias Pinc.0
 26 Tombol_set Alias Pinc.1
 27 
 28 
 29 Date$ = "23/03/11"
 30 Time$ = "00:00:00"
 31 Minuto = _min
 32 
 33 Cls
 34 Cursor Off
 35 
 36 Awal:
 37    Locate 1 , 1 : Lcd "BINA ELEKTRONIKA"
 38    Locate 3 , 1 : Lcd "JAM :"
 39    Locate 2 , 1 : Lcd "TGL :"
 40    Locate 4 , 1 : Lcd "         "
 41 
 42 Awal1:
 43 
 44    If Tombol_select = 0 Then
 45 
 46       Waitms 5
 47       Bitwait Tombol_select , Set
 48       Goto Seting_detik
 49 
 50    End If
 51 
 52    Call Actual
 53    Goto Awal1
 54 
 55 Seting_detik:
 56 
 57    Locate 4 , 1 : Lcd "SET DETIK"
 58 
 59 Seting_detik1:
 60 
 61    If Tombol_select = 0 Then
 62 
 63       Waitms 5
 64       Bitwait Tombol_select , Set
 65       Goto Seting_menit
 66 
 67    End If
 68 
 69    If Tombol_set = 0 Then
 70 
 71       Waitms 5
 72       _sec = 0
 73       Bitwait Tombol_set , Set
 74 
 75    End If
 76 
 77    Call Actual
 78    Goto Seting_detik1
 79 
 80 
 81 Seting_menit:
 82 
 83    Locate 4 , 1 : Lcd "SET MENIT "
 84 
 85 Seting_menit1:
 86 
 87    If Tombol_select = 0 Then
 88 
 89       Waitms 5
 90       Bitwait Tombol_select , Set
 91       Goto Seting_jam
 92 
 93    End If
 94 
 95    If Tombol_set = 0 Then
 96 
 97       Waitms 5
 98       Incr _min
 99       If _min = 60 Then
100          _min = 0
101       End If
102       Bitwait Tombol_set , Set
103 
104    End If
105 
106    Call Actual
107    Goto Seting_menit1
108 
109 Seting_jam:
110 
111    Locate 4 , 1 : Lcd "SET JAM  "
112 
113 Seting_jam1:
114 
115    If Tombol_select = 0 Then
116 
117       Waitms 5
118       Bitwait Tombol_select , Set
119       Goto Seting_hari
120 
121    End If
122 
123    If Tombol_set = 0 Then
124 
125       Waitms 5
126       Incr _hour
127       If _hour = 24 Then
128          _hour = 0
129       End If
130       Bitwait Tombol_set , Set
131 
132    End If
133 
134    Call Actual
135    Goto Seting_jam1
136 
137 Seting_hari:
138 
139    Locate 4 , 1 : Lcd "SET TANGGAL  "
140 
141 Seting_hari1:
142 
143    If Tombol_select = 0 Then
144 
145       Waitms 5
146       Bitwait Tombol_select , Set
147       Goto Seting_bulan
148 
149    End If
150 
151    If Tombol_set = 0 Then
152 
153       Waitms 5
154       Incr _day
155       If _day = 32 Then
156          _day = 1
157       End If
158       Bitwait Tombol_set , Set
159 
160    End If
161 
162    Call Actual
163    Goto Seting_hari1
164 
165 Seting_bulan:
166 
167    Locate 4 , 1 : Lcd "SET BULAN  "
168 
169 Seting_bulan1:
170 
171    If Tombol_select = 0 Then
172 
173       Waitms 5
174       Bitwait Tombol_select , Set
175       Goto Seting_tahun
176 
177    End If
178 
179    If Tombol_set = 0 Then
180 
181       Waitms 5
182       Incr _month
183       If _month = 13 Then
184          _month = 1
185       End If
186       Bitwait Tombol_set , Set
187 
188    End If
189 
190    Call Actual
191    Goto Seting_bulan1
192 
193 
194 Seting_tahun:
195 
196    'Locate 4 , 1 : Lcd "A"
197    'Locate 4 , 2 : Lcd Chr(0)
198    Locate 4 , 1 : Lcd "SET TAHUN  "
199 
200 Seting_tahun1:
201 
202    If Tombol_select = 0 Then
203 
204       Waitms 5
205       Bitwait Tombol_select , Set
206       Goto Awal
207 
208    End If
209 
210    If Tombol_set = 0 Then
211 
212       Waitms 5
213       Incr _year
214       If _year = 100 Then
215          _year = 00
216       End If
217       Bitwait Tombol_set , Set
218 
219    End If
220 
221    Call Actual
222    Goto Seting_tahun1
223 
224 
225 Actual:
226 
227    Locate 2 , 7 : Lcd Date$
228    Locate 3 , 7 : Lcd Time$
229    If _min <> Minuto Then
230 
231       Minuto = _min
232       Toggle Portd.2
233 
234    End If
235 
236 Return
237 
238 End
Share:

Jadwal Waktu Sholat

TIME WIB

TV EDUKASI LIVE

Popular Posts

Recent Posts

Pages