| ??? 08/26/02 05:31 Read: times |
#27934 - help me on ds12887A RTC |
sir
i am using DS12887A RTC in my design with c8051f005 .we have written code for the above chip but it is not working properly may be due to timing problem .can any body go through this program and check with the rtc because i have doubt on weather my rtc is proper or not ? if the program is wrong can any body give me the suggetion or may be code . #include<C8051F000.h> #include<stdio.h> #include<stdlib.h> #include<intrins.h> sbit DS_PORT = P2^7; sbit RW_PORT = P2^6; sbit AS_PORT = P2^5; sbit CS_PORT = P2^4; #define REGA 0x0a #define REGB 0x0b #define REGC 0x0c #define REGD 0x0d #define RS2 0x05 //#define DAYS "Sun Mon Tue Wed Thu Fri Sat " /*********************** Function Prototypes **************************/ void init_rtc(); void writebyte(char,char); char readbyte(char); void clockset(); void intr_init(); void crossbar_init(); void delay(unsigned long); //*********************************************************************/ //*********************** Global Variables *****************************/ int Cnt; int Reg_loc; char Array[10]; char Array1[10]; int dataready; /**********************************************************************/ main (void) { int Cnt=0; intr_init(); crossbar_init(); init_rtc(); clockset(); } void init_rtc() { char rtcdata[15]; int i; char rega; for(i=0;i<13;i++) { rtcdata[i] = readbyte(i); } rega=0; rega = readbyte(REGA); if( (rega & 0x60) != 0x20) /* DV2=0 & DV1=1 for the RTC to keep time */ { /* if they're not, assume we need to initialize the RTC */ writebyte(REGA, (0x20 + RS2) ); /* turn on osc, enable countdown chain, select 2hZ SQW */ rega = 0x20 + RS2; } //delay(400000); rega = readbyte(REGA); writebyte(REGB, 0x9a); // if( !(readbyte(0x0d) & (0x80)) ) /* if VRT bit is 0, warn that RTC is N/G */ // { // printf("nWarning: RTC battery low - invalid RTC data"); // } } void intr_init() { IE = 0x84; //Interrupt Enable TCON = 0x04; } void crossbar_init() { XBR0 = 0x00; // XBAR0: Initial Reset Value XBR1 = 0x14; // XBAR1: Initial Reset Value XBR2 = 0x40; // XBAR2: Initial Reset Value PRT0CF = 0x01; PRT1CF = 0x00; PRT2CF = 0xF0; // Output configuration for P2 PRT3CF = 0x00; // Output configuration for P3 //---------------------------------------------------------------- // Oscillator Configuration //---------------------------------------------------------------- OSCXCN = 0x00; // EXTERNAL Oscillator Control Register OSCICN = 0x07; // Internal Oscillator Control Register } void clockset() { char ch[] = {"30101101010202"}; int ch_cnt = 0; Cnt = 0; Reg_loc = 0; ch_cnt = 0; while(ch_cnt < 14) { ch[ch_cnt] &= 0x0f ; ch[ch_cnt] = ch[ch_cnt]<<4; ch_cnt++; ch[ch_cnt] &= 0x0f; ch[ch_cnt-1] += ch[ch_cnt]; Array[Cnt] = ch[ch_cnt-1]; ch_cnt++; Cnt++; } Cnt = 0; while(Cnt < 3) { writebyte(Reg_loc,Array[Cnt]); Reg_loc = Reg_loc + 2; Cnt = Cnt + 1; } while(Cnt < 7) { writebyte(Reg_loc,Array[Cnt]); Reg_loc = Reg_loc + 1; Cnt = Cnt + 1; } delay(200000); Cnt = 0; Reg_loc = 0; while(Cnt < 3) { Array1[Cnt] = readbyte(Reg_loc); Reg_loc = Reg_loc + 2; Cnt = Cnt + 1; } while(Cnt < 7) { Array1[Cnt] = readbyte(Reg_loc); Reg_loc = Reg_loc + 1; Cnt = Cnt + 1; } writebyte(REGB, 0x1a); } /*void writebyte( char location, char data1) { DS_PORT = 1; RW_PORT = 1; AS_PORT = 1; CS_PORT = 0; P3 = location; _nop_(); _nop_(); AS_PORT = 0; RW_PORT = 0; _nop_(); _nop_(); _nop_(); P3 = data1; RW_PORT = 1; CS_PORT = 1; return ; } char readbyte(char location) { char data1 =0; RW_PORT = 1; DS_PORT = 1; AS_PORT = 1; CS_PORT = 0; P3 = location; _nop_(); AS_PORT = 0; _nop_(); DS_PORT = 0; _nop_(); _nop_(); _nop_(); data1 = P3; _nop_(); DS_PORT = 1; CS_PORT = 1; return(data1) ; }*/ void delay(unsigned long q) { while((q--)!=0); } void writebyte( char location, char data1) { CS_PORT = 0; DS_PORT = 1; RW_PORT = 1; P3 = location; AS_PORT = 1; _nop_(); _nop_(); RW_PORT = 0; AS_PORT = 0; _nop_(); P3 = data1; _nop_(); _nop_(); RW_PORT = 1; _nop_(); _nop_(); CS_PORT = 1; return ; } char readbyte(char location) { char data1 =0; CS_PORT = 0; RW_PORT = 1; DS_PORT = 1; _nop_(); P3 = location; AS_PORT = 1; _nop_(); _nop_(); AS_PORT = 0; _nop_(); DS_PORT = 0; _nop_(); _nop_(); _nop_(); data1 = P3; _nop_(); _nop_(); DS_PORT = 1; _nop_(); CS_PORT = 1; return(data1) ; } |
| Topic | Author | Date |
| help me on ds12887A RTC | 01/01/70 00:00 | |
| RE: help me on ds12887A RTC | 01/01/70 00:00 | |
| RE: help me on ds12887A RTC | 01/01/70 00:00 | |
RE: help me on ds12887A RTC | 01/01/70 00:00 |



