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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
05/14/09 10:59
Read: times


 
#165320 - Still no luck ! !
Responding to: ???'s previous message
hey guys as you all suggested, i have changed my Receive function. I have also changed the way the HT1380 is being initialized. This time i am initializing it in Burst mode.

I have changed my TH 1380 just in case it was bad. The 32768Hz crystal is of 20ppm. I am using 10pF capacitor as the 8pF capacitor is not available.

according to the register 0 to 7, i get a reply as

seconds register : 80
minutes register : 00
hours register : 00
date register : 01
month register : 01
day register : 01
year register : 00
write protect register : 80

All values in are in hex

I cannot understand one thing is that the why is the seconds register showing 80, as this would mean that the MSB is 1 and the MSB is the bit for clock halt(CH). thus 80 means that the clock is not running.

MY PRESENT CODE IS :
***********************************************************************************

#include "8051.h"
#include "serial.h"

#define SCLK P2_0
#define DATA_IO P2_1
#define RESET_ P2_2
#define YELLOW_LED P3_6
#define RED_LED P3_7

unsigned char serial_storage=0x00;
unsigned char display;

void usec_wait(unsigned char);
void msec_wait(unsigned char);
void sec_wait(unsigned char);
void convert_and_send(unsigned char);
unsigned char receive_convert(void);


//**************************************************************
//DELAY FUNCTIONS - USEC_WAIT ; MSEC_WAIT ; SEC_WAIT
//**************************************************************
void usec_wait(unsigned char k)
{
while(k!=0)
{
k--;
}
}
//////////////////////////////////////////////////////
void msec_wait(unsigned char j)
{
while(j!=0)
{
usec_wait(165);
j--;
}
}
//////////////////////////////////////////////////////
void sec_wait(unsigned char sec_count)
{
while(sec_count!=0)
{
msec_wait(250);
msec_wait(250);
msec_wait(250);
msec_wait(250);
sec_count--;
}
}
//////////////////////////////////////////////////////

//**************************************************************
//SERIAL INTERRUPT FUNCTION
//**************************************************************

void serial_interrupt() interrupt 4
{
if(TI)
TI=0;

if(RI)
{
serial_storage=SBUF;
usec_wait(1);
RI=0;
RED_LED=1;
}
}


//*******************************************************************
//FUNCTION THAT SENDS ADDRESS OR DATA_IO AFTER CONVERTING IT TO BITS
//*******************************************************************
void convert_and_send(unsigned char hex_data1)
{
bit sending_bit;
unsigned char comparing_byte=0x01;
unsigned char i;
unsigned char storing_byte=0x00;
SBUF=hex_data1;
usec_wait(5);

for(i=0;i<8;i++)
{
storing_byte=(hex_data1&comparing_byte);
if(storing_byte==0x00)
sending_bit=0;
else
sending_bit=1;
SCLK=0;
SCLK=0;
DATA_IO = sending_bit; //Clock to DATA_IO delay is 250ns (max)
comparing_byte<<=1;
SCLK=1;
}
serial_storage=0x00;
usec_wait(2);
}


//**************************************************************************************
//FUNCTION THAT RECEIVES DATA AND THEN CONVERTS IT TO CHARACTER AND PASSES TO ITS CALLER
//**************************************************************************************
unsigned char receive_convert(void)
{

bit receiving_bit;
unsigned char comparing_byte=0x00;
unsigned char i=0;
unsigned char received_data=0x00;

for(i=0;i<8;i++)
{
SCLK=1;
SCLK=1; //For giving a DEALY
SCLK=0;
receiving_bit=DATA_IO;
if(receiving_bit==0)
comparing_byte=0x00;
else
comparing_byte=0x80; //comparing byte is 10000000 as the bit is to be placesd in the MSB position
received_data=received_data>>1;
received_data=received_data|comparing_byte;
}
return(received_data);
}


void main()
{

initialize_serial(); //INITIALIZES THE SERIAL PORT

//FUNCTION THAT INITIALIZES THE TIMMER IC BY SETTING CH AND WP BIT
RED_LED=0; //BOTH LED's GLOW WHEN THE RTC IS BEING SET
YELLOW_LED=0;
RESET_=1;
msec_wait(1);
convert_and_send(0x8E); //SETS THE WP BIT AS ZERO
msec_wait(1);
convert_and_send(0x00);
RESET_=0;
msec_wait(1);
RESET_=1;
msec_wait(1);
convert_and_send(0x80); //SETS THE CH BIT AS ZERO
msec_wait(1);
convert_and_send(0x00);
RESET_=0;
msec_wait(1);

sec_wait(4);

RESET_=1; //INITIALIZING the HT1380
msec_wait(1);
convert_and_send(0xBE); //Burst Mode Command
msec_wait(1);
convert_and_send(0x00); //Sec register, Including the CH=0
msec_wait(1);
convert_and_send(0x00); //min
msec_wait(1);
convert_and_send(0x10); //hour
msec_wait(1);
convert_and_send(0x10); //date
msec_wait(1);
convert_and_send(0x05); //month
msec_wait(1);
convert_and_send(0x07); //day
msec_wait(1);
convert_and_send(0x08); //year
msec_wait(1);
RESET_=0;
msec_wait(10);

RESET_=1;
msec_wait(1);
convert_and_send(0x8E); //SETS THE WP BIT AS ONE
msec_wait(1);
convert_and_send(0x80);
RESET_=0;

RED_LED=1; //BOTH LED's TURN OFF WHEN THE RTC TIME HAS BEEN SET
YELLOW_LED=1;

while(1)
{
RED_LED=0; //This shows that only the while loop is running and system is waiting for command(REGISTER ADDRESS)
msec_wait(500);
if(serial_storage!=0x00)
{
RED_LED=1; //This shows that the serial_storage has the character
RESET_=1;
convert_and_send(serial_storage); //sending the address of the register that we want to read from
msec_wait(1);
display=receive_convert(); //putting the read DATA_IO into display
RESET_=0;
SBUF=display; //sending the read DATA_IO serially to the computer
msec_wait(2);
display=0x00;
}
else
{
RED_LED=1;
msec_wait(500);
}
}

}
************************************************************************************

I GOT A CODE FORM THE HOLTEK SITE . . . . . but i cannot find any difference ????

*************************************************************************************

;*********************************************
;FILE NAME: FRONT PANEL
;MCU: HT48R10A-1
;MAST OPTION: WDT CLOCK SOURCE: DISABLE WDT
; CLR WDT: ONE
; TIMER CLOCK SOURCE: SYSTEM CLOCK
; WAKE-UP PA: NONE
; INPUT TYPE PA: SCHMITT TRIGGER
; PULL-HIGH: PA,PB,PC
; BZ/BZB: ALL DISABLE
; LVR: DISABLE
; OSC: EXT. CRYSTAL
; FOSC: EXTERNAL
; SYSVOLT: 5.0V
; SYSFREQ: 4MHZ
; PWM: DISABLE
; PFD: DISABLE
;AUTHOR: RADOME
;HISTORY: 2003.09.17
;*********************************************
include Ht48r10a-1.inc
PUSH macro
mov acc_bk,a
mov a,status
mov status_bk,a
endm

POP macro
mov a,status_bk
mov status,a
mov a,acc_bk
endm
;----------------------------------------
ht1380_clk equ pa.4
ht1380_clk_ctrl equ pac.4
ht1380_io equ pa.5
ht1380_io_ctrl equ pac.5
ht1380_rest equ pa.6
ht1380_rest_ctrl equ pac.6
;*********************************************
FrontPanel_data .section 'data'
;*********************************************
;System
acc_bk db ?
status_bk db ?

;ht1380
second db ?
minute db ?
hour db ?
date db ?
month db ?
day db ?
yearh db ?
yearl db ?
time_count db ?
time_temp db ?

;BCD/HEX
data_bcd db ?
data_hex db ?
data_count db ?
data_temp db ?

f_test dbit
;*********************************************
FrontPanel_code .section 'code'
;*********************************************
org 0000h
jmp main

org 0004h ;External Interrupt
reti

org 0008h ;Timer Interrupt
timer_int:
push

inc data_temp
mov a,data_temp
sub a,250
snz c
jmp timer_end
clr data_temp

inc data_count
mov a,data_count
sub a,50
snz c
jmp timer_end
set f_test

timer_end:
pop
reti
;*********************************************
;Initializers
;*********************************************
main:
clr wdt
clr intc
clr tmrc

clr pa
clr pac
clr pb
clr pbc
clr pc
clr pcc

mov a,20h
mov mp,a
mov a,64
clr iar
inc mp
sdz acc
jmp $-3 ;clr ram

mov a,00000101b
mov intc,a
mov a,6 ;8ms
mov tmr,a
mov a,10000110b
mov tmrc,a
set tmrc.4
nop
nop
nop
clr tmrc.4
mov a,6 ;8ms
mov tmr,a
mov a,10010110b
mov tmrc,a


mov a,00h
mov second,a
mov a,59h
mov minute,a
mov a,23h
mov hour,a
mov a,30h
mov date,a
mov a,09h
mov month,a
mov a,02h
mov day,a
mov a,03h
mov yearl,a
call init_ht1380

snz f_test
jmp $-1
call get_time
jmp $

;*********************************************
;ht1380
;*********************************************
;-------------------------------------------
;Initialize ht1380
;-------------------------------------------
init_ht1380:
clr ht1380_rest_ctrl
clr ht1380_clk_ctrl
clr ht1380_io_ctrl

clr ht1380_rest
nop
set ht1380_rest
mov a,10001110b
call write_ht1380
mov a,00000000b
call write_ht1380 ;disable the write protect
clr ht1380_rest
nop
set ht1380_rest
mov a,10111110b ;burst mode command
call write_ht1380
mov a,second ;"CH" bit set 0
call write_ht1380
mov a,minute
call write_ht1380
mov a,hour
call write_ht1380
mov a,date
call write_ht1380
mov a,month
call write_ht1380
mov a,day
call write_ht1380
mov a,yearl
call write_ht1380
clr ht1380_rest
ret
;-------------------------------------------
;Write ht1380
;-------------------------------------------
write_ht1380:
mov time_temp,a
mov a,8
mov time_count,a
clr ht1380_io_ctrl
clr ht1380_io
write_ht1380_loop:
rrc time_temp
sz c
set ht1380_io
set ht1380_clk
nop
clr ht1380_clk
clr ht1380_io
sdz time_count
jmp write_ht1380_loop
ret
;-------------------------------------------
;Get time
;-------------------------------------------
get_time:
clr ht1380_rest_ctrl
clr ht1380_clk_ctrl
clr ht1380_io_ctrl

clr ht1380_rest
nop
set ht1380_rest
mov a,10111111b ;burst mode command
call write_ht1380
nop
call read_ht1380
mov second,a
call read_ht1380
mov minute,a
call read_ht1380
mov hour,a
call read_ht1380
mov date,a
call read_ht1380
mov month,a
call read_ht1380
mov day,a
call read_ht1380
mov yearl,a
clr ht1380_rest
ret
;-------------------------------------------
;Read ht1380
;-------------------------------------------
read_ht1380:
clr time_temp
mov a,8
mov time_count,a
set ht1380_io_ctrl
read_ht1380_loop:
clr c
set ht1380_clk
sz ht1380_io
set c
rrc time_temp
clr ht1380_clk
sdz time_count
jmp read_ht1380_loop
mov a,time_temp
ret
;*********************************************
;BCD&HEX
;*********************************************
;-------------------------------------------
;BCD to HEX
;-------------------------------------------
bcd2hex:
swapa data_bcd
and a,0fh
rl acc
mov data_temp,a
rl acc
rl acc
addm a,data_temp
mov a,data_bcd
and a,0fh
add a,data_temp
mov data_hex,a
ret
;-------------------------------------------
;HEX to BCD
;-------------------------------------------
hex2bcd:
clr data_bcd
mov a,8
mov data_count,a
hex2bcd_loop:
rlc data_hex
mov a,data_bcd
adc a,data_bcd
daa data_bcd
sdz data_count
jmp hex2bcd_loop
ret
;*********************************************
end
***********************************************************************************

what else is wrong with my code ?????????


List of 39 messages in thread
TopicAuthorDate
Interfacing HT1380 with 89C51 in C            01/01/70 00:00      
   It looks like you should read when clock is high            01/01/70 00:00      
      Dear David            01/01/70 00:00      
         Yes. You read after the -ve edge.            01/01/70 00:00      
            Should shift before assign            01/01/70 00:00      
               Dear Per            01/01/70 00:00      
                  Dear Ackhil,            01/01/70 00:00      
                     Amazing . . . ! ! !            01/01/70 00:00      
                        Are you a young man ?            01/01/70 00:00      
            David            01/01/70 00:00      
   keep SCLK low when idle            01/01/70 00:00      
      Dear Stefan            01/01/70 00:00      
         re            01/01/70 00:00      
            Dear Stefan            01/01/70 00:00      
   Still no luck ! !            01/01/70 00:00      
      Code?            01/01/70 00:00      
         Sorry for the incorrect post            01/01/70 00:00      
            Please format your code            01/01/70 00:00      
      keep SCLK low and...pen&paper and...            01/01/70 00:00      
   Dear stefan and david            01/01/70 00:00      
      Do you expect people to format and correct code every t            01/01/70 00:00      
         true 99% of the time            01/01/70 00:00      
            a neat program makes a happy programmer            01/01/70 00:00      
         I tried a pen and paper            01/01/70 00:00      
            'arranging' is good, but how about comments?            01/01/70 00:00      
               I'll improve on that front as well ! !            01/01/70 00:00      
      Hi Akhil , check this            01/01/70 00:00      
         Dear Stefan            01/01/70 00:00      
            Dear Stefan            01/01/70 00:00      
               Congratulations. a good write() and read()            01/01/70 00:00      
                  no luck            01/01/70 00:00      
                     You can always send a clock from 8051.            01/01/70 00:00      
                        i'll do that ! !            01/01/70 00:00      
                        Dear David            01/01/70 00:00      
                           at least X2 must be free, not grounded            01/01/70 00:00      
                           32Mhz ?!            01/01/70 00:00      
                           Do it carefully            01/01/70 00:00      
                              Dear David            01/01/70 00:00      
                                 I am sure it is something simple.            01/01/70 00:00      

Back to Subject List