初级会员
- 积分
- 134
- 金钱
- 134
- 注册时间
- 2018-3-26
- 在线时间
- 286 小时
|
30金钱
- #include "led.h"
- #include "delay.h"
- #include "key.h"
- #include "sys.h"
- #include "usart.h"
- #include "timer.h"
- #include "stmflash.h"
- #define FLASH_SAVE_ADDR 0X08001000
- int str;
- int main(void)
- {
- u8 len;
- int t;
- u8 datatemp[2];
- delay_init();
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
- uart_init(115200);
- LED_Init();
- TIM1_PWM_Init(8999, 0);
- TIM2_PWM_Init(8999, 0);
- TIM3_PWM_Init(8999, 0);
- TIM4_PWM_Init(8999, 0);
-
- // STMFLASH_Write(FLASH_SAVE_ADDR,(u16*)str,SIZE);
- STMFLASH_Read(FLASH_SAVE_ADDR,(u16*)datatemp,2);
-
- while(1)
- {
- if(USART_RX_STA&0x8000)
- {
- len=USART_RX_STA&0x3fff;
-
- for(t=0;t<len;t++)
- {
- while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);
- }
-
- USART_RX_STA=0;
- if((0x16==USART_RX_BUF[0])&&(0x09==USART_RX_BUF[1])&&0x01==USART_RX_BUF[2]&&0xB5==USART_RX_BUF[3]&&0xAA==USART_RX_BUF[4]&&0x11==USART_RX_BUF[5])
- {
- PWM_control(10);
- str=10;
- STMFLASH_Write(FLASH_SAVE_ADDR,(u16*)str,2);
- }
- else if((0x16==USART_RX_BUF[0])&&(0x09==USART_RX_BUF[1])&&0x02==USART_RX_BUF[2]&&0xB5==USART_RX_BUF[3]&&0xAA==USART_RX_BUF[4]&&0x11==USART_RX_BUF[5])
- {
- PWM_control(70);
- str=70;
- }
- else if((0x16==USART_RX_BUF[0])&&(0x09==USART_RX_BUF[1])&&0x03==USART_RX_BUF[2]&&0xB5==USART_RX_BUF[3]&&0xAA==USART_RX_BUF[4]&&0x11==USART_RX_BUF[5])
- {
- PWM_control(170);
- str=170;
- }
- else if((0x16==USART_RX_BUF[0])&&(0x09==USART_RX_BUF[1])&&0x04==USART_RX_BUF[2]&&0xB5==USART_RX_BUF[3]&&0xAA==USART_RX_BUF[4]&&0x11==USART_RX_BUF[5])
- {
- PWM_control(270);
- str=270;
- }
- else if((0x16==USART_RX_BUF[0])&&(0x09==USART_RX_BUF[1])&&0x05==USART_RX_BUF[2]&&0xB5==USART_RX_BUF[3]&&0xAA==USART_RX_BUF[4]&&0x11==USART_RX_BUF[5])
- {
- PWM_control(370);
- str=370;
- }
- else if((0x16==USART_RX_BUF[0])&&(0x09==USART_RX_BUF[1])&&0x06==USART_RX_BUF[2]&&0xB5==USART_RX_BUF[3]&&0xAA==USART_RX_BUF[4]&&0x11==USART_RX_BUF[5])
- {
- PWM_control(470);
- str=470;
- }
- else if((0x16==USART_RX_BUF[0])&&(0x09==USART_RX_BUF[1])&&0x07==USART_RX_BUF[2]&&0xB5==USART_RX_BUF[3]&&0xAA==USART_RX_BUF[4]&&0x11==USART_RX_BUF[5])
- {
- PWM_control(570);
- str=570;
- }
- else if((0x16==USART_RX_BUF[0])&&(0x09==USART_RX_BUF[1])&&0x08==USART_RX_BUF[2]&&0xB5==USART_RX_BUF[3]&&0xAA==USART_RX_BUF[4]&&0x11==USART_RX_BUF[5])
- {
- PWM_control(670);
- str=670;
- }
-
- }
-
- if(str==10)
- {
- PWM_control(str);
- LED1=0;
- delay_ms(200);
- LED1=1;
- delay_ms(200);
- }
- }
-
- }
复制代码 工作是这样的,通过串口通信,PWM控制LED的亮度,这点已经完成。现在的问题是,想掉电保护掉电前的参数 ,使得下一次上电后继续亮起前一次上电的亮度值,这一部分怎么修改?
|
|