#include "head.h"
#include "led188_screen.h"
#define SEGA 0x01
#define SEGB 0x02
#define SEGC 0x04
#define SEGD 0x08
#define SEGE 0x10
#define SEGF 0x20
#define SEGG 0x40
#define NUM0 SEGA|SEGB|SEGC|SEGD|SEGE|SEGF
#define NUM1 SEGB|SEGC
#define NUM2 SEGA|SEGB|SEGD|SEGE|SEGG //
#define NUM3 SEGA|SEGB|SEGC|SEGD|SEGG //
#define NUM4 SEGB|SEGC|SEGF|SEGG //
#define NUM5 SEGA|SEGC|SEGD|SEGF|SEGG //-b-e
#define NUM6 SEGA|SEGC|SEGD|SEGE|SEGF|SEGG
#define NUM7 SEGA|SEGB|SEGC //
#define NUM8 SEGA|SEGB|SEGC|SEGD|SEGE|SEGF|SEGG //
#define NUM9 SEGA|SEGB|SEGC|SEGD|SEGF|SEGG
#define NUME SEGA|SEGD|SEGE|SEGF|SEGG //E
#define NUMF SEGA|SEGE|SEGF|SEGG //F
#define NUMG SEGG //-
u8 digit_table[]={ NUM0,NUM1,NUM2,NUM3,NUM4,NUM5,NUM6,NUM7,NUM8,NUM9,NUME,NUMF,NUMG };
typedef union{
struct{
u32 a:1 ;
u32 b:1 ;
u32 c:1 ;
u32 d:1 ;
u32 e:1 ;
u32 f:1 ;
u32 g:1 ;
u32 h:1 ;
};
u8 digital;
}DIGITAL;
typedef struct{
// u32 digit1_a:1 ;
// u32 digit1_d:1 ;
// u32 digit1_e:1 ;
// u32 digit1_f:1 ;
// u32 digit1_g:1 ;
// u32 digit2_a:1 ;
// u32 digit2_b:1 ;
// u32 digit2_c:1 ;
// u32 digit2_d:1 ;
// u32 digit2_e:1 ;
// u32 digit2_f:1 ;
// u32 digit2_g:1 ;
// u32 digit2_h:1 ;
//
// u32 digit3_a:1 ;
// u32 digit3_b:1 ;
// u32 digit3_c:1 ;
// u32 digit3_d:1 ;
// u32 digit3_e:1 ;
// u32 digit3_f:1 ;
// u32 digit3_g:1 ;
// u32 digit3_h:1 ;
DIGITAL digit2;
DIGITAL digit3;
u32 digit1_b:1 ;
u32 digit1_c:1 ;
u32 charge_thunder:1 ;
}LED_SEGMENTS;
LED_SEGMENTS LED188_SEG;
void LED188_test(u8 allon1_alloff0)
{
#if 0
static u8 scan_idx=0;
LED188_ALL_OFF;
if(++scan_idx>=5)scan_idx=0;
switch (scan_idx)
{
case 0:
LED188_P1_ON; LED188_P2_LOW;LED188_P3_LOW;LED188_P4_LOW; LED188_P5_LOW;
break;
case 1:
LED188_P2_ON; LED188_P1_LOW;LED188_P3_LOW;LED188_P4_LOW; LED188_P5_LOW;
break;
case 2:
LED188_P3_ON; LED188_P1_LOW;LED188_P2_LOW;LED188_P4_LOW; LED188_P5_LOW;
break;
case 3:
LED188_P4_ON; LED188_P1_LOW;LED188_P3_LOW;LED188_P2_LOW; LED188_P5_LOW;
break;
case 4:
LED188_P5_ON; LED188_P1_LOW;LED188_P2_LOW;LED188_P3_LOW;LED188_P4_LOW;
break;
default:
break;
}
#else
if(allon1_alloff0)
{
LED188_SEG.digit2.digital=0xff;
LED188_SEG.digit3.digital=0xff;
LED188_SEG.charge_thunder=1;
LED188_SEG.digit1_b=1;
LED188_SEG.digit1_c=1;
}
else
{
LED188_SEG.digit2.digital=0;
LED188_SEG.digit3.digital=0;
LED188_SEG.charge_thunder=0;
LED188_SEG.digit1_b=0;
LED188_SEG.digit1_c=0;
}
#endif
}
u8 LED188_set(u8 num,u8 charge_sig)
{
#if 1//
u8 dig[3]={0};
u8 i=0;
if(charge_sig) LED188_SEG.charge_thunder=1;
else LED188_SEG.charge_thunder=0;
do
{
dig[i++]= num%10;
num/=10;
// digit2_g:1 ;
}
while(num>0);
if( dig[2]>0) { LED188_SEG.digit1_b = LED188_SEG.digit1_c=1; }
else { LED188_SEG.digit1_b = LED188_SEG.digit1_c=0; }
LED188_SEG.digit2.digital = digit_table[dig[1]];
LED188_SEG.digit3.digital = digit_table[dig[0]];
#else //test
static u8 idx;
if(++idx>8) idx=1;
switch (idx)
{
case 0: LED188_SEG.digit3.a=1; LED188_SEG.digit2.a=1;
break;
case 1: LED188_SEG.digit2.a=0; LED188_SEG.digit3.a=0; LED188_SEG.digit2.b=1; LED188_SEG.digit3.b=1;
break;
case 2: LED188_SEG.digit2.b=0; LED188_SEG.digit3.b=0; LED188_SEG.digit2.c=1; LED188_SEG.digit3.c=1;
break;
case 3: LED188_SEG.digit2.c=0; LED188_SEG.digit3.c=0; LED188_SEG.digit2.d=1; LED188_SEG.digit3.d=1;
break;
case 4: LED188_SEG.digit2.d=0; LED188_SEG.digit3.d=0; LED188_SEG.digit2.e=1; LED188_SEG.digit3.e=1;
break;
case 6: LED188_SEG.digit2.e=0; LED188_SEG.digit3.e=0; LED188_SEG.digit2.f=1; LED188_SEG.digit3.f=1;
break;
case 7: LED188_SEG.digit2.f=0; LED188_SEG.digit3.f=0; LED188_SEG.digit2.g=1; LED188_SEG.digit3.g=1;
break;
case 8: LED188_SEG.digit2.g=0; LED188_SEG.digit3.g=0; LED188_SEG.digit2.a=1; LED188_SEG.digit3.a=1;
break;
default:
break;
}
#endif
}
//enum ALARM
//{
// LOWBAT, // 00
// TEMPHIGH,//FF
// TIMEOUT, //F8
// SHORT, //E2
// NOINSERT,//-- dash line虚线的
//} ;
ALARM_TYPEDEF alarmTYpe=0; // LED188_alarm( alarmTYpe) ;
void LED188_alarm(enum ALARM type)
{
LED188_SEG.charge_thunder=0; LED188_SEG.digit1_b =0; LED188_SEG.digit1_c=0;
switch (type)
{
case LOWBAT:
LED188_SEG.digit2.digital = digit_table[0];
LED188_SEG.digit3.digital = digit_table[0]; //00
break;
case TEMPHIGH:
LED188_SEG.digit2.digital = digit_table[11]; //FF
LED188_SEG.digit3.digital = digit_table[11];
break;
break;
case TIMEOUT:
LED188_SEG.digit2.digital = digit_table[11]; //F8
LED188_SEG.digit3.digital = digit_table[8];
break;
case SHORT:
LED188_SEG.digit2.digital = digit_table[10]; //E2
LED188_SEG.digit3.digital = digit_table[2];
break;
case NOINSERT:
LED188_SEG.digit2.digital = digit_table[12]; //-- dash line虚线的
LED188_SEG.digit3.digital = digit_table[12]; //
break;
default:
break;
}
}
void breath_charge()
{
#define MAX_DUTY 20//40
static u8 duty_cnt=0;
static u8 duty_val=0;
static u8 breath_dir=0;;
if(USB_DET_IN)
{
if(duty_cnt < duty_val)
{
LED188_SEG.charge_thunder=1;
}
else
{
LED188_SEG.charge_thunder=0;
}
if(++duty_cnt>MAX_DUTY)
{
duty_cnt=0;
if(breath_dir)
{
if(duty_val< MAX_DUTY) duty_val+=3;
else breath_dir=0;
}
else //if(breath_dir)
{
if(duty_val > 0) duty_val-=3;
else breath_dir=1;
}
}
}
else LED188_SEG.charge_thunder=0;
}
void LED188_scan()
{
static u8 scan_idx=0;
LED188_ALL_OFF;
if(++scan_idx>=6)scan_idx=0;
breath_charge();
switch (scan_idx)
{
case 0:
LED188_P1_ON;
if(LED188_SEG.digit3.a) LED188_P2_LOW;
if(LED188_SEG.digit3.c)LED188_P3_LOW;
if(LED188_SEG.digit3.e)LED188_P4_LOW;
//LED188_P5_LOW;
break;
case 3:
case 1:
LED188_P2_ON;
if(LED188_SEG.digit3.b)LED188_P1_LOW;
if(LED188_SEG.digit2.a)LED188_P3_LOW;
if(LED188_SEG.digit1_c)LED188_P4_LOW;
if(LED188_SEG.charge_thunder)
{ LED188_P5_LOW; //呼吸
}
break;
case 2:
LED188_P3_ON;
if(LED188_SEG.digit3.d)LED188_P1_LOW;
if(LED188_SEG.digit2.b)LED188_P2_LOW;
if(LED188_SEG.digit1_b)LED188_P4_LOW;
//LED188_P5_LOW;
break;
case 3+2:
LED188_P4_ON;
if(LED188_SEG.digit3.f)LED188_P1_LOW;
if(LED188_SEG.digit2.d)LED188_P2_LOW;
if(LED188_SEG.digit2.c) LED188_P3_LOW;
//LED188_P5_LOW;
break;
case 4:
LED188_P5_ON;
if(LED188_SEG.digit3.g)LED188_P1_LOW;
if(LED188_SEG.digit2.e)LED188_P2_LOW;
if(LED188_SEG.digit2.f)LED188_P3_LOW;
if(LED188_SEG.digit2.g)LED188_P4_LOW;
break;
default:
break;
}
}
void LED188_scan0 ()
{
static u8 scan_idx=0;
LED188_ALL_OFF;
if(++scan_idx>=18)scan_idx=0;
switch (scan_idx)
{
case 0:
LED188_P1_ON; if(LED188_SEG.digit3.a) {LED188_P2_LOW; break;}
case 1: LED188_P1_ON; if(LED188_SEG.digit3.c) {LED188_P3_LOW; break;}
case 2:LED188_P1_ON; if(LED188_SEG.digit3.e) {LED188_P4_LOW; break; }
//LED188_P5_LOW;
break;
case 4:LED188_P2_ON; if(LED188_SEG.digit3.b){LED188_P1_LOW; break; }
case 5:LED188_P2_ON; if(LED188_SEG.digit2.a){LED188_P3_LOW; break;}
case 6:LED188_P2_ON; if(LED188_SEG.digit1_c){LED188_P4_LOW; break;}
case 7:LED188_P2_ON; if(LED188_SEG.charge_thunder){LED188_P5_LOW; break; }
case 8:
LED188_P3_ON; if(LED188_SEG.digit3.d) //
{LED188_P1_LOW; break; }
case 9: LED188_P3_ON; if(LED188_SEG.digit2.b){LED188_P2_LOW;break; }
case 10: LED188_P3_ON; if(LED188_SEG.digit1_b){LED188_P4_LOW;break;}
//LED188_P5_LOW;
break;
case 11:
LED188_P4_ON;
if(LED188_SEG.digit3.f){LED188_P1_LOW; break;}
case 12: LED188_P4_ON;
if(LED188_SEG.digit2.d) //
{LED188_P2_LOW; break;}
case 13: LED188_P4_ON; if(LED188_SEG.digit2.c) {LED188_P3_LOW; break;}
//LED188_P5_LOW;
break;
case 14:
LED188_P5_ON;
if(LED188_SEG.digit3.g){LED188_P1_LOW;break;}
case 15: LED188_P5_ON; if(LED188_SEG.digit2.e){LED188_P2_LOW; break;}
case 16: LED188_P5_ON; if(LED188_SEG.digit2.f){LED188_P3_LOW; break; }
case 17: LED188_P5_ON; if(LED188_SEG.digit2.g){LED188_P4_LOW;break; }
break;
default:
break;
}
}
头文件
#ifndef __LED188_H
#define __LED188_H
#ifdef __cplusplus
extern "C" {
#endif
#define GPIO_DIRIN(GPIOx,Pinx) do{GPIOx->MODER &= ~(3ul << (Pinx * 2));}while(0) // do{GPIOX->MODER = ~(3ul<<Pinx*2 );}while(0) //Pinx=0~15
#define GPIO_DIROUT(GPIOx,Pinx) do{GPIOx->MODER = GPIOx->MODER&(~(3ul<<(Pinx*2) )) |(1ul<<(Pinx*2));}while(0)//Pinx=0~15
#define GPIO_MODE_AF(GPIOx,Pinx) do{GPIOx->MODER = GPIOx->MODER&(~(3ul<<(Pinx*2) )) |(2ul<<(Pinx*2));}while(0)//Pinx=0~15
#define GPIO_MODE_AN(GPIOx,Pinx) do{GPIOx->MODER = GPIOx->MODER&(~(3ul<<(Pinx*2) )) |(3ul<<(Pinx*2));}while(0)//Pinx=0~15
#define LED188_ALL_OFF do{GPIO_DIRIN(GPIOB,3); GPIO_DIRIN(GPIOB,4); GPIO_DIRIN(GPIOB,5); GPIO_DIRIN(GPIOB,6); GPIO_DIRIN(GPIOB,7);}while(0)
#define LED188_P1_ON do{GPIO_DIROUT(GPIOB,3);GPIO_SetBits(GPIOB,GPIO_Pin_3); }while(0)
#define LED188_P1_OFF do{GPIO_DIRIN(GPIOB,3) ; }while(0)
#define LED188_P2_ON do{GPIO_DIROUT(GPIOB,4);GPIO_SetBits(GPIOB,GPIO_Pin_4); }while(0)
#define LED188_P2_OFF do{GPIO_DIRIN(GPIOB,4) ; }while(0)
#define LED188_P3_ON do{GPIO_DIROUT(GPIOB,5);GPIO_SetBits(GPIOB,GPIO_Pin_5); }while(0)
#define LED188_P3_OFF do{GPIO_DIRIN(GPIOB,5) ; }while(0)
#define LED188_P4_ON do{GPIO_DIROUT(GPIOB,6);GPIO_SetBits(GPIOB,GPIO_Pin_6); }while(0)
#define LED188_P4_OFF do{GPIO_DIRIN(GPIOB,6) ; }while(0)
#define LED188_P5_ON do{GPIO_DIROUT(GPIOB,7);GPIO_SetBits(GPIOB,GPIO_Pin_7); }while(0)
#define LED188_P5_OFF do{GPIO_DIRIN(GPIOB,7) ; }while(0)
#define LED188_P1_LOW do{GPIO_DIROUT(GPIOB,3);GPIO_ResetBits(GPIOB,GPIO_Pin_3); }while(0)
#define LED188_P2_LOW do{GPIO_DIROUT(GPIOB,4);GPIO_ResetBits(GPIOB,GPIO_Pin_4); }while(0)
#define LED188_P3_LOW do{GPIO_DIROUT(GPIOB,5);GPIO_ResetBits(GPIOB,GPIO_Pin_5); }while(0)
#define LED188_P4_LOW do{GPIO_DIROUT(GPIOB,6);GPIO_ResetBits(GPIOB,GPIO_Pin_6); }while(0)
#define LED188_P5_LOW do{GPIO_DIROUT(GPIOB,7);GPIO_ResetBits(GPIOB,GPIO_Pin_7); }while(0)
typedef enum ALARM
{
LOWBAT, // 00
TEMPHIGH,//FF
TIMEOUT, //F8
SHORT, //E2
NOINSERT,//--
}ALARM_TYPEDEF ;
extern ALARM_TYPEDEF alarmTYpe;//=0;
void LED188_alarm(enum ALARM type);
void LED188_test(u8 allon1_alloff0);
u8 LED188_set(u8 num,u8 charge_sig) ;
void LED188_scan();
#ifdef __cplusplus
}
#endif
#endif /* __FT32F0XX_GPIO_H */