/* Copyright (C) 2007 DJ Delorie Licensed under the terms of the GNU General Public license, either version 2 or (your choice) any later version. */ #include "r8c27.h" #define A 0x04 #define B 0x40 #define C 0x01 #define D 0x10 #define E 0x08 #define F 0x80 #define G 0x20 #define H 0x02 static unsigned char font[] = { A|B|C|D|E|F, B|C, A|B|G|E|D, A|B|G|C|D, F|G|B|C, A|F|G|C|D, A|F|E|D|C|G, A|B|C, A|B|C|D|E|F|G, G|F|A|B|C|D, E|F|A|B|C|G, F|E|G|C|D, A|F|E|D, B|C|G|E|D, A|F|G|E|D, A|F|G|E }; static volatile int tick; static char digits[8]; static int didx = 0; static __attribute__((interrupt)) timer_ra_isr () { unsigned char c; if (tick) tick--; pd1 = 0; c = font[digits[didx]]; if (didx == 4) c |= H; prcr.prc2 = 1; /* disable pd0 protection */ pd0 = c; pd1 = 1 << didx; didx = (didx+1) & 7; } main() { unsigned int i = 0; unsigned int j = 0; unsigned int b = 0; /* TIMERS */ tracr.b = 0x00; traioc.b = 0x00; tramr.b = 0x00; /* timer mode, f1 */ trapre = 100; /* prescaler */ tra = 200; /* cycle count */ set_ivect (timer_ra_isr, ivec_timer_ra); traic = 5; tracr.tstart = 1; /* PORTS */ p1drr = 0xff; p0 = 0xff; p1 = 0x00; prcr.prc2 = 1; /* disable pd0 protection */ pd0 = 0x18; pd1 = 0x18; /* MAIN */ b = 0x01; for (i=0; i<8; i++) digits[i] = 0; i = 0; j = 0; while (1) { while (tick) ; tick = 1; for (i=7; i>=0; i--) if (digits[i] == 9) digits[i] = 0; else { digits[i]++; break; } } }