首页 > 代码库 > 回头看看 血氧鼠标
回头看看 血氧鼠标
昨晚听师兄讲新项目是怎么开展的。
1需求分析转化
鼠标功能(鼠标芯片)
血氧功能(血氧模块)
mcu功能(采集存储数据)
usb功能(有线和无线)
2开始工程
(1)芯片选型:要用多少接口,内部资源要多大,低功耗用L型的
(2)工程建立(加外设,初始化)
(3)模块初始化:设置功能函数,需要怎么使用资源。
(4)功能逻辑实现:要一个个外设开始调试(这个过程会反复验证)
3实现功能
一个个功能实现后,做整体测试。
二 师兄让我一段段解释代码
int main(void)
{
u8 t;
// SystemInit();
usb_port_set(0); //USB?è???a
delay_init(72); //?óê±3?ê??ˉ
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ó4k×??úó?óú′?·?êy?Y
Mass_Block_Size[0] =512;//òò?a?ò???úInità???éè??á?SD?¨μ?2ù×÷×??ú?a512??,?ùò??aà?ò??¨ê?512??×??ú.
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?ê??ˉ
Adc_Init(); //ADC3?ê??ˉ
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;
}
}
发现问题:
1 c语法:参数定义,解读功能函数,语法格式,函数调用。
2 逻辑:程序框图 ,功能实现逻辑。
3 自己做的速度:代码速度和准确率,移植,验证,调试错误。
解决办法:
1 c语法规范
2 做好外设初始化(熟悉手册)
3 积累逻辑力(多看新项目代码,多代码练习)
给的建议:
1别依赖别人帮忙解决问题
2推到历程自己重新做一次
3熟能生巧
4思路要明确
回头看看 血氧鼠标