سلام
من یه برنامه ساعت با اتمگا 8 و ds1307 و سون سگمنت نوشتم
میخوام بدونم مشکل این برنامه چیه ؟
تو پروتئوس عالی کار میکنه ولی در عمل نه.
من یه برنامه ساعت با اتمگا 8 و ds1307 و سون سگمنت نوشتم
میخوام بدونم مشکل این برنامه چیه ؟
تو پروتئوس عالی کار میکنه ولی در عمل نه.
کد:
#include <mega8.h> #include <delay.h> // I2C Bus functions #asm .equ __i2c_port=0x12 ;PORTD .equ __sda_bit=1 .equ __scl_bit=0 #endasm #include <i2c.h> // DS1307 Real Time Clock functions #include <ds1307.h> // Declare your global variables here unsigned char H=0,M=0,S=0; //char hd[4],md[4],sd[4]; //unsigned int S,H,M; // Declare your global variables here unsigned char yekanM,dahganM,yekanH,dahganH; //,yekanS,dahganSint i, //*************************************************************** //*************************************************************** taghsim(){ //dahganS=S/10; //yekanS=S%10; dahganM=M/10; yekanM=M%10; dahganH=H/10; yekanH=H%10; } //************************************************************** //************************************************************** unsigned char coding(unsigned int data){ switch(data) { case 0: return 0x3f; break; case 1: return 0x06; break; case 2: return 0x5b; break; case 3: return 0x4f; break; case 4: return 0x66; break; case 5: return 0x6d; break; case 6: return 0x7d; break; case 7: return 0x07; break; case 8: return 0xff; break; case 9: return 0x6f; break; } } //************************************************** //************************************************** Display(){ /*PORTB=0b11111110; PORTD=coding(yekanS); delay_ms(10); PORTB=0b00111101; PORTD=coding(dahganS); delay_ms(10);*/ PORTC=0b11111110; PORTB=coding(yekanM); delay_ms(10); PORTC=0b10111101; PORTB=coding(dahganM); delay_ms(10); PORTC=0b11111011; PORTB=coding(yekanH); delay_ms(10); PORTC=0b11110111; PORTB=coding(dahganH); delay_ms(10); } void main(void) { // Declare your local variables here // Input/Output Ports initialization // Port B initialization // Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out // State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0 PORTB=0x00; DDRB=0xFF; // Port C initialization // Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out // State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0 PORTC=0x00; DDRC=0x7F; // 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=0x00; // Timer/Counter 0 initialization // Clock source: System Clock // Clock value: Timer 0 Stopped TCCR0=0x00; TCNT0=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 MCUCR=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 // Analog Comparator Output: Off ACSR=0x80; SFIOR=0x00; // I2C Bus initialization i2c_init(); // DS1307 Real Time Clock initialization // Square wave output on pin SQW/OUT: On // Square wave frequency: 1Hz rtc_init(0,1,0); while (1) { // Place your code here if(PIND.6==0) { //minute switch M++; if(M==60) M=0; rtc_set_time(H, M, S); while(PIND.6==0) { } taghsim(); Display(); } if(PIND.7==0) { //hour switch H++; if(H==24) H=0; rtc_set_time(H, M, S); while(PIND.7==0) { } taghsim(); Display(); } rtc_get_time(&H,&M,0); /*dahganM=M/10; yekanM=M%10; dahganH=H/10; yekanH=H%10; PORTB=0b01111100; PORTD=coding(yekanM); delay_ms(10); //rtc_set_time(H,M, 0); PORTB=0b10111100; PORTD=coding(dahganM); delay_ms(10); //rtc_set_time(H,M, 0); PORTB=0b11011100; PORTD=coding(yekanH); delay_ms(10); //rtc_set_time(H,M, 0); PORTB=0b11101100; PORTD=coding(dahganH); delay_ms(10);*/ //rtc_set_time(H,M, 0); taghsim(); Display(); //rtc_set_time(H,M, 0); }; }
دیدگاه