MFLAGS = -mds390 --model-flat24 --stack-10bit
LFLAGS = --xram-loc 0x100080 --code-loc 0x10000 -Wl-r
+OBJECTS = clock390.rel
+
all: clock390.hex
clean:
rm -f *~ \#* *.asm *.cdb *.rel *.hex *.ihx *.lst *.map *.rst *.sym *.lnk
-clock390.hex: clock390.ihx
+clock390.hex: $(OBJECTS)
+ $(CC) $(MFLAGS) $(LFLAGS) $(OBJECTS)
packihx clock390.ihx >clock390.hex
-
-clock390.ihx: clock390.rel lcd.rel
- $(CC) $(MFLAGS) $(LFLAGS) clock390.rel lcd.rel
+ #tinitalk -c execute clock390.hex
%.rel: %.c
$(CC) -c $(MFLAGS) $<
-/* This example compiles right out of the box for TINI after you did a
- make install of sdcc (latest revision :).
-
- Just do a "make" which compiles and compresses it a little.
- Than use JavaKit to load clock390.hex (it goes into bank 1, see Makefile)
- Type 'E' in JavaKit and enjoy :) */
-
-/* if you are using the (default) interrupt scheme for serial i/o,
- you need to include this in the main program, so the vector will
- be initialized */
-#include <serial390.h>
-
-#include <ds80c390.h>
#include <stdio.h>
-#include "lcd.h"
-
-volatile unsigned long milliSeconds=0;
-
-#define RELOAD_VALUE 18432000/2/1000 // appr. 1ms
-void Timer2Handler (void) interrupt 5 using 1 {
- TF2=0; // reset overflow flag
- milliSeconds++;
- // that's all for now :)
-}
-
-// we can't just use milliSeconds
-unsigned long GetMilliSeconds(void) {
- unsigned long ms;
- ET2=0;
- ms=milliSeconds;
- ET2=1;
- return ms;
-}
+/* If you don't have an lcd display, don't worry, it will just
+ toggle some bits in the void, but ok
+*/
+#define USE_LCD
void main (void) {
unsigned long ms, seconds, oldSeconds=-1;
- printf ("\n\rStarting timer 2 test.\n\r");
+ printf ("\nStarting systemclock test.\n");
- // initialise timer
- ET2=0; // disable timer interrupts initially
- T2CON=0; // stop, timer mode, autoreload
- T2MOD&=0xf4;
-
- TL2=RTL2=(-RELOAD_VALUE)&0xff;
- TH2=RTH2=(-RELOAD_VALUE)>>8;
- TR2=1; // run
-
- ET2=1; // enable timer interrupts
-
- // now do something
+#ifdef USE_LCD
LcdInit();
- LcdLPutString(0, "Testing timer2");
+ LcdLPutString(0, "Testing clock");
LcdLPutString(2, "ms: ");
+#endif
+
while (1) {
- ms=GetMilliSeconds();
+ ms=ClockTicks();
seconds=ms/1000;
+
+#ifdef USE_LCD
LcdLPrintf (2 + (4<<8), "%ld", ms);
+#endif
+
if (seconds!=oldSeconds) {
- printf ("%02d:%02d.%02d\n\r", (int)seconds/3600,
+ printf ("%02d:%02d.%02d\n", (int)seconds/3600,
(int)(seconds/60)%60,
(int)seconds%60);
oldSeconds=seconds;
cpl P3.5 ; toggle led
_endasm;
}
+ if (Serial0CharArrived()) {
+ switch (getchar()) {
+ case '2': CpuSpeed(2); break;
+ case '4': CpuSpeed(4); break;
+ }
+ }
}
}
-hello390.hex: hello390.ihx
- packihx hello390.ihx >hello390.hex
-
-hello390.ihx: hello390.c
+hello390.hex: hello390.c
sdcc -mds390 --model-flat24 --stack-10bit \
--xram-loc 0x100080 --code-loc 0x10000 \
-Wl-r hello390.c
+ packihx hello390.ihx >hello390.hex
+ #tinitalk -c execute hello390.hex
clean:
rm -f *~ \#* *.asm *.cdb *.rel *.hex *.ihx *.lst *.map *.rst *.sym *.lnk
-/* This example compiles right out of the box for TINI after you did a
- make install of sdcc (latest revision :).
-
- Just do a "make" which compiles and compresses it a little.
- Than use JavaKit to load hello390.hex (it goes into bank 1, see Makefile)
- Type 'E' in JavaKit and enjoy :) */
-
-/* if you are using the (default) interrupt scheme for serial i/o,
- you need to include this in the main program, so the vector will
- be initialized */
-#include <serial390.h>
-
#include <stdio.h>
void main (void) {
- printf ("\n\rHello from 390.\n\rSee you, bye...");
+ printf ("\nHello from 390.\nSee you, bye...");
}
MFLAGS = -mds390 --model-flat24 --stack-10bit
LFLAGS = --xram-loc 0x100080 --code-loc 0x10000 -Wl-r
+OBJECTS = i2c390.rel ds1621.rel pcf8591.rel
+
all: i2c390.hex
clean:
rm -f *~ \#* *.asm *.cdb *.rel *.hex *.ihx *.lst *.map *.rst *.sym *.lnk
-OBJECTS = i2c390.rel i2clole.rel ds1621.rel pcf8591.rel
-
-i2c390.hex: i2c390.ihx
- packihx i2c390.ihx >i2c390.hex
-
-i2c390.ihx: $(OBJECTS)
+i2c390.hex: $(OBJECTS)
$(CC) $(MFLAGS) $(LFLAGS) $(OBJECTS)
+ packihx i2c390.ihx >i2c390.hex
+ #tinitalk -c execute i2c390.hex
%.rel: %.c
$(CC) -c $(MFLAGS) $<
-#include "i2clole.h"
-#include "ds1621.h"
-
+#include <tinibios.h>
+#include "ds1621.h"
float ReadDS1621(char address) {
float temperature;
-/* This example compiles right out of the box for TINI after you did a
- make install of sdcc (latest revision :).
-
- It prints the value of the DS1621 temperature sensor (at address 2)
- and the 4 values of the PCF8591 ad-convertor (at address 0).
- It (ab)uses the CAN CTX and CTR pins of the DS80C390.
- Make sure you have pull-up resistors connected or it WON'T work.
-
- Just do a "make" which compiles and compresses it a little.
- Than use JavaKit to load i2c390.hex (it goes into bank 1, see Makefile)
- Type 'E' in JavaKit and enjoy :) */
-
-/* if you are using the (default) interrupt scheme for serial i/o,
- you need to include this in the main program, so the vector will
- be initialized */
-#include <serial390.h>
-
#include <stdio.h>
#include "ds1621.h"
-#include "i2clole.h"
+#include <tinibios.h>
+
#include "pcf8591.h"
unsigned char ReadPCF8591(char address, char channel) {
#define PCF8591_ID 0x90
+
extern unsigned char ReadPCF8591(char address, char channel);
#VERBOSE = --verbose
-OBJECTS = tinibios.rel memcpyx.rel
+OBJECTS = tinibios.rel memcpyx.rel rtc390.rel lcd390.rel i2c390.rel
SOURCES = $(patsubst %.rel,%.c,$(OBJECTS))
// CKCON|=0xc0;
// default stretch cycles for MOVX
- CKCON = (CKCON&0xf8)|(CPU_MOVX_STRETCH&0x07);
+ //CKCON = (CKCON&0xf8)|(CPU_MOVX_STRETCH&0x07);
+ CKCON=0xf9;
// use internal 4k RAM as data(stack) memory at 0x400000 and
// move CANx memory access to 0x401000 and upwards
pop ar0; lsb
- mov _ESP,#0x00; reinitialize the stack
- mov _SP,#0x00
-
mov _TA,#0xaa; timed access
mov _TA,#0x55
mov _ACON,#0x06; 24 bit addresses, 10 bit stack at 0x400000
+ mov _ESP,#0x00; reinitialize the stack
+ mov _SP,#0x00
+
; restore the 24-bit return address
push ar0; lsb
push ar1
// set the baud rate
Serial1Baud(baud);
- serial0Buffered=buffered;
+ serial1Buffered=buffered;
if (buffered) {
RI_1=TI_1=0; // clear "pending" interrupts
// now let's go for the clock stuff
-//#define TIMER_0_RELOAD_VALUE 18432000L/2/1000 // appr. 1ms
-
+// these REALLY need to be in data space for the irq routine!
static data unsigned long milliSeconds=0;
static data unsigned int timer0ReloadValue;
case 2: // not tested yet
default: timerReloadValue/=2; break;
}
- timer0ReloadValue=timerReloadValue;
+ timer0ReloadValue=~timerReloadValue;
// initialise timer 0
ET0=0; // disable timer interrupts initially
TCON = (TCON&0xcc)|0x00; // stop timer, clear overflow
TMOD = (TMOD&0xf0)|0x01; // 16 bit counter
- CKCON|=0x80; // timer uses xtal/4
+ CKCON|=0x08; // timer uses xtal/4
- TL0=~(timer0ReloadValue&0xff);
- TH0=~(timer0ReloadValue>>8);
+ TL0=timer0ReloadValue&0xff;
+ TH0=timer0ReloadValue>>8;
ET0=1; // enable timer interrupts
TR0=1; // start timer
}
+// This needs to be SUPER fast. What we really want is:
+
+#if 0
void ClockIrqHandler (void) interrupt 1 {
- // we have lost some time here
- TL0=~(timer0ReloadValue&0xff);
- TH0=~(timer0ReloadValue>>8);
+ TL0=timer0ReloadValue&0xff;
+ TH0=timer0ReloadValue>>8;
milliSeconds++;
- // that's all for now :)
}
+#else
+// but look at the code, and the pushes and pops, so:
+#pragma EXCLUDE b,dpl,dph,dpx
+void ClockIrqHandler (void) interrupt 1 {
+ _asm
+ mov _TL0,_timer0ReloadValue
+ mov _TH0,_timer0ReloadValue+1
+ mov a,#0x01
+ add a,_milliSeconds+0
+ mov _milliSeconds,a
+ jnc _ClockIrqHandlerDone
+ clr a
+ addc a,_milliSeconds+1
+ mov _milliSeconds+1,a
+ jnc _ClockIrqHandlerDone
+ clr a
+ addc a,_milliSeconds+2
+ mov _milliSeconds+1,a
+ jnc _ClockIrqHandlerDone
+ clr a
+ addc a,_milliSeconds+3
+ mov _milliSeconds+1,a
+ _ClockIrqHandlerDone:
+ _endasm;
+}
+#pragma EXCLUDE NONE
+#endif
// we can't just use milliSeconds
unsigned long ClockTicks(void) {