Author Topic: Question About 8051 Software Real Time Clock (RTC)  (Read 5065 times)

0 Members and 1 Guest are viewing this topic.

Offline moimoiTopic starter

  • Newbie
  • Posts: 6
  • Country: id
Question About 8051 Software Real Time Clock (RTC)
« on: November 26, 2014, 03:39:54 pm »
Hello guys,

My name is Tim and I'm currently in my second year of EE.  I'm trying to make a 8051 Real Time Clock based on the tutorial from 8052.com http://8052.com/tutrtc. I followed their code and make some changes according to the hardware that i am using and modify the code a bit to produce output to 6 7-segment displays (hook up with 7447) to display the time. I've got some questions that i don't understand, and since that 8052.com site forum is no longer active, I don't know anywhere else to ask except here. So here is the code

Code: [Select]
HOURS EQU 07CH
MINUTES EQU 07DH
SECONDS EQU 07EH
TICKS EQU 07FH

;CRYSTAL EQU 22118400
;TMRCYCLE EQU 12
;TMR_SEC EQU CRYSTAL/TMRCYCLE

;F50TH_OF_SEC EQU TMR_SEC*0.02
;F50TH_OF_SEC EQU 36864

;RESET_VALUE EQU 65536 - F50TH_OF_SEC
RESET_VALUE EQU 28672

ORG 0000H
   LJMP _MAIN

ORG 001BH
   PUSH ACC
   PUSH PSW
   CLR TR1
   MOV TH1,#HIGH RESET_VALUE
   MOV TL1,#LOW RESET_VALUE
   SETB TR1
   
   DJNZ TICKS,EXIT_RTC
   MOV TICKS,#50
   INC SECONDS 
   
   MOV A,SECONDS
   CJNE A,#60,EXIT_RTC
   MOV SECONDS,#0
   INC MINUTES
   
   MOV A,MINUTES
   CJNE A,#60,EXIT_RTC
   MOV MINUTES,#0
   INC HOURS
   
   MOV A,HOURS
   CJNE A,#24,EXIT_RTC
   MOV HOURS,#0
   
   EXIT_RTC:
     ; Convert the time to BCD and display it to the 7-segment display
      MOV A,SECONDS
      MOV B,#10D
      DIV AB
      RL A
      RL A
      RL A
      RL A
      ADD A,B
      MOV P2,A
     
      MOV A,MINUTES
      MOV B,#10D
      DIV AB
      RL A
      RL A
      RL A
      RL A
      ADD A,B
      MOV P0,A
     
      MOV A,HOURS
      MOV B,#10D
      DIV AB
      RL A
      RL A
      RL A
      RL A
      ADD A,B
      MOV P1,A
      POP PSW
      POP ACC
      RETI

_MAIN:
   MOV TH1,#HIGH RESET_VALUE
   MOV TL1,#LOW RESET_VALUE
   MOV TMOD,#10H
   SETB TR1
   
   MOV HOURS,#00
   MOV MINUTES,#55
   MOV SECONDS,#00
   ; 50 Ticks is needed for the timer to count a second
   MOV TICKS,#50
   
   SETB EA
   SETB ET1
   
END

So according to the tutorial, if I want to start the timer to count from 23:00:00, i need only to set the HOURS value to 23 like this
Code: [Select]
MOV HOURS,#23
   MOV MINUTES,#00
   MOV SECONDS,#00
   MOV TICKS,#50

But after i tried, it still starts at 00:00:00 after reset. I've been trying to find the problem and changing code here and there for 3 hours but i still got no luck.
Strangely, i have also tried to remove the initialization process
Code: [Select]
MOV HOURS,#23
   MOV MINUTES,#00
   MOV SECONDS,#00
   MOV TICKS,#50

But it doesn't produce an error and it still starts from 00:00:00. I have no idea where i was doing wrong. I'm still a beginner with the 8051 programming, so i might have overlook something stupid here. I'm using M-IDE51 and FLIP to program the board. The board is custom made by my school. Any help is appreciated, and thank you for your time guys :)

EDIT : The solution for the problem is adding a loop like

           loop:  sjmp loop

           Before the END statement of the program

           Thumbs up for @PA0PBZ


Cheers  :),
Best Regards,
Tim
« Last Edit: November 27, 2014, 02:09:28 pm by moimoi »
"I Reject the Reality and Substitute My Own" - Adam Savage
 

Offline JoeO

  • Frequent Contributor
  • **
  • Posts: 527
  • Country: us
  • I admit to being deplorable
Re: Question About 8051 Software Real Time Clock (RTC)
« Reply #1 on: November 26, 2014, 09:13:46 pm »
You need to comment your code.  The few comments you have are insufficient.

Your instructor should be emphasizing this. 

Put the comments in as you write the code, not after.  You may think you are saving yourself time but you are not.
The day Al Gore was born there were 7,000 polar bears on Earth.
Today, only 26,000 remain.
 

Offline moimoiTopic starter

  • Newbie
  • Posts: 6
  • Country: id
Re: Question About 8051 Software Real Time Clock (RTC)
« Reply #2 on: November 27, 2014, 12:37:53 pm »
You need to comment your code.  The few comments you have are insufficient.

Your instructor should be emphasizing this. 

Put the comments in as you write the code, not after.  You may think you are saving yourself time but you are not.

Hi there, sorry for the lack of comments, i know i should add more comments, and my instructor never emphasized about writing comment (His example code also lacks comments). I will edit the code  :-+
"I Reject the Reality and Substitute My Own" - Adam Savage
 

Online PA0PBZ

  • Super Contributor
  • ***
  • Posts: 5127
  • Country: nl
Re: Question About 8051 Software Real Time Clock (RTC)
« Reply #3 on: November 27, 2014, 12:54:11 pm »
I'd put a
loop:  sjmp loop
just before the end. I haven's seen the output of your assembler but chances are that it just continues to run and loops around.
Keyboard error: Press F1 to continue.
 

Offline moimoiTopic starter

  • Newbie
  • Posts: 6
  • Country: id
Re: Question About 8051 Software Real Time Clock (RTC)
« Reply #4 on: November 27, 2014, 02:07:41 pm »
I'd put a
loop:  sjmp loop
just before the end. I haven's seen the output of your assembler but chances are that it just continues to run and loops around.

Hi there, thanks for the reply, in fact that is the problem, iIve found out about that also. I forgot to update this thread about the answer. Thumbs up sir  :-+ Btw, do you know or have any references about configuring the 8051 input ? I've found some but its not very clear to me yet. I'm trying to connect a 4x4 keypad for the user to input the starting time. Thanks in advance  :)
"I Reject the Reality and Substitute My Own" - Adam Savage
 

Offline JoeO

  • Frequent Contributor
  • **
  • Posts: 527
  • Country: us
  • I admit to being deplorable
Re: Question About 8051 Software Real Time Clock (RTC)
« Reply #5 on: November 28, 2014, 03:40:44 am »
You need to comment your code.  The few comments you have are insufficient.

Your instructor should be emphasizing this. 

Put the comments in as you write the code, not after.  You may think you are saving yourself time but you are not.

Hi there, sorry for the lack of comments, i know i should add more comments, and my instructor never emphasized about writing comment (His example code also lacks comments). I will edit the code  :-+
That is too bad that your instructor does not enforce the use of comments.  He/she would not last long in industry.
Out of curiosity, where do you go to school?
The day Al Gore was born there were 7,000 polar bears on Earth.
Today, only 26,000 remain.
 

Offline vsq

  • Contributor
  • Posts: 13
  • Country: fi
Re: Question About 8051 Software Real Time Clock (RTC)
« Reply #6 on: November 28, 2014, 06:37:23 am »
You need to comment your code.  The few comments you have are insufficient.

Your instructor should be emphasizing this. 

Put the comments in as you write the code, not after.  You may think you are saving yourself time but you are not.

Hi there, sorry for the lack of comments, i know i should add more comments, and my instructor never emphasized about writing comment (His example code also lacks comments). I will edit the code  :-+
That is too bad that your instructor does not enforce the use of comments.  He/she would not last long in industry.
Out of curiosity, where do you go to school?

Well-written and -structured code does not need comments.
 

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: Question About 8051 Software Real Time Clock (RTC)
« Reply #7 on: November 28, 2014, 06:42:40 am »
^ As long as it's read by the original programmer and s/he might even have trouble remembering after a few years.

Comments are good, documentation and unit tests even better.
 

Offline JoeO

  • Frequent Contributor
  • **
  • Posts: 527
  • Country: us
  • I admit to being deplorable
Re: Question About 8051 Software Real Time Clock (RTC)
« Reply #8 on: November 28, 2014, 08:10:49 pm »
^ As long as it's read by the original programmer and s/he might even have trouble remembering after a few years.

Comments are good, documentation and unit tests even better.
Totally agree.

Most people who code, work for a living.  Someone will most likely have to pick up their code at a later time in order to fix or add features.  Comments are a necessity.

The Obfuscated C contests prove that comments are needed.
The day Al Gore was born there were 7,000 polar bears on Earth.
Today, only 26,000 remain.
 

Offline moimoiTopic starter

  • Newbie
  • Posts: 6
  • Country: id
Re: Question About 8051 Software Real Time Clock (RTC)
« Reply #9 on: November 29, 2014, 06:48:12 am »
You need to comment your code.  The few comments you have are insufficient.

Your instructor should be emphasizing this. 

Put the comments in as you write the code, not after.  You may think you are saving yourself time but you are not.

Hi there, sorry for the lack of comments, i know i should add more comments, and my instructor never emphasized about writing comment (His example code also lacks comments). I will edit the code  :-+
That is too bad that your instructor does not enforce the use of comments.  He/she would not last long in industry.
Out of curiosity, where do you go to school?

Hi there, sorry for the late reply, have been busy all day with school and trying to add functions to the RTC project.

I'm currently taking my degree in Electrical Engineering in Taiwan (National Chung Cheng University), I'm an overseas students from Indonesia :).
"I Reject the Reality and Substitute My Own" - Adam Savage
 

Offline moimoiTopic starter

  • Newbie
  • Posts: 6
  • Country: id
Re: Question About 8051 Software Real Time Clock (RTC)
« Reply #10 on: November 29, 2014, 06:54:07 am »
^ As long as it's read by the original programmer and s/he might even have trouble remembering after a few years.

Comments are good, documentation and unit tests even better.

Yes indeed, if I were to write a C code, i will always put comments along when i was typing the code, but in assembly i don't know why i write comments later. I think it might have something to do with the MIDE-51 IDE which is bad for typing codes.
"I Reject the Reality and Substitute My Own" - Adam Savage
 

Offline JoeO

  • Frequent Contributor
  • **
  • Posts: 527
  • Country: us
  • I admit to being deplorable
Re: Question About 8051 Software Real Time Clock (RTC)
« Reply #11 on: November 29, 2014, 02:02:35 pm »
You need to comment your code.  The few comments you have are insufficient.

Your instructor should be emphasizing this. 

Put the comments in as you write the code, not after.  You may think you are saving yourself time but you are not.

Hi there, sorry for the lack of comments, i know i should add more comments, and my instructor never emphasized about writing comment (His example code also lacks comments). I will edit the code  :-+
That is too bad that your instructor does not enforce the use of comments.  He/she would not last long in industry.
Out of curiosity, where do you go to school?

Hi there, sorry for the late reply, have been busy all day with school and trying to add functions to the RTC project.

I'm currently taking my degree in Electrical Engineering in Taiwan (National Chung Cheng University), I'm an overseas students from Indonesia :).
Thank you for taking the time to answer.  Good luck to you!
The day Al Gore was born there were 7,000 polar bears on Earth.
Today, only 26,000 remain.
 

Offline moimoiTopic starter

  • Newbie
  • Posts: 6
  • Country: id
Re: Question About 8051 Software Real Time Clock (RTC)
« Reply #12 on: November 29, 2014, 02:36:47 pm »
You need to comment your code.  The few comments you have are insufficient.

Your instructor should be emphasizing this. 

Put the comments in as you write the code, not after.  You may think you are saving yourself time but you are not.

Hi there, sorry for the lack of comments, i know i should add more comments, and my instructor never emphasized about writing comment (His example code also lacks comments). I will edit the code  :-+
That is too bad that your instructor does not enforce the use of comments.  He/she would not last long in industry.
Out of curiosity, where do you go to school?

Hi there, sorry for the late reply, have been busy all day with school and trying to add functions to the RTC project.

I'm currently taking my degree in Electrical Engineering in Taiwan (National Chung Cheng University), I'm an overseas students from Indonesia :).
Thank you for taking the time to answer.  Good luck to you!

Thanks sir!  :)
"I Reject the Reality and Substitute My Own" - Adam Savage
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf