MSP430與DS1302之1602顯示
/*****************讀出年的十進制數(shù)***************************/
uchar readyear()
{
uchar dat;
dat=read_1302add(0x8d);
year=((dat&0xf0)>>4)*10+(dat&0x0f);
return year;
}
/************************讀出所有時間**********************/
void readtime()
{
readsecond();
readminute();
readhour();
readday();
readmonth();
readweek();
readyear();
}
/*********************向1602寫入時間****************************/
void write_second()
{
uchar shi,ge;
shi=second/10;
ge=second%10;
Write1602(0x80+0x40+9,0x30+shi);
Write1602(0x80+0x40+10,0x30+ge);
}
void write_minute()
{
uchar shi,ge;
shi=minute/10;
ge=minute%10;
Write1602(0x80+0x40+6,0x30+shi);
Write1602(0x80+0x40+7,0x30+ge);
}
void write_hour()
{
uchar shi,ge;
shi=hour/10;
ge=hour%10;
Write1602(0x80+0x40+3,0x30+shi);
Write1602(0x80+0x40+4,0x30+ge);
}
void write_day()
{
uchar shi,ge;
shi=day/10;
ge=day%10;
Write1602(0x80+8,0x30+shi);
Write1602(0x80+9,0x30+ge);
}
void write_month()
{
uchar shi,ge;
shi=month/10;
ge=month%10;
Write1602(0x80+5,0x30+shi);
Write1602(0x80+6,0x30+ge);
}
void write_year()
{
uchar shi,ge;
shi=year/10;
ge=year%10;
Write1602(0x80+2,0x30+shi);
Write1602(0x80+3,0x30+ge);
}
void write_week()
{
Write1602(0x80+12,0x30+week);
//uchar week;
switch(week)
{
case 1: Write1602(0x80+12,M);
Write1602(0x80+13,O);
Write1602(0x80+14,N);
break;
case 2:Write1602(0x80+12,T);
Write1602(0x80+13,U);
Write1602(0x80+14,E);
break;
case 3:Write1602(0x80+12,W);
Write1602(0x80+13,E);
Write1602(0x80+14,N);
break;
case 4:Write1602(0x80+12,T);
Write1602(0x80+13,H);
Write1602(0x80+14,U);
break;
case 5:Write1602(0x80+12,F);
Write1602(0x80+13,R);
Write1602(0x80+14,I);
break;
case 6:Write1602(0x80+12,S);
Write1602(0x80+13,A);
Write1602(0x80+14,T);
break;
case 7:Write1602(0x80+12,S);
Write1602(0x80+13,U);
Write1602(0x80+14,N);
break;
}
}
/*************************主函數(shù)*************************/
void main( void )
{
/*下面六行程序關(guān)閉所有的IO口*/
P1DIR = 0XFF;P1OUT = 0XFF;
P2DIR = 0XFF;P2OUT = 0XFF;
P3DIR = 0XFF;P3OUT = 0XFF;
P4DIR = 0XFF;P4OUT = 0XFF;
P5DIR = 0XFF;P5OUT = 0XFF;
P6DIR = 0XFF;P6OUT = 0XFF;
WDTCTL = WDTPW + WDTHOLD; //關(guān)狗
LcdReset();
//zifuchuan("The time is:");
//循環(huán)讀數(shù)顯示
init_1302();
while(1)
{
readtime();
write_second();
write_minute();
write_hour();
write_day();
write_month();
write_year();
write_week();
}
}
評論