This repository has been archived on 2024-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
justhomework/EmbededSTM32/lab4'/Core/Src/ZLG7290.c

49 lines
1.4 KiB
C
Raw Permalink Normal View History

2023-06-23 09:30:03 +00:00
#include "ZLG7290.h"
#define wAddr (uint16_t)0x70U //ZLG7290д<30><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
#define rAddr (uint16_t)0x71U //ZLG7290<39><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
#define DpramAddr (uint16_t)0x10 //ZLG7290<39><30>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD>ӵ<EFBFBD>ַ
#define KeyAddr (uint16_t)0x01 //ZLG7290<39><30>ֵ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD>ӵ<EFBFBD>ַ
static const uint8_t keyval[] = {0x03, 0x1c, 0x1b, 0x1a, 0x14, 0x13, 0x12, 0x0c, 0x0b, 0x0a, 0x19, 0x11, 0x09, 0x01, 0x02};
static const uint8_t SegCode[] = {0xfc, 0x0c, 0xda, 0xf2, 0x66, 0xb6, 0xbe, 0xe0, 0xfe, 0xe6, 0xee, 0x3e, 0x9c, 0x7a, 0x00}; //<2F><><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD>
extern I2C_HandleTypeDef hi2c1;
uint8_t ZLG7290_Read(void)
{
uint8_t i;
uint8_t buf[1];
while(HAL_I2C_Mem_Read (&hi2c1, rAddr, KeyAddr, 1, buf, 1, 0x10) != HAL_OK );
for(i = 0; i < 15; i++)
{
if(buf[0] == keyval[i]) break;
}
return i;
}
void ZLG7290_Write1Byte(uint16_t r, uint8_t *p) //дһλ<D2BB>ֶ<EFBFBD><D6B6><EFBFBD>
{
while(HAL_I2C_Mem_Write (&hi2c1, wAddr, r, 1, p, 1, 0x10) != HAL_OK);
}
void ZLG7290_Write(uint8_t *buf) //д8λ<38>ֶ<EFBFBD><D6B6><EFBFBD>
{
uint8_t DBuff[8];
uint8_t i;
uint16_t p = DpramAddr;
uint8_t *p1;
for(i = 0; i < 8; i++)
{
DBuff[i] = SegCode[buf[i]]; //<2F><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>
}
p1 = &DBuff[0]; //p1ָ<31><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>
for(i = 0; i < 8; i++)
{
ZLG7290_Write1Byte(p++, p1++); //<2F><><EFBFBD><EFBFBD>һ<EFBFBD>Σ<EFBFBD>дһλ<D2BB>ֶ<EFBFBD><D6B6><EFBFBD>
HAL_Delay(5);
}
}