BIKIN SENDIRI JAM DIGITAL pake Chip AVR

Discussion in 'Elektronika Umum' started by astina76pav, May 22, 2012.

  1. astina76pav

    astina76pav New Member

    Messages:
    245
    Likes Received:
    191
    Trophy Points:
    0
    Silahkan Boss, yang mau mencoba bikin jam digital...
    Chip mikrokontrol nya pake ATtiny2313, ga susah nyari chip nya, banyak yang jual koq..
    Jam Digital ini udah saya coba, bisa berfungsi dengan baik...

    ini skema nya :

    [​IMG]
    Daftar Komponen :
    R1, R10,R11 = 2K2
    R2 sampe R9 = 270
    R12 sampe R17 = 22K
    C1 = 1n
    C2, C3 = 33p
    Q1 sampe Q6 = BC556
    U1 = AT90s2313 / ATtiny2313
    U2 = Kristal 4MHz
    D1 sampe D6 = Seven segment Led Common Anoda
    D7 sampe D10 = Led 5mm
    S1, S2 = saklar Push Button


    ini Source code nya, ditulis dengan bahasa AVRGCC oleh Werner Hoch :

    /************************************************
    project: 7segment clock
    author: Werner Hoch <werner.ho@gmx.de>
    file: main.c
    ************************************************/

    #include <avr/signal.h> /* interrupt vectors */
    #include <avr/interrupt.h> /* sei(), cli(),... */
    #include <string.h>
    #include "global.h"
    #include "seg7.h"
    #include "keys.h"

    #define SUB_CLOCK 360L

    uint8_t second=0, minute=58, hour=23;
    uint16_t prescaler;

    volatile uint8_t flag_sec=0, flag_halfsec=0;
    volatile uint8_t flag_key1=0, flag_key2=0;

    #define STATE_NORMAL 0
    #define STATE_CHANGE_SEC 1
    #define STATE_CHANGE_MIN 2
    #define STATE_CHANGE_HOUR 3
    uint8_t state=STATE_NORMAL;


    SIGNAL
    (SIG_OUTPUT_COMPARE1A) {
    #if UC_CLOCK % SUB_CLOCK
    OCR1A = UC_CLOCK / SUB_CLOCK - 1; // compare SUB_CLOCK - 1 times
    #endif
    if( --prescaler == 0 ){
    prescaler = SUB_CLOCK;
    flag_sec=1;
    #if UC_CLOCK % SUB_CLOCK // handle remainder
    OCR1A = UC_CLOCK / SUB_CLOCK + UC_CLOCK % SUB_CLOCK - 1; // compare once per second
    #endif
    }
    if (prescaler == SUB_CLOCK/2)
    flag_halfsec=1;

    seg7_off();
    key_check();
    flag_key1=key_rised(KEY1);
    flag_key2=key_rised(KEY2);
    seg7_multiplex();
    }

    int
    main() {
    seg7_init();
    /* seg7_test(); */

    TCCR1B = _BV(CTC1) | _BV(CS10); /* clear on compare match, prescaler 1 */

    OCR1A = UC_CLOCK / SUB_CLOCK - 1;
    TCNT1 = 0;
    prescaler = SUB_CLOCK;

    TIMSK = _BV(OCIE1A);
    sei();

    while (1) { /* infinite loop */
    if (flag_halfsec){
    flag_halfsec=0;
    switch (state){
    case STATE_NORMAL:
    break;
    case STATE_CHANGE_HOUR:
    seg7_data_set(0,0);
    seg7_data_set(1,0);
    break;
    case STATE_CHANGE_MIN:
    seg7_data_set(2,0);
    seg7_data_set(3,0);
    break;
    case STATE_CHANGE_SEC:
    seg7_data_set(4,0);
    seg7_data_set(5,0);
    break;
    }
    seg7_set_dots();
    }
    if (flag_sec) {
    flag_sec=0;
    if (++second == 60){
    second=0;
    if (++minute == 60) {
    minute=0;
    if (++hour == 24) {
    hour=0;
    }
    }
    }
    seg7_dec_set(0,hour);
    seg7_dec_set(2,minute);
    seg7_dec_set(4,second);
    seg7_clear_dots();
    }
    if (flag_key1) {
    flag_key1=0;
    switch (state){
    case STATE_NORMAL: state=STATE_CHANGE_HOUR; break;
    case STATE_CHANGE_HOUR: state=STATE_CHANGE_MIN; break;
    case STATE_CHANGE_MIN: state=STATE_CHANGE_SEC; break;
    case STATE_CHANGE_SEC: state=STATE_NORMAL; break;
    default: state=STATE_NORMAL;
    }
    }
    if (flag_key2) {
    flag_key2=0;
    switch (state){
    case STATE_CHANGE_HOUR:
    if (++hour==24)
    hour=0;
    seg7_dec_set(0,hour);
    break;
    case STATE_CHANGE_MIN:
    if (++minute == 60)
    minute=0;
    seg7_dec_set(2,minute);
    break;
    case STATE_CHANGE_SEC:
    TCNT1 = 0;
    OCR1A = UC_CLOCK / SUB_CLOCK - 1;
    prescaler = SUB_CLOCK;
    second=0;
    seg7_dec_set(4,second);
    break;
    default:
    state=STATE_NORMAL;
    }
    }
    }
    }



    Selamat Mencoba...

    Bravo
     
  2. astina76pav

    astina76pav New Member

    Messages:
    245
    Likes Received:
    191
    Trophy Points:
    0
    ini file-file buat headernya...

    Header Global:

    #include <inttypes.h>
    #include <avr/io.h>
    #include <avr/pgmspace.h>

    #define TRUE 1
    #define FALSE 0

    #define UC_CLOCK 4000000
     
    noerkrw likes this.
  3. astina76pav

    astina76pav New Member

    Messages:
    245
    Likes Received:
    191
    Trophy Points:
    0
    Header seg7:

    #define SEG7_DIGITS 6

    #define SEG_A 0x01
    #define SEG_B 0x02
    #define SEG_C 0x04
    #define SEG_D 0x08
    #define SEG_E 0x10
    #define SEG_F 0x20
    #define SEG_G 0x40
    #define SEG_DOT 0x80

    #define SEG_CHAR_0 (SEG_A + SEG_B + SEG_C + SEG_D + SEG_E + SEG_F )
    #define SEG_CHAR_1 ( SEG_B + SEG_C )
    #define SEG_CHAR_2 (SEG_A + SEG_B + SEG_D + SEG_E + SEG_G)
    #define SEG_CHAR_3 (SEG_A + SEG_B + SEG_C + SEG_D + SEG_G)
    #define SEG_CHAR_4 ( SEG_B + SEG_C + SEG_F + SEG_G)
    #define SEG_CHAR_5 (SEG_A + SEG_C + SEG_D + SEG_F + SEG_G)
    #define SEG_CHAR_6 (SEG_A + SEG_C + SEG_D + SEG_E + SEG_F + SEG_G)
    #define SEG_CHAR_7 (SEG_A + SEG_B + SEG_C )
    #define SEG_CHAR_8 (SEG_A + SEG_B + SEG_C + SEG_D + SEG_E + SEG_F + SEG_G)
    #define SEG_CHAR_9 (SEG_A + SEG_B + SEG_C + SEG_D + SEG_F + SEG_G)

    #define DATA_DDR DDRB
    #define DATA_PORT PORTB

    #define DIGIT_DDR DDRD
    #define DIGIT_PORT PORTD
    #define DIGIT_0 0x01
    #define DIGIT_1 0x04
    #define DIGIT_2 0x08
    #define DIGIT_3 0x10
    #define DIGIT_4 0x20
    #define DIGIT_5 0x40
    #define DIGIT_MASK (DIGIT_0+ DIGIT_1+ DIGIT_2+ DIGIT_3+ DIGIT_4+ DIGIT_5)

    void seg7_init(); /* clear the display */
    void seg7_multiplex(); /* multiplex to the next digit */
    void seg7_data_set(uint8_t digitnr,uint8_t data); /* put data to segment */
    void seg7_digit_set(uint8_t digitnr,uint8_t data); /* put 0-F data to segment */
    void seg7_test(); /* test for the hardware */
    void seg7_dec_set(uint8_t digitnr,uint8_t data); /* put a decimal number into the display */
    void seg7_set_dots(); /* turn the dots on */
    void seg7_clear_dots(); /* turn the dots off */
    void seg7_off(); /* turn leds off, make ports highz */
     
  4. astina76pav

    astina76pav New Member

    Messages:
    245
    Likes Received:
    191
    Trophy Points:
    0
    Header keys:

    #define KEY1_PORT_OUT PORTB
    #define KEY1_PORT_IN PINB
    #define KEY1_PORT_DDR DDRB
    #define KEY1_PIN 7

    #define KEY2_PORT_OUT PORTB
    #define KEY2_PORT_IN PINB
    #define KEY2_PORT_DDR DDRB
    #define KEY2_PIN 6

    /* key numbers */
    #define KEY1 0
    #define KEY2 1

    /* key status */
    #define KEY_PRESSED 0 /* key is on */
    #define KEY_RELEASED 1 /* key is off */
    #define KEY_RISE 2 /* key has just been pressed */
    #define KEY_FALL 3 /* key has just been releasd */

    void key_check(); /* read all pins and ajust status registers */

    void key_status_ajust(uint8_t nr, uint8_t k); /* subroutine of key_status */

    uint8_t key_rised(uint8_t key); /* return TRUE if the key rised */

    void key_delay_2us(); /* needed because signals are too slow */
     
  5. Abilcomsell

    Abilcomsell New Member

    Messages:
    14
    Likes Received:
    1
    Trophy Points:
    0
    Dalam hitungan lebih kurang 1 jam, ada perbedaan sekian detik dengan waktu normal nggak bos ?
    Trus dari pada susah2 ngeprogramnya, saya bisa pesan IC yang sdh diprogram ( AT90s2313 / ATtiny2313 ) ?

    Thx atas infonya
     
  6. astina76pav

    astina76pav New Member

    Messages:
    245
    Likes Received:
    191
    Trophy Points:
    0
    Tingkat akurasi nya lumayan bagus sih, walau ga sebagus jam yang pake chip RTC external kaya DS1307...
    Jam Digital yang ini dalam 1 hari ada selisih sekitar 1 detik dibanding dengan waktu normal...

    Kalo mau yang lebih akurat, ane ada lagi skema Jam Digital pake ATmega8+DS1307, selain lebih akurat, juga dilengkapi backup waktu, jadi walaupun tegangannya hilang ga perlu setting waktu lagi.. nanti ane bikin threadnya...


    oh ya, kalo boss mau IC yg udah di program, bisa ane bantu, apalagi kalo bos tinggal di seputaran bandung-garut silahkan datang langsung ke rumah ane...
    ato tanya-tanya lewat pm aja, soalnya disini bukan room jual beli, ntar ane bisa-bisa dimarahin sama om admin... :peace:

    Oke boss...

    bravo..
     

Share This Page