Dear All
My RTC project is success some extend
now I need put RTC result to LCD
I know that RTC result is BCD, so I have to convert BCD to ASCII before I send to LCD
Can any one advice me, how BCD to ASCII convert using assembly
my RTC is DS1307
pic 16f877a
Thanks in advance
1. swapf temp,w ;put the first digit into the lower bits of w
2. andlw 0x0F ;get rid of the high bits
3. addlw '0' ;add ascii zero
4. movwf FirstDigit
5. movf temp,w ;recover the original BCD number
6. andlw 0x0F ;get rid of the high bits
7. addlw '0' ;add ascii zero
8. movwf SecondDigit
The BCD number is now split into two ASCII characters, the most significant is returned in FirstDigit, the least significant in SecondDigit - and all in 8 instructions.
Dear Brian
Thanks for reply and help, I did it as you said, now LCD display only 00 it does not update the time
can you please advice on this . please see image
Please see coff file and Proteus file in the attachment
I do not have Proteus but the asm file suggests you simply copied my code example at the end of the program. I gave you an example which showed how to do the conversion, I didn't intend you to use it literally. You must take the BCD number and process it in the way I showed, split it into a top 4-bit half and a bottom 4-bit half, then add 0x30 (or character zero) to the results of both before passing them to the LCD.
You can use the method papunblg showed which is the same but directly writes each character to the LCD rather than saving them as individual digits first. Their code isn't for a PIC though.
Dear Brian,
Thank you so much for advice, I change program the way you guide me, So problem remaining the same
Code:
swapf sec,w
andlw 0x0F ;get rid of the high bits
addlw 0x30 ;add ascii zero
movwf FD
call data_wrt
movf sec,w ;recover the original BCD number
andlw 0x0F ;get rid of the high bits
addlw 0x30 ;add ascii zero
movwf SD
call data_wrt
return
Can you explain following code I can not understand. what is this .13 is it related to ds1307 or any
Code:
BANKSEL SSPSTAT ; ### point to correct BANK for SSPSTAT
bsf SSPSTAT,SMP ; ### Set for Standard speed slew rate
movlw .13
movwf SSPADD
SSPADD is the I2C address register. You load it with the address of the I2C device you are accessing. The address is 8 bits long with the LSB being 0 if you are reading the device and 1 if you are writing to it. According to the data sheet for the DS1307, it's slave address is 1101000x where 'x' is the read or write bit so to read it you should use address 0xD0 (.208) and to write to it 0xD1 (.209), perhaps this is where the problem lies.
Dear Brian,
Thanks for reply
As I know, We should insert slave address to SSPADD in slave mode and in master mode we should load to SSPADD baud rate. I have little bit confuse on this. can you please explain it. in my program I set in master mode but still it does not read the value from RTC. If you can point out where the fault is, it is really really helpful me
Thanks in advance
SSPADD is the I2C address register. You load it with the address of the I2C device you are accessing. The address is 8 bits long with the LSB being 0 if you are reading the device and 1 if you are writing to it. According to the data sheet for the DS1307, it's slave address is 1101000x where 'x' is the read or write bit so to read it you should use address 0xD0 (.208) and to write to it 0xD1 (.209), perhaps this is where the problem lies.