التماس دعا
کد:
/***************************************************** This program was produced by the CodeWizardAVR V2.03.3 Evaluation Automatic Program Generator © Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l. http://www.hpinfotech.com Project : Version : Date : 2008/06/10 Author : Freeware, for evaluation and non-commercial use only Company : Comments: Chip type : ATmega8 Program type : Application Clock frequency : 1.000000 MHz Memory model : Small External RAM size : 0 Data Stack size : 256 *****************************************************/ #include <mega8.h> // Alphanumeric LCD Module functions #asm .equ __lcd_port=0x18 ;PORTB #endasm #include <lcd.h> #include<delay.h> #include<string.h> // Declare your global variables here //**tarife sabet baraye afzayeshe sa@ #define q PIND.0 //**tarife sabet baraye afzayeshe daghighe #define w PIND.1 //**yekan va dahgane saniye int s1,s2; //**yekan va dahgane daghighe int m1,m2; //**yekan va dahgane sa@ int h1,h2; //**tarife reshte baraye namayesh char a[]="00:00:00"; //**tabee ke dar soorat estefade sa@ ra afzayesh midahad void incr_h(void) { if (h1<0x39) { h1+=1; } else { h1=0x30; if (h2<0x32) { h2+=1; } else { h2=0x30; } } if (h2==0x32 && h1==0x34) { s1=0x30; m1=0x30; h1=0x30; s2=0x30; m2=0x30; h2=0x30; } }; //**tabee ke dar soorat estefade daghighe ra afzayesh midahad void incr_m(void) { if (m1<0x39) { m1+=1; } else { m1=0x30; if (m2<0x35) { m2+=1; } else { m2=0x30; } } }; void main(void) { // Declare your local variables here // Input/Output Ports initialization // Port B 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 PORTB=0x00; DDRB=0x00; // Port C initialization // Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTC=0x00; DDRC=0x00; // Port D 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 PORTD=0x00; DDRD=0x00; // Timer/Counter 0 initialization // Clock source: System Clock // Clock value: Timer 0 Stopped TCCR0=0x00; TCNT0=0x00; // 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: Off TCCR1A=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: Disconnected ASSR=0x00; TCCR2=0x00; TCNT2=0x00; OCR2=0x00; // External Interrupt(s) initialization // INT0: Off // INT1: Off MCUCR=0x00; // Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x00; // Analog Comparator initialization // Analog Comparator: Off // Analog Comparator Input Capture by Timer/Counter 1: Off ACSR=0x80; SFIOR=0x00; // LCD module initialization lcd_init(16); //**avalin namayeshe lcd lcd_puts(a); //**sefr kardane hame motaghayerha ghabl az shoro barname s1=0x30; m1=0x30; h1=0x30; s2=0x30; m2=0x30; h2=0x30; //**adade 30 hex barabare 0 dar kode aski ast va be hamin tartib 31 hex barabare 1 dar kode aski while (1) { // Place your code here //**dar sorati ke kelidi ke be pinc.0 vasl ast ke q mo'arefi shode feshar dahim q barabare sefr mishavad va sa@ yeki ziad mishavad if (q==0) { incr_h(); } //**dar sorati ke kelidi ke be pinc.1 vasl ast ke w mo'arefi shode feshar dahim w barabare sefr mishavad va daghighe yeki ziad mishavad if (w==0) { incr_m(); } if (s1<0x39) { s1+=1; //**in halghe s1 ra ta 9 bala mibarad } else { s1=0x30; //** s1 barabare sefr mishavad ta dar halghe badi 2bare shoro be shomaresh konad if (s2<0x35) { s2+=1; //**in halghe s2 ra ta 5 bala mibarad } else { s2=0x30; //** s2 barabare sefr mishavad ta dar halghe badi 2bare shoro be shomaresh konad if (m1<0x39) { m1+=1; } else { m1=0x30; if (m2<0x35) { m2+=1; } else { m2=0x30; if (h1<0x39) { h1+=1; } else { h1=0x30; if (h2<0x32) { h2+=1; } } } } } } //**chon dar sa@ 24 sa@ reset mishavad in shart ra gozashtim if (h2==0x32 && h1==0x34) { s1=0x30; m1=0x30; h1=0x30; s2=0x30; m2=0x30; h2=0x30; } //**bekhatere in ke ejraye dasturat khod zaman bar ast delay kamtar az 1s=1000ms entekhab shod delay_ms(820); //**adadha ra dar jaye khod migozarad a[7]=s1; a[6]=s2; a[4]=m1; a[3]=m2; a[1]=h1; a[0]=h2; //**lcd ra pak karde va a jadid ra minevisad lcd_clear(); lcd_puts(a); }; } [left][/left]