#include #define uchar unsigned char #define uint unsigned int #define CS RA5 uchar secs = 0; uchar minutes = 0; uchar hours = 0; unsigned char disbuf[8] = {1,2,3,4,5,6,7,8}; void delay_ms(uint n) { uchar i; while(n--) { for(i=0;i<100;i++); } } void Port_Initial(void) { TRISC = 0xD7; PORTC = 0x00; TRISA = 0x00; PORTA = 0x00; } void Time0_Initial(void) { T0CS = 0; PSA = 1; T0IF = 0; T0IE = 1; GIE = 1; TMR0 = 0x00; } volatile unsigned int cnt = 0; void interrupt ISR(void) { TMR0 = 0x13; T0IF = 0; CLRWDT(); cnt ++; if(cnt==500) { cnt = 0; secs ++; } if(secs==60) { secs = 0; minutes ++; } if(minutes==60) { minutes = 0; hours ++; } if(hours==24) { hours = 0; } } void SPI_Initial(void) { PIR1 = 0; SSPCON = 0x30; SSPSTAT = 0x00; } void Display(uchar *str) { uchar i; for(i=0;i<8;i++) { MAX7221_WRITE(i+1,str[i]); } } void HEXTOBCD(void) { disbuf[0] = hours/10; disbuf[1] = hours%10; disbuf[2] = 10; disbuf[3] = minutes/10; disbuf[4] = minutes%10; disbuf[5] = 10; disbuf[6] = secs/10; disbuf[7] = secs%10; } void main() { SPI_Initial(); delay_ms(10); Port_Initial(); delay_ms(10); Time0_Initial(); delay_ms(10); MAX7221_Initial(); delay_ms(10); while(1) { HEXTOBCD(); delay_ms(10); Display(disbuf); delay_ms(10); } }
设计资源 培训 开发板 精华推荐
- CAV4109 具有独立 PWM 调光功能的 3 通道恒流 RGB LED 驱动器的典型应用
- TimerV2
- AM1S-0307SH30Z 1W DC-DC转换器典型应用
- LT3580,这款 5V 至 12V 升压转换器的 2.5MHz 高开关频率允许使用纤巧的 4mm-4mm 1.7mm 电感器
- RD-404,使用 FSBB10CH120D 10A/1200V Motion SPM 3 模块的工业应用参考设计
- simon
- LTC1261LIMS8-4.5 5V 输入、-4V 输出 GaAs FET 偏置发生器的典型应用电路
- TCR6DA1830 的典型应用、200mA、1.8V 和 3.0V 输出电压双路输出 CMOS 低压降稳压器
- DIY电子负载
- LT3089EFE 高效可调电源的典型应用电路