Skip to content

Instantly share code, notes, and snippets.

@agrif
Created February 8, 2020 04:37
Show Gist options
  • Save agrif/df5353929a1f9a86e20a9bf329297ef4 to your computer and use it in GitHub Desktop.
Save agrif/df5353929a1f9a86e20a9bf329297ef4 to your computer and use it in GitHub Desktop.
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
__sfr __at 0x00 ioLED;
__sfr __at 0x10 ioID0;
__sfr __at 0x11 ioID1;
__sfr __at 0x12 ioID2;
__sfr __at 0x13 ioID3;
__sfr __at 0x14 ioID4;
__sfr __at 0x15 ioID5;
__sfr __at 0x16 ioID6;
__sfr __at 0x17 ioID7;
__sfr __at 0x20 ioSerialData;
__sfr __at 0x21 ioSerialRValid;
__sfr __at 0x22 ioSerialRAvailL;
__sfr __at 0x23 ioSerialRAvailH;
__sfr __at 0x24 ioSerialEnable;
__sfr __at 0x25 ioSerialInterrupt;
__sfr __at 0x26 ioSerialWSpaceL;
__sfr __at 0x27 ioSerialWSpaceH;
volatile __at 0x8000 uint8_t memID[8];
void putchar(char c) {
ioSerialData = c & 0xff;
}
char getchar(void) {
uint8_t data;
uint8_t valid;
while (true) {
data = ioSerialData;
valid = ioSerialRValid;
if (valid & (1 << 7))
return data;
}
}
void sleep(uint8_t amt) {
while (amt > 0) {
uint16_t counter = 0xffff;
while (counter > 0)
counter--;
amt--;
}
}
void copy_system_id(void) {
memID[0] = ioID0;
memID[1] = ioID1;
memID[2] = ioID2;
memID[3] = ioID3;
memID[4] = ioID4;
memID[5] = ioID5;
memID[6] = ioID6;
memID[7] = ioID7;
}
void main() {
char buffer[64];
unsigned int val;
copy_system_id();
while (true) {
printf("set LEDs to: ");
gets(buffer);
val = atoi(buffer);
val &= 0xff;
printf("setting LEDs to 0x%02x\n", val);
ioLED = val;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment