پاسخ : درخواست ساعت با rtc داخلی mega16
همون پروژه رو باز کردم
همون پروژه رو باز کردم
#include <mega16a.h>
#include <delay.h>
#include <stdio.h>
#include <alcd.h>
unsigned char h,m,s;
char str[16];
// Timer1 output compare A interrupt service routine
interrupt [TIM1_COMPA] void timer1_compa_isr(void)
{
if(++s == 60)
{
s=0;
if(++m == 60)
{
m=0;
if(++h == 24)
h=0;
}
}
lcd_clear();
lcd_putsf("Time = ");
sprintf (str,"%2d : %2d : %2d",h,m,s);
lcd_gotoxy(1,1);
lcd_puts(str);
}
void Display_LCD_Start(void)
{
lcd_clear();
lcd_putsf("Hello");
lcd_gotoxy(0,1);
lcd_putsf("Welcome");
delay_ms(3000);
lcd_clear();
delay_ms(200);
}
void Refresh(void)
{
lcd_clear();
lcd_putsf("Time = ");
sprintf (str,"%2d : %2d : %2d",h,m,s);
lcd_gotoxy(1,1);
lcd_puts(str);
}
void main()
{
DDRA=0x00;
PORTA = 0xff;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 15.625 kHz
// Mode: CTC top=OCR1A
// Input Capture on Falling Edge
// Compare A Match Interrupt: On
TCCR1B=0x0B;
OCR1AH=0x3D;
OCR1AL=0x08;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x10;
// Alphanumeric LCD initialization
// Connections are specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTB Bit 0
// RD - PORTB Bit 1
// EN - PORTB Bit 2
// D4 - PORTB Bit 4
// D5 - PORTB Bit 5
// D6 - PORTB Bit 6
// D7 - PORTB Bit 7
// Characters/line: 16
lcd_init(16);
Display_LCD_Start();
// Global enable interrupts
#asm("sei")
while(1)
{
if(PINA.0 == 0 && m > 0)
{
m--;
Refresh();
while(PINA.0 == 0);
}
if(PINA.1 == 0 && m <59)
{
m++;
Refresh();
while(PINA.1 == 0);
}
if(PINA.2 == 0 && h > 0)
{
h--;
Refresh();
while(PINA.2 == 0);
}
if(PINA.3 == 0 && h <23)
{
h++;
Refresh();
while(PINA.3 == 0);
}
}
}



دیدگاه