/******************************************************************
**
** File : Display.c | Display led segment |
** Version : 1.0
** Description : led 7 segment display
*******************************************************************/
#include "MSP430x24x.h"
#define uint unsigned int
#define uchar unsigned char
/***Set the digital tube display****/
#define L1_OFF P4OUT|=BIT0 //
Turn off L1 #define L1_NO P4OUT&=~BIT0 //Light up L1
#define L2_OFF P4OUT|=BIT1 //Turn off L2
#define L2_NO P4OUT&=~BIT1 //Light up L2
#define L3_OFF P4OUT|=BIT2 //Turn off L3
#define L3_NO P4OUT&=~BIT2 //Light up L3
#define L4_OFF P4OUT|=BIT3 //Turn off L4
#define L4_NO P4OUT&=~BIT3 //Light up L4
#define L5_OFF P4OUT|=BIT4 //Turn off L5
#define L5_NO P4OUT&=~BIT4 //Light up L5
#define L6_OFF P4OUT|=BIT5 //Turn off L6
#define L6_NO P4OUT&=~BIT5 //Light up L6
#define L7_OFF P4OUT|=BIT6 //Turn off L7
#define L7_NO P4OUT&=~BIT6 //Light up L7
#define L8_OFF P4OUT|=BIT7 //Turn off L8
#define L8_NO P4OUT&=~BIT7 //Light up L8
uchar const Segment1[]={0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f}; //without decimal point encoding
uchar const Segment2[]={0x40, 0x79, 0x24, 0x30, 0x19, 0x12, 0x02, 0x78, 0x00, 0x10}; //with decimal point encoding
void Display( fly num1, fly num2, fly num3, fly num4, fly num5, fly num6, fly num7, fly num8);
void Delay(void)
{
uint m;
for(m=1000;m>0;m--);
}
void main(void)
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD; //Watchdog
P4DIR = 0XFF; //P4 is set as output, bit code control
P4SEL = 0;
P5DIR = 0XFF; //P5 is set as output, bit code control
P5SEL = 0;
while(1)
{
// volatile unsigned int i;
// i = 50000; // Delay
// do (i--);
// while (i != 0);
Display(1,2,3,4,5,6,7,8);
}
}
void Display( uchar num1, uchar num2, uchar num3, uchar num4, uchar num5, uchar num6, uchar num7, uchar num8)
{
P5OUT = Segment1[ num1 ];//
L1_NO;
Delay();
L1_OFF;
P5OUT = Segment1[ num2 ];//
L2_NO;
Delay();
L2_OFF;
P5OUT = Segment1[ num3 ];//
L3_NO;
Delay();
L3_OFF;
P5OUT = Segment1[ num4 ];//
L4_NO;
Delay();
L4_OFF;
P5OUT = Segment1[ num5 ];//
L5_NO;
Delay();
L5_OFF;
P5OUT = Segment1[ num6 ];//
L6_NO;
Delay();
L6_OFF;
P5OUT = Segment1[ num7 ];//
L7_NO;
Delay();
L7_OFF;
P5OUT = Segment1[ num8 ];//
L8_NO;
Delay();
L8_OFF;
}
|