:cry:من چند وقت روی ساخت ساعت با 1307 کار میکنم اما نتیجه ای نگرفتم ساعت من از 6 سون سگمنت ساخته شده که برنامه آن به شرح زیر است
#include <mega16.h>
#include <delay.h>
#include<stdio.h>
#include<math.h>
#define xtal 8000000
// I2C Bus functions
#asm
.equ __i2c_port=0x15 ;PORTC
.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;
unsigned char yd[10]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x0 9};
unsigned char dd[10]={0x00,0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80,0x9 0};
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=0xff;
// 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=0xff;
// 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=0xff;
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=0xff;
// 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;
ACSR=0x80;
SFIOR=0x00;
i2c_init();
rtc_init(0,0,0);
// LCD module initialization
//lcd_init(16);
while (1)
{
char sa,sb,ma,mb,ca,cb;
rtc_get_time(&hour,&minute,&second);
rtc_get_date(&day,&month,&year);
//miltoshmcv(year,month,day);
//key=PINC & 0b11111100;
//if (key!=keystate)
//{
// if (key!=0b11111100)
// {
if (PINC.5==0) //if key 2 pressed set the month
{
month++;
if (month==13)
month=1;
}
if (PINC.4==0) //if key 3 pressed set the day
{
day++;
if (day==32)
day=1;
}
if (PINC.2==0) //if key 4 pressed set the hour
{
hour++;
if (hour==24)
hour=0;
}
if (PINC.3==0) //if key 5 pressed set the minute
{
minute++;
if (minute==60)
minute=0;
}
rtc_set_time(hour,minute,second);
rtc_set_date(day,month,year);
//}else
// keystate=0b11111100;
if(second==0){
sa=day%10;
sb=(day-sa)/10;
ma=month%10;
mb=(month-ma)/10;
ca=year%10;
cb=(year-ca)/10;
}else
{
sa=second%10;
sb=(second-sa)/10;
ma=minute%10;
mb=(minute-ma)/10;
ca=hour%10;
cb=(hour-ca)/10;
}
PORTA=(dd[sa]|yd[sb]);
PORTD=(dd[ma]|yd[mb]);
PORTB=(dd[cb]|yd[ca]);
if(second==0){
if(minute==30){
delay_ms(500);
} }
// 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);
}
}
من برای هر سون سگمنت یک 4511قرار دادم وبدون 1307 با rtcداخل میکرو به راحتی کار میکند ولی با1307 بروی سون سگمنتها به ترتیب 05:07:07نمایش داده می شود لطفا به من کمک کنید[img][/img]
#include <mega16.h>
#include <delay.h>
#include<stdio.h>
#include<math.h>
#define xtal 8000000
// I2C Bus functions
#asm
.equ __i2c_port=0x15 ;PORTC
.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;
unsigned char yd[10]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x0 9};
unsigned char dd[10]={0x00,0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80,0x9 0};
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=0xff;
// 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=0xff;
// 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=0xff;
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=0xff;
// 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;
ACSR=0x80;
SFIOR=0x00;
i2c_init();
rtc_init(0,0,0);
// LCD module initialization
//lcd_init(16);
while (1)
{
char sa,sb,ma,mb,ca,cb;
rtc_get_time(&hour,&minute,&second);
rtc_get_date(&day,&month,&year);
//miltoshmcv(year,month,day);
//key=PINC & 0b11111100;
//if (key!=keystate)
//{
// if (key!=0b11111100)
// {
if (PINC.5==0) //if key 2 pressed set the month
{
month++;
if (month==13)
month=1;
}
if (PINC.4==0) //if key 3 pressed set the day
{
day++;
if (day==32)
day=1;
}
if (PINC.2==0) //if key 4 pressed set the hour
{
hour++;
if (hour==24)
hour=0;
}
if (PINC.3==0) //if key 5 pressed set the minute
{
minute++;
if (minute==60)
minute=0;
}
rtc_set_time(hour,minute,second);
rtc_set_date(day,month,year);
//}else
// keystate=0b11111100;
if(second==0){
sa=day%10;
sb=(day-sa)/10;
ma=month%10;
mb=(month-ma)/10;
ca=year%10;
cb=(year-ca)/10;
}else
{
sa=second%10;
sb=(second-sa)/10;
ma=minute%10;
mb=(minute-ma)/10;
ca=hour%10;
cb=(hour-ca)/10;
}
PORTA=(dd[sa]|yd[sb]);
PORTD=(dd[ma]|yd[mb]);
PORTB=(dd[cb]|yd[ca]);
if(second==0){
if(minute==30){
delay_ms(500);
} }
// 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);
}
}
من برای هر سون سگمنت یک 4511قرار دادم وبدون 1307 با rtcداخل میکرو به راحتی کار میکند ولی با1307 بروی سون سگمنتها به ترتیب 05:07:07نمایش داده می شود لطفا به من کمک کنید[img][/img]
دیدگاه