/*****************************************************************************
 * Module    : Display
 * File      : led_5c7s.h
 * Author    : Hanny
 * Function  : led_5c7s显示函数定义
*****************************************************************************/
#ifndef LED_5C7S_H
#define LED_5C7S_H

#if 1  //user_15_113
/*
D0 	P34
D1 	P27
D2	P26
D3	P25
D4	P24
D5	P23
D6	P22

C0	P21
C1	P20
C2	P12
C3	P11
C4	P10
*/
#define LED_COM0_DIR   P2DIR
#define LED_COM1_DIR   P2DIR
#define LED_COM2_DIR   P1DIR
#define LED_COM3_DIR   P1DIR
#define LED_COM4_DIR   P1DIR

#define LED_COM0       P2
#define LED_COM1       P2
#define LED_COM2       P1
#define LED_COM3       P1
#define LED_COM4       P1

#define LED_COM0_bit   1
#define LED_COM1_bit   0
#define LED_COM2_bit   2
#define LED_COM3_bit   1
#define LED_COM4_bit   0

//SEGx_ON条件: IO口方向设为输入,且下拉使能
#define SEG0_ON()   P2DIR |= BIT(2)     //C0
#define SEG1_ON()   P2DIR |= BIT(3)     //C1
#define SEG2_ON()   P2DIR |= BIT(4)     //C2
#define SEG3_ON()   P2DIR |= BIT(5)     //C3
#define SEG4_ON()   P2DIR |= BIT(6)     //C4
#define SEG5_ON()   P2DIR |= BIT(7)     //C5
#define SEG6_ON()   P3DIR |= BIT(4)     //C6
//SEGx_OFF条件: 关掉下拉, IO口方向设为输出,且输出为1
#define SEG_ALL_OFF()  P2 |= 0xfc; P2DIR &= ~0xfc; P3 |= BIT(4); P3DIR &= ~BIT(4)
//--------------------------------------------------------------------------
#else
#define LED_COM0_DIR   P0DIR
#define LED_COM1_DIR   P0DIR
#define LED_COM2_DIR   P1DIR
#define LED_COM3_DIR   P1DIR
#define LED_COM4_DIR   P2DIR

#define LED_COM0       P0
#define LED_COM1       P0
#define LED_COM2       P1
#define LED_COM3       P1
#define LED_COM4       P2

#define LED_COM0_bit   7
#define LED_COM1_bit   6
#define LED_COM2_bit   6
#define LED_COM3_bit   7
#define LED_COM4_bit   0

//SEGx_ON条件: IO口方向设为输入,且下拉使能
#define SEG0_ON()   P2DIR |= BIT(7)     //C0
#define SEG1_ON()   P2DIR |= BIT(6)     //C1
#define SEG2_ON()   P2DIR |= BIT(5)     //C2
#define SEG3_ON()   P2DIR |= BIT(4)     //C3
#define SEG4_ON()   P2DIR |= BIT(3)     //C4
#define SEG5_ON()   P2DIR |= BIT(2)     //C5
#define SEG6_ON()   P2DIR |= BIT(1)     //C6

//SEGx_OFF条件: 关掉下拉, IO口方向设为输出,且输出为1
#define SEG_ALL_OFF()  P2 |= 0xfe; P2DIR &= ~0xfe
#endif
//--------------------------------------------------------------------------
//COM_ON条件: 共阳LED, COM为高
#define COM0_ON()   LED_COM0 |= BIT(LED_COM0_bit)        //P07
#define COM1_ON()   LED_COM1 |= BIT(LED_COM1_bit)        //P06
#define COM2_ON()   LED_COM2 |= BIT(LED_COM2_bit)        //P16
#define COM3_ON()   LED_COM3 |= BIT(LED_COM3_bit)        //P17
#define COM4_ON()   LED_COM4 |= BIT(LED_COM4_bit)        //P20

#define LED_COM_INIT()  LED_COM0_DIR &= ~BIT(LED_COM0_bit); \
    LED_COM1_DIR &= ~BIT(LED_COM1_bit); \
    LED_COM2_DIR &= ~BIT(LED_COM2_bit); \
    LED_COM3_DIR &= ~BIT(LED_COM3_bit); \
    LED_COM4_DIR &= ~BIT(LED_COM4_bit)

#define COM_ALL_OFF()  LED_COM0 &= ~BIT(LED_COM0_bit); \
    LED_COM1 &= ~BIT(LED_COM1_bit); \
    LED_COM2 &= ~BIT(LED_COM2_bit); \
    LED_COM3 &= ~BIT(LED_COM3_bit); \
    LED_COM4 &= ~BIT(LED_COM4_bit)



//SEGx进入检测复用模式，IO设为输入，关闭500R下拉，打开10K上拉
//#define SEG_ENTER_DETECT()  P2DIR |= 0xfe; P2PD &= ~0xfe; P2PU |= 0xfe

//SEGx退出检测复用模式，关闭10K上拉，打开500R下拉，同时SEG_OFF
//#define SEG_EXIT_DETECT()   P2PU &= ~0xfe; P2PD |= 0xfe


void led_5c7s_init(void);
void led_5c7s_value_set(void);
__near_func void led_5c7s_scan(void);

#endif
