View Single Post
Old 13-07-2010, 11:23 PM   #8
thanhhavdt
Nhập môn đệ tử
 
Tham gia ngày: Apr 2006
Bài gửi: 4
:
Here are some notes from my quick perusal of the code.

1. The format of the 11 element array:
Each element corresponds to the bit pattern for the corresponding digit. Element 0 = pattern for numeral 0, Element 1 = pattern for numeral 1 etc., Element 10 = pattern for blank.
Bit 0=Segment A
Bit 1=Segment F
Bit 2=Segment E
Bit 3=Segment B
Bit 4=Segment D
Bit 5=Segment C
Bit 6=Segment G
If the bit is zero, the segment is ON; if the bit is one, the segment is OFF.

2. The ADC produces a 10 bit number: 0 to 1023

3. The HTO7S routine scales this into a 0 to 30.0 number and separates the 3 digits using integer division and the mod operator. The scaling is done by multiplying by 30 and then dividing by 10230. This gives a value of 0 to 3 for the first digit as expected. The trick here is that because it is integer arithmetic, it's important to multiply by 30, to scale up the number before dividing by 10230. Otherwise, the fractional part would be lost, and hence accuracy would also be lost for subsequent digits. However, as far as I can see the result would be the same if he multiplied by 3 and then divided by 1023. The calculation of the next two digits is done using a similar method. First the previous highest digit is stripped off using the % (mod) operator. You just need to work through the math to satisfy yourself that this works.

A check is done to see if the leading digit is zero (bit pattern for 0 is 0x40):
if (Segment[0]==0x40)
Segment[0]=0xFF;
And if so it is blanked by changing the segment code to 0xFF
4. The "Display" routine does a bit more juggling of the segment codes that were generated in the HTO7S routine, because, while bits 0 to 5 go directly to the corresponding bits in PORTC, bit 6 has to go to bit 5 of PORTA and the 3 column select bits (for multiplexing) are also sent out in bits 0, 1, and 2 of PORTA. That's what this does:
SPORTA = ((Segment[ColCount] & 0b01000000)>>1) | (Column[ColCount]^0x07);
This step strips off all except bit 6 (the & operator) then shifts it right to bit 5 position. The column select lines are set by the remainder of the step. The column select is inverted by Exclusive ORing with 0x07, and then ORed into the bits 0 to 2. All of this then goes out to PORTA.

The way the display routine is set up, only one digit is sent out each time through the routine. So, it has to execute three times before all 3 digits are displayed. This is no problem since the routine is called each time through the main program loop.

Hope this helps.
thanhhavdt vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn