Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- I did only the coding,but,it was fun project afterall
- this project with other 4 friends:
- Karim Gamal [email protected]
- Mohamed El-Halwagy [email protected]
- Mohamed Fawzy [email protected]
- Mohamed Farargy [email protected]
- me: [email protected] :)
- */
- /*****************************************************
- This program was produced by the
- CodeWizardAVR V2.03.4 Standard
- Automatic Program Generator
- © Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.
- http://www.hpinfotech.com
- Chip type : ATmega16
- Program type : Application
- Clock frequency : 4.000000 MHz
- Memory model : Small
- External RAM size : 0
- Data Stack size : 256
- *****************************************************/
- #include <mega16.h>
- #include<delay.h>
- // Declare your global variables here
- float rem=0.0;
- // Mapping digits to the 7segment where each bit maps a segment in the 7 segment
- int ar[]={(1<<6), //0
- (1<<0)| (1<<3)|(1<<4)|(1<<5)|(1<<6), //1
- (1<<2)|(1<<5), //2
- (1<<4)|(1<<5), //3
- (1<<0)|(1<<3)|(1<<4), //4
- (1<<1)|(1<<4), //5
- (1<<1),//6
- (1<<3)|(1<<4)|(1<<5)|(1<<6),//7
- 0,//8
- (1<<4)};
- int l[]={24,60,31,12,10000};//HH,MIN DD,MM,YYYY
- int d[5]={2,10,15,8,2010};
- int tenth[]={1,10,100,1000,10000};
- int mp[12];
- void disAll()
- {
- //G1:
- PORTA.0=PORTA.1=PORTA.2=PORTA.3=PORTA.4=PORTA.5=PORTA.6=1;
- PORTB.7=PORTB.6=PORTB.5=PORTB.4=0;
- //G2:
- PORTB.0=PORTB.3=PORTB.2=PORTB.1=1;
- PORTC.5=PORTC.6=PORTC.2=PORTC.3=PORTC.4=PORTC.7=PORTA.7=0;
- //G3:
- PORTD.2=PORTD.5=PORTD.4=PORTD.3=1;
- PORTC.5=PORTC.6=PORTD.6=PORTD.7=PORTC.0=PORTC.1=PORTC.7=0;
- }
- void sett()
- {
- int i,j,pos=0,x;
- int s[5]={2,2,2,2,4};
- for(i=0;i<5;i++)
- {
- for(j=0;j<s[i];j++)
- {
- mp[pos]=ar[9];
- x=d[i]%tenth[s[i]-j];
- x/=tenth[s[i]-j-1];
- //x=d[i]%((int)pow(10,s[i]-j));
- //x/=((int)pow(10,s[i]-j-1));
- mp[pos++]=ar[x%10]; //x
- // printf("%d ",x);
- }
- // printf("\n");
- }
- }
- void show()
- {
- int cur=0,i_i=0;
- for(i_i=0;i_i<100;i_i++)
- for(cur=0;cur<12;cur++)
- {
- disAll();
- if(0<=cur&&cur<=3)//G1
- {
- if(cur==0) PORTB.7=1;
- else if(cur==1) PORTB.6=1;
- else if(cur==2) PORTB.5=1;
- else PORTB.4=1;
- PORTA.0=(((mp[cur])&(1<<5)) ? 1:0);//A.0=f1
- delay_us(119);
- PORTA.0=1;
- PORTA.1=(((mp[cur])&(1<<6)) ? 1:0);//A.1=g1
- delay_us(119);
- PORTA.1=1;
- PORTA.2=(((mp[cur])&(1<<1)) ? 1:0);//A.2=b1
- delay_us(119);
- PORTA.2=1;
- PORTA.3=(((mp[cur])&(1<<0)) ? 1:0);//A.3=a1
- delay_us(119);
- PORTA.3=1;
- PORTA.4=(((mp[cur])&(1<<4)) ? 1:0);//A.4=e1
- delay_us(119);
- PORTA.4=1;
- PORTA.5=(((mp[cur])&(1<<3)) ? 1:0);//A.5=d1
- delay_us(119);
- PORTA.5=1;
- PORTA.6=(((mp[cur])&(1<<2)) ? 1:0);//A.5=c1
- delay_us(119);
- PORTA.6=1;
- }
- else if(4<=cur&&cur<=7)//G2
- {
- if(cur==4) PORTB.0=0;
- else if(cur==5) PORTB.3=0;
- else if(cur==6) PORTB.2=0;
- else PORTB.1=0;
- PORTC.5=!(((mp[cur])&(1<<0)) ? 1:0);//C.5=a2
- delay_us(119);
- PORTC.5=0;
- PORTC.6=!(((mp[cur])&(1<<1)) ? 1:0);//C.6=b2
- delay_us(119);
- PORTC.6=0;
- PORTC.2=!(((mp[cur])&(1<<2)) ? 1:0);//C.2=c2
- delay_us(119);
- PORTC.2=0;
- PORTC.3=!(((mp[cur])&(1<<3)) ? 1:0);//C.3=d2
- delay_us(119);
- PORTC.3=0;
- PORTC.4=!(((mp[cur])&(1<<4)) ? 1:0);//C.4=e2
- delay_us(119);
- PORTC.4=0;
- PORTA.7=!(((mp[cur])&(1<<5)) ? 1:0);//A.7=f2
- delay_us(119);
- PORTA.7=0;
- PORTC.7=!(((mp[cur])&(1<<6)) ? 1:0);//C.7=g2
- delay_us(119);
- PORTC.7=0;
- }
- else if(8<=cur&&cur<12) //G3
- {
- if(cur==8) PORTD.2=0;
- else if(cur==9) PORTD.5=0;
- else if(cur==10) PORTD.4=0;
- else PORTD.3=0;
- PORTC.5=!(((mp[cur])&(1<<0)) ? 1:0);//C.5=a3
- delay_us(119);
- PORTC.5=0;
- PORTC.6=!(((mp[cur])&(1<<1)) ? 1:0);//C.6=b3
- delay_us(119);
- PORTC.6=0;
- PORTD.6=!(((mp[cur])&(1<<2)) ? 1:0);//D.6=c3
- delay_us(119);
- PORTD.6=0;
- PORTD.7=!(((mp[cur])&(1<<3)) ? 1:0);//D.7=d3
- delay_us(119);
- PORTD.7=0;
- PORTC.0=!(((mp[cur])&(1<<4)) ? 1:0);//C.0=e3
- delay_us(119);
- PORTC.0=0;
- PORTC.1=!(((mp[cur])&(1<<5)) ? 1:0);//C.1=f3
- delay_us(119);
- PORTC.1=0;
- PORTC.7=!(((mp[cur])&(1<<6)) ? 1:0);//C.7=g3
- delay_us(119);
- PORTC.7=0;
- }
- }
- // (7*119*12*100)us/1000=999.6ms....0.4msec fasting per sec
- rem+=0.4;
- if(rem>=1.0)
- {
- rem-=1.0;
- delay_ms(1);
- }
- // */
- }
- void main(void)
- {
- // Declare your local variables here
- int j,i,i_i;
- int csec=0,cur=0;
- int dom[12]={31,28,31,30,31,30,31,31,30,31,30,31};
- // Input/Output Ports initialization
- // Port A 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
- PORTA=0x00;
- DDRA=0xFF;
- // 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
- // 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
- PORTC=0x00;
- DDRC=0xFF;
- // Port D initialization
- // Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=In Func0=In
- // State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=T State0=T
- PORTD=0x00;
- DDRD=0xFC;
- // 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
- // Timer 1 Overflow Interrupt: Off
- // Input Capture Interrupt: Off
- // Compare A Match Interrupt: Off
- // Compare B Match Interrupt: Off
- 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;
- d[0]=6;//hr
- d[1]=0;//min
- d[2]=6;//dd
- d[3]=9;//mm
- d[4]=2010;//year
- sett();
- // show();
- csec=0;
- while (1)
- {
- /* Test on g2&g3:gr8!
- for(cur=4;cur<8;cur++)
- {
- for(i=0;i<10;i++)
- {
- disAll();
- mp[cur]=ar[i];
- if(cur==4) PORTB.0=0;
- else if(cur==5) PORTB.3=0;
- else if(cur==6) PORTB.2=0;
- else PORTB.1=0;
- for(i_i=0;i_i<30;i_i++)
- {
- PORTC.5=!(((mp[cur])&(1<<0)) ? 1:0);//C.5=a2
- delay_ms(1);
- PORTC.5=0;
- PORTC.6=!(((mp[cur])&(1<<1)) ? 1:0);//C.6=b2
- delay_ms(1);
- PORTC.6=0;
- PORTC.2=!(((mp[cur])&(1<<2)) ? 1:0);//C.2=c2
- delay_ms(1);
- PORTC.2=0;
- PORTC.3=!(((mp[cur])&(1<<3)) ? 1:0);//C.3=d2
- delay_ms(1);
- PORTC.3=0;
- PORTC.4=!(((mp[cur])&(1<<4)) ? 1:0);//C.4=e2
- delay_ms(1);
- PORTC.4=0;
- PORTA.7=!(((mp[cur])&(1<<5)) ? 1:0);//A.7=f2
- delay_ms(1);
- PORTA.7=0;
- PORTC.7=!(((mp[cur])&(1<<6)) ? 1:0);//C.7=g2
- delay_ms(1);
- PORTC.7=0;
- }
- }
- }
- for(cur=8;cur<12;cur++)
- {
- for(i=0;i<10;i++)
- {
- disAll();
- mp[cur]=ar[i];
- // PORTD.2=PORTD.5=PORTD.4=PORTD.3=1;
- if(cur==8) PORTD.2=0;
- else if(cur==9) PORTD.5=0;
- else if(cur==10) PORTD.4=0;
- else PORTD.3=0;
- for(i_i=0;i_i<30;i_i++)
- {
- PORTC.5=!(((mp[cur])&(1<<0)) ? 1:0);//C.5=a3
- delay_ms(1);
- PORTC.5=0;
- PORTC.6=!(((mp[cur])&(1<<1)) ? 1:0);//C.6=b3
- delay_ms(1);
- PORTC.6=0;
- PORTD.6=!(((mp[cur])&(1<<2)) ? 1:0);//D.6=c3
- delay_ms(1);
- PORTD.6=0;
- PORTD.7=!(((mp[cur])&(1<<3)) ? 1:0);//D.7=d3
- delay_ms(1);
- PORTD.7=0;
- PORTC.0=!(((mp[cur])&(1<<4)) ? 1:0);//C.0=e3
- delay_ms(1);
- PORTC.0=0;
- PORTC.1=!(((mp[cur])&(1<<5)) ? 1:0);//C.1=f3
- delay_ms(1);
- PORTC.1=0;
- PORTC.7=!(((mp[cur])&(1<<6)) ? 1:0);//C.7=g3
- delay_ms(1);
- PORTC.7=0;
- }
- }
- }
- */
- // Place your code here
- ///*
- while(!(PIND.0|PIND.1))
- {
- show();
- csec++;
- if(csec>=60)
- {
- csec=0;d[1]++;//Min
- if(d[1]>=60) {d[1]=0;d[0]++;}//hour
- if(d[0]>=24) {d[0]=0;d[2]++;}//day
- if(d[2]>dom[d[3]]) {d[2]=1;d[3]++;}//Month
- if(d[3]>12) {d[3]=1;d[4]++;}//Year
- if(d[4]%4==0) dom[1]=29;
- else dom[1]=28;
- sett();
- }
- }
- j=0;
- delay_ms(2000);
- while(j<5)
- {
- if(PIND.0) {j++;delay_ms(500);}
- if(PIND.1)
- {
- d[j%5]=(d[j%5]+1)%l[j%5];
- sett();
- delay_ms(1000);
- show();
- }
- show();
- delay_ms(50);
- }
- delay_ms(1000);
- };
- }
Add Comment
Please, Sign In to add comment