یه نگاهی به برنامه بنداز برای راه اندازی سون سگمنت هست .
شاید کمکی کرد.
(in EEPROM)
/*
; =============================
; 7 SEGMENT CHARACTER MAPS
; =============================
;
;
; THESE CHARACTER MAPS, IN "C" SOURCE FORM, WERE PROVIDED BY
;
[email protected] IN RESPONSE TO A NEWSGROUP REQUEST.
; INTERESTINGLY ENOUGH, HE ALSO USES THE HDSPA101.
; SOME ARE PRETTY UGLY, BUT THIS IS ONLY 7-SEGMENT AFTER ALL.
;
; NOTE THAT A 1 BIT IN THIS TABLE MEANS THE SEGMENT IS OFF--
; 0XFF = SPACE
;
; GET A DIGIT BY POINTING AT EE_CHAR_SET AND INDEXING.
; PICK THE OTHER LETTERS OUT INDIVIDUALLY BY NAME.
; ORGANIZE A-F AFTER 0-9 FOR HEX DISPLAY.
; AN ALMOST-FULL ALPHABET IS PROVIDED, EVEN THOUGH UGLY CHARS.
;
** Segment mapping in HDSPA101. Segment is on, when the
** respective bit is 0.
** _____
** f / a / b
** /____/
** e / g / c
** /____/ o dp
** d
**
** Assume that the segments are connected in the following way:
** a = bit 0, b = bit 1, ... , dp = bit 7.
*/
/*
* Modified for the BTR334 to:
* -- only include used characters
* -- 0-9, a-f in first 16 positions for easier indexing/display
* of decimal and hexadecimal numbers
*/
eeprom unsigned char ee_char_set[] =
{
0xc0, /* 0 digit */
0xf9,
0xa4,
0xb0,
0x99,
0x92,
0x82,
0xf8,
0x80,
0x90, /* 9 digit */
0x88, /* A = ASCII 65 */
0x83, /* b */
0xc6, /* C */
0xa1, /* d */
0x86, /* E */
0x8e, /* F */
0xc2, /* G (not too bad) */
0x8b, /* h */
0xcf, /* I */
0xe1, /* J */
0xb6, /* K (bad) */
0xc7, /* L */
0xc8, /* M (bad) */
0xab, /* n */
0xc0, /* O (same as 0, different index)*/
0x8c, /* P */
0x80, /* no Q -- same as 8 */
0xaf, /* r */
0x92, /* S -- same as 5 */
0x87, /* t */
0xc1, /* u */
0xe3, /* V (bad) -- same as U */
0x81, /* W (bad) */
0x89, /* no X -- use H */
0x91, /* y (not too bad) */
0xa4, /* Z (bad, same as 2 */
0xff, /* space */
0xbf, /* minus - */
0xb7, /* equal = */
0xa7, /* c */
0xef, /* i */
0xff, /* "another" space that does not have the same index; for indication */
0xa3, /* o */
0x7f, /* . */
0xcf, /* | -- left bar */
0xf9, /* | -- right bar*/
0xc9 /* || -- both bars*/
};
// Indices into the character array
#define CHAR_0 0
#define CHAR_A 10
#define CHAR_SP (CHAR_A + 26)
#define CHAR_MI (CHAR_SP + 1)
#define CHAR_EQ (CHAR_SP + 2)
#define CHAR_LC (CHAR_SP + 3)
#define CHAR_LI (CHAR_SP + 4)
#define CHAR_LO (CHAR_SP + 6)
#define CHAR_DP (CHAR_SP + 7)
#define CHAR_LEFT (CHAR_SP + 8)
#define CHAR_RIGHT (CHAR_SP + 9)
#define CHAR_BOTH (CHAR_SP + 10)
// "map" ASCII upper case characters to
// character array indices
#define OFFSET_ALPHA ('A' - CHAR_A)
#define OFFSET_NUMERIC ('0' - CHAR_0)
...
//=============================================================================
// Hardware Resources:
//=============================================================================
// Processor: ATMega164 or ATMega164P or equivalent
// Clock: Internal Oscillator, ~8MHz
// Memory model: Small
// Internal SRAM: 1024 Bytes
// External SRAM: None
//=============================================================================
// PORTS (Mega164 Function)
//-----------------------------------------------------------------------------
// PIN Mega164 USE DIR INIT DESCRIPTION
// === =========== === ==== ===========
//
// PA.7 (ADC7) In (z) unused in this application; tied low
// PA.6 (ADC6) In (z) Raw VUN nominal +24VDC monitor, 10k/2k ==> 1/6
// PA.5 (ADC5) Out (0) 7-segment LED6 (WELL6) column strobe, SW1/SW2/DIS1 strobe
// PA.4 (ADC4) Out (0) 7-segment LED5 (WELL5) column strobe, SW3/SW4/DIS2 strobe
// PA.3 (ADC3) Out (0) 7-segment LED4 (WELL4) column strobe, SW5/SW6/DIS3 strobe
// PA.2 (ADC2) Out (0) 7-segment LED3 (WELL3) column strobe, SW7/SW8/DIS4 strobe
// PA.1 (ADC1) Out (0) 7-segment LED2 (WELL2) column strobe, SW9/SW10/DIS5 strobe
// PA.0 (ADC0) Out (0) 7-segment LED1 (left; WELL1) column strobe, SW11/SW12/DIS6 strobe
// PB.7 (SCK) Out (1) 7-segment DP
// PB.6 (MISO) Out (1) 7-segment G
// PB.5 (MOSI) Out (1) 7-segment F
// PB.4 (!SS/OC0B) Out (1) 7-segment E
// PB.3 (AIN1/OC0A) Out (1) 7-segment D
// PB.2 (AIN0/INT2) Out (1) 7-segment C
// PB.1 (CLKOT1) Out (1) 7-segment B
// PB.0 (XCK0/T0) Out (1) 7-segment A
...
//
// Display
// =======
//
//
// Display Array of 7-Segment Characters
//
#define SEGMENT_A PORTB.7
#define SEGMENT_B PORTB.6
#define SEGMENT_C PORTB.5
#define SEGMENT_D PORTB.4
#define SEGMENT_E PORTB.3
#define SEGMENT_F PORTB.2
#define SEGMENT_G PORTB.1
#define SEGMENT_DP PORTB.0
#define SEGMENT_ON 0 // inverted logic
#define SEGMENT_OFF 1
// All segments are on the same port, so can be set/cleared with one operation
#define SEGMENT_PORT PORTB
#define SEGMENT_MASK 0xff
#define COLUMN_1 PORTA.5 // WELL6 strobe (rightmost)
#define COLUMN_2 PORTA.4 // WELL5 strobe
#define COLUMN_3 PORTA.3 // WELL4 strobe
#define COLUMN_4 PORTA.2 // WELL3 strobe
#define COLUMN_5 PORTA.1 // WELL2 strobe
#define COLUMN_6 PORTA.0 // WELL1 strobe (leftmost)
#define COLUMN_ON 1
#define COLUMN_OFF 0
// All columns are on the same port, but not all pins
#define COLUMN_PORT PORTA
#define COLUMN_MASK 0x3f
#define NUM_7_SEGS 6
...
unsigned char buffer[NUM_7_SEGS]; // character indices
unsigned char display[NUM_7_SEGS]; // character bitmaps
// macros for decimal_point_on() and decimal_point_off()
// assumes decimal point DP is high-bit in the 7-segment map
#define decimal_point_on( col ) display[ col ] &= 0x7f
#define decimal_point_off( col ) display[ col ] |= 0x80
...
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 31.250 kHz
// Mode: CTC top=OCR0A
// OC0A output: Disconnected
// OC0B output: Disconnected
TCCR0A=0x02;
TCCR0B=0x04;
TCNT0=0x00;
OCR0A=0x4D; // /256, 2.504ms. for multiplexing
OCR0B=0x00;
// Timer/Counter 0 Interrupt(s) initialization
TIMSK0=0x02;
...
// ***********
// Display refresh -- one character every 2.5 ms.
// ***********
/*
;
;
; Remember that the column select is normal--count selects 1-of-6.
; But the row logic is inverted--output pin low selects the segment.
;
; Increment DIGIT & wrap-around if needed for next time.
;
*/
// The previous column's strobe is made (high) for a couple milliseconds.
// Read the sense lines before dropping the strobe for the next column.
// Check for end-of-pass
if (++digit >= NUM_7_SEGS) // set index for this pass
{
// End of pass
digit = 0;
// Display multiplexing
// Turn off column strobes
// COLUMN_PORT &= ~COLUMN_MASK; // low 6 bits of PortA in this design; active high
COLUMN_PORT |= COLUMN_MASK; // low 6 bits of PortA in this design; active low
// Turn off segment strobes
SEGMENT_PORT = SEGMENT_MASK; // all bits of PortB in this design; active low
// ****
// ****
// moved from below to kill a bit of time after turning off one column and enabling the next
// ****
// ****
worknum = ADCW;
adc_pwr = (adc_pwr + worknum) / 2; // rolling average
// ****
// ****
// Set the segments
SEGMENT_PORT = display[digit];
// Set the column
// COLUMN_PORT |= (1 << digit); // digit 0 is column 1 is PA0
COLUMN_PORT &= ~(1 << digit); // digit 0 is column 1 is PA0
// digit 5 is column 6 is PA5
...
// Show the power level of each well.
// Light the DP if on
//
if (tock) (every 500ms)
{
dispclear(); // clears all digits to blank, as well as DPs
workreg = WELL1; // high bit is WELL1
for (looper=0; looper<NUM_WELLS; looper++, workreg >>= 1)
{
if (workreg & well_disable)
{
// This well disabled--leave blank
}
else
{
scratch = ee_well_level[looper];
// Protective code to handle bad well levels
if (scratch > 9)
{
scratch = 0; // "override" to off
ee_well_level[looper] = scratch; // and update table
}
// Output the number, 0-9, into this digit
outchar (looper, scratch);
// Apply the decimal point if on
// (in production, may want to limit to a blip. For now, blink)
// rev. c--customer desires solid-on
if (well_on & workreg)
{
decimal_point_on(looper);
}
...
//
// **************************************************************************************
// *
// * O U T C H A R
// *
// **************************************************************************
//
void outchar (unsigned char digit, unsigned char index)
{
buffer[digit] = index;
display[digit] = ee_char_set[index];
}
//
// **************************************************************************
// *
// * D I S P C L E A R
// *
// **************************************************************************
//
void dispclear (void)
{
unsigned char looper;
for (looper = 0; looper < NUM_7_SEGS; looper++)
{
display[looper] = ee_char_set[CHAR_SP];
buffer[looper] = CHAR_SP;
}
}