Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "msp430x14x.h"
- #include "lcd.h"
- #include "portyLcd.h"
- //---------------- zmienne globalne -------------
- unsigned int i=0;
- unsigned int sekundy=0;
- unsigned int licznik=0;
- int days[]={31,28,31,30,31,30,31,31,30,31,30,31};
- typedef struct
- {
- int year;
- int day;
- int month;
- int hour;
- int minutes;
- int second;
- int milisecond;
- }time;
- time Clock(time czas);
- void InitSpecial()
- {
- SEND_CMD(CG_RAM_ADDR);
- int spec[6][8] = {{2,4,15,2,4,8,15,0}, //ź 8
- {2,4,14,17,17,17,17,0}} ;
- int i,j;
- for(i = 0; i < 2; i++)
- {
- for(j = 0; j < 8; j++)
- {
- SEND_CHAR(spec[i][j]);
- }
- }
- }
- void printmonth(int month)
- {
- switch(month)
- {
- case 1:
- SEND_CHAR('S');
- SEND_CHAR('t');
- SEND_CHAR('y');
- SEND_CHAR('c');
- SEND_CHAR('z');
- SEND_CHAR('e');
- SEND_CHAR(9);
- break;
- case 2:
- SEND_CHAR('L');
- SEND_CHAR('u');
- SEND_CHAR('t');
- SEND_CHAR('y');
- break;
- case 3:
- SEND_CHAR('M');
- SEND_CHAR('a');
- SEND_CHAR('r');
- SEND_CHAR('z');
- SEND_CHAR('e');
- SEND_CHAR('c');
- break;
- case 4:
- SEND_CHAR('K');
- SEND_CHAR('w');
- SEND_CHAR('i');
- SEND_CHAR('e');
- SEND_CHAR('c');
- SEND_CHAR('i');
- SEND_CHAR('e');
- SEND_CHAR(9);
- break;
- case 5:
- SEND_CHAR('M');
- SEND_CHAR('a');
- SEND_CHAR('j');
- break;
- case 6:
- SEND_CHAR('C');
- SEND_CHAR('z');
- SEND_CHAR('e');
- SEND_CHAR('r');
- SEND_CHAR('w');
- SEND_CHAR('i');
- SEND_CHAR('e');
- SEND_CHAR('c');
- break;
- case 7:
- SEND_CHAR('L');
- SEND_CHAR('i');
- SEND_CHAR('p');
- SEND_CHAR('i');
- SEND_CHAR('e');
- SEND_CHAR('c');
- break;
- case 8:
- SEND_CHAR('S');
- SEND_CHAR('i');
- SEND_CHAR('e');
- SEND_CHAR('r');
- SEND_CHAR('p');
- SEND_CHAR('i');
- SEND_CHAR('e');
- SEND_CHAR(9);
- break;
- case 9:
- SEND_CHAR('W');
- SEND_CHAR('r');
- SEND_CHAR('z');
- SEND_CHAR('e');
- SEND_CHAR('s');
- SEND_CHAR('i');
- SEND_CHAR('e');
- SEND_CHAR(9);
- break;
- case 10:
- SEND_CHAR('P');
- SEND_CHAR('a');
- SEND_CHAR(8);
- SEND_CHAR('d');
- SEND_CHAR('z');
- SEND_CHAR('i');
- SEND_CHAR('e');
- SEND_CHAR('r');
- SEND_CHAR('n');
- SEND_CHAR('i');
- SEND_CHAR('k');
- break;
- case 11:
- SEND_CHAR('L');
- SEND_CHAR('i');
- SEND_CHAR('s');
- SEND_CHAR('t');
- SEND_CHAR('o');
- SEND_CHAR('p');
- SEND_CHAR('a');
- SEND_CHAR('d');
- break;
- case 12:
- SEND_CHAR('G');
- SEND_CHAR('r');
- SEND_CHAR('u');
- SEND_CHAR('d');
- SEND_CHAR('z');
- SEND_CHAR('i');
- SEND_CHAR('e');
- SEND_CHAR(9);
- break;
- }
- }
- time updatemonth(time t)
- {
- if(t.month<12)
- {t.month++;}
- else
- {
- t.month=1;
- t.year++;
- if(t.year==3000)
- t.year=1900;
- }
- return t;
- }
- time updateday(time t)
- {
- if((t.year%4==0 && t.year%100!=0 ) || t.year%400==0)
- days[1]=29;
- else
- days[1]=28;
- if(t.day<days[t.month-1])
- {
- t.day++;
- }
- else
- {
- t.day=1;
- t=updatemonth(t);
- }
- return t;
- }
- time updatehour(time t)
- {
- if(t.hour<23)
- { t.hour++;}
- else
- {
- t.hour=0;
- t=updateday(t);
- }
- return t;
- }
- time updateminutes(time t)
- {
- if(t.minutes<59)
- {t.minutes++;}
- else
- {
- t.minutes=0;
- t=updatehour(t);
- }
- return t;
- }
- time updatesecond(time t)
- {
- if(t.second<59)
- {
- t.second++;
- }
- else
- {
- t.second=0;
- t=updateminutes(t);
- }
- return t;
- }
- time updatemilisecond(time t)
- {
- if(t.milisecond<9)
- {
- t.milisecond++;
- }
- else
- {
- t.milisecond=0;
- t=updatesecond(t);
- }
- return t;
- }
- //----------------- main program -------------------
- void main( void )
- {
- time czas;
- czas.day=29;
- czas.month=2;
- czas.hour=23;
- czas.minutes=59;
- czas.second=58;
- czas.milisecond=0;
- czas.year=2004;
- if(czas.year<1900)//anti-debilizm
- czas.year=1900;
- P2DIR |= BIT1 ; // STATUS LED
- WDTCTL=WDTPW + WDTHOLD; // Wyłączenie WDT
- InitPortsLcd(); // inicjalizacja portów LCD
- InitLCD(); // inicjalizacja LCD
- clearDisplay(); // czyszczenie wyświetlacza
- // Basic Clock Module ustawiamy na ACLK(zegar 8 MHz ) i dzielimy częstotliwość przez 2 (4 MHz)
- BCSCTL1 |= XTS; // ACLK = LFXT1 = HF XTAL 8MHz
- do
- {
- IFG1 &= ~OFIFG; // Czyszczenie flgi OSCFault
- for (i = 0xFF; i > 0; i--); // odczekanie
- }
- while ((IFG1 & OFIFG) == OFIFG); // dopóki OSCFault jest ciągle ustawiona
- BCSCTL1 |= DIVA_1; // ACLK=8 MHz/2=4 MHz
- BCSCTL2 |= SELM0 | SELM1; // MCLK= LFTX1 =ACLK
- // Timer_A ustawiamy na 500 kHz
- // a przerwanie generujemy co 100 ms
- TACTL = TASSEL_1 + MC_1 +ID_3; // Wybieram ACLK, ACLK/8=500kHz,tryb Up
- CCTL0 = CCIE; // włączenie przerwań od CCR0
- CCR0=50000; // podzielnik 50000: przerwanie co 100 ms
- _EINT(); // włączenie przerwań
- for (;;)
- {
- _BIS_SR(LPM3_bits); // przejscie do trybu LPM3
- czas=Clock(czas);
- }
- }
- time Clock(time czas)
- {
- //if (licznik %10 ==0) // gdy mineła sekunda (10 * 100 milisekund)
- //{
- SEND_CMD(DD_RAM_ADDR);
- licznik=0;
- P2OUT ^=BIT1; //zapal diodę
- czas=updatemilisecond(czas);
- /*if(czas.hour==0 && czas.minutes==0 && czas.second==0)
- {
- czas=updateday(czas);
- }*/
- printDecDigit(czas.day/10);
- printDecDigit(czas.day%10);
- SEND_CHAR(' ');
- printmonth(czas.month);
- SEND_CMD(DD_RAM_ADDR2);
- printDecDigit(czas.hour/10);
- printDecDigit(czas.hour%10);
- SEND_CHAR(':');
- printDecDigit(czas.minutes/10);
- printDecDigit(czas.minutes%10);
- SEND_CHAR(':');
- printDecDigit(czas.second/10);
- printDecDigit(czas.second%10);
- SEND_CHAR(':');
- printDecDigit(czas.milisecond);
- SEND_CHAR(' ');
- printDecDigit(czas.year/1000);
- printDecDigit((czas.year/100)-(czas.year/1000)*10);
- printDecDigit((czas.year%100)/10);
- printDecDigit(czas.year%10);
- SEND_CMD(DD_RAM_ADDR);
- int j;
- for(j=0;j<9;j++)
- {
- SEND_CMD(CUR_SHIFT_LEFT);// wróć kursorem na początek
- }
- return czas;
- //}
- //return czas;
- }
- // procedura obsługi przerwania od TimerA
- #pragma vector=TIMERA0_VECTOR
- __interrupt void Timer_A (void)
- {
- ++licznik;
- _BIC_SR_IRQ(LPM3_bits); // wyjście z trybu LPM3
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement