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

Back to Subject List

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


 
#93026 - Need help with a real clock on a aes-51
here is my code!! what do u think i should do to get my clock to run with a interrupt.!! i got t to run with out and interrupt

ser equ 0000h
MAIN EQU 0300h ;sets the address for the main function
;SERVICE EQU 1000H ;sets the address for the interrupt service routine
;serv2 equ 70f0h
HOURS SET R2 ;Our HOURS variable set to register 2
MINUTES SET R3 ;Our MINUTES variable set to register 3
SECONDS SET R4 ;Our SECONDS variable set to register 4
loop_cnt set R5
TICKS EQU 07Fh ;Our 20th of a second countdown timer
;CRYSTAL EQU 11059200 ;The crystal speed
;TMRCYCLE EQU 12 ;The number of crystal cycles per timer increment
;TMR_SEC EQU 921600 ;CRYSTAL/TMRCYCLE ;The # of timer increments per second
;F20TH_OF_SECOND EQU 46080 ;TMR_SEC/20
RESET_VALUE EQU 19456 ;65536-F20TH_OF_SECOND
PSW DATA 0D0H
TMOD DATA 089H ;TIMER MOD
;TF0 BIT 08DH
TF1 BIT 08FH ;TIMER1 FLAG
TR1 BIT 08EH ;TIMER1 ON/OFF
TL1 DATA 08BH ;TIMER1 LOW BYTE
TH1 DATA 08DH ;TIMER1 HIGH BYTE
TH0 DATA 08CH
TL0 DATA 08AH

TR0 BIT 08CH
EA BIT 0AFH
ET1 BIT 0ABH
ET0 BIT 0A9H
colon equ ':'
LCDC DATA 020H ;LCD CURSOR POSITION (0 TO 1FH)
LCD_RS BIT 090H ;PIN P1.0, H=instruction L=data
LCD_E BIT 091H ;PIN P1.1, enable L=active
LCD_D EQU 0FFF3H ;LCD data port address
ACC DATA 0E0H
XR6 DATA 01EH ;R6 OF BANK#3, SCRATCH MEMORY
XR7 DATA 01FH ;R7 OF BANK#3, SCRATCH MEMORY
DPL DATA 082H
DPH DATA 083H
B DATA 0F0H
TF0 BIT 08DH
IE DATA 0A8H ;INTERRUPT ENABLE
EX0 BIT 0A8H ;INTERRUPT 0 ENABLE

ser1:
reti
time:
reti
;*****************************************************************************************
;this is the portion of code that the intterupt service routine refers to
;*****************************************************************************************
org 0003h
jmp main
org 000bh
jmp ser
ORG 4005H
;LJMP MAIN1
org main
CLR ET0
PUSH DPH
PUSH DPL
PUSH ACC
push psw
MOV B,#20 ;initializing the count inside the intterrupt routine
del: CLR TR0 ;Turn off timer 1 as we reset the value
MOV TH0,#00H ;putting the upper byte of the reset value into the high count
MOV TL0,#00H ;putting the lower byte of the reset value into the low count
CLR TF0 ;clr overflow flag so for future detection
SETB TR0 ;start the timer zero counter
TLOOP: JNB TF0,TLOOP ;wait until the overflow flag is set, meaning count is finished
CLR TR0 ;stop the timer
DJNZ B,DEL ;keep counting until 20 cycles are done
MOV A,SECONDS ;Move the seconds variable into the accumulator
ADD A,#01h ;Increment the second varaiable
DA A ;adjust the decimal count
MOV SECONDS,A ;mov result back into seconds register
CJNE SECONDS,#60h,EXIT_RTC ;If we haven't counted 60 seconds, we're done.
MOV SECONDS,#00h ;Reset the seconds varaible
MOV A,MINUTES ;Move the minutes variable into the accumulator
ADD A,#01h ;Increment the number of minutes
DA A
MOV MINUTES,A ;move results back into minutes register
CJNE MINUTES,#60h,EXIT_RTC ;If we haven't counted 60 minutes, we're done
MOV MINUTES,#00h ;Reset the minutes variable
MOV A,HOURS ;Move the HOURS variable into the accumulator
ADD A,#01h ;Increment the number of HOURS
DA A
MOV HOURS,A ;move results back into HOURS register
CJNE HOURS,#24h,EXIT_RTC ;If we haven't counted 24 HOURS, we're done
MOV HOURS,#00h ;Reset the HOURS variable
EXIT_RTC:
pop psw
POP ACC
POP DPL
POP DPH
LCALL DISPLAY ;call the display sub routine
SETB ET0
RETI
;*****************************************************************************************
;this ends the intterupt service routine
;*****************************************************************************************
;*****************************************************************************************
;*****************************************************************************************
;*****************************************************************************************
;this is the beginning of the main function
;*****************************************************************************************

main1: ;org 7000h ;start of the main function
MOV HOURS,#0 ;initializing hrs,mins, and secs
MOV MINUTES,#0
MOV SECONDS,#0
MOV B,#20 ;initializing the count register
MOV TMOD,#01H ;setting the 16 bit mode for the counter
SETB EA ;Initialize interrupts
CLR 25h.6
SETB ET0 ;Initialize Timer 0 interrupt
LP: SJMP LP ;the loop wait part for the main funtion that will later
;detect the users interruption to set the clock
;*****************************************************************************************
;the main function code ends here.
;*****************************************************************************************
;*****************************************************************************************


;*****************************************************************************************
;*****************************************************************************************
;*****************************************************************************************
;*****************************************************************************************
;*****************************************************************************************
;*****************************************************************************************
;this portion of code converts the hex numbers to ascii for printability to lcd display
;(this portion of code works perfectly according to good.asm trial code)
;***************************************************************************************
DISPLAY:
mov A,HOURS ;hour display
swap A
anl A,#0fh
orl A,#30h ;make it ASCII
mov dptr,#7800h
movx @dptr,A ;put the digit in the string
mov A,HOURS
anl A,#0fh
orl A,#30h ;make it ASCII
inc dptr
movx @dptr,A
mov A,#colon
inc dptr
movx @dptr,A ;display ':' between digits
;
mov A,MINUTES ;first minute digit
swap A
anl A,#0fh
orl A,#30h ;make it ASCII
inc dptr
movx @dptr,A
mov A,MINUTES ;second minute digit
anl A,#0fh
orl A,#30h
inc dptr
movx @dptr,A
mov A,#colon
inc dptr
movx @dptr,A ;put in the second colon
;
mov A,SECONDS ;get the second's number
swap A
anl A,#0fh
orl A,#30h
inc dptr
movx @dptr,A ;put in the first second's digit
mov A,SECONDS
Anl A,#0fh
orl A,#30h
inc dptr
movx @dptr,A
inc dptr
mov A,#00h ;put in the stop indicator
movx @dptr,A

;
mov dptr,#7800h
LCALL SHOW
ret
;*****************************************************************************************
;ASCII convertion code ends here
;*****************************************************************************************
;*****************************************************************************************
;*****************************************************************************************
;this portion takes care of the lcd initialization, clear, cursor home positioning, and display
;(this portion of code works perfectly accoding to good.asm, trial code)
;*****************************************************************************************
SHOW: MOV R5,#9
lcall 4100h
PUSH ACC
LOOP: MOVX A,@DPTR
PUSH DPH
PUSH DPL
MOV DPTR,#0FFF3H
clr LCD_RS
MOVX @DPTR,A
CALL DELAY1
POP DPL
POP DPH
INC DPTR
INC LCDC
DJNZ R5,LOOP
POP ACC
RET

DELAY1: MOV XR6, #02
MOV XR7, #0
DJNZ XR7, $
DJNZ XR6, $-3
CLR LCD_E
SETB LCD_E
RET
linit:
; INITIALIZE LCD
PUSH ACC
PUSH DPH
PUSH DPL
MOV R0, #50 ; DELAY ABOUT 25MS
MOV R1, #0 ; This is a count-down delay which
DJNZ R1, $ ; takes about 23000 machine cycles
DJNZ R0, $-2 ; to complete.
SETB LCD_E ; DISABLE LCD
SETB LCD_RS ; SELECT INSTRUCTION
MOV A, #38H ; LCD RESET CODE
MOV DPTR, #LCD_D ; LCD PORT ADDRESS
MOVX @DPTR, A
MOV R0, #6 ;DELAY ABOUT 3MS
MOV R1, #0
DJNZ R1, $
DJNZ R0, $-2
CALL DELAYI ; DELAY ABOUR 1MS AND PULSE LCD ENABLE, 4 TIMES
CALL DELAYI ; DELAYI is a 1MS delay subroutine which you
CALL DELAYI ; will find listed below. It does a delay and
CALL DELAYI ; it sets and clears the LCD enable pin.
MOV A, #06H
MOVX @DPTR, A
CALL DELAYI
MOV A, #0DH
MOVX @DPTR, A
CALL DELAYI
MOV A, #01H
MOVX @DPTR, A
CALL DELAYI
MOV R0, #16 ; DELAY ADDITIONAL 8MS
MOV R1, #0
DJNZ R1, $
DJNZ R0, $-2
MOV A, #80H
MOVX @DPTR, A
CALL DELAYI
POP DPL
POP DPH
POP ACC
ret
; END OF LCD INITIALIZATION SEQUENCE
DELAYI:
mov loop_cnt,#20
clr ET1
mov TMOD,#10H

again: clr TF1
mov TH1,#3ch
MOV TL1,#0afh
setb TR1
wait: jnb TF1,wait
djnz loop_cnt,again
ret
;*****************************************************************************************
;lcd dislpay code ends here
;*****************************************************************************************
END

List of 4 messages in thread
TopicAuthorDate
Need help with a real clock on a aes-51            01/01/70 00:00      
   What ?            01/01/70 00:00      
   OK            01/01/70 00:00      
      It does            01/01/70 00:00      

Back to Subject List