Job 5
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Job 5

on

  • 592 views

embedded

embedded

Statistics

Views

Total Views
592
Views on SlideShare
592
Embed Views
0

Actions

Likes
0
Downloads
11
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Job 5 Document Transcript

  • 1. LAPORAN PRAKTIKUM SISTEM TERBENAM JOB 5 “Timer (Counter)” Disusun oleh : Isty Ayu Cahyani IK-3A 3.34.10.0.16PROGRAM STUDI TEKNIK INFORMATIKA JURUSAN TEKNIK ELEKTRO POLITEKNIK NEGERI SEMARANG 2012
  • 2. PRAKTEK V TIMER (COUNTER)I. Peralatan dan Bahan 1. PC Processor Intel, dan sistem operasi Windows XP / 7 2. Software Code Vision AVR 3. Software ISIS ProfesionalII. Langkah Kerja 1. Hidupkan Komputer. 2. Buka Software Code Vision AVR 3. Buat projek baru dengan pilih File  New 4. Kemudian akan muncul kotak seperti ini ,dan pilih Project  Yes 2
  • 3. 5. Setelah klik yes, akan muncul kotak seperti berikut dan pilih option paling atas lalu OK6. Kemudian akan muncul Code Wizard AVR, atur Chip, AlphanumericLCD, dan Port nya seperti berikut : a. Chip  pilih jenis chip ATMega8535 dan Clock 8.000000 Mhz 3
  • 4. b. Pada Alphanumeric LCD, atur Character /Line menjadi 16c. Pada Timers, pilih Timer1 untuk menjalankannya. Atur Clock Source menjadi T1 pin Falling Edge. 4
  • 5. d. Lalu pilih Menu Program  Generate Save and Exite. Kemudian simpan file C dengan nama counter Savef. Kemudian simpan projek dengan nama counter.prj  Save 5
  • 6. 4. Pemulisan kode program a. Mengetest LED dengan menggunakan timer /***************************************************** This program was produced by the CodeWizardAVR V2.05.3 Standard Automatic Program Generator © Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l. http://www.hpinfotech.com Project : Version : Date : 11/23/2012 Author : Sh.mukti Company : Jangan gunakan software bajakan! Comments: Chip type : ATmega8535 Program type : Application AVR Core Clock frequency: 8.000000 MHz Memory model : Small External RAM size : 0 Data Stack size : 128 *****************************************************/ 6
  • 7. #include <mega8535.h>#include <stdio.h>// Alphanumeric LCD functions#include <alcd.h>// Declare your global variables herevoid main(void){unsigned int dataCounter=0, dataCounterOld=0;unsigned char buf[16];// Declare your local variables here// Input/Output Ports initialization// Port A initialization// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=InFunc1=In Func0=In// State7=T State6=T State5=T State4=T State3=T State2=TState1=T State0=TPORTA=0x00;DDRA=0x00;// Port B initialization// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=InFunc1=In Func0=In// State7=T State6=T State5=T State4=T State3=T State2=TState1=T State0=TPORTB=0x00;DDRB=0x00;// Port C initialization// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=InFunc1=In Func0=In// State7=T State6=T State5=T State4=T State3=T State2=TState1=T State0=TPORTC=0x00;DDRC=0x00; 7
  • 8. // Port D initialization// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=InFunc1=In Func0=In// State7=T State6=T State5=T State4=T State3=T State2=TState1=T State0=TPORTD=0x00;DDRD=0x00;// Timer/Counter 0 initialization// Clock source: System Clock// Clock value: Timer 0 Stopped// Mode: Normal top=0xFF// OC0 output: DisconnectedTCCR0=0x00;TCNT0=0x00;OCR0=0x00;// Timer/Counter 1 initialization// Clock source: T1 pin Falling Edge// Mode: Normal top=0xFFFF// OC1A output: Discon.// OC1B output: Discon.// Noise Canceler: Off// Input Capture on Falling Edge// Timer1 Overflow Interrupt: Off// Input Capture Interrupt: Off// Compare A Match Interrupt: Off// Compare B Match Interrupt: OffTCCR1A=0x00;TCCR1B=0x06;TCNT1H=0x00;TCNT1L=0x00;ICR1H=0x00;ICR1L=0x00;OCR1AH=0x00;OCR1AL=0x00;OCR1BH=0x00;OCR1BL=0x00;// Timer/Counter 2 initialization// Clock source: System Clock 8
  • 9. // Clock value: Timer2 Stopped// Mode: Normal top=0xFF// OC2 output: DisconnectedASSR=0x00;TCCR2=0x00;TCNT2=0x00;OCR2=0x00;// External Interrupt(s) initialization// INT0: Off// INT1: Off// INT2: OffMCUCR=0x00;MCUCSR=0x00;// Timer(s)/Counter(s) Interrupt(s) initializationTIMSK=0x00;// USART initialization// USART disabledUCSRB=0x00;// Analog Comparator initialization// Analog Comparator: Off// Analog Comparator Input Capture by Timer/Counter 1: OffACSR=0x80;SFIOR=0x00;// ADC initialization// ADC disabledADCSRA=0x00;// SPI initialization// SPI disabledSPCR=0x00;// TWI initialization// TWI disabledTWCR=0x00;// Alphanumeric LCD initialization 9
  • 10. // Connections are specified in the// Project|Configure|C Compiler|Libraries|Alphanumeric LCDmenu:// RS - PORTA Bit 0// RD - PORTA Bit 1// EN - PORTA Bit 2// D4 - PORTA Bit 4// D5 - PORTA Bit 5// D6 - PORTA Bit 6// D7 - PORTA Bit 7// Characters/line: 16lcd_init(16);while (1) { // Place your code here dataCounter = (int) (TCNT1H * 256) + (int) TCNT1L; if (dataCounter > 1000) { TCNT1H = 0; TCNT1L = 0; dataCounter = 0; } if (dataCounterOld != dataCounter) { sprintf (buf,"Counter: %4u", dataCounter); lcd_clear(); lcd_puts(buf); dataCounterOld = dataCounter; } }}Tambahkan kode untuk pendeklarasian variabel global seperti berikut int frek; { frek++; if (frek== 2900) { TGLBIT(PORTA,0); frek=0; } 10
  • 11. }5. Pilih menu Project  Build  OK6. Kemudian buka Aplikasi ISIS Profesional7. Tampilkan ATMega 8535 dengan cara Klik tombol P  ketik ATMega 8535 pada kotak Keywords  OK8. Double klik pada lembar kerja dan atur posisinya9. Tampilkan lm016  OK 11
  • 12. 10. Kemudian tampilkan pulse dengan cara pilih Generator  Pulse11. Atur posisi semuanya dan hubungkan satu sama lain seperti berikut 12
  • 13. 12. Atur Pulse Generator dengan cara double klik pada icon pulse. Ubah nilai Pulsed (HIgh) Voltage menjadi 5  OK13. Masukkan kode program dari Code Vision AVR yang telah dicompile tadi dengan cara double klik pada IC ATMega8535 .Pada program file browse file hexa dari 13
  • 14. counter  OK. Lalu atur juga pada CKSEL Fuses menjadi (0100) Int. RC 8MHz. Lalu OK.14. Kemudian klik tombol Play di sisi kiri bawah, maka pada layar LCD akan muncul karakter string seperti berikut : 14
  • 15. III. Tugas1. Buatlah counter yang outputnya ditampilkan melalui seven segment. Jawab : a. Buat projek baru pada AVR b. Kemudian atur Chip  pilih jenis chip ATMega8535 dan Clock 8.000000 Mhz c. Atur Ports menjadi output pullup 15
  • 16. d. Pada Alphanumeric LCD, atur Character /Line menjadi 16e. Pada Timers, pilih Timer1 untuk menjalankannya. Atur Clock Source menjadi T1 pin Falling Edge. 16
  • 17. f. Lalu pilih Menu Program  Generate Save and Exitg. Masukkan kode program seperti berikut : /***************************************************** This program was produced by the CodeWizardAVR V2.05.3 Standard Automatic Program Generator © Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l. http://www.hpinfotech.com Project : Version : Date : 11/23/2012 Author : Company : Comments: Chip type : ATmega8535 Program type : Application AVR Core Clock frequency: 8.000000 MHz Memory model : Small 17
  • 18. External RAM size : 0Data Stack size : 128*****************************************************/#include <mega8535.h>// Declare your global variables hereunsigned int dataCounter,dataCounterO;void main(void){// Declare your local variables hereunsigned char _7segmen[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0xFF,0x6F};// Input/Output Ports initialization// Port A initialization// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=InFunc1=In Func0=In// State7=T State6=T State5=T State4=T State3=T State2=TState1=T State0=TPORTA=0x00;DDRA=0xFF;// Port B initialization// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=InFunc1=In Func0=In// State7=T State6=T State5=T State4=T State3=T State2=TState1=T State0=TPORTB=0x00;DDRB=0x00;// Port C initialization// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=InFunc1=In Func0=In// State7=T State6=T State5=T State4=T State3=T State2=TState1=T State0=TPORTC=0x00;DDRC=0x00;// Port D initialization// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In 18
  • 19. Func1=In Func0=In// State7=T State6=T State5=T State4=T State3=T State2=TState1=T State0=TPORTD=0x00;DDRD=0x00;// Timer/Counter 0 initialization// Clock source: T0 pin Falling Edge// Mode: Normal top=0xFF// OC0 output: DisconnectedTCCR0=0x06;TCNT0=0x00;OCR0=0x00;// Timer/Counter 1 initialization// Clock source: System Clock// Clock value: Timer1 Stopped// Mode: Normal top=0xFFFF// OC1A output: Discon.// OC1B output: Discon.// Noise Canceler: Off// Input Capture on Falling Edge// Timer1 Overflow Interrupt: Off// Input Capture Interrupt: Off// Compare A Match Interrupt: Off// Compare B Match Interrupt: OffTCCR1A=0x00;TCCR1B=0x00;TCNT1H=0x00;TCNT1L=0x00;ICR1H=0x00;ICR1L=0x00;OCR1AH=0x00;OCR1AL=0x00;OCR1BH=0x00;OCR1BL=0x00;// Timer/Counter 2 initialization// Clock source: System Clock// Clock value: Timer2 Stopped// Mode: Normal top=0xFF 19
  • 20. // OC2 output: DisconnectedASSR=0x00;TCCR2=0x00;TCNT2=0x00;OCR2=0x00;// External Interrupt(s) initialization// INT0: Off// INT1: Off// INT2: OffMCUCR=0x00;MCUCSR=0x00;// Timer(s)/Counter(s) Interrupt(s) initializationTIMSK=0x00;// USART initialization// USART disabledUCSRB=0x00;// Analog Comparator initialization// Analog Comparator: Off// Analog Comparator Input Capture by Timer/Counter 1: OffACSR=0x80;SFIOR=0x00;// AdataCounter initialization// AdataCounter disabledADCSRA=0x00;// SPI initialization// SPI disabledSPCR=0x00;// TWI initialization// TWI disabledPORTA=_7segmen[dataCounter]; while (1) { // Place your code here 20
  • 21. dataCounter = (int)(TCNT0); if(dataCounter > 9){ TCNT0 = 0; dataCounter=0; } if(dataCounterO!= dataCounter){ PORTA=_7segmen[dataCounter]; dataCounterO= dataCounter; } } }h. Buka aplikasi ISIS, kemudian buat desain seperti berikut :i. Atur Pulse Generator dengan cara double klik pada icon pulse. Ubah nilai Pulsed (HIgh) Voltage menjadi 5  OK 21
  • 22. j. Masukkan kode program dari Code Vision AVR yang telah dicompile tadi dengan cara double klik pada IC ATMega8535 .Pada program file browse file hexa dari counter  OK. 22
  • 23. k. Kemudian klik tombol Play di sisi kiri bawah, maka pada layar LCD akan muncul karakter string seperti berikut : 23