update examples to use tinibios
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 2 Feb 2001 15:39:24 +0000 (15:39 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 2 Feb 2001 15:39:24 +0000 (15:39 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@564 4a8a32a2-be11-0410-ad9d-d568d2c75423

device/examples/ds390/clock390/Makefile
device/examples/ds390/clock390/clock390.c
device/examples/ds390/hello390/Makefile
device/examples/ds390/hello390/hello390.c
device/examples/ds390/i2c390/Makefile
device/examples/ds390/i2c390/ds1621.c
device/examples/ds390/i2c390/i2c390.c
device/examples/ds390/i2c390/pcf8591.c
device/examples/ds390/i2c390/pcf8591.h
device/lib/ds390/Makefile
device/lib/ds390/tinibios.c

index e5ebe0995d8039326b2dbed6b924c5e1314f287d..caa9b3a05b6e7a379300c8701caf9ad3758ce803 100644 (file)
@@ -3,16 +3,17 @@ CC = sdcc
 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) $<
index a2b0785ace59229731063366585e53ff3a2b5628..d1f12edb40e11811cd8a630fd63fa91814f40888 100644 (file)
@@ -1,64 +1,31 @@
-/* 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;
@@ -66,6 +33,12 @@ void main (void) {
        cpl P3.5 ; toggle led
       _endasm;
     }
+    if (Serial0CharArrived()) {
+      switch (getchar()) {
+      case '2': CpuSpeed(2); break;
+      case '4': CpuSpeed(4); break;
+      }
+    }
   }
 }
 
index 73cb15ae1440505744ae8f54e47150b5d5d457ad..e165af46e3a8d902cca5f3a474bd49ab98848b03 100644 (file)
@@ -1,10 +1,9 @@
-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
index b735641b51e1ef4676877d46c9fdb8418febd125..5504f736db3dec0637af9f93a8f4f8ea011354d1 100644 (file)
@@ -1,17 +1,5 @@
-/* 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...");
 }
index b6d233de71ff2285aac9ce2bf2675ea74223171f..d077d0f5bba3f2b6607ddbe36827b33301c811f0 100644 (file)
@@ -3,18 +3,17 @@ CC = sdcc
 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) $<
index f91ac5ffc54fb6f690535bdae3ece5d722bb0c7f..7592991b010118126b23dedf01ccfb78759bbaec 100644 (file)
@@ -1,7 +1,6 @@
-#include "i2clole.h"
-#include "ds1621.h"
-
+#include <tinibios.h>
 
+#include "ds1621.h"
 
 float ReadDS1621(char address) {
   float temperature;
index c034a6e7d145ae2119c73dbcb4acebad802e0e36..7bd00d377d57939c9939ea358337a2b9e6d516ea 100644 (file)
@@ -1,20 +1,3 @@
-/* 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"
index c6f3981ca9e8011cb668c0898a065568d7736f84..82d6420fc35ed7bbe7aa5e74e1e8a99567942df5 100644 (file)
@@ -1,4 +1,5 @@
-#include "i2clole.h"
+#include <tinibios.h>
+
 #include "pcf8591.h"
 
 unsigned char ReadPCF8591(char address, char channel) {
index 72f10b5a5b45930419cd2cd4b14a8275f82ea286..7e38b39d8bcf534419d92343bf66be89c44dd4dd 100644 (file)
@@ -1,2 +1,3 @@
 #define PCF8591_ID 0x90
+
 extern unsigned char ReadPCF8591(char address, char channel);
index 78a0ee898f903f68bfcf632bfaa6739b1da126f0..1ea1235e32c1f7a1801d135864c4237eea93819e 100755 (executable)
@@ -2,7 +2,7 @@ CC = ../../../bin/sdcc
 
 #VERBOSE = --verbose
 
-OBJECTS = tinibios.rel memcpyx.rel
+OBJECTS = tinibios.rel memcpyx.rel rtc390.rel lcd390.rel i2c390.rel
 
 SOURCES = $(patsubst %.rel,%.c,$(OBJECTS))
 
index 3a6743aad06fbd444b4f6f0b776d07909d672729..d70e4427cfbe8874f62a76526def2da11f9d46c6 100755 (executable)
@@ -44,7 +44,8 @@ unsigned char _sdcc_external_startup(void)
   // 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
@@ -61,13 +62,13 @@ unsigned char _sdcc_external_startup(void)
     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
@@ -357,7 +358,7 @@ void Serial1Init (unsigned long baud, unsigned char buffered) {
   // set the baud rate
   Serial1Baud(baud);
   
-  serial0Buffered=buffered;
+  serial1Buffered=buffered;
 
   if (buffered) {
     RI_1=TI_1=0; // clear "pending" interrupts
@@ -455,8 +456,7 @@ void Serial1Flush() {
 
 // 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;
 
@@ -469,27 +469,55 @@ void ClockInit() {
   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) {