单片机源程序如下:
#include #include "cry1602.h" #include "cry1602.c" #include "DS1302.c" unsigned char counter=0; unsigned char second=0; unsigned char minute=0; unsigned char hour=0; //signed char miao=10; struct sTime bufTime; //time buffer /*write 1 bcd byte on screen,(x,y)-position on screen, bcd-BCD byte to display*/ void Show2DigitNumber(unsigned char x, unsigned char y,unsigned char number) { Disp1Char(x,y,(number/10+0x30 )); Disp1Char(x+1,y,(number%10 +0x30 )); } int main( void ) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT if (CALBC1_1MHZ==0xFF) // If calibration constant erased { while(1); // do not load, trap CPU!! } DCOCTL = 0; // Select lowest DCOx and MODx settings BCSCTL1 = CALBC1_1MHZ; // Set DCO DCOCTL = CALDCO_1MHZ; P1DIR |= 0x01; // P1.0 output CCTL0 = CCIE; // CCR0 interrupt enabled CCR0 = 50000; TACTL = TASSEL_2 + MC_2; // SMCLK, contmode //P6DIR &= ~BIT2; //P6.2 input P3SEL = 0x30; // P3.4,5 = USCI_A0 TXD/RXD UCA0CTL1 |= UCSSEL_2; // SMCLK UCA0BR0 = 104; // 1MHz 9600; (104)decimal = 0x068h UCA0BR1 = 0; // 1MHz 9600 UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1 UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt InitDS1302(); /* P1DIR |= BIT0;//p1.0输出模式 P1DIR |= BIT1;//p1.1输出模式 P1DIR |= BIT7;//p1.7输出模式 P1IE |= BIT2;//使能p1.2中断 P1IES |= BIT2;//下降沿触发 P1IFG &= ~BIT2;//清除p1.2中断 P1IE |= BIT3;//使能p1.3中断 P1IES |= BIT3;//下降沿触发 P1IFG &= ~BIT3;//清除p1.3中断 //P2DIR = 0XFF;P2OUT = 0XFF; //P6DIR = 0XFF;P6OUT = 0XFF; */ LcdReset(); Delay5ms(); DispStr(0,0,"Serial Output:"); DispStr(0,1,"00:00:00"); GetRealTime(&bufTime); //get current time minute=bufTime.min;minute=(minute>>4)*10+(minute&0x0f); hour=bufTime.hour;hour=(hour>>4)*10+(hour&0x0f); Show2DigitNumber(3,1,minute); Show2DigitNumber( 0,1,hour); second=DS1302SingleRead(0); second=(second>>4)*10+(second&0x0f); Show2DigitNumber(6,1,second); //DispStr(8,1," "); // __enable_interrupt(); __bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled } /* #pragma vector = PORT1_VECTOR __interrupt void P1_Interrupt()//P1口中断函数 { if(P1IFG&BIT2)//如果P1.2有中断 { P1IFG &= ~BIT2;//清除P1.2引脚中断标志位 P1OUT ^= BIT0;//P1.0引脚取反 P1OUT ^= BIT7;//P1.7 while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready? UCA0TXBUF = 97; while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready? UCA0TXBUF = 62; //Disp1Char(0,1,97); //Disp1Char(1,1,62); } if(P1IFG&BIT3)//如果P1.3有中断 { P1IFG &= ~BIT3;//清除P1.3引脚中断标志位 P1OUT ^= BIT1;//P1.1引脚取反 P1OUT ^= BIT7;//P1.7 while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready? UCA0TXBUF = 50; //Disp1Char(0,1,50); //Disp1Char(1,1,32); } } */ void Read_RTC(void) //读取 日历 { second=DS1302SingleRead(0); second=(second>>4)*10+(second&0x0f); minute=DS1302SingleRead(1); minute=(minute>>4)*10+(minute&0x0f); hour=DS1302SingleRead(2); hour=(hour>>4)*10+(hour&0x0f); } // Timer A0 interrupt service routine #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=TIMERA0_VECTOR __interrupt void Timer_A (void) #elif defined(__GNUC__) void __attribute__ ((interrupt(TIMERA0_VECTOR))) Timer_A (void) #else #error Compiler not supported! #endif { counter++; if (counter==20) { counter=0; /*second++; if (second==60) { second=0; minute++; if (minute==60) { minute=0; hour++; if (hour==24) { hour=0;} Show2DigitNumber(0,1,hour); //DispStr(2,1,":"); } Show2DigitNumber(3,1,minute); //DispStr(5,1,":"); } */ //Read_RTC(); P1OUT ^= 0x01; // Toggle P1.0 second=DS1302SingleRead(0); second=(second>>4)*10+(second&0x0f); while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready? UCA0TXBUF = hour/10+0x30; while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready? UCA0TXBUF = hour%10+0x30; while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready? UCA0TXBUF = 58; while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready? UCA0TXBUF = minute/10+0x30; while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready? UCA0TXBUF = minute%10+0x30; while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready? UCA0TXBUF = 58; while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready? UCA0TXBUF = second/10+0x30; while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready? UCA0TXBUF = second%10+0x30; while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready? UCA0TXBUF = 13; // Show2DigitNumber(0,1,hour); //DispStr(2,1,":"); // Show2DigitNumber(3,1,minute); //DispStr(5,1,":"); Show2DigitNumber(6,1,second); //DispStr(8,1," "); //miao = DS1302SingleRead(0); //miao=(miao>>4)*10+(miao&0x0f); //miao=DS1302SingleRead(0); miao=(miao>>4)*10+(miao&0x0f); if (second ==0) { GetRealTime(&bufTime); //get current time minute=bufTime.min;minute=(minute>>4)*10+(minute&0x0f); hour=bufTime.hour;hour=(hour>>4)*10+(hour&0x0f); Show2DigitNumber(3,1,minute); ……………………
上一篇:基于MSP430的电池电压检测仿真
下一篇:MSP403单片机+TLC5615+ADC0808恒流源Proteus仿真程序设计
推荐阅读最新更新时间:2024-11-10 22:12
设计资源 培训 开发板 精华推荐
- DC2186A-A,用于 LT8580 升压的演示板,3V = VIN = 10V,Vout = 12V,120mA
- LT6656BCS6-4.096 的典型应用,用于基本连接的 4.096V 电压基准
- 智能温度变送器参考设计
- SPIRIT1-低数据速率收发器-169 MHz-子板-范围扩展器
- LM317L、5V 电子关断稳压器的典型应用
- 96配列RGB砖头
- LTC2321-14 双通道、14 位 + 符号、2Msps 差分输入 ADC 的典型应用
- LTC1690 的典型应用 - 具有故障保护接收器输出的差分驱动器和接收器对
- #第五届立创电子设计大赛#数字输出直流电源
- KA431S 带输出控制的三端固定稳压器的典型应用