(1)dengan timer

Download (1)Dengan Timer

If you can't read please download the document

Upload: safik-dwi-nova

Post on 23-Jan-2016

7 views

Category:

Documents


3 download

DESCRIPTION

timer

TRANSCRIPT

/*****************************************************This program was produced by theCodeWizardAVR V2.03.4 StandardAutomatic Program Generator Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.http://www.hpinfotech.comProject : Version : Date : 5/19/2015Author : Company : Comments: Chip type : ATmega8535Program type : ApplicationClock frequency : 4.000000 MHzMemory model : SmallExternal RAM size : 0Data Stack size : 128*****************************************************/#include #include // Alphanumeric LCD Module functions#asm .equ __lcd_port=0x1B ;PORTA#endasm#include #define LED_TICKS PORTD.7int i;unsigned char jam=0,menit=0,detik=0;unsigned char lcd_buff [30];// Timer 0 output compare interrupt service routineinterrupt [TIM0_COMP] void timer0_comp_isr(void){// Place your code here if(++i==39) { LED_TICKS=~LED_TICKS; i=0; if (++detik==60) { detik=0; if (++menit==60) { menit=0; if(++jam==24) { jam=0; } } } }}// Declare your global variables herevoid main(void){DDRD.7=1;PORTD.7=0;// Declare your local variables here// Input/Output Ports initialization// Port A initialization// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTA=0x00;DDRA=0x00;// Timer/Counter 0 initialization// Clock source: System Clock// Clock value: 3.906 kHz// Mode: CTC top=OCR0// OC0 output: DisconnectedTCCR0=0x0D;TCNT0=0x00;OCR0=0x64;// Timer/Counter 1 initialization// Clock source: System Clock// Clock value: Timer 1 Stopped// Mode: Normal top=FFFFh// OC1A output: Discon.// OC1B output: Discon.// Noise Canceler: Off// Input Capture on Falling Edge// Timer 1 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: Timer 2 Stopped// Mode: Normal top=FFh// 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=0x02;ACSR=0x80;SFIOR=0x00;// LCD module initializationlcd_init(20);// Global enable interrupts#asm("sei")while (1) { // Place your code here lcd_gotoxy (0,1); sprintf (lcd_buff, "time=%02d:%02d:%02d",jam,menit,detik); lcd_puts (lcd_buff); };}