一、题目内容分析
二、LCD单字符高亮显示实现
本次要求显示两个字符,此函数高亮pos及它后面一个字符
void highlight(uint8_t *str,uint8_t pos)
{
int i = 0;
for(i = 0; i <= 20; i++)
{
if(i != pos && i!= (pos+1))
LCD_DisplayChar(Line3,(320 - (16 * i)),str[i]);
}
LCD_SetBackColor(Yellow);
LCD_DisplayChar(Line3,(320 - (16 * pos)),str[pos]);
LCD_SetBackColor(Yellow);
LCD_DisplayChar(Line3,(320 - (16 * (pos+1))),str[pos+1]);
LCD_SetBackColor(Black);
}
三、EEPROM
我们主要编写这两个函数
//字节写函数
void at24c02_Byte_Write(unsigned char addr,unsigned char cSendByte);
//随机读
unsigned char at24c02_Byte_read(unsigned char addr);
找到竞赛平台里的资料
字节写:
- 起始信号
- 器件地址————write为低电平 -> 0xa0
- 等待应答
- 发送字节地址
- 等待应答
- 发送数据
- 等待应答
- 结束信号
//字节写函数
void at24c02_Byte_Write(unsigned char addr,unsigned char cSendByte)
{
I2CStart();
I2CSendByte(0xa0);
I2CWaitAck();
I2CSendByte(addr);
I2CWaitAck();
I2CSendByte(cSendByte);
I2CWaitAck();
I2CStop();
}
随机读时序
- 开始信号
- 器件地址写——0xa0
- 等待应答
- 发送字节地址
- 等待应答
- 器件地址读——0xa1
- 等待应答
- 接收字节
- 发送无应答
- 结束信号
//随机读
unsigned char at24c02_Byte_read(unsigned char addr)
{
unsigned char dat;
I2CStart();
I2CSendByte(0xa0);
I2CWaitAck();
I2CSendByte(addr);
I2CWaitAck();
I2CStart();
I2CSendByte(0xa1);
I2CWaitAck();
dat = I2CReceiveByte();
I2CSendNotAck();
I2CStop();
return dat;
}
四、usr.c
#include "usr.h"
/* values ------------------------------------------------------------------*/
char time_state = Runing;
struct keys key[4] = {0,0,0,0};
uint8_t storage_location = 1;
uint8_t hour = 1,min = 2,sec = 10;
char timer_run_flag = 0;
int hightlight_sel = -1;
unsigned char read_data = 0;
void read_initial_data(void){
hour = at24c02_Byte_read(1);