Error Handling in C (PI5): Unterschied zwischen den Versionen
Die Seite wurde neu angelegt: „Since we currently don't have a way to display information directly to us, we'll use the LED to indicate when something goes wrong. To do this, we’ll create a function that displays an error code using the LED. We will extend our "led.c" code with the following function: <syntaxhighlight lang="C"> void LED_Error(u32 errorcode) { while (TRUE) { for (u32 z = 0; z < errorcode; z++) { LED_on(); // Turn the LED on…“ |
KKeine Bearbeitungszusammenfassung |
||
| (2 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
| Zeile 38: | Zeile 38: | ||
Until we have a better way to display errors, we will use this function. | Until we have a better way to display errors, we will use this function. | ||
You can download the source code as a ZIP file from the following link: https://www.satyria.de/arm/sources/C/error.zip | |||
----- | |||
{| style="width: 100%; | |||
| style="width: 33%;" | [[Making the LED Blink in C (PI5)|< Back (Making the LED Blink in C (PI5))]] | |||
| style="width: 33%; text-align:center;" | [[English|< Home >]] | |||
| style="width: 33%; text-align:right;" | [[Graphics in C (PI5)|Next (Graphics in C (PI5)) >]] | |||
|} | |||
Aktuelle Version vom 23. August 2024, 12:01 Uhr
Since we currently don't have a way to display information directly to us, we'll use the LED to indicate when something goes wrong. To do this, we’ll create a function that displays an error code using the LED.
We will extend our "led.c" code with the following function:
void LED_Error(u32 errorcode)
{
while (TRUE)
{
for (u32 z = 0; z < errorcode; z++)
{
LED_on(); // Turn the LED on
wait(0x100000); // Short wait time
LED_off(); // Turn the LED off
wait(0x100000); // Short wait time
}
wait(0x100000); // Additional wait time to make the error code recognizable
}
}
This function will make the LED blink according to the error code provided. The error code indicates how many times the LED blinks before a short pause occurs.
To test the function, we will modify our "main.c" code as follows:
//
// kernel.c
//
#include "led.h"
#include "time.h"
int main (void)
{
LED_off(); // Turn off the LED first
LED_Error(2); // Test error code 2
}
First, we turn off the LED. Then, we test the new function with "LED_Error(2)." This will cause the LED to blink twice in quick succession, pause briefly, and then repeat this sequence.
Until we have a better way to display errors, we will use this function.
You can download the source code as a ZIP file from the following link: https://www.satyria.de/arm/sources/C/error.zip
| < Back (Making the LED Blink in C (PI5)) | < Home > | Next (Graphics in C (PI5)) > |