-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
84 lines (75 loc) · 1.76 KB
/
Copy pathmain.c
File metadata and controls
84 lines (75 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "stm32f10x.h" // Device header
#include "Delay.h"
#include "OLED.h"
#include "Key.h"
#include "PWM.h"
#include "AD.h"
#include "W25Q64.h"
/*uint8_t MID;
uint16_t DID;*/
uint8_t ArrayWrite[3];
uint8_t ArrayRead[3];
uint8_t KeyNum=0;
uint16_t ADValue=0;
float Voltage=0;
uint8_t Turn=0;
int main(void)
{
OLED_Init();
Key_Init();
PWM_Init();
AD_Init();
W25Q64_Init();
/*OLED_ShowString(1,1,"MID: DID:"); // EF 4017
W25Q64_ReadID(&MID,&DID);
OLED_ShowHexNum(1,5,MID,2);
OLED_ShowHexNum(1,12,DID,4);*/
OLED_ShowString(1,1,"Duty Cycle: %");
OLED_ShowString(2,1,"Voltage:0.00V");
while(1)
{
ADValue=AD_GetValue();
CCR_Value=(float)(ADValue)/4095*100;
Voltage=(float)ADValue/4095*3.3;
PWM_SetCompare1(CCR_Value); // 調整duty cycle
KeyNum=Key_GetNum();
if(KeyNum == 1)
{
ArrayWrite[0]=CCR_Value;
ArrayWrite[1]=Voltage;
ArrayWrite[2]=(uint8_t)(Voltage*100)%100;
W25Q64_SectorErase(0x000000);
W25Q64_PageProgram(0x000000,ArrayWrite,3);
OLED_ShowString(4,1,"Saved successful");
Delay_ms(3000);
OLED_ShowString(4,1," ");
}
if(KeyNum == 2 && Turn == 0)
{
W25Q64_ReadData(0x000000,ArrayRead,3);
OLED_Clear();
OLED_ShowString(1,1,"Last saved:");
OLED_ShowString(2,1,"Duty Cycle: %");
OLED_ShowString(3,1,"Voltage:0.00V");
OLED_ShowNum(2,13,ArrayRead[0],2);
OLED_ShowNum(3,9,ArrayRead[1],1);
OLED_ShowNum(3,11,ArrayRead[2],2);
Turn=1;
}
else if(KeyNum == 2 && Turn ==1)
{
OLED_Clear();
OLED_ShowString(1,1,"Duty Cycle: %");
OLED_ShowString(2,1,"Voltage:0.00V");
Turn=0;
}
if(Turn == 0)
{
OLED_ShowNum(1,13,CCR_Value,2);
OLED_ShowNum(2,9,Voltage,1);
OLED_ShowNum(2,11,(uint8_t)(Voltage*100)%100,2);
Turn=0;
}
Delay_ms(100);
}
}