Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/04/07 20:51
Read: times


 
#136628 - code for spi interface of ade7756
Responding to: ???'s previous message
i havent included the entire code ,only where i take the 40 bit reading from anergy register of ADE7756 and send it to pc via max232 serial interface while using the lcd to display sending data or receiving data
----------------------------------------------------------
;energy meter USING 7756

LCDRS BIT P0.0
LCDEN BIT P0.1
LCDDATA EQU P2
SDA1 BIT P0.3
SCL1 BIT p0.2
cs bit p1.3
clk bit p1.2
dout bit p1.1
din bit p1.0

DS1307W EQU 0D0H
DS1307R EQU 0D1H
datah equ 30h
delr0 equ 3Ah
delr1 equ 3Bh
delr2 equ 3Ch
delr3 equ 3Dh
rd_no equ 3eh
wr_no equ 3fh
buff equ 50h
org 0000h
ajmp over

org 0050h
;this is how my circuit is connected
i also have rtc ds 1307 connected to the 89c51
--------------------------------------------------------

over:
ACALL LCDDISP
ACALL CLEAR
mov dptr,#MSG1
mov R7,#16
ACALL DISP_MSG
MOV A,#0C0H
ACALL COMMAND
mov dptr,#MSG2
mov R7,#16
ACALL DISP_MSG
acall clear
MOV TMOD,#20H
MOV TH1,#0FDH
MOV TL1,#0FDH
MOV SCON,#40H
SETB TR1
acall actGain
acall cmode
; LCALL WRITE_RTC
cnt1:
LCALL READ_RTC
LCALL DISP_RTC
acall disp_read
ACALL SENDTOPC
acall bdelay
ajmp cnt1

disp_read:
mov a,#80h
acall command
mov dptr,#read1
mov R7,#16
ACALL DISP_MSG
ACALL readAeng ;read active energy from7756
ret
SENDTOPC:
mov a,#80h
acall command
mov dptr,#snd1
mov R7,#16
ACALL DISP_MSG
mov a,#'*'
acall trans
MOV R0,#BUFF
MOV R1,#5
LPB:
MOV A,@R0
ACALL TRANS
INC R0
DJNZ R1,LPB
RET
TRANS:
MOV SBUF,A
JNB TI,$
CLR TI
RET


bdelay: mov r7,#3
l3: mov r6,#0ffh
l2: mov r5,#0ffh
ll1: djnz r5,ll1
djnz r6,l2
djnz r7,l3
ret
delay1:
mov r6,#50
l_2: mov r5,#200
l_1: djnz r5,l_1
djnz r6,l_2
ret

--------------------------------------------------------

MSG2: DB ' ENERGY METER '
MSG1: DB '7756 BASED '
read1: db 'Reading Data '
snd1: db 'Sending Data... '

lcddisp:
mov a,#38h
acall command
mov a,#0eh
acall command
mov a,#06h
acall command
clear:
mov a,#01h
acall command
ret

;lcd strobe subroutine

-----------------------------------------------------------

-----------------------------------------------------------
actGain:
mov A,#0bH ;ACTIVE ENERGY REGISTER
clr cs ;write 8 bit data to 7756
CLR clk
SETB clk
CLR clk
ORL A,#10000000B
ACALL GIVE8
mov A,#00001000B
ACALL GIVE4
mov A,#00000000B
ACALL GIVE8
setb cs
ret

cmode:
mov A,#06H ;ACTIVE ENERGY REGISTER
clr cs ;write 8 bit data to 7756
CLR clk
SETB clk
CLR clk
ORL A,#10000000B
ACALL GIVE8
mov A,#00000000B
ACALL GIVE8
mov A,#10000000B ;bit 7 of comde
ACALL GIVE8
setb cs
ret
readAeng:
MOV R0,#BUFF
mov A,#02H ;ACTIVE ENERGY REGISTER
clr cs ;write 8 bit data to 7756
CLR clk
SETB clk
CLR clk
ORL A,#00000000B
ACALL GIVE8
ACALL TAKE40
setb cs ;DESELECT
RET

GIVE8: MOV R2,#8 ;send data on port pin
GIVE: RLC A
MOV din,C
SETB clk
CLR clk
DJNZ R2,GIVE
RET

GIVE4: MOV R2,#4 ;send data on port pin
swap a
GIVE1: RLC A
MOV din,C
SETB clk
CLR clk
DJNZ R2,GIVE1
RET

TAKE40: MOV R3,#5 ; 40 bit from anergy register
T40:
MOV R2,#8 ;READ data from port pin
TAKE: SETB clk
CLR clk
MOV C,dout
RLC A
DJNZ R2,TAKE
MOV @R0,A
INC R0
DJNZ R3,T40
RET


;------------------------------------------------
END


List of 3 messages in thread
TopicAuthorDate
ade7756 interface with 89c51            01/01/70 00:00      
   code for spi interface of ade7756            01/01/70 00:00      
   Post it            01/01/70 00:00      

Back to Subject List