Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

Help me to show some error in DS12887 interface code

Status
Not open for further replies.

hbaocr

Full Member level 4
Joined
May 13, 2007
Messages
235
Helped
25
Reputation
48
Reaction score
5
Trophy points
1,298
Location
Hochiminh City university of technology (VietNam)
Activity points
2,777
Code:
PLZ show me some error I have met on this code below to interface AT89s52 to RTC(DS12887)


#include "REG52.h"
#include "ABSACC.h"

//define some variable for RTC
#define RTC P2
#define RTC_RegA 0x000A
#define RTC_RegC 0x000B
#define RTC_RegB 0x000C
#define RTC_RegD 0x000D
sbit INT = P3^3;
//declare function
void SetRTC(unsigned char value,unsigned char mode);
//main function

void main()
{
//set INT1
INT=1;	//cong nhap
IE=0x84;//cho phep ngat ngaoi 1
IT1=1;//ngat canh xuong
P2=12;
SetRTC(0,0);		 //xoa giay
SetRTC(0,2);		 //xoa phut
SetRTC(0,4);		 //xoa gio
while(1);

}
//===========chuong trinh phuc vu ngat========================
//ngat ngoai 1
void RTC_READY(void) interrupt 2
{
unsigned char kt;
EX1=0;//cam ngat
P2=PBYTE[0];
kt=PBYTE[RTC_RegC];//xoa thanh ghi C
EX1=1;//cho phep ngat lai

}

//==========set RTC========================
void SetRTC(unsigned char value,unsigned char mode)	//mode =0 Second ,=1 Second alarm, =2 Minutes,=3 Minutes alram;
//=4 Hour ,=5 Hour alarm,=6 day of week,=7 day of month,=8 month,=9 year,=50 century
{
// cac bit trong thnah ghi B
// SET	 PIE	 AIE	 UIE	 SQWE	 DM	 24/12	 DSE
PBYTE[RTC_RegB]= 0x80;//set=1 o che do update du lieu ta co the ghi vao cac thanh ghi
//thanh ghi A
//UIP	DV2	DV1	DV0	RS3	RS2	RS1	RS0 = 10101111

PBYTE[mode]=value;	 //cap nhat du lieu
PBYTE[RTC_RegA]= 0xAF; //DV2 DV1 DV0 =010 OSC on;INT1=0.5ms
PBYTE[RTC_RegB]=0x1A; //UIE=1 enable Interupt ended upate
                      //DM=0 data BCD mode, 24/12=1 24h
					  //set=0 automatic update data
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top