Search This Blog

Tuesday, December 27, 2011

Why program in C??

First and the most obvious reason is that programming in assembly language is tedious and a little time consuming. Secondly C is easier to modify and update and is highly reusable. Thirdly code available in function libraries can be used. Finally its highly portable to other microcontrollers with little or no modification.

Friday, December 23, 2011

Program for setting date in RTC DS12887

; TURNING ON RTC
MOV R0, #10    ; REGISTER A ADDRESS IN R0
MOV A, #20H    ; 010 TO TURN ON RTC
MOVX @RO,A    ; SEND IT TO REGISTER A OF RTC


; SETTING TIME MODE
; AS DECIDED WE SET BCD, 24 HRS, DAYLIGHT SAVING
; MEANING SENDING 83H TO REGISTER B OF RTC
MOV R0, #11    ; REGISTER B ADDRESS IN R0
MOV A, #83H    ; FOR REASONS SITED ABOVE
MOVX @R0, A    ; SEND IT TO REGISTER B OF RTC

; TURNING ON AND SETTING TIME MODE REMAINS SAME
; DURING ALL SETTING THINGS

; SETTING THE DATE
; LETS GET SOME THINGS CLEAR
; 07 - DAY OF MONTH
; 08 - MONTH
; 09 - YEAR
; FOR FULL TABLE SEE THE POST..

; SETTING DAY OF MONTH
MOV R0, #07    ; POINT TO THE DAY OF MONTH
MOV A, #20H    ; DAY = 20
MOVX @R0, A    ; SET DAY OF MONTH

; SETTING MONTH
MOV R0, #08    ; POINT TO MONTH
MOV A, #12H    ; MONTH = 12 = DECEMBER
MOVX @R0, A    ; SET THE MONTH

; SETTINH YEAR
MOV R0, #09    ; POINT TO YEAR
MOV A, #11H    ; FOR 2011
MOVX @R0, A    ; SET THE YEAR

; REGISTER B
MOV R0, #11    ; POINT TO REGISTER B
MOV A, #03    ; D7 = 0 TO ALLOW UPDATE
MOVX @R0, A    ; SEND IT TO REGISTER B


END

Program for Setting time in RTC DS12887

; TURNING ON RTC
MOV R0, #10    ; REGISTER A ADDRESS IN R0
MOV A, #20H    ; 010 TO TURN ON RTC
MOVX @RO,A    ; SEND IT TO REGISTER A OF RTC


; SETTING TIME MODE
; AS DECIDED WE SET BCD, 24 HRS, DAYLIGHT SAVING
; MEANING SENDING 83H TO REGISTER B OF RTC
MOV R0, #11    ; REGISTER B ADDRESS IN R0
MOV A, #83H    ; FOR REASONS SITED ABOVE
MOVX @R0, A    ; SEND IT TO REGISTER B OF RTC


; SETTING THE TIME
; LET GET ONE THING CLEAR
; 0 - SECONDS
; 2 - MINUTES
; 4 - HOURS
; FOR INFO RELATED ABOVE SEE THE POST...


; SETTING SECONDS
MOV R0, #0    ; POINT TO SECONDS ADDRESS
MOV A, #SSH    ; SECONDS = SS MEANS PUT ANY VALUE
; CAREFULL SECONDS 0 - 60 AND IN BCD
; SO SS = 00H,02H......09H,10H,11H,.......29H,30H,...,59H
; H IS MUST FOR BCD
MOVX @R0, A    ; SET SECONDS


; SETTING MINUTES
MOV R0, #02    ; POINT TO MINUTES ADDRESS
MOV A, #MM    ; MINUTES = MM MEANS PUT ANY VALUE
; CAREFULL MINUTES 0 - 60 AND IN BCD
; SO MM = 00H,02H......09H,10H,11H,.......29H,30H,...,59H
; H IS MUST FOR BCD
MOVX @R0, A    ; SET MINUTES


; SETTING HOURS
MOV R0, #04    ; POINT TO HOURS ADDRESS
MOV A, #HH    ; HOURS = HH
; CAREFULL HOURS HERE IS IN 24 HOURS FORMAT
; SO HH CAN BE 1,2,...., 14,15......,23 NOT OUTSIDE THIS
; H IS MUST FOR BCD
MOVX @R0, A    ; SET HOURS


; REGISTER B
MOV R0, #11    ; POINT TO REGISTER B ADDRESS
MOV A, #03    ; D7 = 0 TO ALLOW UPDATE
MOVX @R0, A    ; SEND IT TO REGISTER B OF RTC

END

RTC address map

The address map of DS12887
  • This has total of 128 bytes of RAM space with addresses 00-7Fh.
  • The first 10 i.e. 00-09 are kept aside for RTC values of time, calendar and alarm data.
  • The next 4 are control and status registers.
  • The next 114 bytes from address 0E-7F are available for data storage.
  • Register C and D are read only.
  • The D7 of register A is read only.
  • The high order bits of seconds byte are read only.

Address map
0 – 00h
Seconds
1 – 01h
Seconds alarm
2 – 02h
Minutes
3 – 03h
Minutes alarm
4 – 04h
Hours
5 – 05h
Hours alarm
6 – 06h
Day of week
7 – 07h
Day of month
8 – 08h
Month
9 – 09h
Year
10 – 0Ah
Register A
11 – 0Bh
Register B
12 – 0Ch
Register C
13 – 0Dh
Register D


Register A
UIP
DV2
DV1
DV0
RS3
RS2
RS1
RS0

UIP update in progress. This is a read only bit.

DV2 – 0
DV1 – 1
DV0 – 0
Will turn the oscillator on.

RS3,RS2,RS1,RS0 provides 14 different frequencies at the SQW pin.
Value of register a will remain as..
0
0
1
0
0
0
0
0
A = 20h


Register B
SET
PIE
AIE
UIE
SQWE
DM
24/12
DSE

SET
SET =0; clock is counting once per second and times and dates are updated.
SET =1; update is inhibited(during initialization we must set SET=1)
PIE
Periodic interrupt enable
AIE
Alarm interrupt enable. The AIE=1 will allow the IRQ to be asserted, when all 3 bytes of time equals alarm bytes. In short will raise an interrupt when time equals alarm time.
UIE
Don’t know so see the datasheet.
SQWE
Square wave enable.
DM
Data mode.
DM=0; for BCD data format.
DM=1; for binary(hex) data format.
24/12
1 for 24 hour mode
0 for 12 hour mode
DSE
Daylight saving enable.
1 enables daylight saving(first Sunday in april and last Sunday in October)
0 disables daylight saving
 So we will keep the setting BCD data format. 24 hrs time, and daylight saving on.
Giving us the value of register.
1
0
0
0
0
0
1
1
B = 83h.


RTC DS12887 address location for time, calendar and alarm.
Address Location
Function
Decimal range
Binary(hex)
BCD
0
Seconds
0-59
00-3B
00-59
1
Seconds alarm
0-59
00-3B
00-59
2
Minutes
0-59
00-3B
00-59
3
Minutes alarm
0-59
00-3B
00-59
4
Hours, 12 hour mode
1-12
01-0C AM
01-12 AM

Hours, 12 hour mode
1-12
81-8C PM
81-92 PM

Hours, 24 hour mode
0-23
0-17
0-23
5
Hours alarm, 12 hour
1-12
01-0C AM
01-12 AM

Hours alarm, 12 hour
1-12
81-8C PM
81-92 PM

Hours alarm, 24 hour
0-23
0-17
0-23
6
Days of the week SUN=1
1-7
01-07
01-07
7
Day of the month
1-31
01-1F
01-31
8
Month
1-12
01-0C
01-12
9
Year
0-99
00-63
00-99
 one needs to remember above tables to write a program for RTC interfacing with 8051.