salam.....
projeye fareghotahsilim sakhte ye CALLER ID ke ye seri emkanate dige be joz namayeshe shomare telephon bayad dashte bashe ke yekish namayeshe zamane...
ba inke madaram to proteus kamelan dorost javab mide,nemidoonam ke chera sakhtafzaram javab nemide....
kasayee ke az in madar javab gereftan,khahesh mikonam rahnamayeem konan....
TNX...
projeye fareghotahsilim sakhte ye CALLER ID ke ye seri emkanate dige be joz namayeshe shomare telephon bayad dashte bashe ke yekish namayeshe zamane...
ba inke madaram to proteus kamelan dorost javab mide,nemidoonam ke chera sakhtafzaram javab nemide....
kasayee ke az in madar javab gereftan,khahesh mikonam rahnamayeem konan....
TNX...
کد:
/***************************************************** Chip type : ATmega16 Program type : Application Clock frequency : 8.000000 MHz Memory model : Small External SRAM size : 0 Data Stack size : 256 *****************************************************/ #include <mega16.h> #include <delay.h> #include<stdio.h> // I2C Bus functions #asm .equ __i2c_port=0x1B ;PORTA .equ __sda_bit=0 .equ __scl_bit=1 #endasm #include <i2c.h> // DS1307 Real Time Clock functions #include <ds1307.h> // Alphanumeric LCD Module functions #asm .equ __lcd_port=0x18 ;PORTB #endasm #include <lcd.h> // Declare your global variables here unsigned char hour,minute,second; char lcd1[16],lcd2[16]; unsigned char year,month,day; unsigned char key,keystate; struct days{ char d[4];} daysofweek[7]={{"Sun"},{"Mon"},{"Tue"},{"Wed"},{"Thu"},{"Fri"},{"Sat"}}; flash unsigned char Table[13]={0,0,3,3,6,1,4,6,2,5,0,3,5}; flash unsigned char miltable[6][12]={ {20,19,19,19,20,20,21,21,21,21,20,20}, {10,11,10,12,11,11,10,10,10,9,10,10}, {19,18,20,20,21,21,22,22,22,22,21,21}, {11,12,10,11,10,10,9,9,9,8,9,9}, {20,19,20,20,21,21,22,22,22,22,21,21}, {10,11,9,11,10,10,9,9,9,8,9,9}}; struct date{ unsigned char day; unsigned char month; unsigned char year; }; struct date shmdate,mildate ; /*************************************************************************/ void miltoshmcv(unsigned char ym,unsigned char mm,unsigned char dm) { unsigned char k,t1,t2; k=ym%4; if(k==3) k=2; k*=2; t1=miltable[k][mm-1]; t2=miltable[k+1][mm-1]; if(mm<3 || (mm==3 && dm<=miltable[k][mm-1])) shmdate.year = ym + 78; else shmdate.year = ym + 79; if(dm<=t1) { shmdate.day=dm+t2; shmdate.month=(mm+8)%12+1; } else { shmdate.day=dm-t1; shmdate.month=(mm+9)%12+1; } } /**********************************************************************/ char IsLeapYear(int Year) { Year=Year&0x0003; if(Year==0) return 1; else return 0; } ////////////// char GetDayofWeek(unsigned char CurrentYear,unsigned char Month,unsigned char Day) { unsigned int TempYear; unsigned char AccValue; TempYear = 1990;/*Comparation start with year 1990*/ AccValue = 0;/*Init AccValue to 0*/ /* If TempYear is a leap year AccValue +2, else AccValue+1 */ while(TempYear != (CurrentYear+2000)) { AccValue++; if(IsLeapYear(TempYear)) AccValue++; TempYear++; } if(Month > 2) { if(IsLeapYear(TempYear)==1) AccValue++; } AccValue += Table[Month]; AccValue += Day; AccValue= AccValue%7; return (AccValue); } /***************************************************************************/ void main(void) { // 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; // 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 // 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 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=0xFF; DDRD=0x00; // Timer/Counter 0 initialization // Clock source: System Clock // Clock value: Timer 0 Stopped // Mode: Normal top=FFh // OC0 output: Disconnected TCCR0=0x00; TCNT0=0x00; OCR0=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 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 // INT2: Off MCUCR=0x00; MCUCSR=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; // I2C Bus initialization i2c_init(); // DS1307 Real Time Clock initialization // Square wave output on pin SQW/OUT: Off // SQW/OUT pin state: 0 rtc_init(0,0,0); // LCD module initialization lcd_init(16); while (1) { rtc_get_time(&hour,&minute,&second); rtc_get_date(&day,&month,&year); miltoshmcv(year,month,day); key=PIND & 0b11111100; if (key!=keystate) { if (key!=0b11111100) { if (key==0xF8) //if key 1 pressed set the year { year++; if (year==100) year=0; } if (key==0xF4) //if key 2 pressed set the month { month++; if (month==13) month=1; } if (key==0xEC) //if key 3 pressed set the day { day++; if (day==32) day=1; } if (key==0xDC) //if key 4 pressed set the hour { hour++; if (hour==24) hour=0; } if (key==0xBC) //if key 5 pressed set the minute { minute++; if (minute==60) minute=0; } if (key==0x7C) //if key 6 pressed set the second { second++; if (second==60) second=0; } rtc_set_time(hour,minute,second); rtc_set_date(day,month,year); keystate=key; }else keystate=0b11111100; } //sprintf(lcd1,"%02u:%02u:%02u",hour,minute,second,); //sprintf(lcd2,"%02u/%02u/%02u",shmdate.year,shmdate.month,shmdate.day); sprintf(lcd1,"%02u/%02u/%02u ",shmdate.year,shmdate.month,shmdate.day); sprintf(lcd2,"%s %02u:%02u:%02u",daysofweek[GetDayofWeek(year,month,day)].d,hour,minute,second); lcd_clear(); lcd_gotoxy(0,0); lcd_puts(lcd1); lcd_gotoxy(0,1); lcd_puts(lcd2); delay_ms(100); }; } [img][/img]
دیدگاه