/**
  ******************************************************************************
  * @file    VK16K33B.h 
  * @author  kevin_guo
  * @version V1.1
  * @date    07-05-2024
  * @brief   Header files for VK16K33B
  ******************************************************************************
  * @attention
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __VK16K33B_H
#define __VK16K33B_H

/* Includes ------------------------------------------------------------------*/
//此包含文件根据客户单片机做相应的修改
#include "M451Series.h"
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported define -----------------------------------------------------------*/
//基本设置
//I2C地址
#define VK16K33B_ADDR   					0x70 //A2=0(悬空) A1=0(悬空) 	A0=0(悬空)  
//#define VK16K33B_ADDR   					0x71 //A2=0(悬空) A1=0(悬空) 	A0=0(1)  
//#define VK16K33B_ADDR   					0x72 //A2=0(悬空) A1=0(1) 		A0=0(悬空) 
//#define VK16K33B_ADDR   					0x73 //A2=0(悬空) A1=0(1) 		A0=0(1)  
//#define VK16K33B_ADDR   					0x74 //A2=0(1) 		A1=0(悬空) 	A0=0(悬空) 
//#define VK16K33B_ADDR   					0x75 //A2=0(1) 		A1=0(悬空) 	A0=0(1)  
//#define VK16K33B_ADDR   					0x76 //A2=0(1) 		A1=0(1) 		A0=0(悬空)  
//#define VK16K33B_ADDR   					0x77 //A2=0(1) 		A1=0(1) 		A0=0(1)  
//I2C地址写
#define VK16K33B_ADDRWR   					0xE0 //A2=0(悬空) A1=0(悬空) 	A0=0(悬空) bit0=0写
//#define VK16K33B_ADDRWR   					0xE2 //A2=0(悬空) A1=0(悬空) 	A0=0(1)    bit0=0写
//#define VK16K33B_ADDRWR   					0xE4 //A2=0(悬空) A1=0(1) 		A0=0(悬空) bit0=0写 
//#define VK16K33B_ADDRWR   					0xE6 //A2=0(悬空) A1=0(1) 		A0=0(1)    bit0=0写
//#define VK16K33B_ADDRWR   					0xE8 //A2=0(1) 		A1=0(悬空) 	A0=0(悬空) bit0=0写 
//#define VK16K33B_ADDRWR   					0xEA //A2=0(1) 		A1=0(悬空) 	A0=0(1)    bit0=0写
//#define VK16K33B_ADDRWR   					0xEC //A2=0(1) 		A1=0(1) 		A0=0(悬空) bit0=0写  
//#define VK16K33B_ADDRWR   					0xEE //A2=0(1) 		A1=0(1) 		A0=0(1)  
//I2C地址读
#define VK16K33B_ADDRRD   					0xE1 //A2=0(悬空) A1=0(悬空) 	A0=0(悬空)  bit0=1读
//#define VK16K33B_ADDRRD   					0xE3 //A2=0(悬空) A1=0(悬空) 	A0=0(1)     bit0=1读
//#define VK16K33B_ADDRRD   					0xE5 //A2=0(悬空) A1=0(1) 		A0=0(悬空)  bit0=1读
//#define VK16K33B_ADDRRD   					0xE7 //A2=0(悬空) A1=0(1) 		A0=0(1)     bit0=1读
//#define VK16K33B_ADDRRD   					0xE9 //A2=0(1) 		A1=0(悬空) 	A0=0(悬空)  bit0=1读
//#define VK16K33B_ADDRRD   					0xEB //A2=0(1) 		A1=0(悬空) 	A0=0(1)     bit0=1读
//#define VK16K33B_ADDRRD   					0xED //A2=0(1) 		A1=0(1) 		A0=0(悬空)  bit0=1读 
//#define VK16K33B_ADDRRD   					0xEF //A2=0(1) 		A1=0(1) 		A0=0(1)     bit0=1读
//按键RAM起始地址
#define VK16K33B_KEYSTARTADDR   		0x40 //0x40-0x45 6byte
//显示RAM起始地址
#define VK16K33B_DISPSTARTADDR   	0x00 //0x00-0x0F 16byte

//系统设置命令(bit7~bit4=0010) 
#define VK16K33B_SYSOSC_OFF       	0x20  //bit1=0系统振荡器关(待机模式) 上电默认
#define VK16K33B_SYSOSC_ON       	0x21  //bit1=1系统振荡器开(正常模式)
//显示设置命令(bit7~bit4=1000) 
#define VK16K33B_DISP_OFF       		0x80  //bit0=0显示关  上电默认
#define VK16K33B_DISP_ON       		0x81  //bit0=1显示开 bit2-bit1=00 闪烁关闭
#define VK16K33B_BLINKOFF       		0x81  //bit0=1显示开 bit2-bit1=00 闪烁关闭
#define VK16K33B_BLINK2HZ       		0x83  //bit0=1显示开 bit2-bit1=01 闪烁2HZ
#define VK16K33B_BLINK1HZ       		0x85  //bit0=1显示开 bit2-bit1=10 闪烁1HZ
#define VK16K33B_BLINKD5HZ      		0x87  //bit0=1显示开 bit2-bit1=11 闪烁0.5HZ

//SEG/INT脚设置命令(bit7~bit4=1010)
#define VK16K33B_INTSETSEG       	0xA0  //bit1-bit0=00 SEG/INT脚设置为SEG脚  上电默认
#define VK16K33B_INTSETINTL       	0xA1  //bit1-bit0=01 SEG/INT脚设置为INT脚低有效  
#define VK16K33B_INTSETINTH       	0xA1  //bit1-bit0=11 SEG/INT脚设置为INT脚高有效 

//INT标志寄存器(键按下Bit7-Bit0置1 全部键读取清0)
#define VK16K33B_INTREG       	0x60  //

//显示亮度设置 0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef 
//分别对应     1/16,2/16,3/16,4/16,5/16,6/16,7/16,8/16,9/16,10/16,11/16,12/16,13/16,14/16,15/16,16/16  
#define 	VK16K33B_PDUTY_1_16      0xe0  //显示控制设置为脉冲宽度1/16  
#define 	VK16K33B_PDUTY_2_16      0xe1  //显示控制设置为脉冲宽度2/16  
#define 	VK16K33B_PDUTY_3_16      0xe2  //显示控制设置为脉冲宽度3/16  
#define 	VK16K33B_PDUTY_4_16      0xe3  //显示控制设置为脉冲宽度4/16  
#define 	VK16K33B_PDUTY_5_16      0xe4  //显示控制设置为脉冲宽度5/16  
#define 	VK16K33B_PDUTY_6_16      0xe5  //显示控制设置为脉冲宽度6/16  
#define 	VK16K33B_PDUTY_7_16      0xe6  //显示控制设置为脉冲宽度7/16  
#define 	VK16K33B_PDUTY_8_16      0xe7  //显示控制设置为脉冲宽度8/16  
#define 	VK16K33B_PDUTY_9_16      0xe8  //显示控制设置为脉冲宽度9/16  
#define 	VK16K33B_PDUTY_10_16     0xe9  //显示控制设置为脉冲宽度10/16  
#define 	VK16K33B_PDUTY_11_16     0xea  //显示控制设置为脉冲宽度11/16  
#define 	VK16K33B_PDUTY_12_16     0xeb  //显示控制设置为脉冲宽度12/16  
#define 	VK16K33B_PDUTY_13_16     0xec  //显示控制设置为脉冲宽度13/16  
#define 	VK16K33B_PDUTY_14_16     0xed  //显示控制设置为脉冲宽度14/16  
#define 	VK16K33B_PDUTY_15_16     0xee  //显示控制设置为脉冲宽度15/16  
#define 	VK16K33B_PDUTY_16_16     0xef  //显示控制设置为脉冲宽度16/16 

//以下管脚配置根据客户单片机做相应的修改 
#define VK16K33B_SCL_PIN    BIT15
#define VK16K33B_SCL_PORT   PB
#define VK16K33B_SCL_IO     PB15

#define VK16K33B_SDA_PIN    BIT5
#define VK16K33B_SDA_PORT   PB
#define VK16K33B_SDA_IO     PB5

//以下管脚输出定义根据客户单片机做相应的修改
#define VK16K33B_SCL_H() 				VK16K33B_SCL_IO = 1 
#define VK16K33B_SCL_L() 				VK16K33B_SCL_IO = 0 

#define VK16K33B_SDA_H() 				VK16K33B_SDA_IO = 1 
#define VK16K33B_SDA_L() 				VK16K33B_SDA_IO = 0 

#define VK16K33B_GET_SDA() 			VK16K33B_SDA_IO

//SDA脚设为输入脚，用于读ACK和读RAM数据
#define VK16K33B_SET_SDA_IN() 	{\
	GPIO_SetMode(VK16K33B_SDA_PORT, VK16K33B_SDA_PIN, GPIO_MODE_INPUT);\
}
//SDA脚设为输出脚，用于发送命令和写显示RAM数据
#define VK16K33B_SET_SDA_OUT() 	{\
	GPIO_SetMode(VK16K33B_SDA_PORT, VK16K33B_SDA_PIN, GPIO_MODE_OUTPUT);\
}

/* Exported functions ------------------------------------------------------- */
void VK16K33B_Init(void);
void VK16K33B_DisAll(unsigned char dat);
void VK16K33B_DisDotOn(unsigned char seg,unsigned char com);
void VK16K33B_DisDotOff(unsigned char seg,unsigned char com);
unsigned char VK16K33B_Enter_PowerOff(void);
void VK16K33B_Exit_PowerOff(void);

void VK16K33B_Main(void);
#endif  /*__VK16K33B_H*/

/************************END OF FILE****/
