home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
drdobbs
/
1991
/
08
/
vansick
/
listing3.asc
< prev
next >
Wrap
Text File
|
1990-12-19
|
9KB
|
188 lines
6805 'C' COMPILER V3.3 10-Jul-1990 PAGE 1
#pragma option v
#include "hc05j1.h"
0000 #pragma portrw PORTA @ 0x00;
0001 #pragma portrw PORTB @ 0x01;
0003 #pragma portr PORTD @ 0x03;
0004 #pragma portrw DDRA @ 0x04;
0005 #pragma portrw DDRB @ 0x05;
0008 #pragma portrw TCST @ 0x08;
0009 #pragma portrw TCNT @ 0x09;
07F0 #pragma portrw __COPSVS @ 0x7f0;
07F8 #pragma vector __TIMER @ 0x07f8;
07FA #pragma vector __IRQ @ 0x07fa;
07FC #pragma vector __SWI @ 0x07fc ;
07FE #pragma vector __RESET @ 0x07fe;
#pragma has STOP ;
#pragma has WAIT ;
#pragma has MUL ;
00C0 0040 #pragma memory RAMPAGE0 [64] @ 0xc0;
0300 0400 #pragma memory ROMPROG [1024] @ 0x300;
0000 #define RT0 0 /* bits of timer_cont_stat */
0001 #define RT1 1
0004 #define RTIE 4
0005 #define TOFE 5
0006 #define RTIF 6
0007 #define TOF 7
#include "general.h"
0001 #define TRUE 1
0000 #define FALSE 0
0001 #define FOREVER while(TRUE)
0002 #define max(a,b) (a) > (b) ? (a) : (b)
0003 #define min(a,b) (a) < (b) ? (a) : (b)
0004 #define abs(a) (a) >= 0 ? (a) : -(a)
/* define the global variables */
00C0 00C1 00C2 int hrs,mts,sec;
00C3 int count;
00C4 00C5 00C6 int corr1,corr2,corr3; /* used to correct the time errors */
main(void)
{
0300 3F C6 CLR $C6 corr1=corr2=corr3=0; /* time corrections */
0302 3F C5 CLR $C5
0304 3F C4 CLR $C4
0306 11 08 BCLR 0,$08 TCST.RT0=0; /* 57.3 ms cop timer */
0308 13 08 BCLR 1,$08 TCST.RT1=0; /* 8.192 ms RTI */
030A 18 08 BSET 4,$08 TCST.RTIE=1; /* Turn on the RTI */
030C 1D 08 BCLR 6,$08 TCST.RTIF=0; /* Reset interruput */
030E 1F 08 BCLR 7,$08 TCST.TOF=0; /* flags */
6805 'C' COMPILER V3.3 10-Jul-1990 PAGE 2
0310 9A CLI CLI(); /* turn on interrupt */
FOREVER
{
0311 B6 C2 LDA $C2 if(sec==60) /* do clock things each minute */
0313 A1 3C CMP #$3C
0315 26 18 BNE $032F
{
0317 3F C2 CLR $C2 sec=0;
0319 3C C1 INC $C1 if(++mts==60)
031B B6 C1 LDA $C1
031D A1 3C CMP #$3C
031F 26 0E BNE $032F
{
0321 3F C1 CLR $C1 mts=0;
0323 3C C0 INC $C0 if(++hrs==13)
0325 B6 C0 LDA $C0
0327 A1 0D CMP #$0D
0329 26 04 BNE $032F
032B A6 01 LDA #$01 hrs=1;
032D B7 C0 STA $C0
}
}
032F 8F WAIT WAIT(); /* wait here to save the energy */
0330 20 DF BRA $0311 }
0332 81 RTS }
void __TIMER(void) /* routine executed every RTI (8.192 ms) */
07F8 03 33 {
0333 1F 08 BCLR 7,$08 TCST.TOF=0; /* reset the interrupt */
0335 1D 08 BCLR 6,$08 TCST.RTIF=0; /* flags */
0337 3C C3 INC $C3 if (++count==122)
0339 B6 C3 LDA $C3
033B A1 7A CMP #$7A
033D 26 39 BNE $0378
{
033F 3C C2 INC $C2 sec++; /* increment seconds */
0341 3C C4 INC $C4 if(++corr1==14) /* To correct for 8.192 ms per tick */
0343 B6 C4 LDA $C4
0345 A1 0E CMP #$0E
0347 26 2D BNE $0376
{
0349 3F C4 CLR $C4 corr1=0; /* run 122 ticks per second for 13 */
034B 3C C5 INC $C5 if(++corr2==80) /* seconds, and 123 for the 14th second */
034D B6 C5 LDA $C5
034F A1 50 CMP #$50
0351 26 1D BNE $0370
{ /* With this algorithm there are 14.000128 */
0353 3F C5 CLR $C5 corr2=0; /* actual seconds per 14 indicated. Then run */
0355 3C C6 INC $C6 if(++corr3==4)
0357 B6 C6 LDA $C6
0359 A1 04 CMP #$04
035B 26 0F BNE $036C
{
6805 'C' COMPILER V3.3 10-Jul-1990 PAGE 3
035D A6 01 LDA #$01 count=1;
035F B7 C3 STA $C3
0361 B6 C6 LDA $C6 corr3==0;
0363 26 04 BNE $0369
0365 A6 01 LDA #$01
0367 20 01 BRA $036A
0369 4F CLRA
}
036A 20 02 BRA $036E else
036C 3F C3 CLR $C3 count=0;/* 79 of these cycles followed by one cycle of */
} /* 14 seconds with 122 ticks per second. The */
036E 20 04 BRA $0374 else /* elapsed time for this cycle is 1120.002048 */
0370 A6 FF LDA #$FF count=(-1); /* seconds for and indicated time of 1120 */
0372 B7 C3 STA $C3
} /* seconds. Repeat this cycle 4 times and on*/
0374 20 02 BRA $0378 else /* the last cycle drop one tick makes the */
0376 3F C3 CLR $C3 count=0; /* indicate and elapsed time exactly 4480 seconds.*/
}
0378 80 RTI }
07FE 03 00
6805 'C' COMPILER V3.3 10-Jul-1990 PAGE 4
SYMBOL TABLE
LABEL VALUE LABEL VALUE LABEL VALUE LABEL VALUE
DDRA 0004 | DDRB 0005 | FALSE 0000 | PORTA 0000
PORTB 0001 | PORTD 0003 | RT0 0000 | RT1 0001
RTIE 0004 | RTIF 0006 | TCNT 0009 | TCST 0008
TOF 0007 | TOFE 0005 | TRUE 0001 | __COPSVS 07F0
__IRQ 07FA | __RESET 07FE | __STARTUP 0000 | __SWI 07FC
__TIMER 0333 | corr1 00C4 | corr2 00C5 | corr3 00C6
count 00C3 | hrs 00C0 | main 0300 | mts 00C1
sec 00C2 |
MEMORY USAGE MAP ('X' = Used, '-' = Unused)
0300 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
0340 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXX-------
0380 : ---------------- ---------------- ---------------- ----------------
03C0 : ---------------- ---------------- ---------------- ----------------
0700 : ---------------- ---------------- ---------------- ----------------
0740 : ---------------- ---------------- ---------------- ----------------
0780 : ---------------- ---------------- ---------------- ----------------
07C0 : ---------------- ---------------- ---------------- --------XX----XX
All other memory blocks unused.
Errors : 0
Warnings : 0