code ds1307 dùng avr
sao mình chỉnh hoài mà led 7 đoạn vẫn nhấp nháy , các bạn xem giúp mình ...nếu mà dùng thêm nút nhấn để chỉnh giờ thì có nên thêm 1 ngắt để quét led còn trong main để kiểm tra nút nhân không các bạn?
/************************************************** ***
This program was produced by the
CodeWizardAVR V2.05.3 Standard
Automatic Program Generator
© Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 13/05/2013
Author : Nguyen Van Son
Company :
Comments:
Chip type : ATmega32
Program type : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 512
************************************************** ***/
#include <mega32.h>
#include <i2c.h>
#include <delay.h>
#include <ds1307.h>
unsigned char hour, min, sec;
unsigned char thu,ngay,thang,nam;
char const MAP[10] = {0x81,0xe7,0x92,0xc2,0xe4,0xc8,0x88,0xe1,0x80,0xc0 };//Anode
void hien_thi();
void main(void)
{
DDRA=255;DDRD.0=1;DDRD.1=1;DDRD.2=1;DDRD.3=1;DDRD. 4=1;DDRD.5=1;DDRD.6=1;
DDRB=255;
i2c_init();
rtc_init(0,1,0);
//rtc_set_time(01,22,00);
//rtc_set_date(7,12,5,13);
while (1)
{
rtc_get_time(&hour,&min,&sec);
rtc_get_date(&thu,&ngay,&thang,&nam);
hien_thi();
}
}
void hien_thi()
{
PORTA = MAP[sec%10]; PORTD.6=0; delay_us(50);PORTD.6=1;
PORTA = MAP[sec/10]; PORTD.5=0; delay_us(50);PORTD.5=1;
PORTA = MAP[min%10]; PORTD.4=0; delay_us(50);PORTD.4=1;
PORTA = MAP[min/10]; PORTD.3=0; delay_us(50);PORTD.3=1;
PORTA =MAP[hour%10]; PORTD.2=0; delay_us(50);PORTD.2=1;
PORTA = MAP[hour/10]; PORTD.1=0; delay_us(50);PORTD.1=1;
PORTA = MAP[thu]; PORTD.0=0; delay_us(50);PORTD.0=1;
//================================================== ===
PORTA = MAP[ngay/10]; PORTB.0=0; delay_us(50);PORTB.0=1;
PORTA = MAP[ngay%10]; PORTB.1=0; delay_us(50);PORTB.1=1;
PORTA = MAP[thang/10]; PORTB.2=0; delay_us(50);PORTB.2=1;
PORTA = MAP[thang%10]; PORTB.3=0; delay_us(50);PORTB.3=1;
PORTA =MAP[2]; PORTB.4=0; delay_us(50);PORTB.4=1;
PORTA = MAP[0]; PORTB.5=0; delay_us(150);PORTB.5=1;
PORTA = MAP[nam/10]; PORTB.6=0; delay_us(50);PORTB.6=1;
PORTA = MAP[nam%10]; PORTB.7=0; delay_us(50);PORTB.7=1;
}
sao mình chỉnh hoài mà led 7 đoạn vẫn nhấp nháy , các bạn xem giúp mình ...nếu mà dùng thêm nút nhấn để chỉnh giờ thì có nên thêm 1 ngắt để quét led còn trong main để kiểm tra nút nhân không các bạn?
/************************************************** ***
This program was produced by the
CodeWizardAVR V2.05.3 Standard
Automatic Program Generator
© Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 13/05/2013
Author : Nguyen Van Son
Company :
Comments:
Chip type : ATmega32
Program type : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 512
************************************************** ***/
#include <mega32.h>
#include <i2c.h>
#include <delay.h>
#include <ds1307.h>
unsigned char hour, min, sec;
unsigned char thu,ngay,thang,nam;
char const MAP[10] = {0x81,0xe7,0x92,0xc2,0xe4,0xc8,0x88,0xe1,0x80,0xc0 };//Anode
void hien_thi();
void main(void)
{
DDRA=255;DDRD.0=1;DDRD.1=1;DDRD.2=1;DDRD.3=1;DDRD. 4=1;DDRD.5=1;DDRD.6=1;
DDRB=255;
i2c_init();
rtc_init(0,1,0);
//rtc_set_time(01,22,00);
//rtc_set_date(7,12,5,13);
while (1)
{
rtc_get_time(&hour,&min,&sec);
rtc_get_date(&thu,&ngay,&thang,&nam);
hien_thi();
}
}
void hien_thi()
{
PORTA = MAP[sec%10]; PORTD.6=0; delay_us(50);PORTD.6=1;
PORTA = MAP[sec/10]; PORTD.5=0; delay_us(50);PORTD.5=1;
PORTA = MAP[min%10]; PORTD.4=0; delay_us(50);PORTD.4=1;
PORTA = MAP[min/10]; PORTD.3=0; delay_us(50);PORTD.3=1;
PORTA =MAP[hour%10]; PORTD.2=0; delay_us(50);PORTD.2=1;
PORTA = MAP[hour/10]; PORTD.1=0; delay_us(50);PORTD.1=1;
PORTA = MAP[thu]; PORTD.0=0; delay_us(50);PORTD.0=1;
//================================================== ===
PORTA = MAP[ngay/10]; PORTB.0=0; delay_us(50);PORTB.0=1;
PORTA = MAP[ngay%10]; PORTB.1=0; delay_us(50);PORTB.1=1;
PORTA = MAP[thang/10]; PORTB.2=0; delay_us(50);PORTB.2=1;
PORTA = MAP[thang%10]; PORTB.3=0; delay_us(50);PORTB.3=1;
PORTA =MAP[2]; PORTB.4=0; delay_us(50);PORTB.4=1;
PORTA = MAP[0]; PORTB.5=0; delay_us(150);PORTB.5=1;
PORTA = MAP[nam/10]; PORTB.6=0; delay_us(50);PORTB.6=1;
PORTA = MAP[nam%10]; PORTB.7=0; delay_us(50);PORTB.7=1;
}
Comment