|
#include <mega16.h>
#include <delay.h>
#include "DS1302.h"
#include "key.h"
#define uchar unsigned char
#define uint unsigned int
flash char led_7[12]={0xd7,0x14,0xcd,0x5d,0x1e,0x5b,0xdb,0x15,0xdf,0x5f,0x9f};//0-9
flash unsigned char position[4]={0x1f,0x2f,0x4f,0x8f};//选择第几个数码管亮
unsigned char dis_buff[4]; // 显示缓冲区,存放要显示的4个字符的段码值
unsigned char time[2];
unsigned char posit,i=0,c=0xff;
unsigned int count=0;
bit point_on;
void display(void) // 4位LED数码管动态扫描函数
{
PORTA = 0xff;
PORTC = led_7[dis_buff[posit]];
if (point_on && (posit==2||posit==4)) PORTA |= 0x80;
PORTA = position[posit];
PORTA &= c;
if (++posit >=4 ) posit = 0; // (3)
}
interrupt [TIM0_COMP] void timer0_comp_isr(void)//中断服务函数
{
display();
count++;
if(count>=1000){
count=0;
c=~(1<<i);
if(++i>=4)i=0;
point_on++;
}
}
void main(void)
{
PORTA = 0xFF; /*打开上拉*/
DDRA = 0xFF; /*方向输入*/
PORTB = 0xF0; /*电平设置*/
DDRB = 0xFF; /*方向输出*/
PORTC = 0x00; // 显示控制I/O端口初始化
DDRC = 0xFF;
PORTD = 0xFF;
DDRD = 0xFF;
TCCR0=0x0A; // 内部时钟,8分频(1M/8=125KHz),CTC模式
TCNT0=0x00;
OCR0=0x7C; // OCR0 = 0x7C(124),(124+1)/125=1ms
TIMSK=0x02; // 允许T/C0比较匹配中断
delay_us(500);
#asm("sei") // 开放全局中断
delay_us(500);
ds1302_init();
delay_ms(10);
ds1302_write_time();
ds1302_read_time();
while (1)
|
|