converting BCD
Dear All,
I need to make BCD 4 digit in 7-segment display.
My spi recieved data is 14 bit, take a look this sample code in another MCU.
void toBCD(int16 val,int8 * buff) {
//converts 16bit value, to five BCD digits. Tries to do it fairly
//efficiently, both in size, and speed.
int1 temp_bit;
int8 nibctr;
buff[0]=buff[1]=buff[2]=0;
do {
if ((buff[0] & 0xF)>=5) buff[0]+=3;
if ((buff[0] & 0xF0)>=0x50) buff[0]+=0X30;
if ((buff[1] & 0xF)>=5) buff[1]+=3;
if ((buff[1] & 0xF0)>=0x50) buff[1]+=0X30;
if ((buff[2] & 0xF)>=5) buff[2]+=3;
temp_bit=shift_left(&val,2,0);
shift_left(buff,3,temp_bit);
} while (val!=0);
}
void main() {
int16 val;
//three bytes for packed BCD result
int8 buff[3];
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
val=12345;
toBCD(val,buff);
//At this point, the three bytes will contain:
// 45
// 23
// 01
while (true);
}
1. How can I implement this idea in RTC application?
2. Is it possible to apply this link ..http://embedded-lab.com/blog/stm32s-internal-rtc/
Kindly help me.
Refference code is required.