با سلام
تو این پروژه نحوه راه اندازی DS1307 و ( GLCD( KS0108 و جهت نمایش زمان و تاریخ و ایام هفته میلادی ارائه شده .
کامپایلر : CodeVisionAVR V2.05.3
توضیحات برنامه و اتصالات به صورت کامند داخل برنامه ارائه شده.
فایل برنامه:
RTC_DS1307_GLCD.rar
برنامه :
تو این پروژه نحوه راه اندازی DS1307 و ( GLCD( KS0108 و جهت نمایش زمان و تاریخ و ایام هفته میلادی ارائه شده .
کامپایلر : CodeVisionAVR V2.05.3
توضیحات برنامه و اتصالات به صورت کامند داخل برنامه ارائه شده.
فایل برنامه:
RTC_DS1307_GLCD.rar
برنامه :
کد:
#include <90usb162.h> // I2C Bus functions #include <i2c.h> // DS1307 Real Time Clock functions #include <ds1307.h> // Graphic LCD functions #include <glcd.h> /* include the prototype for sprintf */ #include <stdio.h> /* include the prototypes for the delay functions */ #include <delay.h> char display_buffer[17]; /* LCD display buffer for 1 line */ // Font used for displaying text // on the graphic LCD #include <font5x7.h> // Declare your global variables here void main(void) { // Declare your local variables here unsigned char hour,min,sec,week_day,day,month,year; char i,name[]="Mojtaba Rostami"; struct days{ char d[4];} daysofweek[7]={{"Sun"},{"Mon"},{"Tue"},{"Wed"},{"Thu"},{"Fri"},{"Sat"}}; // Graphic LCD initialization data GLCDINIT_t glcd_init_data; // Crystal Oscillator division factor: 1 #pragma optsize- CLKPR=0x80; CLKPR=0x00; #ifdef _OPTIMIZE_SIZE_ #pragma optsize+ #endif // I2C Bus initialization // I2C Port: PORTD // I2C SDA bit: 6 // I2C SCL bit: 7 // Bit Rate: 100 kHz // Note: I2C settings are specified in the // Project|Configure|C Compiler|Libraries|I2C menu. i2c_init(); // DS1307 Real Time Clock initialization // Square wave output on pin SQW/OUT: On // Square wave frequency: 1Hz rtc_init(0,1,0); /*note: to adjast the time and date delete the back slash then ste them*/ //rtc_set_time(16,54,0); /* set time 12:00:00 */ //rtc_set_date(2,3,13,12); /* set date Tuesday 1/02/2011 */ // Graphic LCD initialization // The KS0108 connections are specified in the // Project|Configure|C Compiler|Libraries|Graphic LCD menu: // DB0 - PORTB Bit 0 // DB1 - PORTB Bit 1 // DB2 - PORTB Bit 2 // DB3 - PORTB Bit 3 // DB4 - PORTB Bit 4 // DB5 - PORTB Bit 5 // DB6 - PORTB Bit 6 // DB7 - PORTB Bit 7 // E - PORTD Bit 2 // RD /WR - PORTD Bit 1 // RS - PORTD Bit 0 // /RST - PORTD Bit 5 // CS1 - PORTD Bit 3 // CS2 - PORTD Bit 4 // Specify the current font for displaying text glcd_init_data.font=font5x7; // No function is used for reading // image data from external memory glcd_init_data.readxmem=NULL; // No function is used for writing // image data to external memory glcd_init_data.writexmem=NULL; glcd_init(&glcd_init_data); //Turns LCD on glcd_display(1); //Sets the current background color:black(pixel --> off) glcd_setbkcolor(0); //Sets the current foreground color:white(pixel --> on) glcd_setcolor(1); //Clears the LCD glcd_clear(); //Specifies the current font used for displaying text glcd_setfont(font5x7) //start: glcd_outtextxy(0, 0, " In The Name Of Allah"); glcd_putcharxy(10, 15, ' '); //write a string on glcd with glcd_putchar function for(i=0;i<15;i++) glcd_putchar(name[i]); while (1) { /* read the time from the RTC */ rtc_get_time(&hour,&min,&sec); /* read the date from the RTC */ rtc_get_date(&week_day,&day,&month,&year); /* display the time on the LCD */ sprintf(display_buffer,"Time: %2d:%02d:%02d\n",hour,min,sec); glcd_outtextxy(0, 30,display_buffer); /* display the date on the LCD */ sprintf(display_buffer,"Date: %2d/%02d/%d",day,month,2000+year); glcd_outtextxy(0, 50,display_buffer); /* display the daysofweek on the LCD */ rtc_get_date(&week_day,&day,&month,&year); glcd_outtextxy(128-28, 50,daysofweek[week_day].d); } }