找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 988|回复: 0
打印 上一主题 下一主题
收起左侧

atmega16 ds1302

[复制链接]
跳转到指定楼层
楼主
ID:559809 发表于 2019-6-26 16:02 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#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

59.22 KB, 下载次数: 8, 下载积分: 黑币 -5

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表