JAM DIGITAL RTC DS1307 Skematik Rangkaian Board PCB…


JAM DIGITAL RTC DS1307

Skematik Rangkaian

Board PCB

Layout Komponen

Listing Program

http://www.4shared.com/file/OzBtgCo2/jam.html

About these ads

63 pemikiran pada “JAM DIGITAL RTC DS1307 Skematik Rangkaian Board PCB…

    • jadikan 1 file asm51.exe dan oh.exe dan file program jam.asm simpan di drive bebas misal : D

      buka command prompt windows accesories
      ketik d: enter

      ketik asm51 jam.asm kemudian enter

      keluar no error found jika tidak terdapat error

      ketik oh jam.obj kemudian enter

      maka file .hex akan ada di drive :D

  1. ini listing yang sudah bisa dikompile di m-ide :
    ;==============================================================;
    ; Inisialisasi Port
    ;==============================================================;
    Down BIT P3.0
    Menu bit p3.1
    Up BIT P3.2

    CD4094_CP BIT P1.1
    CD4094_D BIT P1.0
    CD4094_Str BIT P1.2

    I2C_SDA BIT P2.6
    I2C_SCL BIT P2.7

    LEDDigit1 DATA 30h
    LEDDigit2 DATA 31h
    LEDDigit3 DATA 32h
    LEDDigit4 DATA 33h
    LEDDigit5 DATA 34h
    LEDDigit6 DATA 35h
    LEDDigit7 DATA 36h
    LEDDigit8 DATA 37h
    LEDDigit9 DATA 38h
    LEDDigit10 DATA 39h
    LEDDigit11 DATA 3ah
    LEDDigit12 DATA 3bh
    LEDDigit13 DATA 3ch
    LEDDigit14 DATA 3dh

    puluhan data 40h
    RTCDetik DATA 41h ;00
    RTCMenit DATA 42h ;01
    RTCjam DATA 43h ;02
    RTCHari DATA 44h ;03
    RTCTanggal DATA 45h ;04
    RTCBulan DATA 46h ;05
    RTCTahun DATA 47h ;06
    RTCControl DATA 48h ;07
    decl equ 49h
    dech equ 4ah
    tmp equ 4bh

    org 00h
    ;==============================================================;
    ; Program Utama
    ;==============================================================;

    ProgramLoop:
    loop: jb menu,Lanjut
    call Delay250uS
    jnb menu,$
    call ReadAllRTC
    jmp Edit_rtc

    lanjut: call ReadAllRTC
    ACall StreamRTC
    ACall SendMsgLED
    Jmp Loop
    ;==============================================================;
    ; Edit RTC
    ;==============================================================;
    Edit_rtc: CLR CD4094_CP
    Clr CD4094_Str
    ACall ClrDispLED
    MOV A,#0ffh
    ACall CD4094_Shift
    MOV A,#0ffh
    ACall CD4094_Shift
    MOV A,LEDDigit3
    ACall CD4094_Shift
    MOV A,LEDDigit4
    ACall CD4094_Shift
    MOV A,#0ffh
    ACall CD4094_Shift
    MOV A,#0ffh
    ACall CD4094_Shift
    SetB CD4094_Str
    Clr CD4094_Str
    call Tunda1Detik

    Call StreamRTC
    call SendMsgLED
    call Tunda1Detik
    up_jam: jb up,down_jam
    call Delay250uS
    jnb up,$
    MOV A,RTCJam
    CJNE A,#23h,Up_jam2
    MOV A,#0
    Jmp Up_jam3
    Up_jam2: add a,#1
    Up_jam3: da a
    MOV RTCJam,A
    call tulis_rtc_jam
    jmp edit_rtc

    down_jam: jb down,cek_Menit
    call Delay250uS
    jnb down,$
    MOV A,rtcjam
    mov DPTR,#tabel_dec
    movc A,@A+DPTR
    dec a
    CJNE A,#0ffh,down_jam2
    MOV A,#23
    down_jam2: mov DPTR,#tabel_hex
    movc A,@A+DPTR
    MOV RTCJam,A
    call tulis_rtc_jam
    jmp edit_rtc

    cek_Menit: jb menu,Edit_rtc
    call Delay250uS
    jnb menu,$
    Cek_menit_2: CLR CD4094_CP
    Clr CD4094_Str
    ACall ClrDispLED
    MOV A,LEDDigit5
    ACall CD4094_Shift
    MOV A,LEDDigit6
    ACall CD4094_Shift
    MOV A,#0ffh
    ACall CD4094_Shift
    MOV A,#0ffh
    ACall CD4094_Shift
    MOV A,#0ffh
    ACall CD4094_Shift
    MOV A,#0ffh
    ACall CD4094_Shift
    SetB CD4094_Str
    Clr CD4094_Str
    call Tunda1Detik
    Call StreamRTC
    call SendMsgLED
    call Tunda1Detik

    up_menit: jb up,down_menit
    call Delay250uS
    jnb up,$
    MOV A,RTCmenit
    CJNE A,#59h,Up_menit2
    MOV A,#0
    Jmp Up_menit3
    Up_menit2: add a,#1
    Up_menit3: da a
    MOV RTCmenit,A
    call tulis_rtc_menit
    jmp Cek_menit_2

    down_menit: jb down,Keluar
    call Delay250uS
    jnb down,$
    MOV A,rtcmenit
    mov DPTR,#tabel_dec
    movc A,@A+DPTR
    dec a
    CJNE A,#0ffh,down_menit2
    MOV A,#59
    down_menit2: mov DPTR,#tabel_hex
    movc A,@A+DPTR
    MOV RTCmenit,A
    call tulis_rtc_menit
    jmp Cek_menit_2

    Keluar: jb menu,Cek_menit_2
    call Delay250uS
    jnb menu,$
    call tulis_rtc_detik
    jmp Loop

    ;==============================================================;
    ; Hexa ke desimal
    ;==============================================================;
    tabel_hex:
    db 00h,01h,02h,03h,04h,05h,06h,07h,08h,09h,10h
    db 11h,12h,13h,14h,15h,16h,17h,18h,19h,20h
    db 21h,22h,23h,24h,25h,26h,27h,28h,29h,30h
    db 31h,32h,33h,34h,35h,36h,37h,38h,39h,40h
    db 41h,42h,43h,44h,45h,46h,47h,48h,49h,50h
    db 51h,52h,53h,54h,55h,56h,57h,58h,59h,60h
    db 61h,62h,63h,64h,65h,66h,67h,68h,69h,70h
    db 71h,72h,73h,74h,75h,76h,77h,78h,79h,80h
    db 81h,82h,83h,84h,85h,86h,87h,88h,89h,90h
    db 91h,82h,93h,94h,95h,96h,97h,98h,99h

    tabel_dec:
    db 00,01,02,03,04,05,06,07,08,09,00,00,00,00,00,00
    db 10,11,12,13,14,15,16,17,18,19,00,00,00,00,00,00
    db 20,21,22,23,24,25,26,27,28,29,00,00,00,00,00,00
    db 30,31,32,33,34,35,36,37,38,39,00,00,00,00,00,00
    db 40,41,42,43,44,45,46,47,48,49,00,00,00,00,00,00
    db 50,51,52,53,54,55,56,57,58,59,00,00,00,00,00,00
    db 60,61,62,63,64,65,66,67,68,69,00,00,00,00,00,00
    db 70,71,72,73,74,75,76,77,78,79,00,00,00,00,00,00
    db 80,81,82,83,84,85,86,87,88,89,00,00,00,00,00,00
    db 90,91,82,93,94,95,96,97,98,99,00,00,00,00,00,00

    ;==============================================================;
    ; Tampilan 7segment
    ;==============================================================;
    SendMsgLED: CLR CD4094_CP
    Clr CD4094_Str
    ACall ClrDispLED

    MOV A,LEDDigit5
    ACall CD4094_Shift
    MOV A,LEDDigit6
    ACall CD4094_Shift

    MOV A,LEDDigit3
    ACall CD4094_Shift
    MOV A,LEDDigit4
    ACall CD4094_Shift

    MOV A,LEDDigit1
    ACall CD4094_Shift
    MOV A,LEDDigit2
    ACall CD4094_Shift
    SetB CD4094_Str
    Clr CD4094_Str
    Ret

    ClrDispLED: MOV A,#0FFh
    CD4094_Shift: MOV R4,#8
    CD4094_ShLoop: RLC A
    MOV CD4094_D,C
    SetB CD4094_CP
    CLR CD4094_CP
    DJNZ R4,CD4094_ShLoop
    Ret
    ;==============================================================;
    ; Delay
    ;==============================================================;
    Tunda1Detik: MOV R7,#1
    Tunda1DetikL2: MOV R6,#100
    Tunda1DetikL1: MOV R5,#230
    DJNZ R5,$
    DJNZ R6,Tunda1DetikL1
    DJNZ R7,Tunda1DetikL2
    Ret

    ;==============================================================;
    Delay250uS: Push Acc
    MOV A,#250
    DJNZ Acc,$
    Pop Acc
    Ret
    ;==============================================================;
    ; Konversi ke tampilan 7 segment
    ;==============================================================;
    GetLEDNum: Inc A
    MOVC A,@A+PC
    Ret

    CharLED0: DB 11000000b ;0
    DB 11111001b ;1
    DB 10100100b;2
    DB 10110000b;3
    DB 10011001b;4
    DB 10010010b;5
    DB 10000010b;6
    DB 11111000b;7
    DB 10000000b;8
    DB 10010000b;9
    DB 10001000b ;A
    DB 10000011b ;B
    DB 11000110b ;C
    DB 10100001b ;D
    DB 10000110b ;E
    DB 10001110b ;F
    ;==============================================================;
    ; Ambil data RTC simpan ke RAM mikro
    ;==============================================================;
    StreamRTC: MOV A,rtcdetik
    SWAP A
    ANL A,#00Fh
    ACall GetLEDNum
    MOV LEDDigit1,A
    MOV A,rtcdetik
    ANL A,#00Fh
    ACall GetLEDNum
    MOV LEDDigit2,A

    MOV A,rtcmenit
    SWAP A
    ANL A,#00Fh
    ACall GetLEDNum
    MOV LEDDigit3,A
    MOV A,rtcmenit
    ANL A,#00Fh
    ACall GetLEDNum
    MOV LEDDigit4,A

    MOV A,rtcjam
    SWAP A
    ANL A,#00Fh
    ACall GetLEDNum
    MOV LEDDigit5,A
    MOV A,rtcjam
    ANL A,#00Fh
    ACall GetLEDNum
    MOV LEDDigit6,A

    Ret
    ;==============================================================;
    ; Tulis / baca eeprom
    ;==============================================================;
    Tulis_memori: mov A,#10100000b ;SlaveAdd AT24C04
    mov B,#10h ;Alamat 10h
    mov R1,#50 ;datanya
    ACall I2C_WriteByte
    JC Error_tulis
    ret
    Error_tulis: jmp Tulis_memori

    Baca_memori: mov A,#10100001b ;SlaveAdd AT24C04
    mov B,#10h ;Alamat 10h
    ACall I2C_ReadByte
    JC Error_baca
    mov puluhan,A ;simpan di puluhan
    ret
    Error_baca: jmp Baca_memori

    ;==============================================================;
    ; Tulis / baca rtc
    ;==============================================================;
    Tulis_rtc_jam: MOV A,#11010000b
    mov B,#02h ;Alamat
    mov R1,rtcjam ;datanya
    ACall I2C_WriteByte
    JC Error_Jam_rtc
    ret
    Error_Jam_rtc: jmp Tulis_rtc_jam

    Tulis_rtc_menit: MOV A,#11010000b
    mov B,#01h ;Alamat
    mov R1,rtcmenit ;datanya
    ACall I2C_WriteByte
    JC Error_menit_rtc
    ret
    Error_menit_rtc: jmp Tulis_rtc_menit

    Tulis_rtc_Detik: MOV A,#11010000b
    mov B,#00h ;Alamat
    mov R1,#00h ;datanya
    ACall I2C_WriteByte
    JC Error_Detik_rtc
    ret
    Error_Detik_rtc: jmp Tulis_rtc_Detik

    Baca_rtc: mov A,#11010001b ;SlaveAdd DS1307
    mov B,#00h ;Alamat 00h
    ACall I2C_ReadByte
    JC Error_b_rtc
    mov puluhan,A ;simpan di puluhan
    ret
    Error_b_rtc: jmp Baca_rtc

    StartRTC: MOV A,RTCDetik
    ANL A,#7Fh
    MOV R1,A
    MOV A,#11010000b
    MOV B,#0
    ACall I2C_WriteByte ; ACC = SlaveAddress, B = WordAddress, R1 = Data byte
    MOV R1,#10h
    MOV A,#11010000b
    MOV B,#07 ;address For Control
    ACall I2C_WriteByte ; ACC = SlaveAddress, B = WordAddress, R1 = Data byte

    ReadAllRTC: MOV A,#11010001b ;SlaveAddress
    MOV B,#0
    MOV R1,#RTCDetik
    MOV R2,#9
    ACall I2C_ReadData ; ACC = SlaveAddress, B = WordAddress, R1 = DataMemoryOffset, R2 = Counter
    ret
    ;==============================================================;
    ; pengendali Bus IIC disusun oleh
    ; Dhanny Dhuzell 2008 Bandar Lampung
    ; Single Master Sudah diuji-coba dan sangat baik
    ; Bandwidth sekitar 80 kHz (Mode-Normal-Speed)
    ; Modul ini butuh “ErrorsEqu.inc”
    ;==============================================================;
    Err_DL_WrongCommand EQU 1
    Err_DL_BadConvert EQU 2
    Err_DL_OutOfMemory EQU 3
    Err_DL_InvalidCheckSum EQU 4
    Err_DL_InvalidCmdFormat EQU 5
    Err_DL_WriteFail EQU 6
    Err_DL_VerifyGotError EQU 7

    Err_IIC_BusFailToStart EQU 11
    Err_IIC_InvalidSlaAddr EQU 12
    Err_IIC_InvalidAddress EQU 13
    Err_IIC_PrematureNOACK EQU 14

    Delay_3MC:
    NOP
    NOP
    NOP
    ret

    Delay_4Mc:
    NOP
    NOP
    NOP
    NOP
    ret

    Release_SCL_High:
    SETB I2C_SCL
    JNB I2C_SCL,$
    ret

    ;==============================================================;
    I2C_Start: SetB I2C_SDA
    SetB I2C_SCL
    JNB I2C_SDA, I2C_BusBusy
    JNB I2C_SCL, I2C_BusBusy
    Clr I2C_SDA
    Push ACC
    POP ACC
    Clr I2C_SCL
    Push ACC
    POP ACC
    Clr C
    Ret
    I2C_BusBusy: SetB C
    Ret

    ;==============================================================;
    I2C_Stop: Clr I2C_SDA
    call Release_SCL_High
    call Delay_3MC
    SetB I2C_SDA
    Ret

    ;==============================================================;
    I2C_SendByte: PUSH B
    MOV B,#8

    I2C_SendByteL: RLC A ;1MC |
    MOV I2C_SDA,C ;2MC |
    call Release_SCL_High
    call Delay_3MC
    Clr I2C_SCL ;1MC +-+
    DJNZ B,I2C_SendByteL ;2MC |

    call Release_SCL_High
    call Delay_4Mc
    MOV C,I2C_SDA ;1MC | read ACK/NOACK
    Clr I2C_SCL ;1MC +-+
    call Delay_3MC
    POP B ;2MC |
    RET

    ; Low = 6MC High = 5MC

    ;==============================================================;
    I2C_GetByte: PUSH B
    PUSH PSW ;Save CY
    MOV B,#8
    SetB I2C_SDA ;1MC |

    I2C_GetByteL: call Release_SCL_High
    call Delay_3Mc
    MOV C,I2C_SDA ;1MC |
    RLC A ;1MC |
    Clr I2C_SCL ;1MC +-+
    call Delay_3MC
    DJNZ B,I2C_GetByteL ;2MC |

    POP PSW ;1MC | Load CY
    MOV I2C_SDA,C ;2MC |
    call Release_SCL_High
    call Delay_3MC
    Clr I2C_SCL ;1MC +-+
    SetB I2C_SDA ;1MC |
    NOP
    NOP
    POP B ;1MC | Load CY
    RET

    ; Low = 6MC High = 5MC
    ;==============================================================;

    ;==============================================================;
    I2C_WriteByte: Call I2C_Start
    JC l_ERROR1
    Clr ACC.0
    Call I2C_SendByte ;Send SlaveAddress
    JC l_ERROR2
    MOV A,B
    Call I2C_SendByte ;Send Word Address
    JC l_ERROR3
    MOV A,R1
    Call I2C_SendByte ;Send Data Byte
    JC l_ERROR4
    Call I2C_Stop
    Clr C
    Call I2C_WriteDelay
    Clr A
    MOV B,A ;max 5mS
    I2C_WriteByteL: DJNZ ACC,I2C_WriteByteL
    DJNZ B,I2C_WriteByteL
    Ret
    ; ACC = SlaveAddress, B = WordAddress, R1 = Data byte

    ;==============================================================;
    I2C_ReadByte: Call I2C_Start
    JC l_ERROR1
    MOV DPL,A ;Save SlaveAddress
    Clr ACC.0
    Call I2C_SendByte ;Send SlaveAddress
    JC l_ERROR2
    MOV A,B
    Call I2C_SendByte ;Send Word Address
    JC l_ERROR3

    Call I2C_Start
    JC l_ERROR1
    MOV A,DPL ;Load SlaveAddress again
    SetB ACC.0
    Call I2C_SendByte ;Send SlaveAddress
    JC l_ERROR2

    SetB C ;Set to NOACK
    Call I2C_GetByte ;Get Data Byte
    Call I2C_Stop
    Clr C
    Ret

    ; ACC = SlaveAddress, B = WordAddress

    ;==============================================================;
    I2C_WriteData: Call I2C_Start
    JC l_ERROR1
    Clr ACC.0
    Call I2C_SendByte ;Send SlaveAddress
    JC l_ERROR2
    MOV A,B
    Call I2C_SendByte ;Send Word Address
    JC l_ERROR3
    I2C_WriteDataL: MOV A,@R1
    call I2C_SendByte ;Send Data Byte
    INC R1
    JC l_ERROR4
    DJNZ R2,I2C_WriteDataL
    I2C_WriteDataE: Call I2C_Stop
    Clr C
    Call I2C_WriteDelay
    I2C_WriteDelay: Clr A
    MOV B,A ;max 5mS (( 2 *256 ) * 256 )
    I2C_WriteDataF: DJNZ ACC,I2C_WriteDataF
    DJNZ B,I2C_WriteDataF
    Ret

    ; ACC = SlaveAddress, B = WordAddress, R1 = DataMemoryOffset, R2 = Counter,

    ;==============================================================;
    l_ERROR1: MOV A,#Err_IIC_BusFailToStart
    Call I2C_Stop
    Ret
    l_ERROR2: MOV A,#Err_IIC_InvalidSlaAddr
    Call I2C_Stop
    Ret
    l_ERROR3: MOV A,#Err_IIC_InvalidAddress
    Call I2C_Stop
    Ret
    l_ERROR4: MOV A,#Err_IIC_PrematureNOACK
    Call I2C_Stop
    Ret

    ;==============================================================;
    I2C_ReadData: Call I2C_Start
    JC l_ERROR1
    MOV DPL,A ;Save SlaveAddress
    Clr ACC.0
    Call I2C_SendByte ;Send SlaveAddress
    JC l_ERROR2
    MOV A,B
    Call I2C_SendByte ;Send Word Address
    JC l_ERROR3

    Call I2C_Start
    JC l_ERROR1
    MOV A,DPL ;Load SlaveAddress again
    SetB ACC.0
    Call I2C_SendByte ;Send SlaveAddress
    JC l_ERROR2

    DEC R2
    I2C_ReadDataL: Clr C ;Set to ACK
    Call I2C_GetByte ;Get Data Byte
    MOV @R1,A
    INC R1
    DJNZ R2,I2C_ReadDataL
    SetB C ;Set to NOACK
    Call I2C_GetByte ;Get Data Byte
    MOV @R1,A
    Call I2C_Stop
    Clr C
    Ret

    ; ACC = SlaveAddress, B = WordAddress, R1 = DataMemoryOffset, R2 = Counter
    END

  2. gan, udd di simulasikan ke isis tapi enggak mau run,,,,
    oy diskematiknya P1.5, P1.6, P1.7 kemana itu gan larinyya???
    help me,,,,
    (y)

    • ini coba yang tidak error
      ;==============================================================;
      ; Inisialisasi Port
      ;==============================================================;
      Down BIT P3.0
      Menu bit p3.1
      Up BIT P3.2

      CD4094_CP BIT P1.1
      CD4094_D BIT P1.0
      CD4094_Str BIT P1.2

      I2C_SDA BIT P2.6
      I2C_SCL BIT P2.7

      LEDDigit1 DATA 30h
      LEDDigit2 DATA 31h
      LEDDigit3 DATA 32h
      LEDDigit4 DATA 33h
      LEDDigit5 DATA 34h
      LEDDigit6 DATA 35h
      LEDDigit7 DATA 36h
      LEDDigit8 DATA 37h
      LEDDigit9 DATA 38h
      LEDDigit10 DATA 39h
      LEDDigit11 DATA 3ah
      LEDDigit12 DATA 3bh
      LEDDigit13 DATA 3ch
      LEDDigit14 DATA 3dh

      puluhan data 40h
      RTCDetik DATA 41h ;00
      RTCMenit DATA 42h ;01
      RTCjam DATA 43h ;02
      RTCHari DATA 44h ;03
      RTCTanggal DATA 45h ;04
      RTCBulan DATA 46h ;05
      RTCTahun DATA 47h ;06
      RTCControl DATA 48h ;07
      decl equ 49h
      dech equ 4ah
      tmp equ 4bh

      org 00h
      ;==============================================================;
      ; Program Utama
      ;==============================================================;

      ProgramLoop:
      loop: jb menu,Lanjut
      call Delay250uS
      jnb menu,$
      call ReadAllRTC
      jmp Edit_rtc

      lanjut: call ReadAllRTC
      ACall StreamRTC
      ACall SendMsgLED
      Jmp Loop
      ;==============================================================;
      ; Edit RTC
      ;==============================================================;
      Edit_rtc: CLR CD4094_CP
      Clr CD4094_Str
      ACall ClrDispLED
      MOV A,#0ffh
      ACall CD4094_Shift
      MOV A,#0ffh
      ACall CD4094_Shift
      MOV A,LEDDigit3
      ACall CD4094_Shift
      MOV A,LEDDigit4
      ACall CD4094_Shift
      MOV A,#0ffh
      ACall CD4094_Shift
      MOV A,#0ffh
      ACall CD4094_Shift
      SetB CD4094_Str
      Clr CD4094_Str
      call Tunda1Detik

      Call StreamRTC
      call SendMsgLED
      call Tunda1Detik
      up_jam: jb up,down_jam
      call Delay250uS
      jnb up,$
      MOV A,RTCJam
      CJNE A,#23h,Up_jam2
      MOV A,#0
      Jmp Up_jam3
      Up_jam2: add a,#1
      Up_jam3: da a
      MOV RTCJam,A
      call tulis_rtc_jam
      jmp edit_rtc

      down_jam: jb down,cek_Menit
      call Delay250uS
      jnb down,$
      MOV A,rtcjam
      mov DPTR,#tabel_dec
      movc A,@A+DPTR
      dec a
      CJNE A,#0ffh,down_jam2
      MOV A,#23
      down_jam2: mov DPTR,#tabel_hex
      movc A,@A+DPTR
      MOV RTCJam,A
      call tulis_rtc_jam
      jmp edit_rtc

      cek_Menit: jb menu,Edit_rtc
      call Delay250uS
      jnb menu,$
      Cek_menit_2: CLR CD4094_CP
      Clr CD4094_Str
      ACall ClrDispLED
      MOV A,LEDDigit5
      ACall CD4094_Shift
      MOV A,LEDDigit6
      ACall CD4094_Shift
      MOV A,#0ffh
      ACall CD4094_Shift
      MOV A,#0ffh
      ACall CD4094_Shift
      MOV A,#0ffh
      ACall CD4094_Shift
      MOV A,#0ffh
      ACall CD4094_Shift
      SetB CD4094_Str
      Clr CD4094_Str
      call Tunda1Detik
      Call StreamRTC
      call SendMsgLED
      call Tunda1Detik

      up_menit: jb up,down_menit
      call Delay250uS
      jnb up,$
      MOV A,RTCmenit
      CJNE A,#59h,Up_menit2
      MOV A,#0
      Jmp Up_menit3
      Up_menit2: add a,#1
      Up_menit3: da a
      MOV RTCmenit,A
      call tulis_rtc_menit
      jmp Cek_menit_2

      down_menit: jb down,Keluar
      call Delay250uS
      jnb down,$
      MOV A,rtcmenit
      mov DPTR,#tabel_dec
      movc A,@A+DPTR
      dec a
      CJNE A,#0ffh,down_menit2
      MOV A,#59
      down_menit2: mov DPTR,#tabel_hex
      movc A,@A+DPTR
      MOV RTCmenit,A
      call tulis_rtc_menit
      jmp Cek_menit_2

      Keluar: jb menu,Cek_menit_2
      call Delay250uS
      jnb menu,$
      call tulis_rtc_detik
      jmp Loop

      ;==============================================================;
      ; Hexa ke desimal
      ;==============================================================;
      tabel_hex:
      db 00h,01h,02h,03h,04h,05h,06h,07h,08h,09h,10h
      db 11h,12h,13h,14h,15h,16h,17h,18h,19h,20h
      db 21h,22h,23h,24h,25h,26h,27h,28h,29h,30h
      db 31h,32h,33h,34h,35h,36h,37h,38h,39h,40h
      db 41h,42h,43h,44h,45h,46h,47h,48h,49h,50h
      db 51h,52h,53h,54h,55h,56h,57h,58h,59h,60h
      db 61h,62h,63h,64h,65h,66h,67h,68h,69h,70h
      db 71h,72h,73h,74h,75h,76h,77h,78h,79h,80h
      db 81h,82h,83h,84h,85h,86h,87h,88h,89h,90h
      db 91h,82h,93h,94h,95h,96h,97h,98h,99h

      tabel_dec:
      db 00,01,02,03,04,05,06,07,08,09,00,00,00,00,00,00
      db 10,11,12,13,14,15,16,17,18,19,00,00,00,00,00,00
      db 20,21,22,23,24,25,26,27,28,29,00,00,00,00,00,00
      db 30,31,32,33,34,35,36,37,38,39,00,00,00,00,00,00
      db 40,41,42,43,44,45,46,47,48,49,00,00,00,00,00,00
      db 50,51,52,53,54,55,56,57,58,59,00,00,00,00,00,00
      db 60,61,62,63,64,65,66,67,68,69,00,00,00,00,00,00
      db 70,71,72,73,74,75,76,77,78,79,00,00,00,00,00,00
      db 80,81,82,83,84,85,86,87,88,89,00,00,00,00,00,00
      db 90,91,82,93,94,95,96,97,98,99,00,00,00,00,00,00

      ;==============================================================;
      ; Tampilan 7segment
      ;==============================================================;
      SendMsgLED: CLR CD4094_CP
      Clr CD4094_Str
      ACall ClrDispLED

      MOV A,LEDDigit5
      ACall CD4094_Shift
      MOV A,LEDDigit6
      ACall CD4094_Shift

      MOV A,LEDDigit3
      ACall CD4094_Shift
      MOV A,LEDDigit4
      ACall CD4094_Shift

      MOV A,LEDDigit1
      ACall CD4094_Shift
      MOV A,LEDDigit2
      ACall CD4094_Shift
      SetB CD4094_Str
      Clr CD4094_Str
      Ret

      ClrDispLED: MOV A,#0FFh
      CD4094_Shift: MOV R4,#8
      CD4094_ShLoop: RLC A
      MOV CD4094_D,C
      SetB CD4094_CP
      CLR CD4094_CP
      DJNZ R4,CD4094_ShLoop
      Ret
      ;==============================================================;
      ; Delay
      ;==============================================================;
      Tunda1Detik: MOV R7,#1
      Tunda1DetikL2: MOV R6,#100
      Tunda1DetikL1: MOV R5,#230
      DJNZ R5,$
      DJNZ R6,Tunda1DetikL1
      DJNZ R7,Tunda1DetikL2
      Ret

      ;==============================================================;
      Delay250uS: Push Acc
      MOV A,#250
      DJNZ Acc,$
      Pop Acc
      Ret
      ;==============================================================;
      ; Konversi ke tampilan 7 segment
      ;==============================================================;
      GetLEDNum: Inc A
      MOVC A,@A+PC
      Ret

      CharLED0: DB 11000000b ;0
      DB 11111001b ;1
      DB 10100100b;2
      DB 10110000b;3
      DB 10011001b;4
      DB 10010010b;5
      DB 10000010b;6
      DB 11111000b;7
      DB 10000000b;8
      DB 10010000b;9
      DB 10001000b ;A
      DB 10000011b ;B
      DB 11000110b ;C
      DB 10100001b ;D
      DB 10000110b ;E
      DB 10001110b ;F
      ;==============================================================;
      ; Ambil data RTC simpan ke RAM mikro
      ;==============================================================;
      StreamRTC: MOV A,rtcdetik
      SWAP A
      ANL A,#00Fh
      ACall GetLEDNum
      MOV LEDDigit1,A
      MOV A,rtcdetik
      ANL A,#00Fh
      ACall GetLEDNum
      MOV LEDDigit2,A

      MOV A,rtcmenit
      SWAP A
      ANL A,#00Fh
      ACall GetLEDNum
      MOV LEDDigit3,A
      MOV A,rtcmenit
      ANL A,#00Fh
      ACall GetLEDNum
      MOV LEDDigit4,A

      MOV A,rtcjam
      SWAP A
      ANL A,#00Fh
      ACall GetLEDNum
      MOV LEDDigit5,A
      MOV A,rtcjam
      ANL A,#00Fh
      ACall GetLEDNum
      MOV LEDDigit6,A

      Ret
      ;==============================================================;
      ; Tulis / baca eeprom
      ;==============================================================;
      Tulis_memori: mov A,#10100000b ;SlaveAdd AT24C04
      mov B,#10h ;Alamat 10h
      mov R1,#50 ;datanya
      ACall I2C_WriteByte
      JC Error_tulis
      ret
      Error_tulis: jmp Tulis_memori

      Baca_memori: mov A,#10100001b ;SlaveAdd AT24C04
      mov B,#10h ;Alamat 10h
      ACall I2C_ReadByte
      JC Error_baca
      mov puluhan,A ;simpan di puluhan
      ret
      Error_baca: jmp Baca_memori

      ;==============================================================;
      ; Tulis / baca rtc
      ;==============================================================;
      Tulis_rtc_jam: MOV A,#11010000b
      mov B,#02h ;Alamat
      mov R1,rtcjam ;datanya
      ACall I2C_WriteByte
      JC Error_Jam_rtc
      ret
      Error_Jam_rtc: jmp Tulis_rtc_jam

      Tulis_rtc_menit: MOV A,#11010000b
      mov B,#01h ;Alamat
      mov R1,rtcmenit ;datanya
      ACall I2C_WriteByte
      JC Error_menit_rtc
      ret
      Error_menit_rtc: jmp Tulis_rtc_menit

      Tulis_rtc_Detik: MOV A,#11010000b
      mov B,#00h ;Alamat
      mov R1,#00h ;datanya
      ACall I2C_WriteByte
      JC Error_Detik_rtc
      ret
      Error_Detik_rtc: jmp Tulis_rtc_Detik

      Baca_rtc: mov A,#11010001b ;SlaveAdd DS1307
      mov B,#00h ;Alamat 00h
      ACall I2C_ReadByte
      JC Error_b_rtc
      mov puluhan,A ;simpan di puluhan
      ret
      Error_b_rtc: jmp Baca_rtc

      StartRTC: MOV A,RTCDetik
      ANL A,#7Fh
      MOV R1,A
      MOV A,#11010000b
      MOV B,#0
      ACall I2C_WriteByte ; ACC = SlaveAddress, B = WordAddress, R1 = Data byte
      MOV R1,#10h
      MOV A,#11010000b
      MOV B,#07 ;address For Control
      ACall I2C_WriteByte ; ACC = SlaveAddress, B = WordAddress, R1 = Data byte

      ReadAllRTC: MOV A,#11010001b ;SlaveAddress
      MOV B,#0
      MOV R1,#RTCDetik
      MOV R2,#9
      ACall I2C_ReadData ; ACC = SlaveAddress, B = WordAddress, R1 = DataMemoryOffset, R2 = Counter
      ret
      ;==============================================================;
      ; pengendali Bus IIC disusun oleh
      ; Dhanny Dhuzell 2008 Bandar Lampung
      ; Single Master Sudah diuji-coba dan sangat baik
      ; Bandwidth sekitar 80 kHz (Mode-Normal-Speed)
      ; Modul ini butuh “ErrorsEqu.inc”
      ;==============================================================;
      Err_DL_WrongCommand EQU 1
      Err_DL_BadConvert EQU 2
      Err_DL_OutOfMemory EQU 3
      Err_DL_InvalidCheckSum EQU 4
      Err_DL_InvalidCmdFormat EQU 5
      Err_DL_WriteFail EQU 6
      Err_DL_VerifyGotError EQU 7

      Err_IIC_BusFailToStart EQU 11
      Err_IIC_InvalidSlaAddr EQU 12
      Err_IIC_InvalidAddress EQU 13
      Err_IIC_PrematureNOACK EQU 14

      Delay_3MC:
      NOP
      NOP
      NOP
      ret

      Delay_4Mc:
      NOP
      NOP
      NOP
      NOP
      ret

      Release_SCL_High:
      SETB I2C_SCL
      JNB I2C_SCL,$
      ret

      ;==============================================================;
      I2C_Start: SetB I2C_SDA
      SetB I2C_SCL
      JNB I2C_SDA, I2C_BusBusy
      JNB I2C_SCL, I2C_BusBusy
      Clr I2C_SDA
      Push ACC
      POP ACC
      Clr I2C_SCL
      Push ACC
      POP ACC
      Clr C
      Ret
      I2C_BusBusy: SetB C
      Ret

      ;==============================================================;
      I2C_Stop: Clr I2C_SDA
      call Release_SCL_High
      call Delay_3MC
      SetB I2C_SDA
      Ret

      ;==============================================================;
      I2C_SendByte: PUSH B
      MOV B,#8

      I2C_SendByteL: RLC A ;1MC |
      MOV I2C_SDA,C ;2MC |
      call Release_SCL_High
      call Delay_3MC
      Clr I2C_SCL ;1MC +-+
      DJNZ B,I2C_SendByteL ;2MC |

      call Release_SCL_High
      call Delay_4Mc
      MOV C,I2C_SDA ;1MC | read ACK/NOACK
      Clr I2C_SCL ;1MC +-+
      call Delay_3MC
      POP B ;2MC |
      RET

      ; Low = 6MC High = 5MC

      ;==============================================================;
      I2C_GetByte: PUSH B
      PUSH PSW ;Save CY
      MOV B,#8
      SetB I2C_SDA ;1MC |

      I2C_GetByteL: call Release_SCL_High
      call Delay_3Mc
      MOV C,I2C_SDA ;1MC |
      RLC A ;1MC |
      Clr I2C_SCL ;1MC +-+
      call Delay_3MC
      DJNZ B,I2C_GetByteL ;2MC |

      POP PSW ;1MC | Load CY
      MOV I2C_SDA,C ;2MC |
      call Release_SCL_High
      call Delay_3MC
      Clr I2C_SCL ;1MC +-+
      SetB I2C_SDA ;1MC |
      NOP
      NOP
      POP B ;1MC | Load CY
      RET

      ; Low = 6MC High = 5MC
      ;==============================================================;

      ;==============================================================;
      I2C_WriteByte: Call I2C_Start
      JC l_ERROR1
      Clr ACC.0
      Call I2C_SendByte ;Send SlaveAddress
      JC l_ERROR2
      MOV A,B
      Call I2C_SendByte ;Send Word Address
      JC l_ERROR3
      MOV A,R1
      Call I2C_SendByte ;Send Data Byte
      JC l_ERROR4
      Call I2C_Stop
      Clr C
      Call I2C_WriteDelay
      Clr A
      MOV B,A ;max 5mS
      I2C_WriteByteL: DJNZ ACC,I2C_WriteByteL
      DJNZ B,I2C_WriteByteL
      Ret
      ; ACC = SlaveAddress, B = WordAddress, R1 = Data byte

      ;==============================================================;
      I2C_ReadByte: Call I2C_Start
      JC l_ERROR1
      MOV DPL,A ;Save SlaveAddress
      Clr ACC.0
      Call I2C_SendByte ;Send SlaveAddress
      JC l_ERROR2
      MOV A,B
      Call I2C_SendByte ;Send Word Address
      JC l_ERROR3

      Call I2C_Start
      JC l_ERROR1
      MOV A,DPL ;Load SlaveAddress again
      SetB ACC.0
      Call I2C_SendByte ;Send SlaveAddress
      JC l_ERROR2

      SetB C ;Set to NOACK
      Call I2C_GetByte ;Get Data Byte
      Call I2C_Stop
      Clr C
      Ret

      ; ACC = SlaveAddress, B = WordAddress

      ;==============================================================;
      I2C_WriteData: Call I2C_Start
      JC l_ERROR1
      Clr ACC.0
      Call I2C_SendByte ;Send SlaveAddress
      JC l_ERROR2
      MOV A,B
      Call I2C_SendByte ;Send Word Address
      JC l_ERROR3
      I2C_WriteDataL: MOV A,@R1
      call I2C_SendByte ;Send Data Byte
      INC R1
      JC l_ERROR4
      DJNZ R2,I2C_WriteDataL
      I2C_WriteDataE: Call I2C_Stop
      Clr C
      Call I2C_WriteDelay
      I2C_WriteDelay: Clr A
      MOV B,A ;max 5mS (( 2 *256 ) * 256 )
      I2C_WriteDataF: DJNZ ACC,I2C_WriteDataF
      DJNZ B,I2C_WriteDataF
      Ret

      ; ACC = SlaveAddress, B = WordAddress, R1 = DataMemoryOffset, R2 = Counter,

      ;==============================================================;
      l_ERROR1: MOV A,#Err_IIC_BusFailToStart
      Call I2C_Stop
      Ret
      l_ERROR2: MOV A,#Err_IIC_InvalidSlaAddr
      Call I2C_Stop
      Ret
      l_ERROR3: MOV A,#Err_IIC_InvalidAddress
      Call I2C_Stop
      Ret
      l_ERROR4: MOV A,#Err_IIC_PrematureNOACK
      Call I2C_Stop
      Ret

      ;==============================================================;
      I2C_ReadData: Call I2C_Start
      JC l_ERROR1
      MOV DPL,A ;Save SlaveAddress
      Clr ACC.0
      Call I2C_SendByte ;Send SlaveAddress
      JC l_ERROR2
      MOV A,B
      Call I2C_SendByte ;Send Word Address
      JC l_ERROR3

      Call I2C_Start
      JC l_ERROR1
      MOV A,DPL ;Load SlaveAddress again
      SetB ACC.0
      Call I2C_SendByte ;Send SlaveAddress
      JC l_ERROR2

      DEC R2
      I2C_ReadDataL: Clr C ;Set to ACK
      Call I2C_GetByte ;Get Data Byte
      MOV @R1,A
      INC R1
      DJNZ R2,I2C_ReadDataL
      SetB C ;Set to NOACK
      Call I2C_GetByte ;Get Data Byte
      MOV @R1,A
      Call I2C_Stop
      Clr C
      Ret

      ; ACC = SlaveAddress, B = WordAddress, R1 = DataMemoryOffset, R2 = Counter
      END

    • coba menggunakan listing program ini, untuk hardware skematik mengikuti program yaitu akses lcd 8 bit.
      ;##########################################################################
      ; Inisialisasi Port
      ; Program LCD 16×4 mikrokontroler at89s52
      ; Bisa manampilkan jam +_ kalender
      ; Menggunakan rtcds1307 + eeprom at24c64
      ; 4 baris + 16 kolom
      ;##########################################################################
      Free_1 equ 1ah
      Free_2 equ 1bh
      Free_3 equ 1ch
      Free_4 equ 1dh
      DPTR_HIGH equ 1eh
      DPTR_LOW equ 1fh

      data_tombol equ 20h
      LEDDigit1 DATA 21h
      LEDDigit2 DATA 22h
      LEDDigit3 DATA 23h
      LEDDigit4 DATA 24h
      LEDDigit5 DATA 25h
      LEDDigit6 DATA 26h
      LEDDigit7 DATA 27h
      LEDDigit8 DATA 28h
      LEDDigit9 DATA 29h
      LEDDigit10 DATA 2ah

      RTCDetik DATA 2bh ;00
      RTCMenit DATA 2ch ;01
      RTCjam DATA 2dh ;02
      RTCHari DATA 2eh ;03
      RTCTanggal DATA 2fh ;04
      RTCBulan DATA 30h ;05
      RTCTahun DATA 31h ;06
      RTCControl DATA 32h ;07
      tmp equ 33h

      Eeprom_temp equ 35h

      Data_Jam equ 36h
      Data_Menit equ 37h
      Data_Lagu equ 38h
      Data_Detik_lagu equ 39h

      Digit_E1 equ 40h
      Digit_E2 equ 41h
      Digit_E3 equ 42h
      Digit_E4 equ 43h
      Digit_E5 equ 44h
      Digit_E6 equ 45h
      Digit_E7 equ 46h
      Digit_E8 equ 47h

      I2C_SDA BIT P1.1
      I2C_SCL BIT P1.0
      LED bit p1.2

      lcd_en bit p2.2
      lcd_rs bit p2.3

      Up bit p1.5
      Menu bit p1.4
      Down bit p1.3
      Data_8_bit equ P0
      ;##########################################################################
      ; Alamat eeprom
      ;##########################################################################
      WRTCMD EQU 11010000b ;WRITE DATA COMMAND Note 3
      RRDCMD EQU 11010001b ;READ DATA COMMAND Note 3
      WTCMD EQU 10100000B ;WRITE DATA COMMAND Note 3
      RDCMD EQU 10100001B ;READ DATA COMMAND Note 3
      RDEND EQU 01000000B ;READ HIGH-ENDURANCE BLOCK NUMBER COMMAND
      BYTCNT EQU 8
      BYTSTR equ 19h ;STORAGE FOR READ DATA

      Shift equ 12h
      Caps equ 58h
      enter equ 5ah
      Ctrl equ 14h
      Tambah equ 55h
      Kurang equ 4eh

      Data_minggu_1 equ 0
      Data_minggu_2 equ 4
      Data_minggu_3 equ 8
      Data_minggu_4 equ 12
      Data_minggu_5 equ 16
      Data_minggu_6 equ 20
      Data_minggu_7 equ 24
      Data_minggu_8 equ 28
      Data_minggu_9 equ 32
      Data_minggu_10 equ 36
      Data_minggu_11 equ 40
      Data_minggu_12 equ 44
      Data_minggu_13 equ 48
      Data_minggu_14 equ 52
      Data_minggu_15 equ 56
      Data_minggu_16 equ 60
      Data_minggu_17 equ 64
      Data_minggu_18 equ 68
      Data_minggu_19 equ 72
      Data_minggu_20 equ 76

      ;##########################################################################
      ; Program utama
      ;##########################################################################
      org 0h

      Restart: call init_LCD
      call Tulis_Baris_1
      call Tulis_Baris_2
      call tunda_long
      call Tulis_Baris_3
      call Tulis_Baris_4
      call tunda_long

      mulai: call ReadAllRTC
      call StreamRTC
      call Streamkalender
      call tampil_jam
      call tampil_kalender

      Menu_jam: jb menu,Menu_kalender
      call Delay250uS
      jnb menu,$
      call Tulis_Baris_1_Jam
      jmp Scanning_jam
      Menu_kalender: jb up,Menu_Bel
      call Delay250uS
      jnb up,$
      call Tulis_Baris_2_Hari
      jmp Scanning_Kalender

      Menu_Bel: jb Down,mulai
      call Delay250uS
      jnb Down,$
      call Tulis_Baris_1_Minggu
      call Tulis_Baris_2_Bel
      jmp Scanning_Bel
      ;##########################################################################
      Scanning_jam: call ReadAllRTC
      call StreamRTC
      call tampil_jam

      cek_jam_up: jb up,cek_jam_down
      call Delay250uS
      jnb up,$
      call up_jam
      jmp Scanning_jam
      cek_jam_down: jb down,cek_jam_menu
      call Delay250uS
      jnb down,$
      call down_jam
      jmp Scanning_jam
      cek_jam_menu: jb menu,cek_jam_up
      call Delay250uS
      jnb menu,$
      call Tulis_Baris_1_Menit

      Scanning_menit: call ReadAllRTC
      call StreamRTC
      call tampil_jam
      cek_menit_up: jb up,cek_menit_down
      call Delay250uS
      jnb up,$
      call up_menit
      jmp Scanning_menit
      cek_menit_down: jb down,cek_menit_menu
      call Delay250uS
      jnb down,$
      call down_menit
      jmp Scanning_menit
      cek_menit_menu: jb menu,cek_menit_up
      call Delay250uS
      jnb menu,$
      call Tulis_rtc_Detik
      jmp Restart
      ;##########################################################################
      Scanning_Kalender:call ReadAllRTC
      call StreamKalender
      call tampil_kalender
      cek_hari_up: jb up,cek_hari_down
      call Delay250uS
      jnb up,$
      call up_hari
      jmp Scanning_Kalender
      cek_hari_down: jb down,cek_hari_menu
      call Delay250uS
      jnb down,$
      call down_hari
      jmp Scanning_Kalender
      cek_hari_menu: jb menu,cek_hari_up
      call Delay250uS
      jnb menu,$
      call Tulis_Baris_2_Tanggal

      Scanning_Tanggal: call ReadAllRTC
      call StreamKalender
      call tampil_kalender
      cek_tgl_up: jb up,cek_tgl_down
      call Delay250uS
      jnb up,$
      call up_tgl
      jmp Scanning_Tanggal
      cek_tgl_down: jb down,cek_tgl_menu
      call Delay250uS
      jnb down,$
      call down_tgl
      jmp Scanning_Tanggal
      cek_tgl_menu: jb menu,cek_tgl_up
      call Delay250uS
      jnb menu,$
      call Tulis_Baris_2_Bulan

      Scanning_Bulan: call ReadAllRTC
      call StreamKalender
      call tampil_kalender
      cek_bln_up: jb up,cek_bln_down
      call Delay250uS
      jnb up,$
      call up_bln
      jmp Scanning_Bulan
      cek_bln_down: jb down,cek_bln_menu
      call Delay250uS
      jnb down,$
      call down_bln
      jmp Scanning_Bulan
      cek_bln_menu: jb menu,cek_bln_up
      call Delay250uS
      jnb menu,$
      call Tulis_Baris_2_Tahun

      Scanning_Tahun: call ReadAllRTC
      call StreamKalender
      call tampil_kalender
      cek_thn_up: jb up,cek_thn_down
      call Delay250uS
      jnb up,$
      call up_thn
      jmp Scanning_Tahun
      cek_thn_down: jb down,cek_thn_menu
      call Delay250uS
      jnb down,$
      call down_thn
      jmp Scanning_Tahun
      cek_thn_menu: jb menu,cek_thn_up
      call Delay250uS
      jnb menu,$
      jmp Restart
      ;##########################################################################
      Scanning_Bel: jb menu,Bel_Senin
      call Delay250uS
      jnb menu,$
      jmp Setting_minggu

      Bel_Senin: jb up,Scanning_Bel
      call Delay250uS
      jnb up,$
      call Tulis_Baris_1_Senin
      Bel_Senin_masuk: jb menu,Bel_selasa
      call Delay250uS
      jnb menu,$
      jmp Restart

      Bel_selasa: jb up,Bel_Senin_masuk
      call Delay250uS
      jnb up,$
      call Tulis_Baris_1_Selasa
      Bel_Selasa_masuk: jb menu,Bel_rabu
      call Delay250uS
      jnb menu,$
      jmp Restart

      Bel_Rabu: jb up,Bel_Selasa_masuk
      call Delay250uS
      jnb up,$
      call Tulis_Baris_1_Rabu
      Bel_Rabu_masuk : jb menu,Bel_kamis
      call Delay250uS
      jnb menu,$
      jmp Restart

      Bel_Kamis: jb up,Bel_Rabu_masuk
      call Delay250uS
      jnb up,$
      call Tulis_Baris_1_Kamis
      Bel_Kamis_masuk : jb menu,Bel_jumat
      call Delay250uS
      jnb menu,$
      jmp Restart

      Bel_Jumat: jb up,Bel_Kamis_masuk
      call Delay250uS
      jnb up,$
      call Tulis_Baris_1_Jumat
      Bel_Jumat_masuk : jb menu,Bel_sabtu
      call Delay250uS
      jnb menu,$
      jmp Restart

      Bel_Sabtu: jb up,Bel_Jumat_masuk
      call Delay250uS
      jnb up,$
      call Tulis_Baris_1_Sabtu
      Bel_Sabtu_masuk : jb menu,Bel_keluar
      call Delay250uS
      jnb menu,$
      jmp Restart

      Bel_Keluar: jb up,Bel_Sabtu_masuk
      call Delay250uS
      jnb up,$
      call Tulis_Baris_1_Keluar
      call Tulis_Baris_2_Keluar

      Bel_Keluar_tunggu:jb menu,Bel_Ulang_set
      call Delay250uS
      jnb menu,$
      jmp Restart

      Bel_Ulang_set: jb up,Bel_Keluar_tunggu
      call Delay250uS
      jnb up,$
      call Tulis_Baris_1_Minggu
      call Tulis_Baris_2_Bel
      jmp Scanning_Bel
      ;##########################################################################
      Setting_minggu: call Tulis_Baris_1_Bel
      call Tulis_Baris_2_Set_bel
      mov DPTR,#Data_minggu_1

      Tunggu_DPTR_4x: call baca_eeprom
      mov data_jam,eeprom_temp
      inc dptr
      call baca_eeprom
      mov data_menit,eeprom_temp
      inc dptr
      call baca_eeprom
      mov data_lagu,eeprom_temp
      inc dptr
      call baca_eeprom
      mov data_detik_lagu,eeprom_temp
      inc dptr

      Setting_jadwal_1: call Streameeprom
      call tampil_eeprom
      mov DPTR,#Data_minggu_1
      Menu_jam_eeprom: jb menu,Up_Jam_eeprom
      call Delay250uS
      jnb menu,$
      inc dptr
      jmp Setting_jadwal_2
      Up_Jam_eeprom: jb up,Down_jam_eeprom
      call Delay250uS
      jnb up,$
      call up_jame
      jmp Setting_jadwal_1
      Down_Jam_eeprom: jb down,Menu_jam_eeprom
      call Delay250uS
      jnb down,$
      call down_jame
      jmp Setting_jadwal_1

      Setting_jadwal_2: call Streameeprom
      call tampil_eeprom
      Menu_Mnt_eeprom: jb menu,Up_mnt_eeprom
      call Delay250uS
      jnb menu,$
      inc dptr
      jmp Setting_jadwal_3

      Up_Mnt_eeprom: jb up,Down_mnt_eeprom
      call Delay250uS
      jnb up,$
      call up_mnte
      jmp Setting_jadwal_2
      Down_Mnt_eeprom: jb down,Menu_mnt_eeprom
      call Delay250uS
      jnb down,$
      call down_mnte
      jmp Setting_jadwal_2

      Setting_jadwal_3: call Streameeprom
      call tampil_eeprom
      Menu_Lag_eeprom: jb menu,Up_Lag_eeprom
      call Delay250uS
      jnb menu,$
      inc dptr
      jmp restart

      Up_Lag_eeprom: jb up,Down_Lag_eeprom
      call Delay250uS
      jnb up,$
      call up_Lage
      jmp Setting_jadwal_3
      Down_Lag_eeprom: jb down,Menu_Lag_eeprom
      call Delay250uS
      jnb down,$
      call down_Lage
      jmp Setting_jadwal_3
      ;##########################################################################
      up_jame: MOV A,Data_jam
      CJNE A,#23h,Up_jam2e
      MOV A,#0
      Jmp Up_jam3e
      Up_jam2e: add a,#1
      Up_jam3e: da a
      mov R1,a
      mov data_jam,a
      call tulis_eeprom
      ret

      down_jame: MOV A,Data_jam
      call konvert_dec
      CJNE A,#0ffh,down_jam2e
      MOV A,#23
      down_jam2e: call konvert_hex
      mov R1,a
      mov data_jam,a
      call tulis_eeprom
      ret

      up_mnte: MOV A,Data_Menit
      CJNE A,#59h,Up_mnt2e
      MOV A,#0
      Jmp Up_mnt3e
      Up_mnt2e: add a,#1
      Up_mnt3e: da a
      MOV r1,A
      mov data_menit,a
      call tulis_eeprom
      ret

      down_mnte: MOV A,Data_menit
      call konvert_dec
      CJNE A,#0ffh,down_mnt2e
      MOV A,#59
      down_mnt2e: call konvert_hex
      MOV r1,A
      mov data_menit,a
      call tulis_eeprom
      ret

      up_Lage: MOV A,Data_Lagu
      CJNE A,#10h,Up_Lag2e
      MOV A,#0
      Jmp Up_Lag3e
      Up_Lag2e: add a,#1
      Up_Lag3e: da a
      MOV data_Lagu,A
      mov R1,data_Lagu
      ret

      down_Lage: MOV A,Data_Lagu
      call konvert_dec
      CJNE A,#0ffh,down_Lag2e
      MOV A,#10
      down_Lag2e: call konvert_hex
      MOV data_Lagu,A
      mov R1,data_Lagu
      call tulis_eeprom
      ret
      ;##########################################################################
      ; Subrutin untuk menampilkan tulisan Data eeprom / rtc pada baris 1
      ;##########################################################################
      tampil_jam: mov r1,#0c0h
      call tulis_inst
      mov A,leddigit1
      call tulis_data
      mov r1,#0c1h
      call tulis_inst
      mov A,leddigit2
      call tulis_data
      mov r1,#0c3h
      call tulis_inst
      mov A,leddigit3
      call tulis_data
      mov r1,#0c4h
      call tulis_inst
      mov A,leddigit4
      call tulis_data
      mov r1,#0c6h
      call tulis_inst
      mov A,leddigit5
      call tulis_data
      mov r1,#0c7h
      call tulis_inst
      mov A,leddigit6
      call tulis_data
      ret

      Tampil_eeprom: mov r1,#0c0h
      call tulis_inst
      mov A,Digit_e1
      call tulis_data
      mov r1,#0c1h
      call tulis_inst
      mov A,Digit_e2
      call tulis_data

      mov r1,#0c4h
      call tulis_inst
      mov A,Digit_e3
      call tulis_data
      mov r1,#0c5h
      call tulis_inst
      mov A,Digit_e4
      call tulis_data

      mov r1,#0c8h
      call tulis_inst
      mov A,Digit_e5
      call tulis_data
      mov r1,#0c9h
      call tulis_inst
      mov A,Digit_e6
      call tulis_data

      mov r1,#0cch
      call tulis_inst
      mov A,Digit_e7
      call tulis_data
      mov r1,#0cdh
      call tulis_inst
      mov A,Digit_e8
      call tulis_data
      ret

      Tampil_kalender: mov A,rtchari
      call konversi_hari
      call tulis_hari
      mov r1,#080h
      call tulis_inst
      mov A,leddigit7
      call tulis_data
      mov r1,#081h
      call tulis_inst
      mov A,leddigit8
      call tulis_data
      mov A,rtcbulan
      call konversi_bulan
      call tulis_bulan
      mov r1,#08eh
      call tulis_inst
      mov A,leddigit9
      call tulis_data
      mov r1,#08fh
      call tulis_inst
      mov A,leddigit10
      call tulis_data
      ret

      ;##########################################################################
      ; Subrutin LCD
      ;##########################################################################
      Init_lcd: mov r1,#00000001b ;Display clear
      call tulis_inst
      mov r1,#00111000b ;Function set,Data 8 bit,2 line font 5×7
      call tulis_inst
      mov r1,#00001100b ;Display on, cursor off,cursor blink off
      call tulis_inst
      mov r1,#00000110b ;Entry mode, Set increment
      call tulis_inst
      ret

      tulis_inst: clr lcd_rs
      mov Data_8_bit,R1
      setb lcd_en
      call delay
      clr lcd_en
      ret

      tulis_data: setb lcd_rs
      mov Data_8_bit,A ; P0 = A
      setb lcd_en
      call delay
      call delay
      clr lcd_en
      ret

      Tulis_Baris_1_Jam: mov dptr,#Pesan_Jam
      jmp Tulis_baris_ke_1_16
      Tulis_Baris_1_Menit: mov dptr,#Pesan_Menit
      jmp Tulis_baris_ke_1_16
      Tulis_Baris_1_Minggu: mov dptr,#Pesan_Bel_Minggu
      jmp Tulis_baris_ke_1_16
      Tulis_Baris_1_Senin : mov dptr,#Pesan_Bel_Senin
      jmp Tulis_baris_ke_1_16
      Tulis_Baris_1_Selasa: mov dptr,#Pesan_Bel_Selasa
      jmp Tulis_baris_ke_1_16
      Tulis_Baris_1_Rabu : mov dptr,#Pesan_Bel_Rabu
      jmp Tulis_baris_ke_1_16
      Tulis_Baris_1_Kamis : mov dptr,#Pesan_Bel_Kamis
      jmp Tulis_baris_ke_1_16
      Tulis_Baris_1_Jumat : mov dptr,#Pesan_Bel_Jumat
      jmp Tulis_baris_ke_1_16
      Tulis_Baris_1_Sabtu : mov dptr,#Pesan_Bel_Sabtu
      jmp Tulis_baris_ke_1_16
      Tulis_Baris_1_Keluar: mov dptr,#Pesan_Bel_Keluar
      jmp Tulis_baris_ke_1_16
      Tulis_Baris_1_Bel : mov dptr,#Pesan_setting_Bel
      jmp Tulis_baris_ke_1_16

      Tulis_Baris_2_Hari: mov dptr,#Pesan_Hari
      jmp Tulis_baris_ke_2_16
      Tulis_Baris_2_Tanggal: mov dptr,#Pesan_Tanggal
      jmp Tulis_baris_ke_2_16
      Tulis_Baris_2_Bulan: mov dptr,#Pesan_Bulan
      jmp Tulis_baris_ke_2_16
      Tulis_Baris_2_Tahun: mov dptr,#Pesan_Tahun
      jmp Tulis_baris_ke_2_16
      Tulis_Baris_2_Bel : mov dptr,#Pesan_Bel
      jmp Tulis_baris_ke_2_16
      Tulis_Baris_2_Keluar: mov dptr,#Pesan_Bel_Keluar_2
      jmp Tulis_baris_ke_2_16
      Tulis_Baris_2_Set_bel: mov dptr,#Pesan_5
      jmp Tulis_baris_ke_2_16

      Tulis_Baris_1: mov dptr,#Pesan_1
      Tulis_baris_ke_1_16: mov r3,#16
      mov r1,#80h
      jmp Tulis_0
      Tulis_Baris_2: mov dptr,#Pesan_2
      Tulis_baris_ke_2_16 : mov r3,#16
      mov r1,#0C0H
      jmp Tulis_0
      Tulis_Baris_3: mov dptr,#Pesan_3
      mov r3,#16
      mov r1,#80h
      jmp Tulis_0
      Tulis_Baris_4: mov dptr,#Pesan_4
      mov r3,#16
      mov r1,#0d0h
      jmp Tulis_0
      Tulis_hari: mov r3,#6
      mov r1,#0cah
      jmp Tulis_0
      Tulis_bulan: mov r3,#8
      mov r1,#83h
      jmp Tulis_0

      Tulis_0: call tulis_inst
      Tulis1: clr a
      movc a,@a+dptr
      mov r1,A
      inc dptr
      call tulis_data
      djnz r3,TULIS1
      ret
      ;##########################################################################
      ; Subrutin Tabel Data Konversi
      ;##########################################################################
      Pesan_1: DB ‘ Bel Otomatis ‘
      Pesan_2: DB ‘ : : ‘
      Pesan_3: DB ‘ 20 ‘
      Pesan_4: DB ‘Tekan Ctrl+L Set’
      Pesan_Jam: DB ‘Atur~Jam ‘
      Pesan_Menit: DB ‘Atur~Menit ‘
      Pesan_Hari: DB ‘Atur~Hari ‘
      Pesan_Tanggal: DB ‘Atur~Tgl ‘
      Pesan_Bulan: DB ‘Atur~Blan ‘
      Pesan_Tahun: DB ‘Atur~Thun ‘
      Pesan_Bel_Minggu: DB ‘Atur Bel Minggu ‘
      Pesan_Bel_Senin : DB ‘Atur Bel Senin ‘
      Pesan_Bel_Selasa: DB ‘Atur Bel Selasa ‘
      Pesan_Bel_Rabu : DB ‘Atur Bel Rabu ‘
      Pesan_Bel_Kamis : DB ‘Atur Bel Kamis ‘
      Pesan_Bel_Jumat : DB ‘Atur Bel Jum`at ‘
      Pesan_Bel_Sabtu : DB ‘Atur Bel Sabtu ‘
      Pesan_Bel_Keluar: DB ‘Atur Tekan (+) ~’
      Pesan_Bel_Keluar_2: DB ‘Keluar Tekan (M)’
      Pesan_Bel : DB ‘Masuk Tekan (M)~’
      Pesan_Setting_Bel : DB ‘Jam:Men:Lag:Det~’
      Pesan_5: DB ‘ : : : 1′
      ;##########################################################################
      ; Subrutin Delay (tundaan)
      ;##########################################################################
      TUNDA_LONG: MOV R5,#010H
      JJz: CALL TUNDAan
      DJNZ R5,JJz
      RET
      TUNDAan: MOV R7,#100
      LD11: DJNZ R6,$
      DJNZ R7,LD11
      RET
      delay: mov R7,#0
      delay1: mov R6,#0fh
      djnz R6,$
      djnz R7,delay1
      ret
      ;##########################################################################
      Delay250uS: Push Acc
      mov R7,#100
      lagi_delay: MOV A,#250
      DJNZ Acc,$
      MOV A,#250
      DJNZ Acc,$
      MOV A,#250
      DJNZ Acc,$
      MOV A,#250
      DJNZ Acc,$
      djnz R7,lagi_delay
      Pop Acc
      Ret
      ;##########################################################################
      ; Edit RTC
      ;##########################################################################
      up_jam: MOV A,RTCJam
      CJNE A,#23h,Up_jam2
      MOV A,#0
      Jmp Up_jam3
      Up_jam2: add a,#1
      Up_jam3: da a
      MOV RTCJam,A
      call tulis_rtc_jam
      ret

      down_jam: MOV A,rtcjam
      call konvert_dec
      CJNE A,#0ffh,down_jam2
      MOV A,#23
      down_jam2: call konvert_hex
      MOV RTCJam,A
      call tulis_rtc_jam
      ret

      up_menit: MOV A,RTCmenit
      CJNE A,#59h,Up_menit2
      MOV A,#0
      Jmp Up_menit3
      Up_menit2: add a,#1
      Up_menit3: da a
      MOV RTCmenit,A
      call tulis_rtc_menit
      ret

      down_menit: MOV A,rtcmenit
      call konvert_dec
      CJNE A,#0ffh,down_menit2
      MOV A,#59
      down_menit2: call konvert_hex
      MOV RTCmenit,A
      call tulis_rtc_menit
      ret

      up_tgl: MOV A,RTCtanggal
      CJNE A,#31h,Up_tgl2
      MOV A,#1
      Jmp Up_tgl3
      Up_tgl2: add a,#1
      Up_tgl3: da a
      MOV RTCtanggal,A
      call tulis_rtc_tgl
      ret

      down_tgl: MOV A,rtctanggal
      call konvert_dec
      CJNE A,#00h,down_tgl2
      MOV A,#31
      down_tgl2: call konvert_hex
      MOV RTCtanggal,A
      call tulis_rtc_tgl
      ret

      up_hari: MOV A,RTChari
      CJNE A,#7h,Up_hari2
      MOV A,#1
      Jmp Up_hari3
      Up_hari2: add a,#1
      Up_hari3: da a
      MOV RTChari,A
      call tulis_rtc_hari
      ret

      down_hari: MOV A,rtchari
      call konvert_dec
      CJNE A,#00h,down_hari2
      MOV A,#7
      down_hari2: call konvert_hex
      MOV RTChari,A
      call tulis_rtc_hari
      ret

      up_bln: MOV A,RTCbulan
      CJNE A,#12h,Up_bln2
      MOV A,#1
      Jmp Up_bln3
      Up_bln2: add a,#1
      Up_bln3: da a
      MOV RTCbulan,A
      call tulis_rtc_bln
      ret

      down_bln: MOV A,rtcbulan
      call konvert_dec
      CJNE A,#00h,down_bln2
      MOV A,#12
      down_bln2: call konvert_hex
      MOV RTCbulan,A
      call tulis_rtc_bln
      ret

      up_thn: MOV A,RTCtahun
      CJNE A,#99h,Up_thn2
      MOV A,#0
      Jmp Up_thn3
      Up_thn2: add a,#1
      Up_thn3: da a
      MOV RTCtahun,A
      call tulis_rtc_thn
      ret

      down_thn: MOV A,rtctahun
      call konvert_dec
      CJNE A,#0ffh,down_thn2
      MOV A,#99
      down_thn2: call konvert_hex
      MOV RTCtahun,A
      call tulis_rtc_thn
      ret
      ;##########################################################################
      konvert_dec: mov DPTR_high,dph
      mov DPTR_low,dpl
      mov DPTR,#tabel_dec
      movc A,@A+DPTR
      dec a
      mov dph,DPTR_high
      mov dpl,DPTR_low
      ret

      konvert_hex: mov DPTR_high,dph
      mov DPTR_low,dpl

      mov DPTR,#tabel_hex
      movc A,@A+DPTR

      mov dph,DPTR_high
      mov dpl,DPTR_low
      ret
      ;##########################################################################
      ; pengendali Bus IIC disusun oleh
      ; Dhanny Dhuzell 2008 Bandar Lampung
      ; Single Master Sudah diuji-coba dan sangat baik
      ; Bandwidth sekitar 80 kHz (Mode-Normal-Speed)
      ; Modul ini butuh “ErrorsEqu.inc”
      ;##########################################################################
      Err_DL_WrongCommand EQU 1
      Err_DL_BadConvert EQU 2
      Err_DL_OutOfMemory EQU 3
      Err_DL_InvalidCheckSum EQU 4
      Err_DL_InvalidCmdFormat EQU 5
      Err_DL_WriteFail EQU 6
      Err_DL_VerifyGotError EQU 7

      Err_IIC_BusFailToStart EQU 11
      Err_IIC_InvalidSlaAddr EQU 12
      Err_IIC_InvalidAddress EQU 13
      Err_IIC_PrematureNOACK EQU 14
      %*DEFINE(Delay_3MC)(
      NOP
      NOP
      NOP
      )

      %*DEFINE(Delay_4MC)(
      NOP
      NOP
      NOP
      NOP
      )

      %*DEFINE(Release_SCL_High)(
      SETB I2C_SCL
      JNB I2C_SCL,$
      )
      ;##########################################################################
      I2C_Start: SetB I2C_SDA
      SetB I2C_SCL
      JNB I2C_SDA, I2C_BusBusy
      JNB I2C_SCL, I2C_BusBusy
      Clr I2C_SDA
      Push ACC
      POP ACC
      Clr I2C_SCL
      Push ACC
      POP ACC
      Clr C
      Ret
      I2C_BusBusy:SetB C
      Ret
      ;##########################################################################
      I2C_Stop: Clr I2C_SDA
      %Release_SCL_High
      %Delay_3MC
      SetB I2C_SDA
      Ret
      ;##########################################################################
      I2C_SendByte:
      PUSH B
      MOV B,#8
      I2C_SendByteL:
      RLC A ;1MC |
      MOV I2C_SDA,C ;2MC |
      %Release_SCL_High
      %Delay_3MC
      Clr I2C_SCL ;1MC +-+
      DJNZ B,I2C_SendByteL ;2MC |

      %Release_SCL_High
      %Delay_4MC
      MOV C,I2C_SDA ;1MC | read ACK/NOACK
      Clr I2C_SCL ;1MC +-+
      %Delay_3MC
      POP B ;2MC |
      RET

      ; Low = 6MC High = 5MC
      ;##########################################################################
      I2C_GetByte:
      PUSH B
      PUSH PSW ;Save CY
      MOV B,#8
      SetB I2C_SDA ;1MC |

      I2C_GetByteL:
      %Release_SCL_High
      %Delay_3MC
      MOV C,I2C_SDA ;1MC |
      RLC A ;1MC |
      Clr I2C_SCL ;1MC +-+
      %Delay_3MC
      DJNZ B,I2C_GetByteL ;2MC |

      POP PSW ;1MC | Load CY
      MOV I2C_SDA,C ;2MC |
      %Release_SCL_High
      %Delay_3MC
      Clr I2C_SCL ;1MC +-+
      SetB I2C_SDA ;1MC |
      NOP
      NOP
      POP B ;1MC | Load CY
      RET

      ; Low = 6MC High = 5MC
      ;##########################################################################
      I2C_WriteByte:
      Call I2C_Start
      JC l_ERROR1
      Clr ACC.0
      Call I2C_SendByte ;Send SlaveAddress
      JC l_ERROR2
      MOV A,B
      Call I2C_SendByte ;Send Word Address
      JC l_ERROR3
      MOV A,R1
      Call I2C_SendByte ;Send Data Byte
      JC l_ERROR4
      Call I2C_Stop
      Clr C
      Call I2C_WriteDelay
      Clr A
      MOV B,A ;max 5mS
      I2C_WriteByteL:
      DJNZ ACC,I2C_WriteByteL
      DJNZ B,I2C_WriteByteL
      Ret
      ; ACC = SlaveAddress, B = WordAddress, R1 = Data byte

      ;##########################################################################
      I2C_ReadByte:
      Call I2C_Start
      JC l_ERROR1
      MOV DPL,A ;Save SlaveAddress
      Clr ACC.0
      Call I2C_SendByte ;Send SlaveAddress
      JC l_ERROR2
      MOV A,B
      Call I2C_SendByte ;Send Word Address
      JC l_ERROR3
      Call I2C_Start
      JC l_ERROR1
      MOV A,DPL ;Load SlaveAddress again
      SetB ACC.0
      Call I2C_SendByte ;Send SlaveAddress
      JC l_ERROR2
      SetB C ;Set to NOACK
      Call I2C_GetByte ;Get Data Byte
      Call I2C_Stop
      Clr C
      Ret

      ; ACC = SlaveAddress, B = WordAddress
      ;##########################################################################
      I2C_WriteData:
      Call I2C_Start
      JC l_ERROR1
      Clr ACC.0
      Call I2C_SendByte ;Send SlaveAddress
      JC l_ERROR2
      MOV A,B
      Call I2C_SendByte ;Send Word Address
      JC l_ERROR3
      I2C_WriteDataL:
      MOV A,@R1
      Call I2C_SendByte ;Send Data Byte
      INC R1
      JC l_ERROR4
      DJNZ R2,I2C_WriteDataL
      I2C_WriteDataE:
      Call I2C_Stop
      Clr C
      Call I2C_WriteDelay
      I2C_WriteDelay:
      Clr A
      MOV B,A ;max 5mS (( 2 *256 ) * 256 )
      I2C_WriteDataF:
      DJNZ ACC,I2C_WriteDataF
      DJNZ B,I2C_WriteDataF
      Ret

      ; ACC = SlaveAddress, B = WordAddress, R1 = DataMemoryOffset, R2 = Counter,

      ;##########################################################################
      l_ERROR1: MOV A,#Err_IIC_BusFailToStart
      Call I2C_Stop
      Ret
      l_ERROR2: MOV A,#Err_IIC_InvalidSlaAddr
      Call I2C_Stop
      Ret
      l_ERROR3: MOV A,#Err_IIC_InvalidAddress
      Call I2C_Stop
      Ret
      l_ERROR4: MOV A,#Err_IIC_PrematureNOACK
      Call I2C_Stop
      Ret
      ;##########################################################################
      I2C_ReadData:
      Call I2C_Start
      JC l_ERROR1
      MOV DPL,A ;Save SlaveAddress
      Clr ACC.0
      Call I2C_SendByte ;Send SlaveAddress
      JC l_ERROR2
      MOV A,B
      Call I2C_SendByte ;Send Word Address
      JC l_ERROR3
      Call I2C_Start
      JC l_ERROR1
      MOV A,DPL ;Load SlaveAddress again
      SetB ACC.0
      Call I2C_SendByte ;Send SlaveAddress
      JC l_ERROR2
      DEC R2

      I2C_ReadDataL:
      Clr C ;Set to ACK
      Call I2C_GetByte ;Get Data Byte
      MOV @R1,A
      INC R1
      DJNZ R2,I2C_ReadDataL
      SetB C ;Set to NOACK
      Call I2C_GetByte ;Get Data Byte
      MOV @R1,A
      Call I2C_Stop
      Clr C
      Ret

      ; ACC = SlaveAddress, B = WordAddress, R1 = DataMemoryOffset, R2 = Counter
      ;##########################################################################
      ; Tulis / baca rtc
      ;##########################################################################
      Tulis_rtc_hari: MOV A,#11010000b
      mov B,#03h ;Alamat
      mov R1,rtchari ;datanya
      Call I2C_WriteByte
      JC Error_hari_rtc
      ret
      Error_hari_rtc: jmp Tulis_rtc_hari

      Tulis_rtc_jam: MOV A,#11010000b
      mov B,#02h ;Alamat
      mov R1,rtcjam ;datanya
      Call I2C_WriteByte
      JC Error_Jam_rtc
      ret
      Error_Jam_rtc: jmp Tulis_rtc_jam

      Tulis_rtc_menit: MOV A,#11010000b
      mov B,#01h
      mov R1,rtcmenit
      Call I2C_WriteByte
      JC Error_menit_rtc
      ret
      Error_menit_rtc: jmp Tulis_rtc_menit

      Tulis_rtc_Detik: MOV A,#11010000b
      mov B,#00h
      mov R1,#00h
      Call I2C_WriteByte
      JC Error_Detik_rtc
      ret
      Error_Detik_rtc: jmp Tulis_rtc_Detik

      Tulis_rtc_tgl: MOV A,#11010000b
      mov B,#04h
      mov R1,rtctanggal
      Call I2C_WriteByte
      JC Error_tgl_rtc
      ret
      Error_tgl_rtc: jmp Tulis_rtc_tgl

      Tulis_rtc_bln: MOV A,#11010000b
      mov B,#05h
      mov R1,rtcbulan
      Call I2C_WriteByte
      JC Error_bln_rtc
      ret
      Error_bln_rtc: jmp Tulis_rtc_bln

      Tulis_rtc_thn: MOV A,#11010000b
      mov B,#06h
      mov R1,rtctahun
      Call I2C_WriteByte
      JC Error_thn_rtc
      ret
      Error_thn_rtc: jmp Tulis_rtc_thn

      ;##########################################################################
      ; Ambil data RTC simpan ke RAM mikro
      ;##########################################################################
      StreamRTC: MOV A,rtcjam
      swap a
      call Anl_A
      mov leddigit1,a
      MOV A,rtcjam
      call Anl_A
      mov leddigit2,a

      MOV A,rtcmenit
      SWAP A
      call Anl_A
      mov leddigit3,a
      MOV A,rtcmenit
      call Anl_A
      mov leddigit4,a

      MOV A,rtcdetik
      SWAP A
      call Anl_A
      mov leddigit5,a
      MOV A,rtcdetik
      call Anl_A
      mov leddigit6,a

      Ret

      Streamkalender: mOV A,rtctanggal
      SWAP A
      call Anl_A
      mov leddigit7,a
      MOV A,rtctanggal
      call Anl_A
      mov leddigit8,a

      MOV A,rtctahun
      SWAP A
      call Anl_A
      mov leddigit9,a
      MOV A,rtctahun
      call Anl_A
      mov leddigit10,a
      ret

      Streameeprom: MOV A,Data_jam
      swap a
      call Anl_A
      mov Digit_E1,a
      MOV A,Data_jam
      call Anl_A
      mov Digit_E2,a

      MOV A,Data_menit
      SWAP A
      call Anl_A
      mov Digit_E3,a
      MOV A,Data_menit
      call Anl_A
      mov Digit_E4,a

      MOV A,Data_lagu
      SWAP A
      call Anl_A
      mov Digit_E5,a
      MOV A,Data_lagu
      call Anl_A
      mov Digit_E6,a

      MOV A,Data_Detik_lagu
      SWAP A
      call Anl_A
      mov Digit_E7,a
      MOV A,Data_Detik_lagu
      call Anl_A
      mov Digit_E8,a
      Ret

      Anl_A: ANL A,#00Fh
      Call GetLEDNum
      ret
      ;##########################################################################
      konversi_hari: cjne A,#1,konversi_hari_2
      mov DPTR,#Minggu
      ret
      konversi_hari_2: cjne A,#2,konversi_hari_3
      mov DPTR,#Senin
      ret
      konversi_hari_3: cjne A,#3,konversi_hari_4
      mov DPTR,#Selasa
      ret
      konversi_hari_4: cjne A,#4,konversi_hari_5
      mov DPTR,#rabu
      ret
      konversi_hari_5: cjne A,#5,konversi_hari_6
      mov DPTR,#kamis
      ret
      konversi_hari_6: cjne A,#6,konversi_hari_7
      mov DPTR,#jumat
      ret
      konversi_hari_7: cjne A,#7,konversi_hari_8
      mov DPTR,#Sabtu
      konversi_hari_8: ret

      Minggu: db ‘Minggu’,0ffh
      Senin : db ‘ Senin’,0ffh
      Selasa: db ‘Selasa’,0ffh
      Rabu : db ‘ Rabu’,0ffh
      Kamis : db ‘ Kamis’,0ffh
      Jumat: db ‘Jum`at’,0ffh
      Sabtu : db ‘ Sabtu’,0ffh

      ;##########################################################################
      konversi_bulan: cjne A,#1h,konversi_bulan_2
      mov DPTR,#Januari
      ret
      konversi_bulan_2: cjne A,#2h,konversi_bulan_3
      mov DPTR,#Februari
      ret
      konversi_bulan_3: cjne A,#3h,konversi_bulan_4
      mov DPTR,#Maret
      ret
      konversi_bulan_4: cjne A,#4h,konversi_bulan_5
      mov DPTR,#April
      ret
      konversi_bulan_5: cjne A,#5h,konversi_bulan_6
      mov DPTR,#Mei
      ret
      konversi_bulan_6: cjne A,#6h,konversi_bulan_7
      mov DPTR,#juni
      ret
      konversi_bulan_7: cjne A,#7h,konversi_bulan_8
      mov DPTR,#Juli
      ret
      konversi_bulan_8: cjne A,#8h,konversi_bulan_9
      mov DPTR,#Agustus
      ret
      konversi_bulan_9: cjne A,#9h,konversi_bulan_10
      mov DPTR,#September
      ret
      konversi_bulan_10:cjne A,#10h,konversi_bulan_11
      mov DPTR,#Oktober
      ret
      konversi_bulan_11:cjne A,#11h,konversi_bulan_12
      mov DPTR,#November
      ret
      konversi_bulan_12:cjne A,#12h,konversi_bulan_13
      mov DPTR,#Desember
      konversi_bulan_13:ret

      Januari: db ‘Januari ‘,0ffh
      Februari : db ‘Februari’,0ffh
      Maret: db ‘Maret ‘,0ffh
      April : db ‘April ‘,0ffh
      Mei : db ‘Mei ‘,0ffh
      Juni: db ‘Juni ‘,0ffh
      Juli : db ‘Juli ‘,0ffh
      Agustus: db ‘Agustus ‘,0ffh
      September: db ‘Septembr’,0ffh
      Oktober: db ‘Oktober ‘,0ffh
      November: db ‘November’,0ffh
      Desember: db ‘Desember’,0ffh
      ;##########################################################################
      ; Konversi ke tampilan 7 segment
      ;##########################################################################
      GetLEDNum: Inc A
      MOVC A,@A+PC
      Ret

      CharLED1: DB ’0′ ;0
      DB ’1′ ;1
      DB ’2′ ;2
      DB ’3′ ;3
      DB ’4′ ;4
      DB ’5′ ;5
      DB ’6′ ;6
      DB ’7′ ;7
      DB ’8′ ;8
      DB ’9′ ;9
      DB ‘A’ ;A
      DB ‘B’ ;B
      DB ‘C’ ;C
      DB ‘D’ ;D
      DB ‘E’ ;E
      DB ‘F’ ;F

      ReadAllRTC: MOV A,#11010001b ;SlaveAddress
      MOV B,#0
      MOV R1,#RTCDetik
      MOV R2,#9
      Call I2C_ReadData ; ACC = SlaveAddress, B = WordAddress, R1 = DataMemoryOffset, R2 = Counter
      ret
      ;##########################################################################
      ; The next four routines are used with the the 24xx32 or 24xx65 only.
      ; These parts require two address bytes, and these routines send the
      ; second byte out. Other than this, these routines are the same as the
      ; previous four.
      ;##########################################################################
      ; THIS ROUTINE READS A BYTE OF DATA FROM EEPROM
      ; From EEPROM current address pointer.
      ; Returns the data byte in R1
      ;##########################################################################
      CREAD: MOV A,#RDCMD ;LOAD READ COMMAND
      CALL OUTS ;SEND IT
      CALL IN ;READ DATA
      MOV Eeprom_temp,A ;STORE DATA
      CALL STOP ;SEND STOP CONDITION
      RET

      ;##########################################################################
      ; This routine writes a byte of data to EEPROM
      ; This routine is for the 24LC32 or 24LC65
      ; The EEPROM address is assumed to be in R3:R4
      ; The DATA to be written is assumed to be in R1
      ;##########################################################################
      Tulis_eeprom: MOV A,#WTCMD ;LOAD WRITE COMMAND
      CALL OUTS ;SEND IT
      MOV A,R3 ;GET HI BYTE ADDRESS
      CALL OUT ;SEND IT
      MOV A,R4 ;GET LOW BYTE ADDRESS
      CALL OUT ;SEND IT
      MOV A,R1 ;GET DATA
      CALL OUT ;SEND IT
      CALL STOP ;SEND STOP CONDITION
      RET

      ;##########################################################################
      ; THIS ROUTINE READS A BYTE OF DATA FROM THE EEPROM
      ; This routine is for the 24CL32 or 24LC65
      ; The EEPROM address is in R3:R4
      ; Returns the data byte in R1
      ;##########################################################################
      Baca_eeprom: call baca_eeprom_2
      ret

      baca_eeprom_2: mov r3,dph
      mov r4,dpl
      MOV A,#WTCMD ;LOAD WRITE COMMAND TO SEND ADDRESS
      CALL OUTS ;SEND IT
      MOV A,R3 ;GET HI BYTE ADDRESS
      CALL OUT ;SEND IT
      MOV A,R4 ;GET LOW BYTE ADDRESS
      CALL OUT ;SEND IT
      CALL CREAD ;GET DATA BYTE
      RET

      ;##########################################################################
      ; THIS ROUTINE SENDS OUT CONTENTS OF THE ACCUMULATOR
      ; to the EEPROM and includes START condition. Refer to the data sheets
      ; for discussion of START and STOP conditions.
      ;##########################################################################
      OUTS: MOV R2,#8 ;LOOP COUNT — EQUAL TO BIT COUNT
      SETB I2C_SDA ;INSURE DATA IS HI
      SETB I2C_SCL ;INSURE CLOCK IS HI
      NOP ;NOTE 1
      NOP
      NOP
      NOP ;NOTE 2
      NOP
      CLR I2C_SDA ;START CONDITION — DATA = 0
      NOP ;NOTE 1
      NOP
      NOP
      NOP ;NOTE 2
      NOP
      CLR I2C_SCL ;CLOCK = 0
      OTSLP: RLC A ;SHIFT BIT
      JNC BITLS
      SETB I2C_SDA ;DATA = 1
      JMP OTSL1 ;CONTINUE
      BITLS: CLR I2C_SDA ;DATA = 0
      OTSL1: SETB I2C_SCL ;CLOCK HI
      NOP ;NOTE 1
      NOP
      NOP
      NOP ;NOTE 2
      NOP
      CLR I2C_SCL ;CLOCK LOW
      DJNZ R2,OTSLP ;DECREMENT COUNTER
      SETB I2C_SDA ;TURN PIN INTO INPUT
      NOP ;NOTE 1
      NOP ;NOTE 2
      NOP
      SETB I2C_SCL ;CLOCK ACK
      NOP ;NOTE 1
      NOP
      NOP
      NOP ;NOTE 2
      NOP
      CLR I2C_SCL
      RET
      ;##########################################################################
      ; THIS ROUTINE SENDS OUT CONTENTS OF ACCUMLATOR TO EEPROM
      ; without sending a START condition.
      ;##########################################################################
      OUT: MOV R2,#8 ;LOOP COUNT — EQUAL TO BIT COUNT
      OTLP: RLC A ;SHIFT BIT
      JNC BITL
      SETB I2C_SDA ;DATA = 1
      JMP OTL1 ;CONTINUE
      BITL: CLR I2C_SDA ;DATA = 0
      OTL1: SETB I2C_SCL ;CLOCK HI
      NOP ;NOTE 1
      NOP
      NOP
      NOP ;NOTE 2
      NOP
      CLR I2C_SCL ;CLOCK LOW
      DJNZ R2,OTLP ;DECREMENT COUNTER
      SETB I2C_SDA ;TURN PIN INTO INPUT
      NOP ;NOTE 1
      NOP ;NOTE 2
      NOP
      SETB I2C_SCL ;CLOCK ACK
      NOP ;NOTE 1
      NOP
      NOP
      NOP ;NOTE 2
      NOP
      CLR I2C_SCL
      RET
      ;##########################################################################
      ; THIS ROUTINE READS IN A BYTE FROM THE EEPROM
      ; and stores it in the accumulator
      ;##########################################################################
      IN: MOV R2,#8 ;LOOP COUNT
      SETB I2C_SDA ;SET DATA BIT HIGH FOR INPUT
      INLP: CLR I2C_SCL ;CLOCK LOW
      NOP ;NOTE 1
      NOP
      NOP
      NOP
      NOP ;NOTE 2
      NOP
      SETB I2C_SCL ;CLOCK HIGH
      CLR C ;CLEAR CARRY
      JNB I2C_SDA,INL1 ;JUMP IF DATA = 0
      CPL C ;SET CARRY IF DATA = 1
      INL1: RLC A ;ROTATE DATA INTO ACCUMULATOR
      DJNZ R2,INLP ;DECREMENT COUNTER
      CLR I2C_SCL ;CLOCK LOW
      RET
      STOP: CLR I2C_SDA ;STOP CONDITION SET DATA LOW
      NOP ;NOTE 1
      NOP
      NOP
      NOP ;NOTE 2
      NOP
      SETB I2C_SCL ;SET CLOCK HI
      NOP ;NOTE 1
      NOP
      NOP
      NOP ;NOTE 2
      NOP
      SETB I2C_SDA ;SET DATA HIGH
      RET

      ;##########################################################################
      ; Hexa X desimal
      ; Dibuat oleh Sindhu Harimukti
      ; Jumat 03 agustus 2012
      ;##########################################################################
      tabel_hex:
      db 00h,01h,02h,03h,04h,05h,06h,07h,08h,09h,10h
      db 11h,12h,13h,14h,15h,16h,17h,18h,19h,20h
      db 21h,22h,23h,24h,25h,26h,27h,28h,29h,30h
      db 31h,32h,33h,34h,35h,36h,37h,38h,39h,40h
      db 41h,42h,43h,44h,45h,46h,47h,48h,49h,50h
      db 51h,52h,53h,54h,55h,56h,57h,58h,59h,60h
      db 61h,62h,63h,64h,65h,66h,67h,68h,69h,70h
      db 71h,72h,73h,74h,75h,76h,77h,78h,79h,80h
      db 81h,82h,83h,84h,85h,86h,87h,88h,89h,90h
      db 91h,82h,93h,94h,95h,96h,97h,98h,99h

      tabel_dec:
      db 00,01,02,03,04,05,06,07,08,09,00,00,00,00,00,00
      db 10,11,12,13,14,15,16,17,18,19,00,00,00,00,00,00
      db 20,21,22,23,24,25,26,27,28,29,00,00,00,00,00,00
      db 30,31,32,33,34,35,36,37,38,39,00,00,00,00,00,00
      db 40,41,42,43,44,45,46,47,48,49,00,00,00,00,00,00
      db 50,51,52,53,54,55,56,57,58,59,00,00,00,00,00,00
      db 60,61,62,63,64,65,66,67,68,69,00,00,00,00,00,00
      db 70,71,72,73,74,75,76,77,78,79,00,00,00,00,00,00
      db 80,81,82,83,84,85,86,87,88,89,00,00,00,00,00,00
      db 90,91,82,93,94,95,96,97,98,99,00,00,00,00,00,00
      ;##########################################################################
      end

      • oke mas.. sya coba dlu.. makash sbelumnya sudah mau berbagi ilmunya… smoga masnya di beri rejeki yg banyak..

    • pada bagian itu diganti sub ini:
      ;==============================================================;
      ; pengendali Bus IIC disusun oleh
      ; Dhanny Dhuzell 2008 Bandar Lampung
      ; Single Master Sudah diuji-coba dan sangat baik
      ; Bandwidth sekitar 80 kHz (Mode-Normal-Speed)
      ; Modul ini butuh “ErrorsEqu.inc”
      ;==============================================================;
      Err_DL_WrongCommand EQU 1
      Err_DL_BadConvert EQU 2
      Err_DL_OutOfMemory EQU 3
      Err_DL_InvalidCheckSum EQU 4
      Err_DL_InvalidCmdFormat EQU 5
      Err_DL_WriteFail EQU 6
      Err_DL_VerifyGotError EQU 7

      Err_IIC_BusFailToStart EQU 11
      Err_IIC_InvalidSlaAddr EQU 12
      Err_IIC_InvalidAddress EQU 13
      Err_IIC_PrematureNOACK EQU 14

      Delay_3MC:
      NOP
      NOP
      NOP
      ret

      Delay_4Mc:
      NOP
      NOP
      NOP
      NOP
      ret

      Release_SCL_High:
      SETB I2C_SCL
      JNB I2C_SCL,$
      ret

      ;==============================================================;
      I2C_Start: SetB I2C_SDA
      SetB I2C_SCL
      JNB I2C_SDA, I2C_BusBusy
      JNB I2C_SCL, I2C_BusBusy
      Clr I2C_SDA
      Push ACC
      POP ACC
      Clr I2C_SCL
      Push ACC
      POP ACC
      Clr C
      Ret
      I2C_BusBusy: SetB C
      Ret

      ;==============================================================;
      I2C_Stop: Clr I2C_SDA
      call Release_SCL_High
      call Delay_3MC
      SetB I2C_SDA
      Ret

      ;==============================================================;
      I2C_SendByte: PUSH B
      MOV B,#8

      I2C_SendByteL: RLC A ;1MC |
      MOV I2C_SDA,C ;2MC |
      call Release_SCL_High
      call Delay_3MC
      Clr I2C_SCL ;1MC +-+
      DJNZ B,I2C_SendByteL ;2MC |

      call Release_SCL_High
      call Delay_4Mc
      MOV C,I2C_SDA ;1MC | read ACK/NOACK
      Clr I2C_SCL ;1MC +-+
      call Delay_3MC
      POP B ;2MC |
      RET

      ; Low = 6MC High = 5MC

      ;==============================================================;
      I2C_GetByte: PUSH B
      PUSH PSW ;Save CY
      MOV B,#8
      SetB I2C_SDA ;1MC |

      I2C_GetByteL: call Release_SCL_High
      call Delay_3Mc
      MOV C,I2C_SDA ;1MC |
      RLC A ;1MC |
      Clr I2C_SCL ;1MC +-+
      call Delay_3MC
      DJNZ B,I2C_GetByteL ;2MC |

      POP PSW ;1MC | Load CY
      MOV I2C_SDA,C ;2MC |
      call Release_SCL_High
      call Delay_3MC
      Clr I2C_SCL ;1MC +-+
      SetB I2C_SDA ;1MC |
      NOP
      NOP
      POP B ;1MC | Load CY
      RET

      ; Low = 6MC High = 5MC
      ;==============================================================;

      ;==============================================================;
      I2C_WriteByte: Call I2C_Start
      JC l_ERROR1
      Clr ACC.0
      Call I2C_SendByte ;Send SlaveAddress
      JC l_ERROR2
      MOV A,B
      Call I2C_SendByte ;Send Word Address
      JC l_ERROR3
      MOV A,R1
      Call I2C_SendByte ;Send Data Byte
      JC l_ERROR4
      Call I2C_Stop
      Clr C
      Call I2C_WriteDelay
      Clr A
      MOV B,A ;max 5mS
      I2C_WriteByteL: DJNZ ACC,I2C_WriteByteL
      DJNZ B,I2C_WriteByteL
      Ret
      ; ACC = SlaveAddress, B = WordAddress, R1 = Data byte

      ;==============================================================;
      I2C_ReadByte: Call I2C_Start
      JC l_ERROR1
      MOV DPL,A ;Save SlaveAddress
      Clr ACC.0
      Call I2C_SendByte ;Send SlaveAddress
      JC l_ERROR2
      MOV A,B
      Call I2C_SendByte ;Send Word Address
      JC l_ERROR3

      Call I2C_Start
      JC l_ERROR1
      MOV A,DPL ;Load SlaveAddress again
      SetB ACC.0
      Call I2C_SendByte ;Send SlaveAddress
      JC l_ERROR2

      SetB C ;Set to NOACK
      Call I2C_GetByte ;Get Data Byte
      Call I2C_Stop
      Clr C
      Ret

      ; ACC = SlaveAddress, B = WordAddress

      ;==============================================================;
      I2C_WriteData: Call I2C_Start
      JC l_ERROR1
      Clr ACC.0
      Call I2C_SendByte ;Send SlaveAddress
      JC l_ERROR2
      MOV A,B
      Call I2C_SendByte ;Send Word Address
      JC l_ERROR3
      I2C_WriteDataL: MOV A,@R1
      call I2C_SendByte ;Send Data Byte
      INC R1
      JC l_ERROR4
      DJNZ R2,I2C_WriteDataL
      I2C_WriteDataE: Call I2C_Stop
      Clr C
      Call I2C_WriteDelay
      I2C_WriteDelay: Clr A
      MOV B,A ;max 5mS (( 2 *256 ) * 256 )
      I2C_WriteDataF: DJNZ ACC,I2C_WriteDataF
      DJNZ B,I2C_WriteDataF
      Ret

      ; ACC = SlaveAddress, B = WordAddress, R1 = DataMemoryOffset, R2 = Counter,

      ;==============================================================;
      l_ERROR1: MOV A,#Err_IIC_BusFailToStart
      Call I2C_Stop
      Ret
      l_ERROR2: MOV A,#Err_IIC_InvalidSlaAddr
      Call I2C_Stop
      Ret
      l_ERROR3: MOV A,#Err_IIC_InvalidAddress
      Call I2C_Stop
      Ret
      l_ERROR4: MOV A,#Err_IIC_PrematureNOACK
      Call I2C_Stop
      Ret

      ;==============================================================;
      I2C_ReadData: Call I2C_Start
      JC l_ERROR1
      MOV DPL,A ;Save SlaveAddress
      Clr ACC.0
      Call I2C_SendByte ;Send SlaveAddress
      JC l_ERROR2
      MOV A,B
      Call I2C_SendByte ;Send Word Address
      JC l_ERROR3

      Call I2C_Start
      JC l_ERROR1
      MOV A,DPL ;Load SlaveAddress again
      SetB ACC.0
      Call I2C_SendByte ;Send SlaveAddress
      JC l_ERROR2

      DEC R2
      I2C_ReadDataL: Clr C ;Set to ACK
      Call I2C_GetByte ;Get Data Byte
      MOV @R1,A
      INC R1
      DJNZ R2,I2C_ReadDataL
      SetB C ;Set to NOACK
      Call I2C_GetByte ;Get Data Byte
      MOV @R1,A
      Call I2C_Stop
      Clr C
      Ret

      ; ACC = SlaveAddress, B = WordAddress, R1 = DataMemoryOffset, R2 = Counter

  3. trimakasih banyak mas,,, saya sudah mempraktekkan a dan berhasil dan juga akurat walau pun masih saya uji dalam 24jam,,, tetapi ada masalah saat saya solder kristal 32,768khz dan tidak sengaja saya tekan pula kaki kristal a saat masih on power dan on batrey 3V a dn sekarang jam a sudah rusak, apa rtc1307 sangat mudah rusak oleh static atau selain itu mas

  4. o… sudah d bagian sensitif sekali ya mas berrti,,, hehe sudah sya coba mas tp tetap saja tidak mau, tak apalah kapan2 nyolder2 jam a lagi, trimakasih ya mas mikroban….

  5. ass. mas saya sudah membuat jam dng bantuan program,circuit a sangat memuas kan 1/2 bulan tetap akurat, tapi sya punya keinginan untuk tampilan 4 digit dng dot yg berkedip2, itu program a gimana ya mas

  6. salam kenal mas….. bagus x tutorialnya. mas saya terarik sama jam digital 7 segment ini. saya kepengen buat. mas saya mau bikin detiknya berkedip gimana caranya yea mas.

  7. mas bro … adik saya dapet tugas dari sekolah nya … disuruh buat rangkaian jam digital dengan led biasa bukan 7segment dan memakai 4094 serta 89c51 nah kira2 apa sama rangkaiannya dengan yang punya mas bro ini ? mohon bantuannya mas bro :) terima kasih sebelumnya

  8. Permisi numpang nanya mas broo.. ini gua dapat tugas dari sekolah, hamper mirip seperti rangkaian nya masbro ini. Kira-kira daftar komponen nya apa aja ya mas broo???

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Logout / Ubah )

Twitter picture

You are commenting using your Twitter account. Logout / Ubah )

Facebook photo

You are commenting using your Facebook account. Logout / Ubah )

Google+ photo

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s