|
#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)
|
-
-
ds1302.zip
2019-6-26 16:02 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
59.22 KB, 下載次數: 8, 下載積分: 黑幣 -5
|