gambarnya ini
berikut listing program nya.;==============================================================;
pLCD_RS BIT P1.0
pLCD_RW BIT P1.2
pLCD_E BIT P1.1
pLCD_D4 BIT P1.4
pLCD_D5 BIT P1.5
pLCD_D6 BIT P1.6
pLCD_D7 BIT P1.7
I2C_SDA BIT P3.7
I2C_SCL BIT P3.6
MENIT bit p3.2
saklar bit p3.3
JAM bit p3.4
Portadc equ p0
dataadc equ 20h
cahaya equ 21h
Detik_lama DATA 22h
RTCDetik DATA 31h ;00
RTCMenit DATA 32h ;01
RTCjam DATA 33h ;02
RTCHari DATA 34h ;03
RTCTanggal DATA 35h ;04
RTCBulan DATA 36h ;05
RTCTahun DATA 37h ;06
RTCControl DATA 38h ;07
Digit_1 DATA 39h ;01
Digit_2 DATA 3ah ;02
Digit_3 DATA 3bh ;03
Digit_4 DATA 3ch ;04
Digit_5 DATA 3dh ;05
Digit_6 DATA 3eh ;06
Digit_7 DATA 3fh ;07
Digit_8 DATA 40h ;08
Digit_9 DATA 41h ;09
wri bit p2.1
re bit p2.2
itr bit p2.0
org 0h
;==============================================================;
call tunda_long
mov 20H,#00h
mov p2,#0ffh
jmp Restart_awal
Restart_awal: setb I2C_SDA ; high
setb I2C_SCL ; high
Call LCD_Init
call LCD_BlinkOff
Call LCD_GoTopLine1
MOV DPTR,#TULISAN_Kirim
Call LCD_DataLine
Call LCD_GoTopLine2
MOV DPTR,#TULISAN_Kirim2
Call LCD_DataLine
Call LCD_Tunda1Dtk
call tunda_long
call Tulis_rtc_Detik
jmp MainLoop
MainLoop: Call LCD_GoTopLine1
MOV DPTR,#TULISAN1
Call LCD_DataLine
Call LCD_GoTopLine2
MOV DPTR,#TULISAN2
Call LCD_DataLine
Call LCD_Tunda1Dtk
Call LCD_Clear
Call LCD_GoTopLine1
MOV DPTR,#Nilai_atas
Call LCD_DataLine
Call LCD_GoTopLine2
MOV DPTR,#Nilai_bawah
Call LCD_DataLine
mulai:
call BACA_ADC
call scanning_adc
Tunggu_jam2: call ReadAllRTC
mov a,RTCDetik
cjne a,detik_lama,update_jam
jmp Tunggu_jam2
update_jam: jb saklar,update_jam2
call reset_memori
update_jam2: JB JAM, UPDATE_MENIT
call ReadAllRTC
INC RTCjam
mov a,rtcjam
cjne a,#24h,uptdate_jam3
mov rtcjam,#00h
uptdate_jam3: call Tulis_rtc_JAM
call Tulis_rtc_Detik
UPDATE_MENIT: JB MENIT, update_detik
call ReadAllRTC
INC RTCmenit
mov a,rtcmenit
cjne a,#60h,uptdate_menit3
mov rtcmenit,#00h
uptdate_menit3: call Tulis_rtc_menit
call Tulis_rtc_Detik
update_detik: cpl p3.0
Call StreamRTC
Jmp mulai
;==============================================================;
scanning_adc: cjne a,#129,adc_130
inc Digit_9
call scanning_rupiah
inc Digit_9
call scanning_rupiah
inc Digit_9
call Tulis_digit_9
call scanning_rupiah
call LCD_GoTopLine22
MOV DPTR,#k_129
Call LCD_DataLine
ret
adc_130: cjne a,#130,adc_131
inc Digit_8
call Tulis_digit_8
call scanning_rupiah
call LCD_GoTopLine22
MOV DPTR,#k_130
Call LCD_DataLine
ret
adc_131: cjne a,#131,adc_132
inc Digit_8
call Tulis_digit_8
call scanning_rupiah
call LCD_GoTopLine22
MOV DPTR,#k_131
Call LCD_DataLine
ret
adc_132: cjne a,#132,adc_133
mov r3,#2
adc_132a: inc Digit_8
call Tulis_digit_8
call scanning_rupiah
djnz r3,adc_132a
call LCD_GoTopLine22
MOV DPTR,#k_132
Call LCD_DataLine
ret
adc_133: cjne a,#133,adc_134
mov r3,#3
adc_133a: inc Digit_8
call Tulis_digit_8
call scanning_rupiah
djnz r3,adc_133a
call LCD_GoTopLine22
MOV DPTR,#k_133
Call LCD_DataLine
ret
adc_134: cjne a,#134,adc_135
mov r3,#3
adc_134a: inc Digit_8
call Tulis_digit_8
call scanning_rupiah
djnz r3,adc_134a
call LCD_GoTopLine22
MOV DPTR,#k_134
Call LCD_DataLine
ret
adc_135: cjne a,#135,adc_136
mov r3,#4
adc_135a: inc Digit_8
call Tulis_digit_8
call scanning_rupiah
djnz r3,adc_135a
call LCD_GoTopLine22
MOV DPTR,#k_135
Call LCD_DataLine
ret
adc_136: cjne a,#136,adc_137
mov r3,#4
adc_136a: inc Digit_8
call Tulis_digit_8
call scanning_rupiah
djnz r3,adc_136a
call LCD_GoTopLine22
MOV DPTR,#k_36
Call LCD_DataLine
ret
adc_137: cjne a,#137,adc_138
mov r3,#5
adc_137a: inc Digit_8
call Tulis_digit_8
call scanning_rupiah
djnz r3,adc_137a
call LCD_GoTopLine22
MOV DPTR,#k_137
Call LCD_DataLine
ret
adc_138: cjne a,#138,adc_139
mov r3,#5
adc_138a: inc Digit_8
call Tulis_digit_8
call scanning_rupiah
djnz r3,adc_138a
call LCD_GoTopLine22
MOV DPTR,#k_138
Call LCD_DataLine
ret
adc_139: cjne a,#139,adc_140
mov r3,#6
adc_139a: inc Digit_8
call Tulis_digit_8
call scanning_rupiah
djnz r3,adc_139a
call LCD_GoTopLine22
MOV DPTR,#k_139
Call LCD_DataLine
ret
adc_140: cjne a,#140,adc_141
mov r3,#6
adc_140a: inc Digit_8
call Tulis_digit_8
call scanning_rupiah
djnz r3,adc_140a
call LCD_GoTopLine22
MOV DPTR,#k_140
Call LCD_DataLine
ret
adc_141: cjne a,#141,adc_142
mov r3,#6
adc_141a: inc Digit_8
call Tulis_digit_8
call scanning_rupiah
djnz r3,adc_141a
call LCD_GoTopLine22
MOV DPTR,#k_141
Call LCD_DataLine
ret
adc_142: cjne a,#142,adc_143
mov r3,#7
adc_142a: inc Digit_8
call Tulis_digit_8
call scanning_rupiah
djnz r3,adc_142a
call LCD_GoTopLine22
MOV DPTR,#k_142
Call LCD_DataLine
ret
adc_143: cjne a,#143,adc_144
mov r3,#8
adc_143a: inc Digit_8
call Tulis_digit_8
call scanning_rupiah
djnz r3,adc_143a
call LCD_GoTopLine22
MOV DPTR,#k_143
Call LCD_DataLine
ret
adc_144: cjne a,#144,adc_145
mov r3,#8
adc_144a: inc Digit_8
call Tulis_digit_8
call scanning_rupiah
djnz r3,adc_144a
call LCD_GoTopLine22
MOV DPTR,#k_144
Call LCD_DataLine
ret
adc_145: cjne a,#145,adc_146
mov r3,#9
adc_145a: inc Digit_8
call Tulis_digit_8
call scanning_rupiah
djnz r3,adc_145a
call LCD_GoTopLine22
MOV DPTR,#k_145
Call LCD_DataLine
ret
adc_146: cjne a,#146,adc_147
mov r3,#1
adc_146a: inc Digit_7
call Tulis_digit_7
call scanning_rupiah
inc Digit_9
call Tulis_digit_9
call scanning_rupiah
inc Digit_9
call Tulis_digit_9
call scanning_rupiah
djnz r3,adc_146a
call LCD_GoTopLine22
MOV DPTR,#k_146
Call LCD_DataLine
ret
adc_147: cjne a,#147,adc_148
mov r3,#1
adc_147a: inc Digit_7
call Tulis_digit_7
call scanning_rupiah
inc Digit_9
call Tulis_digit_9
call scanning_rupiah
inc Digit_9
call Tulis_digit_9
call scanning_rupiah
inc Digit_9
call Tulis_digit_9
call scanning_rupiah
inc Digit_9
call Tulis_digit_9
call scanning_rupiah
inc Digit_9
call Tulis_digit_9
call scanning_rupiah
inc Digit_9
call Tulis_digit_9
call scanning_rupiah
djnz r3,adc_147a
call LCD_GoTopLine22
MOV DPTR,#k_147
Call LCD_DataLine
ret
adc_148: cjne a,#148,adc_149
mov r3,#1
adc_148a: inc Digit_7
call Tulis_digit_7
call scanning_rupiah
inc Digit_8
call Tulis_digit_8
call scanning_rupiah
inc Digit_9
call Tulis_digit_9
call scanning_rupiah
inc Digit_9
call Tulis_digit_9
call scanning_rupiah
inc Digit_9
call Tulis_digit_9
call scanning_rupiah
djnz r3,adc_148a
call LCD_GoTopLine22
MOV DPTR,#k_148
Call LCD_DataLine
ret
adc_149: cjne a,#149,adc_150
mov r3,#1
adc_149a: inc Digit_7
call Tulis_digit_7
call scanning_rupiah
inc Digit_8
call Tulis_digit_8
call scanning_rupiah
inc Digit_9
call Tulis_digit_9
call scanning_rupiah
inc Digit_9
call Tulis_digit_9
call scanning_rupiah
inc Digit_9
call Tulis_digit_9
call scanning_rupiah
inc Digit_9
call Tulis_digit_9
call scanning_rupiah
inc Digit_9
call Tulis_digit_9
call scanning_rupiah
inc Digit_9
call Tulis_digit_9
call scanning_rupiah
inc Digit_9
call Tulis_digit_9
call scanning_rupiah
djnz r3,adc_149a
call LCD_GoTopLine22
MOV DPTR,#k_149
Call LCD_DataLine
ret
adc_150: cjne a,#150,adc_151
mov r3,#1
adc_150a: inc Digit_7
call Tulis_digit_7
call scanning_rupiah
inc Digit_8
call Tulis_digit_8
call scanning_rupiah
inc Digit_8
call Tulis_digit_8
call scanning_rupiah
inc Digit_9
call Tulis_digit_9
call scanning_rupiah
inc Digit_9
call Tulis_digit_9
call scanning_rupiah
inc Digit_9
call Tulis_digit_9
call scanning_rupiah
inc Digit_9
call Tulis_digit_9
call scanning_rupiah
djnz r3,adc_150a
call LCD_GoTopLine22
MOV DPTR,#k_150
Call LCD_DataLine
adc_151:call LCD_GoTopLine22
MOV DPTR,#k_151
Call LCD_DataLine
ret
;==============================================================;
k_129: db '0.1',0
k_130: db '0.3',0
k_131: db '0.4',0
k_132: db '0.6',0
k_133: db '0.7',0
k_134: db '0.9',0
k_135: db '1.0',0
k_136: db '1.2',0
k_137: db '1.4',0
k_138: db '1.5',0
k_139: db '1.7',0
k_140: db '1.8',0
k_141: db '2.0',0
k_142: db '2.1',0
k_143: db '2.3',0
k_144: db '2.4',0
k_145: db '2.6',0
k_146: db '2.8',0
k_147: db '2.9',0
k_148: db '3.1',0
k_149: db '3.2',0
k_150: db '3.4',0
k_151: db '0.0',0
;==============================================================;
scanning_rupiah:CLR C
CLR A
mov a,digit_9
subb A,#0Ah
jc rupiah_8
inc digit_8
call Tulis_digit_8
mov digit_9,#0h
call Tulis_digit_9
rupiah_8: CLR C
CLR A
mov a,digit_8
subb A,#0Ah
jc rupiah_7
inc digit_7
call Tulis_digit_7
mov digit_8,#0h
call Tulis_digit_8
rupiah_7: CLR C
CLR A
mov a,digit_7
subb A,#0Ah
JC rupiah_6
inc digit_6
call Tulis_digit_6
mov digit_7,#0h
call Tulis_digit_7
rupiah_6: CLR C
CLR A
mov a,digit_6
subb A,#0Ah
JC rupiah_5
inc digit_5
call Tulis_digit_5
mov digit_6,#0h
call Tulis_digit_6
rupiah_5: CLR C
CLR A
mov a,digit_5
subb A,#0Ah
JC rupiah_4
inc digit_4
call Tulis_digit_4
mov digit_5,#0h
call Tulis_digit_5
rupiah_4: CLR C
CLR A
mov a,digit_4
subb A,#0Ah
JC rupiah_3
inc digit_3
call Tulis_digit_3
mov digit_4,#0h
call Tulis_digit_4
rupiah_3: CLR C
CLR A
mov a,digit_3
subb A,#0Ah
JC rupiah_2
inc digit_2
call Tulis_digit_2
mov digit_3,#0h
call Tulis_digit_3
rupiah_2: CLR C
CLR A
mov a,digit_2
subb A,#0Ah
JC rupiah_1
inc digit_1
call Tulis_digit_1
mov digit_2,#0h
call Tulis_digit_2
rupiah_1: CLR C
CLR A
mov a,digit_1
subb A,#0Ah
JC rupiah_0
call reset_memori
rupiah_0: ret
;==============================================================;
StreamRTC: mov a,RTCDetik
mov Detik_lama,a
Call LCD_GoTopLine2a
call Konversi_r
Call LCD_DataLine
mov a,RTCmenit
Call LCD_GoTopLine2b
call Konversi_r
Call LCD_DataLine
mov a,RTCjam
Call LCD_GoTopLine2c
call Konversi_r
Call LCD_DataLine
mov a,Digit_9
call LCD_Line_9
call Konversi_d
Call LCD_DataLine
mov a,Digit_8
call LCD_Line_8
call Konversi_d
Call LCD_DataLine
mov a,Digit_7
call LCD_Line_7
call Konversi_d
Call LCD_DataLine
mov a,Digit_6
call LCD_Line_6
call Konversi_d
Call LCD_DataLine
mov a,Digit_5
call LCD_Line_5
call Konversi_d
Call LCD_DataLine
mov a,Digit_4
call LCD_Line_4
call Konversi_d
Call LCD_DataLine
mov a,Digit_3
call LCD_Line_3
call Konversi_d
Call LCD_DataLine
mov a,Digit_2
call LCD_Line_2
call Konversi_d
Call LCD_DataLine
mov a,Digit_1
call LCD_Line_1
call Konversi_d
Call LCD_DataLine
ret
;==============================================================;
reset_memori: mov Digit_1,#0
call Tulis_digit_1
mov Digit_2,#0
call Tulis_digit_2
mov Digit_3,#0
call Tulis_digit_3
mov Digit_4,#0
call Tulis_digit_4
mov Digit_5,#0
call Tulis_digit_5
mov Digit_6,#0
call Tulis_digit_6
mov Digit_7,#0
call Tulis_digit_7
mov Digit_8,#0
call Tulis_digit_8
mov Digit_9,#0
call Tulis_digit_9
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_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 ;Alamat
mov R1,rtcmenit ;datanya
Call 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
Call I2C_WriteByte
JC Error_Detik_rtc
ret
Error_Detik_rtc:jmp Tulis_rtc_Detik
Tulis_rtc_tgl: MOV A,#11010000b
mov B,#04h ;Alamat
mov R1,rtctanggal ;datanya
Call I2C_WriteByte
JC Error_tgl_rtc
ret
Error_tgl_rtc: jmp Tulis_rtc_tgl
Tulis_rtc_bln: MOV A,#11010000b
mov B,#05h ;Alamat
mov R1,rtcbulan ;datanya
Call I2C_WriteByte
JC Error_bln_rtc
ret
Error_bln_rtc: jmp Tulis_rtc_bln
Tulis_rtc_thn: MOV A,#11010000b
mov B,#06h ;Alamat
mov R1,rtctahun ;datanya
Call I2C_WriteByte
JC Error_thn_rtc
ret
Error_thn_rtc: jmp Tulis_rtc_thn
StartRTC: MOV A,RTCDetik
ANL A,#7Fh
MOV R1,A
MOV A,#11010000b
MOV B,#0
Call I2C_WriteByte ; ACC = SlaveAddress, B = WordAddress, R1 = Data byte
MOV R1,#10h
MOV A,#11010000b
MOV B,#07 ;address For Control
Call I2C_WriteByte ; ACC = SlaveAddress, B = WordAddress, R1 = Data byte
ReadAllRTC: MOV A,#11010001b ;SlaveAddress
MOV B,#0
MOV R1,#RTCDetik
MOV R2,#16
Call I2C_ReadData ; ACC = SlaveAddress, B = WordAddress, R1 = DataMemoryOffset, R2 = Counter
ret
Tulis_digit_1: MOV A,#11010000b
mov B,#08h ;Alamat
mov R1,digit_1 ;datanya
Call I2C_WriteByte
JC Error_digit_1
ret
Error_digit_1: jmp Tulis_digit_1
Tulis_digit_2: MOV A,#11010000b
mov B,#09h ;Alamat
mov R1,digit_2 ;datanya
Call I2C_WriteByte
JC Error_digit_2
ret
Error_digit_2: jmp Tulis_digit_2
Tulis_digit_3: MOV A,#11010000b
mov B,#0ah ;Alamat
mov R1,digit_3 ;datanya
Call I2C_WriteByte
JC Error_digit_3
ret
Error_digit_3: jmp Tulis_digit_3
Tulis_digit_4: MOV A,#11010000b
mov B,#0bh ;Alamat
mov R1,digit_4 ;datanya
Call I2C_WriteByte
JC Error_digit_4
ret
Error_digit_4: jmp Tulis_digit_4
Tulis_digit_5: MOV A,#11010000b
mov B,#0ch ;Alamat
mov R1,digit_5 ;datanya
Call I2C_WriteByte
JC Error_digit_5
ret
Error_digit_5: jmp Tulis_digit_5
Tulis_digit_6: MOV A,#11010000b
mov B,#0dh ;Alamat
mov R1,digit_6 ;datanya
Call I2C_WriteByte
JC Error_digit_6
ret
Error_digit_6: jmp Tulis_digit_6
Tulis_digit_7: MOV A,#11010000b
mov B,#0eh ;Alamat
mov R1,digit_7 ;datanya
Call I2C_WriteByte
JC Error_digit_7
ret
Error_digit_7: jmp Tulis_digit_7
Tulis_digit_8: MOV A,#11010000b
mov B,#0fh ;Alamat
mov R1,digit_8 ;datanya
Call I2C_WriteByte
JC Error_digit_8
ret
Error_digit_8: jmp Error_digit_8
Tulis_digit_9: MOV A,#11010000b
mov B,#10h ;Alamat
mov R1,digit_9 ;datanya
Call I2C_WriteByte
JC Error_digit_9
ret
Error_digit_9: jmp Tulis_digit_9
;==============================================================;
; 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
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Mengambil data adc simpan ke accumulator
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
BACA_ADC:
SETB WRI
SETB RE
CALL tunda
CLR WRI
CALL tunda
SETB WRI
JB ITR,$
CALL tunda
CLR RE
clr a
MOV A,Portadc
SETB RE
RET
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Konversi data adc tampilkan data ke lcd
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
tunda:
delay: mov R5,#0h
delay1: mov R7,#0h
djnz R7,$
djnz R5,delay1
ret
;==============================================================;
TULISAN1: DB 'Sensor ArusAC20A',0
TULISAN2: DB 'KWHmeter Digital',0
TULISAN_Kirim: DB '................',0
TULISAN_Kirim2: DB ' RESTART SENSOR ',0
Nilai_atas: DB 'Rp. . , ',0
Nilai_bawah: DB '[ A] ..:..:..',0
;==============================================================;
;==============================================================;
LCD_Init: Call LCD_DelayAnime
Push Acc
MOV A,#33h ;LCD 2 Lines, 5x7 Matrix
Call LCD_Command_Go
MOV A,#33h ;Send it Again
Call LCD_Command_Go
MOV A,#33h ;Send it Again
Call LCD_Command_Go
Mov A,#00000010b
Call LCD_Command
Call LCD_Delay2mS
Mov A,#00101000b ;4-bit Data bus
Call LCD_Command
MOV A,#00001111b ;Display On, Cursor On
Call LCD_Command
POP Acc
LCD_Clear: Push Acc
MOV A,#01h ;Clear
Call LCD_Command
Call LCD_Delay2mS
MOV A,#02h ;Home
Call LCD_Command
Call LCD_Delay2mS
POP Acc
Ret
;==============================================================;
LCD_GeserDisp: Push Acc
MOV A,#16
LCD_GeserDLp: Push Acc
MOV A,#18h
Call LCD_Command
Call LCD_DelayAnime
POP Acc
DJNZ Acc,LCD_GeserDLp
Call LCD_Clear
POP Acc
Ret
;==============================================================;
LCD_SetDtToPrt: MOV C,Acc.4
MOV pLCD_D4,C
MOV C,Acc.5
MOV pLCD_D5,C
MOV C,Acc.6
MOV pLCD_D6,C
MOV C,Acc.7
MOV pLCD_D7,C
Ret
;==============================================================;
LCD_Command: Push Acc
Call LCD_SetDtToPrt
Clr pLCD_RS ;RS=0 command
Clr pLCD_RW ;RW=0 Write
Push ACC ;---
SetB pLCD_E ;Pulse H
POP ACC ;---
Clr pLCD_E ; to L for E
Call LCD_Delay40uS
POP Acc
SWAP A
LCD_Command_Go: Call LCD_SetDtToPrt
Clr pLCD_RS ;RS=0 command
Clr pLCD_RW ;RW=0 Write
Push ACC ;---
SetB pLCD_E ;Pulse H
POP ACC ;---
Clr pLCD_E ; to L for E
Call LCD_Delay40uS
Ret
;==============================================================;
LCD_Data: Push Acc
Call LCD_SetDtToPrt
SetB pLCD_RS ;RS=1 Data
Clr pLCD_RW ;RW=0 Write
Push ACC ;---
SetB pLCD_E ;Pulse H
POP ACC ;---
Clr pLCD_E ; to L for E
Call LCD_Delay40uS
POP Acc
SWAP A
Call LCD_SetDtToPrt
SetB pLCD_RS ;RS=1 Data
Clr pLCD_RW ;RW=0 Write
Push ACC ;---
SetB pLCD_E ;Pulse H
POP ACC ;---
Clr pLCD_E ; to L for E
Call LCD_Delay40uS
Ret
;==============================================================;
LCD_DataLine: Clr A
MOVC A,@A+DPTR
JZ LCD_DataLineEnd
Call LCD_Data
INC DPTR
SJmp LCD_DataLine
LCD_DataLineEnd:Ret
;==============================================================;
LCD_DelayAnime: Push Acc
MOV A,#2
Jmp LCD_Tunda1DtkLoop2
;---------------
LCD_Tunda4Dtk: Push Acc
MOV A,#40
Jmp LCD_Tunda1DtkLoop2
;==============================================================;
LCD_Tunda1Dtk: Push Acc ;2MC
MOV A,#10 ;1MC
LCD_Tunda1DtkLoop2:
;====
Push Acc
MOV A,#200
LCD_Tunda1DtkLoop1:
;====
Push Acc
MOV A,#227 ;1MC
DJNZ Acc,$
;====
Pop Acc
DJNZ Acc,LCD_Tunda1DtkLoop1
;====
Pop Acc
DJNZ Acc,LCD_Tunda1DtkLoop2 ;2MC
;====
Pop Acc ;2MC
NOP
Ret ;2MC
;==============================================================;
LCD_Delay2mS: Push Acc
MOV A,#6 ;*** tunda utk LCD 1,64mS
LCD_Delay2mSLp: Push Acc
MOV Acc,#230
DJNZ Acc,$
Pop Acc
DJNZ Acc,LCD_Delay2mSLp
Pop Acc
Ret
;==============================================================;
LCD_Delay40uS: Push Acc
MOV A,#25 ;*** tunda utk LCD 40uS
DJNZ Acc,$
Pop Acc
Ret
;==============================================================;
LCD_ShfCurL: Push Acc
MOV A,#010h ;Geser kursor ke kiri sekali
Call LCD_Command
Pop Acc
Ret
LCD_ShfCurR: Push Acc
MOV A,#014h ;Geser kursor ke kanan sekali
Call LCD_Command
Pop Acc
Ret
LCD_GoTopLine1: Push Acc
MOV A,#080h ;Kembali ke ujung kiri
Call LCD_Command
Call LCD_Delay2mS
Pop Acc
Ret
LCD_Line_1: Push Acc
MOV A,#085h ;Kembali ke ujung kiri
Call LCD_Command
Call LCD_Delay2mS
Pop Acc
Ret
LCD_Line_2: Push Acc
MOV A,#086h ;Kembali ke ujung kiri
Call LCD_Command
Call LCD_Delay2mS
Pop Acc
Ret
LCD_Line_3: Push Acc
MOV A,#087h ;Kembali ke ujung kiri
Call LCD_Command
Call LCD_Delay2mS
Pop Acc
Ret
LCD_Line_4: Push Acc
MOV A,#089h ;Kembali ke ujung kiri
Call LCD_Command
Call LCD_Delay2mS
Pop Acc
Ret
LCD_Line_5: Push Acc
MOV A,#08ah ;Kembali ke ujung kiri
Call LCD_Command
Call LCD_Delay2mS
Pop Acc
Ret
LCD_Line_6: Push Acc
MOV A,#08bh ;Kembali ke ujung kiri
Call LCD_Command
Call LCD_Delay2mS
Pop Acc
Ret
LCD_Line_7: Push Acc
MOV A,#08dh ;Kembali ke ujung kiri
Call LCD_Command
Call LCD_Delay2mS
Pop Acc
Ret
LCD_Line_8: Push Acc
MOV A,#08eh ;Kembali ke ujung kiri
Call LCD_Command
Call LCD_Delay2mS
Pop Acc
Ret
LCD_Line_9: Push Acc
MOV A,#08fh ;Kembali ke ujung kiri
Call LCD_Command
Call LCD_Delay2mS
Pop Acc
Ret
LCD_GoTopLine2: Push Acc
MOV A,#0C0h ;Kembali ke ujung kiri
Call LCD_Command
Call LCD_Delay2mS
Pop Acc
Ret
LCD_GoTopLine22: Push Acc
MOV A,#0C1h ;Kembali ke ujung kiri
Call LCD_Command
Call LCD_Delay2mS
Pop Acc
Ret
LCD_GoTopLine2a: Push Acc
MOV A,#0Ceh ;Kembali ke ujung kiri
Call LCD_Command
Call LCD_Delay2mS
Pop Acc
Ret
LCD_GoTopLine2b: Push Acc
MOV A,#0Cbh ;Kembali ke ujung kiri
Call LCD_Command
Call LCD_Delay2mS
Pop Acc
Ret
LCD_GoTopLine2c: Push Acc
MOV A,#0C8h ;Kembali ke ujung kiri
Call LCD_Command
Call LCD_Delay2mS
Pop Acc
Ret
LCD_BlinkOn: Push Acc
MOV A,#0Eh ;Display On, Cursor On ,Blink Off
Call LCD_Command
Pop Acc
Ret
LCD_BlinkOff: Push Acc
MOV A,#0Ch ;Display On, Cursor Off ,Blink Off
Call LCD_Command
Pop Acc
Ret
TUNDA_LONG: MOV R5,#010H
JJz: CALL TUNDAan
DJNZ R5,JJz
RET
TUNDAan: MOV R7,#10
LD1: DJNZ R6,$
DJNZ R7,LD1
RET
Konversi_d: cjne a,#0h,s_1
mov dptr,#d_0
ret
s_1: cjne a,#1h,s_2
mov dptr,#d_1
ret
s_2: cjne a,#2h,s_3
mov dptr,#d_2
ret
s_3: cjne a,#3h,s_4
mov dptr,#d_3
ret
s_4: cjne a,#4h,s_5
mov dptr,#d_4
ret
s_5: cjne a,#5h,s_6
mov dptr,#d_5
ret
s_6: cjne a,#6h,s_7
mov dptr,#d_6
ret
s_7: cjne a,#7h,s_8
mov dptr,#d_7
ret
s_8: cjne a,#8h,s_9
mov dptr,#d_8
ret
s_9: cjne a,#9h,s_10
mov dptr,#d_9
RET
s_10: mov dptr,#d_0
ret
d_0: db '0',0
d_1: db '1',0
d_2: db '2',0
d_3: db '3',0
d_4: db '4',0
d_5: db '5',0
d_6: db '6',0
d_7: db '7',0
d_8: db '8',0
d_9: db '9',0
d_10: db '0',0
Konversi_r: cjne a,#0h,K_1
mov dptr,#r_0
ret
K_1: cjne a,#1h,K_2
mov dptr,#r_1
ret
K_2: cjne a,#2h,K_3
mov dptr,#r_2
ret
K_3: cjne a,#3h,K_4
mov dptr,#r_3
ret
K_4: cjne a,#4h,K_5
mov dptr,#r_4
ret
K_5: cjne a,#5h,K_6
mov dptr,#r_5
ret
K_6: cjne a,#6h,K_7
mov dptr,#r_6
ret
K_7: cjne a,#7h,K_8
mov dptr,#r_7
ret
K_8: cjne a,#8h,K_9
mov dptr,#r_8
ret
K_9: cjne a,#9h,K_10
mov dptr,#r_9
ret
K_10: cjne a,#10h,K_11
mov dptr,#r_10
ret
K_11: cjne a,#11h,K_12
mov dptr,#r_11
ret
K_12: cjne a,#12h,K_13
mov dptr,#r_12
ret
K_13: cjne a,#13h,K_14
mov dptr,#r_13
ret
K_14: cjne a,#14h,K_15
mov dptr,#r_14
ret
K_15: cjne a,#15h,K_16
mov dptr,#r_15
ret
K_16: cjne a,#16h,K_17
mov dptr,#r_16
ret
K_17: cjne a,#17h,K_18
mov dptr,#r_17
ret
K_18: cjne a,#18h,K_19
mov dptr,#r_18
ret
K_19: cjne a,#19h,K_20
mov dptr,#r_19
ret
K_20: cjne a,#20h,K_21
mov dptr,#r_20
ret
K_21: cjne a,#21h,K_22
mov dptr,#r_21
ret
K_22: cjne a,#22h,K_23
mov dptr,#r_22
ret
K_23: cjne a,#23h,K_24
mov dptr,#r_23
ret
K_24: cjne a,#24h,K_25
mov dptr,#r_24
ret
K_25: cjne a,#25h,K_26
mov dptr,#r_25
ret
K_26: cjne a,#26h,K_27
mov dptr,#r_26
ret
K_27: cjne a,#27h,K_28
mov dptr,#r_27
ret
K_28: cjne a,#28h,K_29
mov dptr,#r_28
ret
K_29: cjne a,#29h,K_30
mov dptr,#r_29
ret
K_30: cjne a,#30h,K_31
mov dptr,#r_30
ret
K_31: cjne a,#31h,K_32
mov dptr,#r_31
ret
K_32: cjne a,#32h,K_33
mov dptr,#r_32
ret
K_33: cjne a,#33h,K_34
mov dptr,#r_33
ret
K_34: cjne a,#34h,K_35
mov dptr,#r_34
ret
K_35: cjne a,#35h,K_36
mov dptr,#r_35
ret
K_36: cjne a,#36h,K_37
mov dptr,#r_36
ret
K_37: cjne a,#37h,K_38
mov dptr,#r_37
ret
K_38: cjne a,#38h,K_39
mov dptr,#r_38
ret
K_39: cjne a,#39h,K_40
mov dptr,#r_39
ret
K_40: cjne a,#40h,K_41
mov dptr,#r_40
ret
K_41: cjne a,#41h,K_42
mov dptr,#r_41
ret
K_42: cjne a,#42h,K_43
mov dptr,#r_42
ret
K_43: cjne a,#43h,K_44
mov dptr,#r_43
ret
K_44: cjne a,#44h,K_45
mov dptr,#r_44
ret
K_45: cjne a,#45h,K_46
mov dptr,#r_45
ret
K_46: cjne a,#46h,K_47
mov dptr,#r_46
ret
K_47: cjne a,#47h,K_48
mov dptr,#r_47
ret
K_48: cjne a,#48h,K_49
mov dptr,#r_48
ret
K_49: cjne a,#49h,K_50
mov dptr,#r_49
ret
K_50: cjne a,#50h,K_51
mov dptr,#r_50
ret
K_51: cjne a,#51h,K_52
mov dptr,#r_51
ret
K_52: cjne a,#52h,K_53
mov dptr,#r_52
ret
K_53: cjne a,#53h,K_54
mov dptr,#r_53
ret
K_54: cjne a,#54h,K_55
mov dptr,#r_54
ret
K_55: cjne a,#55h,K_56
mov dptr,#r_55
ret
K_56: cjne a,#56h,K_57
mov dptr,#r_56
ret
K_57: cjne a,#57h,K_58
mov dptr,#r_57
ret
K_58: cjne a,#58h,K_59
mov dptr,#r_58
ret
K_59: cjne a,#59h,K_60
mov dptr,#r_59
ret
K_60: cjne a,#60h,K_61
mov dptr,#r_60
K_61: ret
r_0: db '00',0
r_1: db '01',0
r_2: db '02',0
r_3: db '03',0
r_4: db '04',0
r_5: db '05',0
r_6: db '06',0
r_7: db '07',0
r_8: db '08',0
r_9: db '09',0
r_10: db '10',0
r_11: db '11',0
r_12: db '12',0
r_13: db '13',0
r_14: db '14',0
r_15: db '15',0
r_16: db '16',0
r_17: db '17',0
r_18: db '18',0
r_19: db '19',0
r_20: db '20',0
r_21: db '21',0
r_22: db '22',0
r_23: db '23',0
r_24: db '24',0
r_25: db '25',0
r_26: db '26',0
r_27: db '27',0
r_28: db '28',0
r_29: db '29',0
r_30: db '30',0
r_31: db '31',0
r_32: db '32',0
r_33: db '33',0
r_34: db '34',0
r_35: db '35',0
r_36: db '36',0
r_37: db '37',0
r_38: db '38',0
r_39: db '39',0
r_40: db '40',0
r_41: db '41',0
r_42: db '42',0
r_43: db '43',0
r_44: db '44',0
r_45: db '45',0
r_46: db '46',0
r_47: db '47',0
r_48: db '48',0
r_49: db '49',0
r_50: db '50',0
r_51: db '51',0
r_52: db '52',0
r_53: db '53',0
r_54: db '54',0
r_55: db '55',0
r_56: db '56',0
r_57: db '57',0
r_58: db '58',0
r_59: db '59',0
r_60: db '60',0
END
Tidak ada komentar:
Posting Komentar