اطلاعیه

Collapse
No announcement yet.

ds1307

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    ds1307

    سلام

    کسی از دوستان برنامه خواندن از ds1307 داره؟البته به زبان c(بدون توابع کتابخانه ای )

    برنامه write درست اجرا شد ولی read هر کاری کردم نشد

    ممنون

    #2
    پاسخ : ds1307

    سلام


    #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;

    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 year,unsigned char month,unsigned char day)
    {
    unsigned char k,t1,t2;
    k=year%4;
    if(k==3)
    k=2;
    k*=2;
    t1=miltable[k][month-1];
    t2=miltable[k+1][month-1];
    if(month<3 || (month==3 && day<=miltable[k][month-1]))
    shmdate.year = year + 78;
    else
    shmdate.year = year + 79;

    if(day<=t1)
    {
    shmdate.day=day+t2;
    shmdate.month=(month+8)%12+1;
    }
    else
    {
    shmdate.day=day-t1;
    shmdate.month=(month+9)%12+1;
    }
    }
    /************************************************** ********************/

    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,minut e,second);
    sprintf(lcd2,"%02u/%02u/%02u",shmdate.year,shmdate.month,shmdate.day) ;

    lcd_clear();
    lcd_gotoxy(0,0);
    lcd_puts(lcd1);
    lcd_gotoxy(0,1);
    lcd_puts(lcd2);
    delay_ms(100);

    };
    }
    " علت هر شکستی عمل کردن بدون فکر است" الکس مکنزی


    [move](---> موسیقی ایرانی <---) [/move]

    دیدگاه


      #3
      پاسخ : ds1307

      ممنون از اینکه کمک کردید ولی شما از توابع کتابخانه ای استفاده کردید
      من بدون استفاده از توابع می خوام این کار بکنم

      دیدگاه


        #4
        پاسخ : ds1307

        وست عزیز وقتی کتابخانه اینکار براحتی در کد ویژن اینکار را برای شما انجام می دهد من نمی فهمم چرا شما نم خواهید از آن استفاده کنید مطمئنا راه رفته را دوباره کاری کردن عقب گرد است

        دیدگاه

        لطفا صبر کنید...
        X