Stap 2: Het schrijven van Code In de KEIL
Nu, open In Keil, in Project-venster 'Configuratie' map. In open, ' Application/gebruiker' daar, open bestand 'main.c'. Scroll naar beneden terwijl lus, zoals weergegeven in figuur:
{Zie afbeelding [6]}
Nu, hier in dit while lus zullen we schrijven code om te schakelen led op of knop wordt ingedrukt en zwenking op vandoor wanneer knop is in versie staat. Dus, schrijf na coderegels in while lus:
//we configured our button as B1 so we will use 'B1_GPIO_Port' and 'B1_Pin'//this function 'HAL_GPIO_ReadPin()' will digitally read the status of givn pin//now if button is pressed it will return 0//and if button is released it will return 1if(HAL_GPIO_ReadPin(B1_GPIO_Port,B1_Pin)==0) //=> Button is Pressed{ //Switch LED ON. //remember that we have configured our LED as Ld2, so //this function 'HAL_GPIO_WritePin()' will digitally write on given pin //writting 1, will give HIGH output //writting 0, will give LOW ouptut HAL_GPIO_WritePin(Ld2_GPIO_Port,Ld2_Pin,1);}else //=>Button is released{ HAL_GPIO_WritePin(Ld2_GPIO_Port,Ld2_Pin,0);}
Nu, moet u Keil venster als volgt uitzien:
{Zie afbeelding [7]}
Na dit, klik nu op de knop opbouwen zoals in de vorige afbeelding. Dit zal u Project bouwen. Klik op de knop 'Laden' Laad nu, ook dit Project op uw bord STM32, zoals in de vorige afbeelding.