Hello! Posting again
I'm working on DALI to monitor the hours of LEDs connected to DALI slave. I'm using LPC1114/302 MCU.
According to Standard DALI protocol I can only send 8 bits to DALI Master. I'm trying to separate the logic by using Modulus operator and send it to the DALI master but it doesn't work. I've attached the in which i applied different logics to separate the digits and send it over.
The stunde is hour, whose value is 329 and I need to split them into 3 digits \
MSB 3,
MIDB 2,
LSB 9
Actually, I've just started programming in C and since it's related to DALI and I'm working on NXP MCU that's why
Assuming that you are trying to extract the decimal digits, here is a bit of code that may help you:
int val = 329 ; // the value to convert
int result[3] ; // an array containing each decimal digit.
// the least significant digit is in result[0]
int digits = 0 ;
while(val > 0){
result[digits++] = val % 10 ;
val = val / 10 ;
}
This will convert a number containing up to 3 decimal digits and place the result into the result[] array (in reverse order). To simplify the code, there is no error checking, so if the value is larger than 999, the result array will overflow and corruption will occur!!! You can modify this code to suit your particular circumstances.
Not to be rude, but what has this to do with "NXP microprocessors" ?
It is a simple beginner C question (in fact, a general programming beginner question).