دوستان عزیز سلام ، من برنامه ای رو که در زیر میارم نوشته ام ( تو کدویژن ) این برنامه تو پرتئوس درست کار میکنه ولی وقتی رو برد اجرا میکنم کار نمیکنه اصلا کلا کار نمیکنه ! هم AVR و هم DS 1307 رو عوض کردم نشد ! پورت ها رو عوض کردم بازم نشد ! باطری بکاپ هم نصب هستش ! لطفا کمک کنید
برنامه اینه :
#include <mega8.h>
#asm
.equ __i2c_port=0x15 ;PORTC
.equ __sda_bit=0
.equ __scl_bit=1
#endasm
#include <i2c.h>
#include <delay.h>
#include <ds1307.h>
// DS1307 Real Time Clock functions
#include <stdio.h>
#include <stdlib.h>
#asm
.equ __lcd_port=0x18 ;PORTB
#endasm
#include <lcd.h>
#define st PIND.1
#define up PINC.4
#define dw PINC.3
#define notused PORTD.5
#define rel PORTD.6
#define led_on PORTD.7
char buf[20];
unsigned int ledbk;
unsigned char on;
unsigned char hour;
unsigned char min;
unsigned char sec;
unsigned char a;
unsigned char cunt=1;
char ho11,ho21,hf11,hf21,mo11,mo21,mf11,mf21;
eeprom char ho1,ho2,hf1,hf2,mo1,mo2,mf1,mf2;
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
led_on=0;
if (cunt==1){min++;if (min>59){min=0;}}
if (cunt==2){hour++;if (hour>23){hour=0;}}
if (cunt==3){mo11++;if (mo11>59){mo11=0;}}
if (cunt==4){ho11++;if (ho11>23){ho11=0;}}
if (cunt==5){mf11++;if (mf11>59){mf11=0;}}
if (cunt==6){hf11++;if (hf11>23){hf11=0;}}
if (cunt==7){mo21++;if (mo21>59){mo21=0;}}
if (cunt==8){ho21++;if (ho21>23){ho21=0;}}
if (cunt==9){mf21++;if (mf21>59){mf21=0;}}
if (cunt==10){hf21++;if (hf21>23){hf21=0;}}
delay_ms(15);
}
// External Interrupt 1 service routine
interrupt [EXT_INT1] void ext_int1_isr(void)
{
led_on=0;
if (cunt==1){if(min>0){min--;}}
if (cunt==2){if(hour>0){hour--;}}
if (cunt==3){if(mo11>0){mo11--;}}
if (cunt==4){if(ho11>0){ho11--;}}
if (cunt==5){if(mf11>0){mf11--;}}
if (cunt==6){if(hf11>0){hf11--;}}
if (cunt==7){if(mo21>0){mo21--;}}
if (cunt==8){if(ho21>0){ho21--;}}
if (cunt==9){if(mf21>0){mf21--;}}
if (cunt==10){if(hf21>0){hf21--;}}
delay_ms(15);
}
// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
if(led_on==0){
ledbk++;
if(ledbk>4000){
ledbk=0;
on++;
if(on>15){
on=0;
led_on=1;
}}}
}
// Declare your global variables here
//////////////////////////////////
//RTC
void get_rtc(void){
rtc_get_time(&hour,&min,&sec);
}
//////////////////////////////////
//Display
void display(void){
lcd_gotoxy(0,0);
sprintf(buf,"TIME: %02u:%02u:%02u",hour,min,sec);
lcd_puts(buf);
lcd_gotoxy(0,1);
lcd_putsf("PRESS & HOLD SET"
;
}
//////////////////////////////////
//check
void chek(void){
if (hour==ho11 & min==mo11){rel=1;}
if (hour==ho21 & min==mo21){rel=1;}
if (hour==hf11 & min==mf11){rel=0;}
if (hour==hf21 & min==mf21){rel=0;}
}
//////////////////////////////////
//SET
void set(void){
if (st==1){
led_on=0;
delay_ms(100);
a=0;
lcd_clear();
while(a<100){
if (st==1){cunt++;delay_ms(150); }
if(cunt>11){cunt=0;}
delay_ms(100);
switch (cunt) {
//
case 1:
lcd_gotoxy(0,0);
sprintf(buf,"TIME: %02u:%02u:%02u",hour,min,sec);
lcd_puts(buf);
delay_ms(30);
lcd_gotoxy(0,0);
sprintf(buf,"TIME: %02u: :%02u",hour,sec);
lcd_puts(buf);
delay_ms(50);
break;
//
case 2:
lcd_gotoxy(0,0);
sprintf(buf,"TIME: %02u:%02u:%02u",hour,min,sec);
lcd_puts(buf);
delay_ms(30);
lcd_gotoxy(0,0);
sprintf(buf,"TIME: :%02u:%02u",min,sec);
lcd_puts(buf);
delay_ms(50);
break;
//
case 3:
lcd_gotoxy(0,0);
sprintf(buf,"TIME-ON1: %02u:%02u",ho11,mo11);
lcd_puts(buf);
delay_ms(30);
lcd_gotoxy(0,0);
sprintf(buf,"TIME-ON1: %02u: ",ho11);
lcd_puts(buf);
delay_ms(50);
break;
//
case 4:
lcd_gotoxy(0,0);
sprintf(buf,"TIME-ON1: %02u:%02u",ho11,mo11);
lcd_puts(buf);
delay_ms(30);
lcd_gotoxy(0,0);
sprintf(buf,"TIME-ON1: :%02u",mo11);
lcd_puts(buf);
delay_ms(50);
break;
//
case 5:
lcd_gotoxy(0,0);
sprintf(buf,"TIME-OFF1: %02u:%02u",hf11,mf11);
lcd_puts(buf);
delay_ms(30);
lcd_gotoxy(0,0);
sprintf(buf,"TIME-OFF1: %02u: ",hf11);
lcd_puts(buf);
delay_ms(50);
break;
//
case 6:
lcd_gotoxy(0,0);
sprintf(buf,"TIME-OFF1: %02u:%02u",hf11,mf11);
lcd_puts(buf);
delay_ms(30);
lcd_gotoxy(0,0);
sprintf(buf,"TIME-OFF1: :%02u",mf11);
lcd_puts(buf);
delay_ms(50);
break;
//
case 7:
lcd_gotoxy(0,0);
sprintf(buf,"TIME-ON2: %02u:%02u",ho21,mo21);
lcd_puts(buf);
delay_ms(30);
lcd_gotoxy(0,0);
sprintf(buf,"TIME-ON2: %02u: ",ho21);
lcd_puts(buf);
delay_ms(50);
break;
//
case 8:
lcd_gotoxy(0,0);
sprintf(buf,"TIME-ON2: %02u:%02u",ho21,mo21);
lcd_puts(buf);
delay_ms(30);
lcd_gotoxy(0,0);
sprintf(buf,"TIME-ON2: :%02u",mo21);
lcd_puts(buf);
delay_ms(50);
break;
//
case 9:
lcd_gotoxy(0,0);
sprintf(buf,"TIME-OFF2: %02u:%02u",hf21,mf21);
lcd_puts(buf);
delay_ms(30);
lcd_gotoxy(0,0);
sprintf(buf,"TIME-OFF2: %02u: ",hf21);
lcd_puts(buf);
delay_ms(50);
break;
//
case 10:
lcd_gotoxy(0,0);
sprintf(buf,"TIME-OFF2: %02u:%02u",hf21,mf21);
lcd_puts(buf);
delay_ms(30);
lcd_gotoxy(0,0);
sprintf(buf,"TIME-OFF2: :%02u",mf21);
lcd_puts(buf);
delay_ms(50);
break;
//
case 11:
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("SAVING."
;
delay_ms(500);
lcd_gotoxy(0,0);
lcd_putsf("SAVING.."
;
delay_ms(500);
lcd_gotoxy(0,0);
lcd_putsf("SAVING..."
;
cunt=0;
a=253; //shart az bein rafte va az halgheh kharej mishavim.
ho1=ho11;mo1=mo11;hf1=hf11;mf1=mf11;ho2=ho21;mo2=m o21;hf2=hf21;mf1=mf21;
delay_ms(500);
rtc_set_time(hour,min,sec);
delay_ms(10);
break;
delay_ms(10);
}
}
}
}
/////////////////////////////////////
void main(void)
{
PORTB=0x00;
DDRB=0x00;
PORTC=0x00;
DDRC=0xFF;
PORTD=0x00;
DDRD=0xE0;
TCCR0=0x01;
TCNT0=0xFF;
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
GICR|=0xC0;
MCUCR=0x0F;
GIFR=0xC0;
TIMSK=0x01;
ACSR=0x80;
SFIOR=0x00;
i2c_init();
rtc_init(0,0,0);
lcd_init(16);
led_on=0;
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("LOADING."
;
delay_ms(500);
lcd_gotoxy(0,0);
lcd_putsf("LOADING.."
;
delay_ms(500);
lcd_gotoxy(0,0);
lcd_putsf("LOADING..."
;
ho11=ho1;mo11=mo1;hf11=hf1;mf11=mf1;ho21=ho2;mo21= mo2;hf21=hf2;mf21=mf2;
delay_ms(500);
lcd_clear();
#asm("sei"
while (1)
{
get_rtc();
display();
set();
chek();
delay_ms(10);
};
}
برنامه اینه :
#include <mega8.h>
#asm
.equ __i2c_port=0x15 ;PORTC
.equ __sda_bit=0
.equ __scl_bit=1
#endasm
#include <i2c.h>
#include <delay.h>
#include <ds1307.h>
// DS1307 Real Time Clock functions
#include <stdio.h>
#include <stdlib.h>
#asm
.equ __lcd_port=0x18 ;PORTB
#endasm
#include <lcd.h>
#define st PIND.1
#define up PINC.4
#define dw PINC.3
#define notused PORTD.5
#define rel PORTD.6
#define led_on PORTD.7
char buf[20];
unsigned int ledbk;
unsigned char on;
unsigned char hour;
unsigned char min;
unsigned char sec;
unsigned char a;
unsigned char cunt=1;
char ho11,ho21,hf11,hf21,mo11,mo21,mf11,mf21;
eeprom char ho1,ho2,hf1,hf2,mo1,mo2,mf1,mf2;
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
led_on=0;
if (cunt==1){min++;if (min>59){min=0;}}
if (cunt==2){hour++;if (hour>23){hour=0;}}
if (cunt==3){mo11++;if (mo11>59){mo11=0;}}
if (cunt==4){ho11++;if (ho11>23){ho11=0;}}
if (cunt==5){mf11++;if (mf11>59){mf11=0;}}
if (cunt==6){hf11++;if (hf11>23){hf11=0;}}
if (cunt==7){mo21++;if (mo21>59){mo21=0;}}
if (cunt==8){ho21++;if (ho21>23){ho21=0;}}
if (cunt==9){mf21++;if (mf21>59){mf21=0;}}
if (cunt==10){hf21++;if (hf21>23){hf21=0;}}
delay_ms(15);
}
// External Interrupt 1 service routine
interrupt [EXT_INT1] void ext_int1_isr(void)
{
led_on=0;
if (cunt==1){if(min>0){min--;}}
if (cunt==2){if(hour>0){hour--;}}
if (cunt==3){if(mo11>0){mo11--;}}
if (cunt==4){if(ho11>0){ho11--;}}
if (cunt==5){if(mf11>0){mf11--;}}
if (cunt==6){if(hf11>0){hf11--;}}
if (cunt==7){if(mo21>0){mo21--;}}
if (cunt==8){if(ho21>0){ho21--;}}
if (cunt==9){if(mf21>0){mf21--;}}
if (cunt==10){if(hf21>0){hf21--;}}
delay_ms(15);
}
// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
if(led_on==0){
ledbk++;
if(ledbk>4000){
ledbk=0;
on++;
if(on>15){
on=0;
led_on=1;
}}}
}
// Declare your global variables here
//////////////////////////////////
//RTC
void get_rtc(void){
rtc_get_time(&hour,&min,&sec);
}
//////////////////////////////////
//Display
void display(void){
lcd_gotoxy(0,0);
sprintf(buf,"TIME: %02u:%02u:%02u",hour,min,sec);
lcd_puts(buf);
lcd_gotoxy(0,1);
lcd_putsf("PRESS & HOLD SET"

}
//////////////////////////////////
//check
void chek(void){
if (hour==ho11 & min==mo11){rel=1;}
if (hour==ho21 & min==mo21){rel=1;}
if (hour==hf11 & min==mf11){rel=0;}
if (hour==hf21 & min==mf21){rel=0;}
}
//////////////////////////////////
//SET
void set(void){
if (st==1){
led_on=0;
delay_ms(100);
a=0;
lcd_clear();
while(a<100){
if (st==1){cunt++;delay_ms(150); }
if(cunt>11){cunt=0;}
delay_ms(100);
switch (cunt) {
//
case 1:
lcd_gotoxy(0,0);
sprintf(buf,"TIME: %02u:%02u:%02u",hour,min,sec);
lcd_puts(buf);
delay_ms(30);
lcd_gotoxy(0,0);
sprintf(buf,"TIME: %02u: :%02u",hour,sec);
lcd_puts(buf);
delay_ms(50);
break;
//
case 2:
lcd_gotoxy(0,0);
sprintf(buf,"TIME: %02u:%02u:%02u",hour,min,sec);
lcd_puts(buf);
delay_ms(30);
lcd_gotoxy(0,0);
sprintf(buf,"TIME: :%02u:%02u",min,sec);
lcd_puts(buf);
delay_ms(50);
break;
//
case 3:
lcd_gotoxy(0,0);
sprintf(buf,"TIME-ON1: %02u:%02u",ho11,mo11);
lcd_puts(buf);
delay_ms(30);
lcd_gotoxy(0,0);
sprintf(buf,"TIME-ON1: %02u: ",ho11);
lcd_puts(buf);
delay_ms(50);
break;
//
case 4:
lcd_gotoxy(0,0);
sprintf(buf,"TIME-ON1: %02u:%02u",ho11,mo11);
lcd_puts(buf);
delay_ms(30);
lcd_gotoxy(0,0);
sprintf(buf,"TIME-ON1: :%02u",mo11);
lcd_puts(buf);
delay_ms(50);
break;
//
case 5:
lcd_gotoxy(0,0);
sprintf(buf,"TIME-OFF1: %02u:%02u",hf11,mf11);
lcd_puts(buf);
delay_ms(30);
lcd_gotoxy(0,0);
sprintf(buf,"TIME-OFF1: %02u: ",hf11);
lcd_puts(buf);
delay_ms(50);
break;
//
case 6:
lcd_gotoxy(0,0);
sprintf(buf,"TIME-OFF1: %02u:%02u",hf11,mf11);
lcd_puts(buf);
delay_ms(30);
lcd_gotoxy(0,0);
sprintf(buf,"TIME-OFF1: :%02u",mf11);
lcd_puts(buf);
delay_ms(50);
break;
//
case 7:
lcd_gotoxy(0,0);
sprintf(buf,"TIME-ON2: %02u:%02u",ho21,mo21);
lcd_puts(buf);
delay_ms(30);
lcd_gotoxy(0,0);
sprintf(buf,"TIME-ON2: %02u: ",ho21);
lcd_puts(buf);
delay_ms(50);
break;
//
case 8:
lcd_gotoxy(0,0);
sprintf(buf,"TIME-ON2: %02u:%02u",ho21,mo21);
lcd_puts(buf);
delay_ms(30);
lcd_gotoxy(0,0);
sprintf(buf,"TIME-ON2: :%02u",mo21);
lcd_puts(buf);
delay_ms(50);
break;
//
case 9:
lcd_gotoxy(0,0);
sprintf(buf,"TIME-OFF2: %02u:%02u",hf21,mf21);
lcd_puts(buf);
delay_ms(30);
lcd_gotoxy(0,0);
sprintf(buf,"TIME-OFF2: %02u: ",hf21);
lcd_puts(buf);
delay_ms(50);
break;
//
case 10:
lcd_gotoxy(0,0);
sprintf(buf,"TIME-OFF2: %02u:%02u",hf21,mf21);
lcd_puts(buf);
delay_ms(30);
lcd_gotoxy(0,0);
sprintf(buf,"TIME-OFF2: :%02u",mf21);
lcd_puts(buf);
delay_ms(50);
break;
//
case 11:
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("SAVING."

delay_ms(500);
lcd_gotoxy(0,0);
lcd_putsf("SAVING.."

delay_ms(500);
lcd_gotoxy(0,0);
lcd_putsf("SAVING..."

cunt=0;
a=253; //shart az bein rafte va az halgheh kharej mishavim.
ho1=ho11;mo1=mo11;hf1=hf11;mf1=mf11;ho2=ho21;mo2=m o21;hf2=hf21;mf1=mf21;
delay_ms(500);
rtc_set_time(hour,min,sec);
delay_ms(10);
break;
delay_ms(10);
}
}
}
}
/////////////////////////////////////
void main(void)
{
PORTB=0x00;
DDRB=0x00;
PORTC=0x00;
DDRC=0xFF;
PORTD=0x00;
DDRD=0xE0;
TCCR0=0x01;
TCNT0=0xFF;
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
GICR|=0xC0;
MCUCR=0x0F;
GIFR=0xC0;
TIMSK=0x01;
ACSR=0x80;
SFIOR=0x00;
i2c_init();
rtc_init(0,0,0);
lcd_init(16);
led_on=0;
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("LOADING."

delay_ms(500);
lcd_gotoxy(0,0);
lcd_putsf("LOADING.."

delay_ms(500);
lcd_gotoxy(0,0);
lcd_putsf("LOADING..."

ho11=ho1;mo11=mo1;hf11=hf1;mf11=mf1;ho21=ho2;mo21= mo2;hf21=hf2;mf21=mf2;
delay_ms(500);
lcd_clear();
#asm("sei"

while (1)
{
get_rtc();
display();
set();
chek();
delay_ms(10);
};
}
دیدگاه