Sunteți pe pagina 1din 14

JAM DIGITAL

#include <Event.h>
#include <Timer.h>

/*
Example Timer1 Interrupt
Flash LED every second
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(16, 17, 18, 20, 21, 22, 23);
int timer1_counter;
unsigned char mikrodetik,detik,menit,jam;
void setup()
{
lcd.begin(16, 2);
// initialize timer1
noInterrupts(); // disable all interrupts
TCCR1A = 0;
TCCR1B = 0;

// Set timer1_counter to the correct value for our interrupt interval


timer1_counter = 65175; // preload timer 65536-12MHz/256/130Hz
//timer1_counter = 64286; // preload timer 65536-1MHz/256/50Hz
//timer1_counter = 63582; // preload timer 65536-1MHz/256/2Hz

TCNT1 = timer1_counter; // preload timer


TCCR1B |= (1 << CS12); // 256 prescaler
TIMSK |= (1 << TOIE1); // enable timer overflow interrupt
interrupts(); // enable all interrupts
}

ISR(TIMER1_OVF_vect) // interrupt service routine


{
TCNT1 = timer1_counter; // preload timer
mikrodetik++;
if (mikrodetik==10)
{
detik++;
mikrodetik=0;

if (detik>=60)
{
menit++;
lcd.clear();
detik=0;

if (menit>=60)
{
jam++;
menit=0;

if (jam==24)
{
jam=0;
}
}
}
}
}
void loop()
{
lcd.setCursor(0, 0);
lcd.print("JAM DIGITAL");

lcd.setCursor(7, 1);
lcd.print(detik);
lcd.setCursor(6, 1);
lcd.print(":");

lcd.setCursor(4, 1);
lcd.print(menit);
lcd.setCursor(3, 1);
lcd.print(":");

lcd.setCursor(1, 1);
lcd.print(jam);
}

7 SEGMEN WOW STOP

#include <Event.h>
#include <Timer.h>

/*
Example Timer1 Interrupt
Flash LED every second
*/

int ubah;
int a;
int sat,pul,rat;
unsigned int data;
int timer1_counter;
unsigned char mikrodetik, detik,menit,jam;
//declare your global variables here
void ubah_ke_format7segment()

//fungsi untuk mengubah ke dalam format 7segment


\

{
if (ubah==0){ubah=0xc0;}
if (ubah==1){ubah=0xf9;}
if (ubah==2){ubah=0xa4;}
if (ubah==3){ubah=0xb0;}
if (ubah==4){ubah=0x99;}
if (ubah==5){ubah=0x92;}
if (ubah==6){ubah=0x82;}
if (ubah==7){ubah=0xf8;}
if (ubah==8){ubah=0x80;}
if (ubah==9){ubah=0x90;}
}

void tampil_7segment()
{
PORTC=sat;
digitalWrite(13,LOW);
digitalWrite(14,HIGH);
digitalWrite(15,LOW);
delayMicroseconds(1100);

PORTC=pul;
digitalWrite(13,HIGH);
digitalWrite(14,LOW);
digitalWrite(15,LOW);
delayMicroseconds(1100);

PORTC=rat;
digitalWrite(13,LOW);
digitalWrite(14,LOW);
digitalWrite(15,LOW);
delayMicroseconds(1100);

}
void setup() {
// put your setup code here, to run once:
DDRC=0xFF;
DDRD=0b11100000;
TCNT0=0;
noInterrupts(); //disable all interrupts
TCCR1A=0;
TCCR1B=0;
PORTB=0XFF;
DDRB=0X00;

//Set timer1_counter to the correct value for our intrrupt interval


//timer1_counter = 65175; //preload timer 6553-16MHz/256/130Hz
//timer1_counter = 64286; //preload timer 65536-1MHz/256/50Hz
//timer1_counter = 63582; //preload timer 65536-1MHz/256/2Hz
timer1_counter = 65175; //preload timer 65536-1MHz/256/2Hz

TCNT1= timer1_counter; //preload timer


TCCR1B |=(1<<CS12); //256 presaler
TIMSK |=(1<<TOIE1);
interrupts(); //enable all interrupt
}

ISR(TIMER1_OVF_vect) //interrupt service routine


{
TCNT1= timer1_counter; //preload timer
mikrodetik++;
if (mikrodetik==10)
{
detik++;
mikrodetik=0;

if(detik>=20)
{
TCCR1B=0;

}
}
}

void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(7)==LOW){
sw1:{
data = detik+0;
sat= data%10;
pul= data/10;
pul= pul%10;
rat= data/100;
rat= rat%100;

loop();
goto sw1;}

//
ubah=sat;
ubah_ke_format7segment();
sat=ubah;
//
ubah=pul;
ubah_ke_format7segment();
pul=ubah;

ubah=rat;
ubah_ke_format7segment();
rat=ubah;
//
tampil_7segment();

COUNTER DOWN

#include <Event.h>
#include <Timer.h>

/*
Example Timer1 Interrupt
Flash LED every second
*/

int ubah;
int a;
int sat,pul,rat;
int data;
int timer1_counter;
int detik=60;
int mikrodetik=50;
//declare your global variables here
void ubah_ke_format7segment()

//fungsi untuk mengubah ke dalam format 7segment


\

{
if (ubah==0){ubah=0xc0;}
if (ubah==1){ubah=0xf9;}
if (ubah==2){ubah=0xa4;}
if (ubah==3){ubah=0xb0;}
if (ubah==4){ubah=0x99;}
if (ubah==5){ubah=0x92;}
if (ubah==6){ubah=0x82;}
if (ubah==7){ubah=0xf8;}
if (ubah==8){ubah=0x80;}
if (ubah==9){ubah=0x90;}
}

void tampil_7segment()
{
PORTC=sat;
digitalWrite(13,LOW);
digitalWrite(14,HIGH);
digitalWrite(15,LOW);
delayMicroseconds(1100);

PORTC=pul;
digitalWrite(13,HIGH);
digitalWrite(14,LOW);
digitalWrite(15,LOW);
delayMicroseconds(1100);

void setup() {
// put your setup code here, to run once:
DDRC=0xFF;
DDRD=0b11100000;
TCNT0=0;
noInterrupts(); //disable all interrupts
TCCR1A=0;
TCCR1B=0;
PORTB=0XFF;
DDRB=0X00;

//Set timer1_counter to the correct value for our intrrupt interval


//timer1_counter = 65175; //preload timer 6553-16MHz/256/130Hz
//timer1_counter = 64286; //preload timer 65536-1MHz/256/50Hz
//timer1_counter = 63582; //preload timer 65536-1MHz/256/2Hz
timer1_counter = 65457; //preload timer 65536-1MHz/256/2Hz

TCNT1= timer1_counter; //preload timer


TCCR1B |=(1<<CS12); //256 prescaler
TIMSK |=(1<<TOIE1);
interrupts(); //enable all interrupt
}

ISR(TIMER1_OVF_vect) //interrupt service routine


{
TCNT1= timer1_counter; //preload timer
mikrodetik--;
if (mikrodetik==0)
{
detik--;
mikrodetik=50;

if(detik<=40)
{
TCCR1B=0;
}
}
}

void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(0)==LOW){
sw1:{
data = detik;
sat= data%10;
pul= data/10;
pul= pul%10;
rat= data/100;
rat= rat%100;

loop();
goto sw1;}
}

//
ubah=sat;
ubah_ke_format7segment();
sat=ubah;
//
ubah=pul;
ubah_ke_format7segment();
pul=ubah;

ubah=rat;
ubah_ke_format7segment();
rat=ubah;
//
tampil_7segment();

LCD MULAI 20

#include <Event.h>
#include <Timer.h>

/*
Example Timer1 Interrupt
Flash LED every second
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(16, 17, 18, 20, 21, 22, 23);
int timer1_counter;
unsigned char mikrodetik,detik,menit,jam;
void setup()
{

lcd.begin(16, 2);
detik=20;
// initialize timer1
noInterrupts(); // disable all interrupts
TCCR1A = 0;
TCCR1B = 0;
// Set timer1_counter to the correct value for our interrupt interval
timer1_counter = 65175; // preload timer 65536-12MHz/256/130Hz
//timer1_counter = 64286; // preload timer 65536-1MHz/256/50Hz
//timer1_counter = 63582; // preload timer 65536-1MHz/256/2Hz

TCNT1 = timer1_counter; // preload timer


TCCR1B |= (1 << CS12); // 256 prescaler
TIMSK |= (1 << TOIE1); // enable timer overflow interrupt
interrupts(); // enable all interrupts
}

ISR(TIMER1_OVF_vect) // interrupt service routine


{
TCNT1 = timer1_counter; // preload timer
mikrodetik++;
if (mikrodetik==10)
{
detik++;
mikrodetik=0;
if (detik==31){detik=20;}

if (detik>=60)
{
menit++;
lcd.clear();
detik=0;

if (menit>=60)
{
jam++;
menit=0;

if (jam==24)
{
jam=0;
}
}
}
}
}
void loop()
{
lcd.setCursor(0, 0);
lcd.print("JAM DIGITAL");

lcd.setCursor(7, 1);
lcd.print(detik);
lcd.setCursor(6, 1);
lcd.print(":");

lcd.setCursor(4, 1);
lcd.print(menit);
lcd.setCursor(3, 1);
lcd.print(":");

lcd.setCursor(1, 1);
lcd.print(jam);
}

7 SEG MULAI 20

#include <Event.h>
#include <Timer.h>

/*
Example Timer1 Interrupt
Flash LED every second
*/

int ubah;
int sat,pul,rat;
unsigned int data;
int timer1_counter;
unsigned char mikrodetik, detik,menit,jam;
//declare your global variables here
void ubah_ke_format7segment()
//fungsi untuk mengubah ke dalam format 7segment

{
if (ubah==0){ubah=0xc0;}
if (ubah==1){ubah=0xf9;}
if (ubah==2){ubah=0xa4;}
if (ubah==3){ubah=0xb0;}
if (ubah==4){ubah=0x99;}
if (ubah==5){ubah=0x92;}
if (ubah==6){ubah=0x82;}
if (ubah==7){ubah=0xf8;}
if (ubah==8){ubah=0x80;}
if (ubah==9){ubah=0x90;}
}

void tampil_7segment()
{
PORTC=sat;
digitalWrite(13,HIGH);
digitalWrite(14,HIGH);
digitalWrite(15,LOW);
delayMicroseconds(1100);

PORTC=pul;
digitalWrite(13,LOW);
digitalWrite(14,HIGH);
digitalWrite(15,LOW);
delayMicroseconds(1100);

}
void setup() {
// put your setup code here, to run once:
detik=20;
DDRC=0xFF;
DDRD=0b11100000;
TCNT0=0;
noInterrupts(); //disable all interrupts
TCCR1A=0;
TCCR1B=0;

//Set timer1_counter to the correct value for our intrrupt interval


//timer1_counter = 65458; //preload timer 65536-1MHz/256/50Hz
timer1_counter = 65175; //preload timer 65536-1MHz/256/50Hz
//timer1_counter = 34286; //preload timer 65536-16MHz/256/2Hz

TCNT1= timer1_counter; //preload timer


TCCR1B |=(1<<CS12); //256 presaler
TIMSK |=(1<<TOIE1); //enable timer overflow interrupt
interrupts(); //enable all interrupt
}

ISR(TIMER1_OVF_vect) //interrupt service routine


{
TCNT1= timer1_counter; //preload timer
mikrodetik++;
if (mikrodetik==10)
{
detik++;
mikrodetik=0;
if (detik==61){detik==20;}

if(detik>=60)
{
menit++;
detik=0;

if(menit>=60)
{
jam++;
menit=0;
}
}
}}

void loop() {
// put your main code here, to run repeatedly:
data=detik;
sat= data%10;
pul= data/10;
pul= pul%10;

data=menit;
rat= data%100;
rat= rat/100;
//
ubah=sat;
ubah_ke_format7segment();
sat=ubah;
//
ubah=pul;
ubah_ke_format7segment();
pul=ubah;
//
ubah=rat;
ubah_ke_format7segment();
rat=ubah;
tampil_7segment();
}

LCD YUHUU
#include <Event.h>
#include <Timer.h>

/*
Example Timer1 Interrupt
Flash LED every second
*/
//include the library code:
#include <LiquidCrystal.h>
//initialize the library with the numbers of the interface pins
LiquidCrystal lcd(16, 17, 18, 20, 21, 22, 23);
int timer1_counter;
unsigned char mikrodetik, detik,menit,jam;

void setup() {
// put your setup code here, to run once:
lcd.begin(16, 2);
//initialize timer1
noInterrupts(); //disable all interrupts
TCCR1A=0;
TCCR1B=0;

//Set timer1_counter to the correct value for our intrrupt interval


timer1_counter = 65175; //preload timer 6553-16MHz/256/130Hz
//timer1_counter = 64286; //preload timer 65536-1MHz/256/50Hz
//timer1_counter = 63582; //preload timer 65536-1MHz/256/2Hz

TCNT1= timer1_counter; //preload timer


TCCR1B |=(1<<CS12); //256 presaler
TIMSK |=(1<<TOIE1); //enable timer overflow interrupt
interrupts(); //enable all interrupt
}

ISR(TIMER1_OVF_vect) //interrupt service routine


{
TCNT1= timer1_counter; //preload timer
mikrodetik++;
if (mikrodetik==10)
{
detik++;
mikrodetik=0;

if(detik>=60)
{
menit++;
lcd.clear();
detik=0;

if(menit>=60)
{
jam++;
menit=0;
if (jam==24)
{
jam=0;
}
}
}
}
}
void loop() {
// put your main code here, to run repeatedly:
lcd.setCursor(0, 0);
lcd.print("JAM DIGITAL");

lcd.setCursor(7, 1);
lcd.print(detik);

lcd.setCursor(6, 1);
lcd.print(":");
lcd.clear();

lcd.setCursor(4, 1);
lcd.print(menit);

lcd.setCursor(3, 1);
lcd.print(":");

lcd.setCursor(1, 1);
lcd.print(jam);

S-ar putea să vă placă și