|
ð |
|||||
нǥ |
||||||
Ÿ̸/ī1 Ͽ ð踦 . о – ð, Ÿ̸ |
||||||
н |
||||||
2 ð踦 . 1. ð迡 Ŭ ϰ ð LCD Ÿ. 2. ð踦 AVR 4 Ʈ 7Ʈ Ͽ ð ǥϰ ð ִ ġ . |
||||||
|
||||||
Ÿ̸/ī1 Ͽ 1ʸ ϴ ͷƮ ʸ Ű 60 Ǹ ϰ, 60 Ǹ ø Ų. Ʒ 4 7Ʈ ̿Ͽ , ǥϴ ð ȸε ̴. SW0,SW1 , ð ϴ ġ̴. |
||||||
ȸε ð ǥ ̴. |
|
|||||
ǽ |
||||||
|
||||||
LCD ðǥ Ʒ 3° Clopck Value, Mode, Interrupt on Ѵ. ̶ 16MHz/256/(1+62499)=1Hz ͷƮ Ѵ. |
||||||
|
|
|
||||
|
||||||
|
1 AVR α [AVRα ޱ] ð LCD Ÿ α Ʒ α . |
|
||||
|
#include <mega128.h> #include
<stdio.h> unsigned char
second=0,minute=0,hour=0; char time[10]=""; // Alphanumeric LCD Module functions #asm .equ __lcd_port=0x1B #endasm #include <lcd.h> // Timer 1 output compare A interrupt service routine interrupt [TIM1_COMPA] void timer1_compa_isr(void) { // Place your code here second++; if(second==60){ second=0; minute++; if(minute==60){ minute=0; hour++;
if(hour==13){ hour=1; } } } sprintf(time,"%2d
%2d %2d",hour,minute,second); lcd_gotoxy(0,0); lcd_puts(time); } // Declare your global variables here void main(void) { // // Timer/Counter 1 initialization // Clock source: System Clock // Clock value: 62.500 kHz // Mode: CTC top=OCR1A // OC1A output: Discon. // OC1B output: Discon. // OC1C output: Discon. // Noise Canceler: Off // Input Capture on Falling Edge TCCR1A=0x00; TCCR1B=0x0C; TCNT1H=0x00; TCNT1L=0x00; OCR1AH=62499>>8; OCR1AL=62499 & 0xff; OCR1BH=0x00; OCR1BL=0x00; OCR1CH=0x00; OCR1CL=0x00; // // LCD module initialization lcd_init(16); // Global enable interrupts #asm("sei") while (1) { // Place your code here }; } |
|
||||
7Ʈ ðǥ AVR A,B,C,D 4 äο 7Ʈ ð ǥѴ. |
||||||
PortA,B,C,D Out Ѵ. |
INT6,7 Falling Edge Ѵ. |
|
||||
|
||||||
|
2 AVR α [AVRα ޱ] ð 7Ʈ Ÿ α second,minute,hour CPU ð ǵ rom Ͽ. |
|
||||
|
#include <mega128.h> #include
<delay.h> #include <stdio.h>
eeprom unsigned char
second,minute,hour; char
time[10]=""; char i,seg[10]={0xA0,0xF9,0xC4,0xD0,0x99,0x92,0x82,0xF8,0x80,0x90}; void displayTime() { sprintf(time,"%2d%2d",hour,minute); if(hour>=10) PORTA=seg[time[0]-0x30]; else PORTA=0xff;
PORTB=seg[time[1]-0x30]; if(minute>=10) PORTC=seg[time[2]-0x30]; else PORTC=0xff;
PORTD=seg[time[3]-0x30]; } // External Interrupt 6 service routine interrupt [EXT_INT6] void ext_int6_isr(void) { minute++; if(minute>=60) minute=0; displayTime(); } // External Interrupt 7 service routine interrupt [EXT_INT7] void ext_int7_isr(void) { hour++; if(hour>=13) hour=0; displayTime(); } // Timer 1 output compare A interrupt service routine interrupt [TIM1_COMPA] void timer1_compa_isr(void) { // Place your code here second++; if(second==60){ second=0; minute++; if(minute==60){ minute=0; hour++;
if(hour==13){ hour=1; } } } displayTime(); } // Declare your global variables here void main(void) { // α // Timer/Counter 1 initialization // Clock source: System Clock // Clock value: 62.500 kHz // Mode: CTC top=OCR1A // OC1A output: Discon. // OC1B output: Discon. // OC1C output: Discon. // Noise Canceler: Off // Input Capture on Falling Edge TCCR1A=0x00; TCCR1B=0x0C; TCNT1H=0x00; TCNT1L=0x00; OCR1AH=62499>>8; OCR1AL=62499 & 0xff; OCR1BH=0x00; OCR1BL=0x00; OCR1CH=0x00; OCR1CL=0x00; // α // Global enable interrupts #asm("sei")
PORTA=0xff; PORTB=0xff; PORTC=0xff; PORTD=0xff; if(hour>12) hour=0; if(minute>60) minute=0; if(second>60) second=0;
while (1) { // Place your code here }; } |
|
||||
|
||||||
|
||||||
|
||||||