yoga1290

yoga1290

Mar 28th, 2011
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.89 KB | None | 0 0
  1. /*
  2. I did only the coding,but,it was fun project afterall
  3. this project with other 4 friends:
  4.     Karim Gamal     [email protected]
  5.     Mohamed El-Halwagy  [email protected]
  6.     Mohamed Fawzy       [email protected]
  7.     Mohamed Farargy     [email protected]
  8. */
  9. /*****************************************************
  10. This program was produced by the
  11. CodeWizardAVR V2.03.4 Standard
  12. Automatic Program Generator
  13. © Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.
  14. http://www.hpinfotech.com
  15.  
  16.  
  17.  
  18. Chip type           : ATmega16
  19. Program type        : Application
  20. Clock frequency     : 4.000000 MHz
  21. Memory model        : Small
  22. External RAM size   : 0
  23. Data Stack size     : 256
  24. *****************************************************/
  25.  
  26. #include <mega16.h>
  27. #include<delay.h>
  28. // Declare your global variables here
  29. float rem=0.0;
  30. // Mapping digits to the 7segment where each bit maps a segment in the 7 segment
  31. int ar[]={(1<<6), //0
  32.               (1<<0)|       (1<<3)|(1<<4)|(1<<5)|(1<<6), //1
  33.               (1<<2)|(1<<5), //2
  34.               (1<<4)|(1<<5), //3
  35.               (1<<0)|(1<<3)|(1<<4), //4
  36.               (1<<1)|(1<<4), //5
  37.               (1<<1),//6
  38.               (1<<3)|(1<<4)|(1<<5)|(1<<6),//7
  39.               0,//8
  40.               (1<<4)};
  41.     int l[]={24,60,31,12,10000};//HH,MIN  DD,MM,YYYY
  42.     int d[5]={2,10,15,8,2010};
  43.     int tenth[]={1,10,100,1000,10000};
  44.     int mp[12];
  45. void disAll()
  46. {
  47.             //G1:
  48.             PORTA.0=PORTA.1=PORTA.2=PORTA.3=PORTA.4=PORTA.5=PORTA.6=1;
  49.             PORTB.7=PORTB.6=PORTB.5=PORTB.4=0;
  50.    
  51.             //G2:
  52.             PORTB.0=PORTB.3=PORTB.2=PORTB.1=1;
  53.             PORTC.5=PORTC.6=PORTC.2=PORTC.3=PORTC.4=PORTC.7=PORTA.7=0;
  54.    
  55.             //G3:
  56.             PORTD.2=PORTD.5=PORTD.4=PORTD.3=1;
  57.             PORTC.5=PORTC.6=PORTD.6=PORTD.7=PORTC.0=PORTC.1=PORTC.7=0;
  58. }
  59. void sett()
  60. {
  61.     int i,j,pos=0,x;
  62.     int s[5]={2,2,2,2,4};
  63.     for(i=0;i<5;i++)
  64.         {
  65.             for(j=0;j<s[i];j++)
  66.             {
  67.                 mp[pos]=ar[9];
  68.                 x=d[i]%tenth[s[i]-j];
  69.                 x/=tenth[s[i]-j-1];
  70.                 //x=d[i]%((int)pow(10,s[i]-j));
  71.                 //x/=((int)pow(10,s[i]-j-1));
  72.                 mp[pos++]=ar[x%10]; //x
  73.         //        printf("%d ",x);
  74.             }
  75.           //  printf("\n");
  76.         }
  77. }
  78. void show()
  79. {
  80.     int cur=0,i_i=0;
  81.     for(i_i=0;i_i<100;i_i++)  
  82.         for(cur=0;cur<12;cur++)
  83.         {
  84.             disAll();
  85.             if(0<=cur&&cur<=3)//G1
  86.             {
  87.                 if(cur==0)  PORTB.7=1;
  88.                 else if(cur==1) PORTB.6=1;
  89.                 else if(cur==2) PORTB.5=1;
  90.                 else    PORTB.4=1;
  91.                         PORTA.0=(((mp[cur])&(1<<5)) ? 1:0);//A.0=f1
  92.                         delay_us(119);
  93.                         PORTA.0=1;
  94.                        
  95.                         PORTA.1=(((mp[cur])&(1<<6)) ? 1:0);//A.1=g1
  96.                         delay_us(119);
  97.                         PORTA.1=1;
  98.                        
  99.                         PORTA.2=(((mp[cur])&(1<<1)) ? 1:0);//A.2=b1
  100.                         delay_us(119);
  101.                         PORTA.2=1;
  102.                        
  103.                         PORTA.3=(((mp[cur])&(1<<0)) ? 1:0);//A.3=a1
  104.                         delay_us(119);
  105.                         PORTA.3=1;
  106.                        
  107.                         PORTA.4=(((mp[cur])&(1<<4)) ? 1:0);//A.4=e1
  108.                         delay_us(119);
  109.                         PORTA.4=1;
  110.                        
  111.                         PORTA.5=(((mp[cur])&(1<<3)) ? 1:0);//A.5=d1
  112.                         delay_us(119);
  113.                         PORTA.5=1;
  114.                        
  115.                         PORTA.6=(((mp[cur])&(1<<2)) ? 1:0);//A.5=c1
  116.                         delay_us(119);
  117.                         PORTA.6=1;
  118.             }
  119.             else if(4<=cur&&cur<=7)//G2
  120.             {
  121.                 if(cur==4)  PORTB.0=0;
  122.                 else if(cur==5) PORTB.3=0;
  123.                 else if(cur==6) PORTB.2=0;
  124.                 else    PORTB.1=0;
  125.                         PORTC.5=!(((mp[cur])&(1<<0)) ? 1:0);//C.5=a2
  126.                         delay_us(119);
  127.                         PORTC.5=0;
  128.                    
  129.                         PORTC.6=!(((mp[cur])&(1<<1)) ? 1:0);//C.6=b2
  130.                         delay_us(119);
  131.                         PORTC.6=0;
  132.                    
  133.                         PORTC.2=!(((mp[cur])&(1<<2)) ? 1:0);//C.2=c2
  134.                         delay_us(119);
  135.                         PORTC.2=0;
  136.                    
  137.                         PORTC.3=!(((mp[cur])&(1<<3)) ? 1:0);//C.3=d2
  138.                         delay_us(119);
  139.                         PORTC.3=0;
  140.                    
  141.                         PORTC.4=!(((mp[cur])&(1<<4)) ? 1:0);//C.4=e2
  142.                         delay_us(119);
  143.                         PORTC.4=0;
  144.                    
  145.                         PORTA.7=!(((mp[cur])&(1<<5)) ? 1:0);//A.7=f2
  146.                         delay_us(119);
  147.                         PORTA.7=0;
  148.                    
  149.                         PORTC.7=!(((mp[cur])&(1<<6)) ? 1:0);//C.7=g2
  150.                         delay_us(119);
  151.                         PORTC.7=0;
  152.             }
  153.             else if(8<=cur&&cur<12) //G3
  154.             {
  155.                 if(cur==8)  PORTD.2=0;
  156.                 else if(cur==9) PORTD.5=0;
  157.                 else if(cur==10) PORTD.4=0;
  158.                 else    PORTD.3=0;
  159.                       PORTC.5=!(((mp[cur])&(1<<0)) ? 1:0);//C.5=a3
  160.                       delay_us(119);
  161.                       PORTC.5=0;
  162.                      
  163.                       PORTC.6=!(((mp[cur])&(1<<1)) ? 1:0);//C.6=b3
  164.                       delay_us(119);
  165.                       PORTC.6=0;
  166.                      
  167.                       PORTD.6=!(((mp[cur])&(1<<2)) ? 1:0);//D.6=c3
  168.                       delay_us(119);
  169.                       PORTD.6=0;
  170.                      
  171.                       PORTD.7=!(((mp[cur])&(1<<3)) ? 1:0);//D.7=d3
  172.                       delay_us(119);
  173.                       PORTD.7=0;
  174.                      
  175.                       PORTC.0=!(((mp[cur])&(1<<4)) ? 1:0);//C.0=e3
  176.                       delay_us(119);
  177.                       PORTC.0=0;
  178.                      
  179.                       PORTC.1=!(((mp[cur])&(1<<5)) ? 1:0);//C.1=f3
  180.                       delay_us(119);
  181.                       PORTC.1=0;
  182.                      
  183.                       PORTC.7=!(((mp[cur])&(1<<6)) ? 1:0);//C.7=g3
  184.                       delay_us(119);
  185.                       PORTC.7=0;
  186.             }
  187.         }
  188.  
  189.         // (7*119*12*100)us/1000=999.6ms....0.4msec fasting per sec
  190.         rem+=0.4;
  191.         if(rem>=1.0)
  192.         {
  193.             rem-=1.0;
  194.             delay_ms(1);
  195.         }
  196.  //        */
  197. }
  198. void main(void)
  199. {
  200. // Declare your local variables here
  201.   int j,i,i_i;
  202. int csec=0,cur=0;
  203. int dom[12]={31,28,31,30,31,30,31,31,30,31,30,31};
  204. // Input/Output Ports initialization
  205. // Port A initialization
  206. // Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
  207. // State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
  208. PORTA=0x00;
  209. DDRA=0xFF;
  210.  
  211. // Port B initialization
  212. // Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
  213. // State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
  214. PORTB=0x00;
  215. DDRB=0xFF;
  216.  
  217. // Port C initialization
  218. // Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
  219. // State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
  220. PORTC=0x00;
  221. DDRC=0xFF;
  222.  
  223. // Port D initialization
  224. // Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=In Func0=In
  225. // State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=T State0=T
  226. PORTD=0x00;
  227. DDRD=0xFC;
  228.  
  229. // Timer/Counter 0 initialization
  230. // Clock source: System Clock
  231. // Clock value: Timer 0 Stopped
  232. // Mode: Normal top=FFh
  233. // OC0 output: Disconnected
  234. TCCR0=0x00;
  235. TCNT0=0x00;
  236. OCR0=0x00;
  237.  
  238. // Timer/Counter 1 initialization
  239. // Clock source: System Clock
  240. // Clock value: Timer 1 Stopped
  241. // Mode: Normal top=FFFFh
  242. // OC1A output: Discon.
  243. // OC1B output: Discon.
  244. // Noise Canceler: Off
  245. // Input Capture on Falling Edge
  246. // Timer 1 Overflow Interrupt: Off
  247. // Input Capture Interrupt: Off
  248. // Compare A Match Interrupt: Off
  249. // Compare B Match Interrupt: Off
  250. TCCR1A=0x00;
  251. TCCR1B=0x00;
  252. TCNT1H=0x00;
  253. TCNT1L=0x00;
  254. ICR1H=0x00;
  255. ICR1L=0x00;
  256. OCR1AH=0x00;
  257. OCR1AL=0x00;
  258. OCR1BH=0x00;
  259. OCR1BL=0x00;
  260.  
  261. // Timer/Counter 2 initialization
  262. // Clock source: System Clock
  263. // Clock value: Timer 2 Stopped
  264. // Mode: Normal top=FFh
  265. // OC2 output: Disconnected
  266. ASSR=0x00;
  267. TCCR2=0x00;
  268. TCNT2=0x00;
  269. OCR2=0x00;
  270.  
  271. // External Interrupt(s) initialization
  272. // INT0: Off
  273. // INT1: Off
  274. // INT2: Off
  275. MCUCR=0x00;
  276. MCUCSR=0x00;
  277.  
  278. // Timer(s)/Counter(s) Interrupt(s) initialization
  279. TIMSK=0x00;
  280.  
  281. // Analog Comparator initialization
  282. // Analog Comparator: Off
  283. // Analog Comparator Input Capture by Timer/Counter 1: Off
  284. ACSR=0x80;
  285. SFIOR=0x00;
  286.  
  287.  
  288.         d[0]=6;//hr
  289.         d[1]=0;//min
  290.         d[2]=6;//dd
  291.         d[3]=9;//mm
  292.         d[4]=2010;//year        
  293.         sett();
  294.       //  show();
  295.         csec=0;
  296.     while (1)
  297.       {
  298.       /* Test on g2&g3:gr8!
  299.       for(cur=4;cur<8;cur++)
  300.        {
  301.                 for(i=0;i<10;i++)
  302.                 {
  303.                     disAll();
  304.                     mp[cur]=ar[i];
  305.                     if(cur==4)  PORTB.0=0;
  306.                     else if(cur==5) PORTB.3=0;
  307.                     else if(cur==6) PORTB.2=0;
  308.                     else    PORTB.1=0;
  309.                     for(i_i=0;i_i<30;i_i++)
  310.                     {
  311.                         PORTC.5=!(((mp[cur])&(1<<0)) ? 1:0);//C.5=a2
  312.                         delay_ms(1);
  313.                         PORTC.5=0;
  314.                    
  315.                         PORTC.6=!(((mp[cur])&(1<<1)) ? 1:0);//C.6=b2
  316.                         delay_ms(1);
  317.                         PORTC.6=0;
  318.                    
  319.                         PORTC.2=!(((mp[cur])&(1<<2)) ? 1:0);//C.2=c2
  320.                         delay_ms(1);
  321.                         PORTC.2=0;
  322.                    
  323.                         PORTC.3=!(((mp[cur])&(1<<3)) ? 1:0);//C.3=d2
  324.                         delay_ms(1);
  325.                         PORTC.3=0;
  326.                    
  327.                         PORTC.4=!(((mp[cur])&(1<<4)) ? 1:0);//C.4=e2
  328.                         delay_ms(1);
  329.                         PORTC.4=0;
  330.                    
  331.                         PORTA.7=!(((mp[cur])&(1<<5)) ? 1:0);//A.7=f2
  332.                         delay_ms(1);
  333.                         PORTA.7=0;
  334.                    
  335.                         PORTC.7=!(((mp[cur])&(1<<6)) ? 1:0);//C.7=g2
  336.                         delay_ms(1);
  337.                         PORTC.7=0;
  338.                     }
  339.                 }
  340.                
  341.        }                
  342.        for(cur=8;cur<12;cur++)
  343.        {
  344.                 for(i=0;i<10;i++)
  345.                 {
  346.                     disAll();
  347.                     mp[cur]=ar[i];
  348.                    // PORTD.2=PORTD.5=PORTD.4=PORTD.3=1;
  349.                     if(cur==8)  PORTD.2=0;
  350.                     else if(cur==9) PORTD.5=0;
  351.                     else if(cur==10) PORTD.4=0;
  352.                     else    PORTD.3=0;
  353.                     for(i_i=0;i_i<30;i_i++)
  354.                     {
  355.                       PORTC.5=!(((mp[cur])&(1<<0)) ? 1:0);//C.5=a3
  356.                       delay_ms(1);
  357.                       PORTC.5=0;
  358.                      
  359.                       PORTC.6=!(((mp[cur])&(1<<1)) ? 1:0);//C.6=b3
  360.                       delay_ms(1);
  361.                       PORTC.6=0;
  362.                      
  363.                       PORTD.6=!(((mp[cur])&(1<<2)) ? 1:0);//D.6=c3
  364.                       delay_ms(1);
  365.                       PORTD.6=0;
  366.                      
  367.                       PORTD.7=!(((mp[cur])&(1<<3)) ? 1:0);//D.7=d3
  368.                       delay_ms(1);
  369.                       PORTD.7=0;
  370.                      
  371.                       PORTC.0=!(((mp[cur])&(1<<4)) ? 1:0);//C.0=e3
  372.                       delay_ms(1);
  373.                       PORTC.0=0;
  374.                      
  375.                       PORTC.1=!(((mp[cur])&(1<<5)) ? 1:0);//C.1=f3
  376.                       delay_ms(1);
  377.                       PORTC.1=0;
  378.                      
  379.                       PORTC.7=!(((mp[cur])&(1<<6)) ? 1:0);//C.7=g3
  380.                       delay_ms(1);
  381.                       PORTC.7=0;
  382.                     }
  383.                 }  
  384.        }
  385.        */
  386.       // Place your code here
  387.         ///*
  388.         while(!(PIND.0|PIND.1))
  389.         {
  390.             show();
  391.             csec++;
  392.             if(csec>=60)
  393.             {
  394.                 csec=0;d[1]++;//Min
  395.                 if(d[1]>=60)  {d[1]=0;d[0]++;}//hour
  396.                 if(d[0]>=24)  {d[0]=0;d[2]++;}//day
  397.                 if(d[2]>dom[d[3]])  {d[2]=1;d[3]++;}//Month
  398.                 if(d[3]>12)  {d[3]=1;d[4]++;}//Year
  399.                 if(d[4]%4==0)   dom[1]=29;
  400.                 else   dom[1]=28;
  401.                 sett();
  402.             }
  403.         }
  404.         j=0;
  405.         delay_ms(2000);
  406.         while(j<5)
  407.         {
  408.             if(PIND.0) {j++;delay_ms(500);}
  409.             if(PIND.1)  
  410.             {
  411.                 d[j%5]=(d[j%5]+1)%l[j%5];
  412.                 sett();
  413.                 delay_ms(1000);
  414.                 show();
  415.             }
  416.             show();
  417.             delay_ms(50);
  418.         }
  419.         delay_ms(1000);
  420.       };
  421.  }
Add Comment
Please, Sign In to add comment