dh.zipem đang làm đồng hồ led 7 thanh(thay led 7 thanh bằng cách ghép led đơn) em có gửi mạch và code mong các pro giúp.em mô phỏng trên proteus thì chạy.nhưng làm mạch thật thì chỗ quét led qua con 4511 không thấy gì cả.và cả nữa là con DS1307 em cho xuất ra chân 7 1hz mà dùng đồng hồ kiểm tra không thấy gì cả.em đã thay con DS1307 mới mà cũng không được.mong các pro giúp em
#include <mega8.h>
#include <delay.h>
// I2C Bus functions
#asm
.equ __i2c_port=0x18 ;PORTB
.equ __sda_bit=0
.equ __scl_bit=1
#endasm
#include <i2c.h>
// DS1307 Real Time Clock functions
#include <ds1307.h>
unsigned char h,m,s;
void disp(int add, unsigned char dat);
void wr(unsigned char add, unsigned char dat);
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
// Place your code here
unsigned char a,i=0;
//#asm("cli");
while(1)
{
if (PIND.2==0) {
a++;
if (a>2) a=0;
delay_ms(100);
}
switch (a){
case 0: {
if (PIND.0==0) {
h++; // up
delay_ms(500);
}
if (PIND.1==0) {
h--; // Down
delay_ms(500);
}
if (h>12) h=h-12;
if (h<1) h=12;
disp(1,(h/10)%10);
disp(2,h%10);
break;
}
case 1: {
if (PIND.0==0) {
m++; // up
if (m==60) m=0;
delay_ms(300);
}
if (PIND.1==0) {
m--; // Down
if (m==0) m=59;
delay_ms(300);
}
disp(3,(m/10)%10);
disp(4,m%10);
break;
}
}
if (PIND.3==0) // Thoat chinh gio.
{
delay_ms(10);
rtc_set_time(h,m,s);
delay_ms(500);
wr(0,0);
break;
}
}
}
// Declare your global variables here
void disp(int add, unsigned char dat)
{
unsigned char num_led[]={0,0x7f,0xbf,0xdf,0xef};
PORTC=dat;
PORTD=num_led[add];
delay_ms(1);
PORTD=0xff;
}
void wr(unsigned char add, unsigned char dat)
{
i2c_start();
i2c_write(0xd0);
i2c_write(add);
i2c_write(dat);
i2c_stop();
}
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func6=In Func5=In Func4=In Func3=Out Func2=Out Func1=Out Func0=Out
// State6=T State5=T State4=T State3=0 State2=0 State1=0 State0=0
PORTC=0x0F;
DDRC=0x0F;
// Port D initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=In Func2=In Func1=In Func0=In
// State7=0 State6=0 State5=0 State4=0 State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0xF0;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x00;
TCNT0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Low level
// INT1: Off
GICR|=0x40;
MCUCR=0x00;
GIFR=0x40;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
// Analog Comparator Output: Off
ACSR=0x80;
SFIOR=0x00;
// I2C Bus initialization
i2c_init();
// DS1307 Real Time Clock initialization
// Square wave output on pin SQW/OUT: On
// Square wave frequency: 1Hz
rtc_init(0,1,0);
//wr(0,0);
//rtc_set_time(19,18,0);
// Global enable interrupts
#asm("sei")
while (1)
{
// Place your code here
rtc_get_time(&h,&m,&s);
if (h>12) h=h-12;
disp(1,(h/10));
disp(2,h%10);
disp(3,(m/10));
disp(4,m%10);
};
}
#include <mega8.h>
#include <delay.h>
// I2C Bus functions
#asm
.equ __i2c_port=0x18 ;PORTB
.equ __sda_bit=0
.equ __scl_bit=1
#endasm
#include <i2c.h>
// DS1307 Real Time Clock functions
#include <ds1307.h>
unsigned char h,m,s;
void disp(int add, unsigned char dat);
void wr(unsigned char add, unsigned char dat);
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
// Place your code here
unsigned char a,i=0;
//#asm("cli");
while(1)
{
if (PIND.2==0) {
a++;
if (a>2) a=0;
delay_ms(100);
}
switch (a){
case 0: {
if (PIND.0==0) {
h++; // up
delay_ms(500);
}
if (PIND.1==0) {
h--; // Down
delay_ms(500);
}
if (h>12) h=h-12;
if (h<1) h=12;
disp(1,(h/10)%10);
disp(2,h%10);
break;
}
case 1: {
if (PIND.0==0) {
m++; // up
if (m==60) m=0;
delay_ms(300);
}
if (PIND.1==0) {
m--; // Down
if (m==0) m=59;
delay_ms(300);
}
disp(3,(m/10)%10);
disp(4,m%10);
break;
}
}
if (PIND.3==0) // Thoat chinh gio.
{
delay_ms(10);
rtc_set_time(h,m,s);
delay_ms(500);
wr(0,0);
break;
}
}
}
// Declare your global variables here
void disp(int add, unsigned char dat)
{
unsigned char num_led[]={0,0x7f,0xbf,0xdf,0xef};
PORTC=dat;
PORTD=num_led[add];
delay_ms(1);
PORTD=0xff;
}
void wr(unsigned char add, unsigned char dat)
{
i2c_start();
i2c_write(0xd0);
i2c_write(add);
i2c_write(dat);
i2c_stop();
}
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func6=In Func5=In Func4=In Func3=Out Func2=Out Func1=Out Func0=Out
// State6=T State5=T State4=T State3=0 State2=0 State1=0 State0=0
PORTC=0x0F;
DDRC=0x0F;
// Port D initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=In Func2=In Func1=In Func0=In
// State7=0 State6=0 State5=0 State4=0 State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0xF0;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x00;
TCNT0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Low level
// INT1: Off
GICR|=0x40;
MCUCR=0x00;
GIFR=0x40;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
// Analog Comparator Output: Off
ACSR=0x80;
SFIOR=0x00;
// I2C Bus initialization
i2c_init();
// DS1307 Real Time Clock initialization
// Square wave output on pin SQW/OUT: On
// Square wave frequency: 1Hz
rtc_init(0,1,0);
//wr(0,0);
//rtc_set_time(19,18,0);
// Global enable interrupts
#asm("sei")
while (1)
{
// Place your code here
rtc_get_time(&h,&m,&s);
if (h>12) h=h-12;
disp(1,(h/10));
disp(2,h%10);
disp(3,(m/10));
disp(4,m%10);
};
}
Comment