So 'buf' become the upper bits of 'time' with 0x30 added to it, that makes the ascii character for the high bits of 'time' ready to be dsplayed. If the current gray code bit is 0, then copy the previous binary code bit, else copy the invert of the previous binary. Other bits of the output binary code can be obtained by checking the gray code bit at that index. You could write +0x30 or +'0', they are identical as far as the compiler is concerned because '0' (character xero) has the value 0x30 anyway. Gray to binary conversion : The Most Significant Bit (MSB) of the binary code is always equal to the MSB of the given gray code. So to make values 0x00 through 0x09 into 0x30 to 0x39 we have to add 0x30 to them. Looking at the ascii chart, the value zero is equal to ascii value 0x30, one is equalto 0x31 and so on. For example 0x50 would now be 0x05 and 0x23 would now be 0x02.Īt this point the result is the actual value that was in the upper 4 bits but they need to be converted to ascii before being displayed. Effectively, the high 4 bits are now where the lower 4 bits used to be. So (time > 4) takes the BCD value and shifts it four bits to the right, the bits already at the right end are lost and zero bits are loaded in from the left. Remember that brackets '(' and ')' are used to change the order in which a calculationis done, just as in normal math. Buf=((time > 4)+'0') 'time' is the BCD value from the clock.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |