Listen to my brother last night about how the new project was carried out.
1 Demand Analysis and transformation
Mouse function (mouse chip)
Blood oxygen function (blood oxygen module)
MCU functions (acquisition and storage data)
USB features (wired and wireless)
2 Starting the project
(1) Chip selection: How many interfaces to use, internal resources to how large, low power consumption with L-type
(2) Construction (addition of peripherals, initialization)
(3) Module initialization: Set function function, how to use resources.
(4) Functional logic implementation: to start a peripheral debugging (this process will be repeatedly verified)
3 Implementation Features
After each function realization, do the whole test.
Two seniors let me explain the code in a paragraph
int main (void)
{
U8 T;
Systeminit ();
Usb_port_set (0); Usb?è??? A
Delay_init (72); ? óê±3?ê?? ˉt
Key_init ();
Nvic_configuration ();
Uart_init (115200);
Spi_flash_init ();
if (spi_flash_type!=w25q64);//error! "); /?ì2a′í?ó
Else//spi FLASH? y3£
{
Mass_memory_size[0]=2046*4096;//1024*1024*8-4*1024;//oó4kx?? úó?óú′?? Êy? Y
Mass_block_size[0] =512;//òò?a?ò??? Úinità??? Éè?? á? Sd?¨μ?2ùx÷x?? ú?a512??,? ùò?? Aà?ò?? ¨ê?512?? X?? Ú.
MASS_BLOCK_COUNT[0]=MASS_MEMORY_SIZE[0]/MASS_BLOCK_SIZE[0];
}
Usb_interrupts_config ();
Set_usbclock ();
Usb_init ();
while ((bdevicestate! = configured));//μè′yusb??? ù3é1|.
Led_init (); Led??? Ú3?ê?? ˉt
Adc_init (); Adc3?ê?? ˉt
Ps2_init ();
Tim3_int_init (24, 7199);
Time_flag = 0;
printf ("3?ê??" ˉ\r\n ");//
Do
{
t = Init_mouse ();
#ifdef Debug
if (t)
printf ("error_code:%d\r\n", t);
else printf ("Êó±ê3?ê?? ˉ3é1|\r\n ");
#endif
}
while (t);
Tim_cmd (TIM3, DISABLE);
Spi_flash_read (BUFFER_OUT,SAVE_FLASH_ADDR, 8);
if (buffer_out[1]==0xff && buffer_out[2]==0xff && buffer_out[3]==0xff && buffer_out[4]==0xff && buffer_out[5]==0xff && Buffer_out[6]==0xff)
{
BUFFER_OUT[1] = 81;
BUFFER_OUT[2] = 58;
BUFFER_OUT[3] = 23;
BUFFER_OUT[4] = 86;
BUFFER_OUT[5] = 0;
BUFFER_OUT[6] = 50;
Spi_flash_write (BUFFER_OUT,SAVE_FLASH_ADDR, 8);
}
while (1)
{
if ((Ps2_status & 0x80) && (bdevicestate = = configured))//μ?μ?á?ò?′?êy? Y
{
if (ps2_data_buf[0]==0x07)//èy??? ü°′??
{
Delay (0xFFFFF);
Ps2_data_buf[0] = 0;
Usb_to_pc_send_data (ENDP2, Ps2_data_buf, 4);
Delay (0xFFFFF);
Bdevicestate = unconnected;
Key_state + +;
if (key_state = = 2) key_state = 0;
Usb_port_set (0);//usb?è??? A
Delay_ms (500);
Usb_init ();
Delay (0xFFFF);
while ((bdevicestate! = configured));//μè′yusb??? ù3é1|
Ps2_en_data_report ();//ê1?üêy? Y±¨??
}
Else
{
Usb_to_pc_send_data (ENDP2, Ps2_data_buf, 4);
Ps2_en_data_report ();//ê1?üêy? Y±¨??
}
Ps2_status = MOUSE;
#ifdef DEBUGPS2
printf ("ps2_data_buf[0]%d\r\n", ps2_data_buf[0]);
printf ("ps2_data_buf[1]%d\r\n", ps2_data_buf[1]);
printf ("ps2_data_buf[2]%d\r\n", ps2_data_buf[2]);
printf ("ps2_data_buf[3]%d\r\n", ps2_data_buf[3]);
#endif
}
use_flag=0;
Sao2process ();
use_flag=1;
if ((Data_valid = = 1) && (bdevicestate = = configured))
{
if (heart_rate>heart_rate1)
{
if ((heart_rate-heart_rate1) >=8) heart_rate_out=heart_rate1+8;
else heart_rate_out=heart_rate;
}
Else
{
if ((heart_rate1-heart_rate) >=8) heart_rate_out=heart_rate1-(heart_rate1-heart_rate)/2;
else heart_rate_out=heart_rate;
}
Heart_rate1=heart_rate_out;
Buffer_in[0] = 1;
BUFFER_IN[1] = heart_rate_out;
BUFFER_IN[2] = SaO2;
Usb_to_pc_send_data (ENDP1, buffer_in, 8);
printf ("ps2_data_buf[3]%d\r\n", SaO2);
Data_valid = 0;
No_finger = 0;
}
else if ((No_finger = = 1) && (bdevicestate = = configured))
{
Buffer_in[0] = 1;
BUFFER_IN[1] = text_1;
BUFFER_IN[2] = text_2;
Usb_to_pc_send_data (ENDP1, buffer_in, 8);
printf ("ps2_data_buf[3]%d\r\n", SaO2);
No_finger = 0;
Data_valid = 0;
heart_rate1=80;
}
}
Problem found:
1 c Syntax: parameter definition, interpretation function function, syntax format, function call.
2 Logic: Program block diagram, function realization logic.
3 Do your own speed: code speed and accuracy rate, porting, validation, debugging errors.
Workaround:
1 C Syntax specification
2 Do peripheral initialization (familiar with manual)
3 Accumulate logical force (see new Project code, multi-code exercise)
Advice for:
1 don't rely on others to help solve problems
2 push to the process and do it yourself again.
3 Practice makes perfect
4 Ideas to be clear
Look back at the blood Oxygen Mouse