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
2023-06-23 17:30:03 +08:00

48 lines
1.4 KiB
C
Executable file

#include "ZLG7290.h"
#define wAddr (uint16_t)0x70U //ZLG7290写器件地址
#define rAddr (uint16_t)0x71U //ZLG7290读器件地址
#define DpramAddr (uint16_t)0x10 //ZLG7290显示缓冲区起始子地址
#define KeyAddr (uint16_t)0x01 //ZLG7290键值寄存器子地址
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}; //定义字段码表
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) //写一位字段码
{
while(HAL_I2C_Mem_Write (&hi2c1, wAddr, r, 1, p, 1, 0x10) != HAL_OK);
}
void ZLG7290_Write(uint8_t *buf) //写8位字段码
{
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]]; //求各字符的字段码
}
p1 = &DBuff[0]; //p1指向待显示字符的字段码
for(i = 0; i < 8; i++)
{
ZLG7290_Write1Byte(p++, p1++); //调用一次,写一位字段码
HAL_Delay(5);
}
}