2021-05-24

在这//按键初始化函数
void KEY_Init(void) //IO初始化
{ 
 	GPIO_InitTypeDef GPIO_InitStructure;
	//初始化KEY0-->GPIOA.13,KEY1-->GPIOA.15  上拉输入
 	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC| RCC_APB2Periph_AFIO,ENABLE);//使能PORTA,PORTE时钟

	
	GPIO_InitStructure.GPIO_Pin  =  GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_12|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_8|GPIO_Pin_9;//PE2~4
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //设置成上拉输入
 	GPIO_Init(GPIOB, &GPIO_InitStructure);//初始化GPIOE2,3,4
	
	
	GPIO_InitStructure.GPIO_Pin  =  GPIO_Pin_15;//PE2~4
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //设置成上拉输入
 	GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化GPIOE2,3,4
	

  GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);
	
	key_value=255;

}
//按键处理函数
//返回按键值里插入代码片
//功    能:扣款和充值
//参数说明: dd_mode[IN]:命令字
//               0xC0 = 扣款
//               0xC1 = 充值
//          addr[IN]:钱包地址
//          pValue[IN]:4字节增(减)值,低位在前
//返    回: 成功返回MI_OK
/                
u8 PcdValue(u8 dd_mode, u8 addr, u8 *pValue)
{
	u8 status;
	u16 unLen;
	u8 i, ucComMF522Buf[MAXRLEN];

	ucComMF522Buf[0] = dd_mode;
	ucComMF522Buf[1] = addr;
	CalulateCRC(ucComMF522Buf, 2, &ucComMF522Buf[2]);

	status = PcdComMF522(PCD_TRANSCEIVE, ucComMF522Buf, 4, ucComMF522Buf,
			&unLen);

	if ((status != MI_OK) || (unLen != 4)
			|| ((ucComMF522Buf[0] & 0x0F) != 0x0A))
	{
		status = MI_ERR;
	}

	if (status == MI_OK)
	{
		for (i = 0; i < 16; i++)
		{
			ucComMF522Buf[i] = *(pValue + i);
		}
		CalulateCRC(ucComMF522Buf, 4, &ucComMF522Buf[4]);
		unLen = 0;
		status = PcdComMF522(PCD_TRANSCEIVE, ucComMF522Buf, 6, ucComMF522Buf,
				&unLen);
		if (status != MI_ERR)
		{
			status = MI_OK;
		}
	}

	if (status == MI_OK)
	{
		ucComMF522Buf[0] = PICC_TRANSFER;
		ucComMF522Buf[1] = addr;
		CalulateCRC(ucComMF522Buf, 2, &ucComMF522Buf[2]);

		status = PcdComMF522(PCD_TRANSCEIVE, ucComMF522Buf, 4, ucComMF522Buf,
				&unLen);

		if ((status != MI_OK) || (unLen != 4)
				|| ((ucComMF522Buf[0] & 0x0F) != 0x0A))
		{
			status = MI_ERR;
		}
	}
	return status;
}
void OLED_Init(void)
{ 	
 
 	 


	  GPIO_InitTypeDef GPIO_InitStructure;
	  //初始化KEY0-->GPIOA.13,KEY1-->GPIOA.15  上拉输入
 	  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO,ENABLE);//使能PORTA,PORTE时钟
    
	  GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_7|GPIO_Pin_6;//PE2~4
	  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 
	  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 	  GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化GPIOE2,3,4
	
	  GPIO_SetBits(GPIOA,GPIO_Pin_7|GPIO_Pin_6);	//PD3,PD6 输出高

	
	  OLED_SCLK_Set();delay_ms(100);
	  OLED_SDIN_Set();delay_ms(100);

  OLED_WR_Byte(0xAE,OLED_CMD);//--display off
	OLED_WR_Byte(0x00,OLED_CMD);//---set low column address
	OLED_WR_Byte(0x10,OLED_CMD);//---set high column address
	OLED_WR_Byte(0x40,OLED_CMD);//--set start line address  
	OLED_WR_Byte(0xB0,OLED_CMD);//--set page address
	OLED_WR_Byte(0x81,OLED_CMD); // contract control
	OLED_WR_Byte(0xFF,OLED_CMD);//--128   
	OLED_WR_Byte(0xA1,OLED_CMD);//set segment remap 
	OLED_WR_Byte(0xA6,OLED_CMD);//--normal / reverse
	OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)
	OLED_WR_Byte(0x3F,OLED_CMD);//--1/32 duty
	OLED_WR_Byte(0xC8,OLED_CMD);//Com scan direction
	OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset
	OLED_WR_Byte(0x00,OLED_CMD);//
	OLED_WR_Byte(0xD5,OLED_CMD);//set osc division
	OLED_WR_Byte(0x80,OLED_CMD);//
	OLED_WR_Byte(0xD8,OLED_CMD);//set area color mode off
	OLED_WR_Byte(0x05,OLED_CMD);//
	OLED_WR_Byte(0xD9,OLED_CMD);//Set Pre-Charge Period
	OLED_WR_Byte(0xF1,OLED_CMD);//
	
	OLED_WR_Byte(0xDA,OLED_CMD);//set com pin configuartion
	OLED_WR_Byte(0x12,OLED_CMD);//
	
	OLED_WR_Byte(0xDB,OLED_CMD);//set Vcomh
	OLED_WR_Byte(0x30,OLED_CMD);//
	
	OLED_WR_Byte(0x8D,OLED_CMD);//set charge pump enable
	OLED_WR_Byte(0x14,OLED_CMD);//
	
	OLED_WR_Byte(0xAF,OLED_CMD);//--turn on oled panel
}  


void ISD_PU(void)
{
ISD_SendData(0x11);
ISD_SendData(0x00);
nSS_1;
}
void ISD_WR_APC2(uint8_t apcdatl,uint8_t apcdath)
{
ISD_SendData(0x75);
ISD_SendData(apcdatl);
ISD_SendData(apcdath);
nSS_1;
}

void ISD_Rd_Status(void)
{
uint8_t i;
for(i=2;i>0;i–)
{;}
SR0_L=ISD_SendData(0x05);
SR0_H=ISD_SendData(0x00);
SR1=ISD_SendData(0x00);
nSS_1;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值