typedef unsigned char byte;
typedef unsigned short word;

int main() {
	volatile byte* tflg1=(byte*)0x1023;
	volatile byte* tflg2=(byte*)0x1025;
	volatile byte* tctl2=(byte*)0x1021;
	volatile byte* doa=(byte*)0x1204;
	volatile byte* dob=(byte*)0x1205;
	volatile byte* da= (byte*)0x1206;
	volatile byte* db= (byte*)0x1207;
	word pulsen, RT_perioden, aantal_leds;
	byte patronen_a[13]={0x00,0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff,0xff,0xff,0xff,0xff};
	byte patronen_b[13]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0f};

	*tctl2=0x10;
	*da=0xff;
	*db=0x0f;
	while (1) {
		pulsen=0;
		RT_perioden=488;
		do {
			if ((*tflg1&0x04)==0x04) {
				*tflg1=0x04;
				pulsen=pulsen+1;
			}
			if ((*tflg2&0x40)==0x40) {
				*tflg2=0x40;
				RT_perioden=RT_perioden-1;
			}
		}
		while (RT_perioden!=0);
		aantal_leds=pulsen*25/100; /* nog afregelen! */	
		if (aantal_leds>12) {
			aantal_leds=12;
		}
		*doa=patronen_a[aantal_leds];
		*dob=patronen_b[aantal_leds];
	}
	return 0;
}
