標(biāo)題: atmega16 ds1302 [打印本頁(yè)]

作者: 2335080009    時(shí)間: 2019-6-26 16:02
標(biāo)題: atmega16 ds1302
#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};//選擇第幾個(gè)數(shù)碼管亮
unsigned char dis_buff[4]; // 顯示緩沖區(qū),存放要顯示的4個(gè)字符的段碼值
unsigned char time[2];
unsigned char posit,i=0,c=0xff;
unsigned int count=0;
bit point_on;
void display(void) // 4位LED數(shù)碼管動(dòng)態(tài)掃描函數(shù)
{
  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)//中斷服務(wù)函數(shù)
{
            display();
                count++;
              if(count>=1000){
                count=0;
                     c=~(1<<i);
                     if(++i>=4)i=0;
                    point_on++;
              }
   
}
void main(void)
{
    PORTA = 0xFF;                /*打開(kāi)上拉*/
    DDRA = 0xFF;                /*方向輸入*/
    PORTB = 0xF0;                /*電平設(shè)置*/
    DDRB = 0xFF;                /*方向輸出*/
    PORTC = 0x00; // 顯示控制I/O端口初始化
    DDRC = 0xFF;
    PORTD = 0xFF;
    DDRD = 0xFF;
   
    TCCR0=0x0A; // 內(nèi)部時(shí)鐘,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") // 開(kāi)放全局中斷
    delay_us(500);
    ds1302_init();
    delay_ms(10);
    ds1302_write_time();
    ds1302_read_time();
    while (1)

ds1302.zip (2019-6-26 16:02 上傳)

59.22 KB, 下載次數(shù): 8, 下載積分: 黑幣 -5






歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1