5 // timer 0 used for systemclock
6 #define TIMER0_RELOAD_VALUE -OSCILLATOR/12/1000 // 0.999348ms for 11.059Mhz
8 // timer 1 used for baudrate generator
9 #define TIMER1_RELOAD_VALUE -(2*OSCILLATOR)/(32*12*BAUD)
11 static long data milliSeconds;
13 void ClockIrqHandler (void) interrupt 1 using 3 {
14 TL0 = TIMER0_RELOAD_VALUE&0xff;
15 TH0 = TIMER0_RELOAD_VALUE>>8;
19 // we can't just use milliSeconds
20 unsigned long ClockTicks(void) {
28 unsigned char _sdcc_external_startup() {
29 // initialize timer0 for system clock
30 TR0=0; // stop timer 0
31 TMOD =(TMOD&0xf0)|0x01; // T0=16bit timer
33 TL0 = -TIMER0_RELOAD_VALUE&0xff;
34 TH0 = -TIMER0_RELOAD_VALUE>>8;
35 milliSeconds=0; // reset system time
36 TR0=1; // start timer 0
37 ET0=1; // enable timer 0 interrupt
39 // initialize timer1 for baudrate
40 TR1=0; // stop timer 1
41 TMOD = (TMOD&0x0f)|0x20; // T1=8bit autoreload timer
42 // baud = ((2^SMOD)*xtal)/(32*12*(256-TH1))
43 PCON |= 0x80; // SMOD=1: double baudrate
44 TH1=TL1=TIMER1_RELOAD_VALUE;
45 TR1=1; // start timer 1
47 // initialize serial port
48 SCON=0x52; // mode 1, ren, txrdy, rxempty
50 EA=1; // enable global interrupt
64 void putchar(char c) {