Initial commit
This commit is contained in:
31
first/cc/blinky.c
Normal file
31
first/cc/blinky.c
Normal file
@@ -0,0 +1,31 @@
|
||||
// let's write blinky.c
|
||||
|
||||
#define LED_ADDR ((volatile char*)0xC000)
|
||||
|
||||
#define led_write(x) (*LED_ADDR = (x))
|
||||
|
||||
#define CYCLES_PER_MS 6666 // ish
|
||||
|
||||
void busy_sleep_1ms() {
|
||||
for (int i = 0; i < CYCLES_PER_MS; ++i) {
|
||||
// nothing
|
||||
}
|
||||
}
|
||||
|
||||
/** waits a general amount of time */
|
||||
void busy_sleep(int ms) {
|
||||
for (int i = 0; i < ms; ++i) {
|
||||
busy_sleep_1ms();
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int onoff = 0;
|
||||
while (1) {
|
||||
led_write(onoff);
|
||||
busy_sleep(100);
|
||||
onoff++;
|
||||
}
|
||||
|
||||
return 0; // actually unreachable
|
||||
}
|
Reference in New Issue
Block a user