电容感应(滑块)没有在 eeprom 中存储数据?
#include"rtc.h"#include
#include"rtc.h"#define LED_OFF 0
#define LED_ON 1
void HandleError(void);
cy_en_em_eeprom_status_t eepromReturnValue;
void HandleError(void);
CY_ISR_PROTO(SwitchInterrupt);// 声明 ISR 原型
#if defined (__ICCARM__)
#pragma data_alignment = CY_FLASH_SIZEOF_ROW
const uint8_t Em_EEPROM_em_EepromStorage[Em_EEPROM_PHYSICAL_SIZE] = {0u};
#else
const uint8_t Em_EEPROM_em_EepromStorage[Em_EEPROM_PHYSICAL_SIZE]
__ALIGNED(CY_FLASH_SIZEOF_ROW) = {0u};
#endif
#define EEPROM_ADDR 0x000u
#define EEPROM_ADDR2 0x001u
#define EEPROM_ADDR3 0x003u
#define EEPROM_ADDR40x004u
#define EEPROM_ADDR5 0x005u
#define EEPROM_DATA_SIZE 2
uint8_t eepromData1[EEPROM_DATA_SIZE];
uint8_t eepromData2[EEPROM_DATA_SIZE];
uint8_t eepromData3[EEPROM_DATA_SIZE];
uint8_t eepromData4[EEPROM_DATA_SIZE];
uint8_t eepromData5[EEPROM_DATA_SIZE];
uint8_t count=0;
uint8_t count2=0;
uint8_t count3=0;
uint8_t count4=0;
uint8_t count5=0;
int main(void)
{
uint16 sliderval=0;
uint16 sliderval2=0;
uint16 sliderval3=0;
uint16 sliderval4=0;
uint16 sliderval5=0;
uint16 oldsliderval =0xFFFF;
uint16 oldsliderval2 =0xFFFF;
uint16 oldsliderval3 =0xFFFF;
uint16 oldsliderval4 =0xFFFF;
uint16 oldsliderval5 =0xFFFF;
CyGlobalIntEnable; /* 启用全局中断。 */
eepromReturnValue = Em_EEPROM_Init((uint32_t)Em_EEPROM_em_EepromStorage);
if(eepromReturnValue != CY_EM_EEPROM_SUCCESS)
{
HandleError();
}
LED_1_Write(LED_OFF);
LED_2_Write(LED_OFF);
LED_3_Write(LED_OFF);
LED_4_Write(LED_OFF);
LED_5_Write(LED_OFF);
Clock_Start();
PWM_Start();
UART_Start();
CapSense_Start();
CapSense_Ini
tializeAllBaselines();
CapSense_ScanEnabledWidgets();
Em_EEPROM_Read(EEPROM_ADDR, eepromData1[0], EEPROM_DATA_SIZE);
if(eepromData1[0] == 1)
{
LED_1_Write(LED_ON);
}
Em_EEPROM_Read(EEPROM_ADDR2, eepromData2[0], EEPROM_DATA_SIZE);
if(eepromData2[0] == 1)
{
LED_2_Write(LED_ON);
}
Em_EEPROM_Read(EEPROM_ADDR3, eepromData3[0], EEPROM_DATA_SIZE);
if(eepromData3[0] == 1)
{
LED_3_Write(LED_ON);
}
Em_EEPROM_Read(EEPROM_ADDR4, eepromData4[0], EEPROM_DATA_SIZE);
if(eepromData4[0] == 1)
{
LED_4_Write(LED_ON);
}
Em_EEPROM_Read(EEPROM_ADDR5, eepromData5[0], EEPROM_DATA_SIZE);
if(eepromData5[0] == 1)
{
LED_5_Write(LED_ON);
}
for(;;)
{if(!CapSense_IsBusy())
{
sliderval = CapSense_GetCentroidPos(CapSense_LINEARSLIDER0__LS);
sliderval2 = CapSense_GetCentroidPos(CapSense_LINEARSLIDER0__LS);
sliderval3 = CapSense_GetCentroidPos(CapSense_LINEARSLIDER0__LS);
sliderval4 = CapSense_GetCentroidPos(CapSense_LINEARSLIDER0__LS);
sliderval5 = CapSense_GetCentroidPos(CapSense_LINEARSLIDER0__LS);
if(sliderval != 0xFFFF sliderval != oldsliderval)
{
count = 0;
LED_1_Write(((sliderval>= 20) || (sliderval> 0)) ? led_on : led_off);
Em_EEPROM_Write(EEPROM_ADDR, sliderval, EEPROM_DATA_SIZE);
PWM_WriteCompare(sliderval);
oldsliderval = sliderval;
}
if(sliderval2 != 0xFFFF sliderval2 != oldsliderval2)
{
count2 = 0;
LED_2_Write(((sliderval2>= 40) || (sliderval2> 20)) ? led_on : led_off);
Em_EEPROM_Write(EEPROM_ADDR2, sliderval2, EEPROM_DATA_SIZE);
PWM_WriteCompare(sliderval2);
oldsliderval2 = sliderval2;
}
if(sliderval3 != 0xFFFF sliderval3 != oldsliderval3)
{
count3 = 0;
LED_3_Write(((sliderval3>= 60) || (sliderval3> 40)) ? led_on : led_off);
Em_EEPROM_Write(EEPROM_ADDR3, sliderval3, EEPROM_DATA_SIZE);
PWM_WriteCompare(sliderval3);
oldsliderval3 = sliderval3;
}
if(sliderval4 != 0xFFFF sliderval4 != oldsliderval4)
{
count4 = 0;
LED_4_Write(((sliderval4>= 80) || (sliderval4> 60)) ? led_on : led_off);
Em_EEPROM_Write(EEPROM_ADDR4, sliderval4, EEPROM_DATA_SIZE);
PWM_WriteCompare(sliderval4);
oldsliderval4 = sliderval4;
}
if(sliderval5 != 0xFFFF sliderval5 != oldsliderval5)
{
count5 = 0;
LED_5_Write(((sliderval5>= 100) || (sliderval5> 80)) ? led_on : led_off);
Em_EEPROM_Write(EEPROM_ADDR5, sliderval5, EEPROM_DATA_SIZE);
PWM_WriteCompare(sliderval5);
oldsliderval5 = sliderval5;
}
CapSense_UpdateEnabledBaselines();
CapSense_ScanEnabledWidgets();
}
}
}
void HandleError(void)
{
__disable_irq(); // 禁用所有中断
while(1u) {}// 无限循环以处理错误
}