0% found this document useful (0 votes)
20 views3 pages

Jam

This document contains the code for an Arduino program that uses a timer interrupt to display the current time in hours, minutes, and seconds on an LCD screen. It initializes Timer/Counter 1 to generate an interrupt every 10 milliseconds. The interrupt service routine increments the second, minute, and hour counters, clears the LCD when the counters roll over, and displays the updated time on the LCD. The main program configures the LCD and enables global interrupts before entering an infinite loop to continuously display the running time.

Uploaded by

teknis komp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views3 pages

Jam

This document contains the code for an Arduino program that uses a timer interrupt to display the current time in hours, minutes, and seconds on an LCD screen. It initializes Timer/Counter 1 to generate an interrupt every 10 milliseconds. The interrupt service routine increments the second, minute, and hour counters, clears the LCD when the counters roll over, and displays the updated time on the LCD. The main program configures the LCD and enables global interrupts before entering an infinite loop to continuously display the running time.

Uploaded by

teknis komp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

/*******************************************************

Chip type : ATmega16 time 10mS


AVR Core Clock frequency: 11,059000 MHz
*******************************************************/

#include <mega16.h>
#include <alcd.h>
#include <delay.h>
#include <stdlib.h>
unsigned int hitung=0, detik=0, menit=0, jam=0;
unsigned char tdetik[10], tmenit[10], tjam[10];

// Timer1 overflow interrupt service routine


interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
// Reinitialize Timer1 value
TCNT1H=0xCA00 >> 8;
TCNT1L=0xCA00 & 0xff;
if (++detik == 100){
detik=0;
lcd_clear();
if (++menit == 60){
menit=0;
lcd_clear();
if (++jam == 24){
jam = 0;
lcd_clear();
}
}
}

lcd_gotoxy(9,0);
lcd_putsf (":");
lcd_gotoxy(10,0);
lcd_puts(tdetik);
lcd_gotoxy(6,0);
lcd_putsf(":");
lcd_gotoxy(7,0);
lcd_puts(tmenit);
lcd_gotoxy(4,0);
lcd_puts(tjam);
lcd_gotoxy(0,1);
lcd_putsf("= Jam Digital =");
}

void main(void)
{
DDRB.3 =1;
PORTB.3 = 1;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=0xFF
// OC0 output: Disconnected
TCCR0=(0<<WGM00) | (0<<COM01) | (0<<COM00) | (0<<WGM01) | (0<<CS02) | (0<<CS01) |
(0<<CS00);
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 1382,375 kHz
// Mode: Normal top=0xFFFF
// OC1A output: Disconnected
// OC1B output: Disconnected
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer Period: 10 ms
// Timer1 Overflow Interrupt: On
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=(0<<COM1A1) | (0<<COM1A0) | (0<<COM1B1) | (0<<COM1B0) | (0<<WGM11) |
(0<<WGM10);
TCCR1B=(0<<ICNC1) | (0<<ICES1) | (0<<WGM13) | (0<<WGM12) | (0<<CS12) | (1<<CS11) |
(0<<CS10);
TCNT1H=0xCA;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0<<AS2;
TCCR2=(0<<PWM2) | (0<<COM21) | (0<<COM20) | (0<<CTC2) | (0<<CS22) | (0<<CS21) |
(0<<CS20);
TCNT2=0x00;
OCR2=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization


TIMSK=(0<<OCIE2) | (0<<TOIE2) | (0<<TICIE1) | (0<<OCIE1A) | (0<<OCIE1B) |
(1<<TOIE1) | (0<<OCIE0) | (0<<TOIE0);

// External Interrupt(s) initialization


// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=(0<<ISC11) | (0<<ISC10) | (0<<ISC01) | (0<<ISC00);
MCUCSR=(0<<ISC2);

// USART initialization
// USART disabled
UCSRB=(0<<RXCIE) | (0<<TXCIE) | (0<<UDRIE) | (0<<RXEN) | (0<<TXEN) | (0<<UCSZ2) |
(0<<RXB8) | (0<<TXB8);

// Analog Comparator initialization


// Analog Comparator: Off
// The Analog Comparator's positive input is
// connected to the AIN0 pin
// The Analog Comparator's negative input is
// connected to the AIN1 pin
ACSR=(1<<ACD) | (0<<ACBG) | (0<<ACO) | (0<<ACI) | (0<<ACIE) | (0<<ACIC) |
(0<<ACIS1) | (0<<ACIS0);
SFIOR=(0<<ACME);

// ADC initialization
// ADC disabled
ADCSRA=(0<<ADEN) | (0<<ADSC) | (0<<ADATE) | (0<<ADIF) | (0<<ADIE) | (0<<ADPS2) |
(0<<ADPS1) | (0<<ADPS0);

// SPI initialization
// SPI disabled
SPCR=(0<<SPIE) | (0<<SPE) | (0<<DORD) | (0<<MSTR) | (0<<CPOL) | (0<<CPHA) |
(0<<SPR1) | (0<<SPR0);

// TWI initialization
// TWI disabled
TWCR=(0<<TWEA) | (0<<TWSTA) | (0<<TWSTO) | (0<<TWEN) | (0<<TWIE);

lcd_init(16);
#asm("sei")
lcd_gotoxy(0,1);
lcd_putsf("= ....... =");
delay_ms(2000);
while (1)
{
// Place your code here

}
}

You might also like