home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1991 / 08 / vansick / listing3.asc < prev    next >
Text File  |  1990-12-19  |  9KB  |  188 lines

  1.  
  2. 6805 'C' COMPILER V3.3    10-Jul-1990                                   PAGE  1
  3.  
  4.  
  5.                                   
  6.                                   #pragma option v
  7.                                   #include "hc05j1.h"
  8. 0000                              #pragma portrw PORTA @ 0x00;
  9. 0001                              #pragma portrw PORTB @ 0x01;
  10. 0003                              #pragma portr  PORTD @ 0x03;
  11. 0004                              #pragma portrw DDRA  @ 0x04;
  12. 0005                              #pragma portrw DDRB  @ 0x05;
  13. 0008                              #pragma portrw TCST  @ 0x08;
  14. 0009                              #pragma portrw TCNT  @ 0x09;
  15.                                   
  16. 07F0                              #pragma portrw __COPSVS @ 0x7f0;
  17. 07F8                              #pragma vector __TIMER @ 0x07f8;
  18. 07FA                              #pragma vector __IRQ @ 0x07fa;
  19. 07FC                              #pragma vector __SWI @ 0x07fc ;
  20. 07FE                              #pragma vector __RESET @ 0x07fe;
  21.                                   
  22.                                   #pragma has STOP ;
  23.                                   #pragma has WAIT ;
  24.                                   #pragma has MUL ;
  25.                                   
  26. 00C0 0040                         #pragma memory RAMPAGE0 [64] @ 0xc0;
  27. 0300 0400                         #pragma memory ROMPROG [1024] @ 0x300;
  28.                                   
  29. 0000                              #define RT0         0       /* bits of timer_cont_stat */
  30. 0001                              #define RT1         1
  31. 0004                              #define RTIE        4
  32. 0005                              #define TOFE        5
  33. 0006                              #define RTIF        6
  34. 0007                              #define TOF         7
  35.                                   #include "general.h"
  36.                                   
  37. 0001                              #define TRUE        1
  38. 0000                              #define FALSE       0
  39. 0001                              #define FOREVER     while(TRUE)
  40. 0002                              #define max(a,b)    (a) > (b) ? (a) : (b)
  41. 0003                              #define min(a,b)    (a) < (b) ? (a) : (b)
  42. 0004                              #define abs(a)      (a) >= 0 ? (a) : -(a)
  43.                                   
  44.                                   /* define the global variables  */
  45.                                   
  46. 00C0 00C1 00C2                    int hrs,mts,sec;    
  47. 00C3                              int count;
  48. 00C4 00C5 00C6                    int corr1,corr2,corr3;       /* used to correct the time errors  */
  49.                                   
  50.                                   main(void)
  51.                                   {
  52. 0300 3F C6     CLR    $C6             corr1=corr2=corr3=0;     /* time corrections */
  53. 0302 3F C5     CLR    $C5         
  54. 0304 3F C4     CLR    $C4         
  55. 0306 11 08     BCLR  0,$08            TCST.RT0=0;   /* 57.3 ms cop timer */
  56. 0308 13 08     BCLR  1,$08            TCST.RT1=0;   /* 8.192 ms RTI */
  57. 030A 18 08     BSET  4,$08            TCST.RTIE=1;  /* Turn on the RTI */
  58. 030C 1D 08     BCLR  6,$08            TCST.RTIF=0;  /* Reset interruput */
  59. 030E 1F 08     BCLR  7,$08            TCST.TOF=0;   /* flags */
  60.  
  61. 6805 'C' COMPILER V3.3    10-Jul-1990                                   PAGE  2
  62.  
  63.  
  64. 0310 9A        CLI                    CLI();                   /* turn on interrupt */
  65.                                   
  66.                                       FOREVER
  67.                                       {
  68. 0311 B6 C2     LDA    $C2                 if(sec==60)  /* do clock things each minute  */
  69. 0313 A1 3C     CMP    #$3C        
  70. 0315 26 18     BNE    $032F       
  71.                                           {
  72. 0317 3F C2     CLR    $C2                     sec=0;
  73. 0319 3C C1     INC    $C1                     if(++mts==60)
  74. 031B B6 C1     LDA    $C1         
  75. 031D A1 3C     CMP    #$3C        
  76. 031F 26 0E     BNE    $032F       
  77.                                               {
  78. 0321 3F C1     CLR    $C1                         mts=0;
  79. 0323 3C C0     INC    $C0                         if(++hrs==13)
  80. 0325 B6 C0     LDA    $C0         
  81. 0327 A1 0D     CMP    #$0D        
  82. 0329 26 04     BNE    $032F       
  83. 032B A6 01     LDA    #$01                            hrs=1;
  84. 032D B7 C0     STA    $C0         
  85.                                               }
  86.                                           }
  87. 032F 8F        WAIT                       WAIT();   /* wait here to save the energy  */
  88. 0330 20 DF     BRA    $0311           }
  89. 0332 81        RTS                }
  90.                                   
  91.                                   void __TIMER(void)   /* routine executed every RTI (8.192 ms) */
  92. 07F8 03 33                        {
  93. 0333 1F 08     BCLR  7,$08            TCST.TOF=0;  /* reset the interrupt */
  94. 0335 1D 08     BCLR  6,$08            TCST.RTIF=0; /* flags  */
  95.                                   
  96. 0337 3C C3     INC    $C3             if (++count==122)
  97. 0339 B6 C3     LDA    $C3         
  98. 033B A1 7A     CMP    #$7A        
  99. 033D 26 39     BNE    $0378       
  100.                                       {
  101. 033F 3C C2     INC    $C2                sec++;               /* increment seconds */
  102. 0341 3C C4     INC    $C4                if(++corr1==14)      /* To correct for 8.192 ms per tick */
  103. 0343 B6 C4     LDA    $C4         
  104. 0345 A1 0E     CMP    #$0E        
  105. 0347 26 2D     BNE    $0376       
  106.                                          {    
  107. 0349 3F C4     CLR    $C4                       corr1=0;         /* run 122 ticks per second for 13  */
  108. 034B 3C C5     INC    $C5                    if(++corr2==80)  /* seconds, and 123 for the 14th second */
  109. 034D B6 C5     LDA    $C5         
  110. 034F A1 50     CMP    #$50        
  111. 0351 26 1D     BNE    $0370       
  112.                                              {                /* With this algorithm there are 14.000128 */
  113. 0353 3F C5     CLR    $C5                            corr2=0;    /* actual seconds per 14 indicated.  Then run */
  114. 0355 3C C6     INC    $C6                            if(++corr3==4)
  115. 0357 B6 C6     LDA    $C6         
  116. 0359 A1 04     CMP    #$04        
  117. 035B 26 0F     BNE    $036C       
  118.                                                      {       
  119.  
  120. 6805 'C' COMPILER V3.3    10-Jul-1990                                   PAGE  3
  121.  
  122.  
  123. 035D A6 01     LDA    #$01                              count=1;
  124. 035F B7 C3     STA    $C3         
  125. 0361 B6 C6     LDA    $C6                               corr3==0;
  126. 0363 26 04     BNE    $0369       
  127. 0365 A6 01     LDA    #$01        
  128. 0367 20 01     BRA    $036A       
  129. 0369 4F        CLRA               
  130.                                                      } 
  131. 036A 20 02     BRA    $036E                          else
  132. 036C 3F C3     CLR    $C3                                count=0;/* 79 of these cycles followed by one cycle of */        
  133.                                                  }               /* 14 seconds with 122 ticks per second.  The */
  134. 036E 20 04     BRA    $0374                      else            /* elapsed time for this cycle is 1120.002048 */
  135. 0370 A6 FF     LDA    #$FF                          count=(-1);  /* seconds for and indicated time of 1120 */
  136. 0372 B7 C3     STA    $C3         
  137.                                          }                    /* seconds. Repeat this cycle 4 times and on*/
  138. 0374 20 02     BRA    $0378              else                 /* the last cycle drop one tick makes the */
  139. 0376 3F C3     CLR    $C3                    count=0;         /* indicate and elapsed time exactly 4480 seconds.*/
  140.                                      }
  141. 0378 80        RTI                }
  142.                                   
  143.                                   
  144.                                   
  145.                                   
  146.                                   
  147. 07FE 03 00                        
  148.  
  149. 6805 'C' COMPILER V3.3    10-Jul-1990                                   PAGE  4
  150.  
  151.  
  152.  
  153.  
  154. SYMBOL TABLE
  155.  
  156. LABEL        VALUE  LABEL        VALUE  LABEL        VALUE  LABEL        VALUE  
  157.  
  158. DDRA         0004 | DDRB         0005 | FALSE        0000 | PORTA        0000 
  159. PORTB        0001 | PORTD        0003 | RT0          0000 | RT1          0001 
  160. RTIE         0004 | RTIF         0006 | TCNT         0009 | TCST         0008 
  161. TOF          0007 | TOFE         0005 | TRUE         0001 | __COPSVS     07F0 
  162. __IRQ        07FA | __RESET      07FE | __STARTUP    0000 | __SWI        07FC 
  163. __TIMER      0333 | corr1        00C4 | corr2        00C5 | corr3        00C6 
  164. count        00C3 | hrs          00C0 | main         0300 | mts          00C1 
  165. sec          00C2 | 
  166.  
  167.  
  168. MEMORY USAGE MAP ('X' = Used, '-' = Unused)
  169.  
  170. 0300 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
  171. 0340 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXX-------
  172. 0380 : ---------------- ---------------- ---------------- ----------------
  173. 03C0 : ---------------- ---------------- ---------------- ----------------
  174.  
  175. 0700 : ---------------- ---------------- ---------------- ----------------
  176. 0740 : ---------------- ---------------- ---------------- ----------------
  177. 0780 : ---------------- ---------------- ---------------- ----------------
  178. 07C0 : ---------------- ---------------- ---------------- --------XX----XX
  179.  
  180. All other memory blocks unused.
  181.  
  182.  
  183.  
  184. Errors             :    0
  185. Warnings           :    0
  186.  
  187.  
  188.