Category : Files from Magazines
Archive   : DDJ8_91.ZIP
Filename : 68HC05.ASC

 
Output of file : 68HC05.ASC contained in archive : DDJ8_91.ZIP
_C PROGRAMMING FOR THE 68HC05 MICROCONTROLLER_
by Truman T. Van Sickle


[LISTING ONE]

#pragma portrw PORTA @ 0x00;
#pragma portrw PORTA @ 0x01;
#pragma portrw DDRA @ 0x04;
#pragma portrw DDRB @ 0x05;
#pragma portrw TCST @ 0x08;
#pragma portr TCNT @ 0x09;

#pragma memory RAMPAGE0 [64] @ 0xc0;
#pragma memory ROMPROG [1024] @ 0x300;

#pragma has STOP ;
#pragma has WAIT ;
#pragma has MUL ;

#pragma vector __TIMER @ 0x07f8;
Š#pragma vector __IRQ @ 0x07fa;
#pragma vector __SWI @ 0x07fc ;
#pragma vector __RESET @ 0x07fe;





#pragma option v
#include "hc05j1.h"
#include "general.h"

/* define the global variables */
int hrs,mts,sec;
int count;
int corr1,corr2,corr3; /* used to correct the time errors */

main(void)
{
corr1=corr2=corr3=0; /* time corrections */
TCST.RT0=0; /* 57.3 ms cop timer */
TCST.RT1=0; /* 8.192 ms RTI */
TCST.RTIE=1; /* Turn on the RTI */
TCST.RTIF=0; /* Reset interruput */
TCST.TOF=0; /* flags */
CLI(); /* turn on interrupt */
FOREVER
{
if(sec==60) /* do clock things each minute */
{
sec=0;
if(++mts==60)
{
mts=0;
if(++hrs==13)
hrs=1;
}
}
WAIT(); /* wait here to save the energy */
}
}
void __TIMER(void) /* routine executed every RTI (8.192 ms) */
{
TCST.TOF=0; /* reset the interrupt */
TCST.RTIF=0; /* flags */
if (++count==122)
{
sec++; /* increment seconds */
if(++corr1==14) /* To correct for 8.192 ms per tick */
{
corr1=0; /* run 122 ticks per second for 13 */
if(++corr2==80) /* seconds, and 123 for the 14th second */
{ /* With this algorithm there are 14.000128 */
corr2=0; /* actual seconds per 14 indicated. Then run */
if(++corr3==4)
{
count=1;
corr3==0;
}
else
count=0;/* 79 of these cycles followed by 1 cycle of */
} /* 14 seconds with 122 ticks per second. The */
else /* elapsed time for this cycle = 1120.002048 */
count=(-1); /* seconds for and indicated time of 1120 */
} /* seconds. Repeat this cycle 4 times; on */
else /* last cycle drop 1 tick makes indicated &
count=0; /* elapsed time exactly 4480 seconds.*/
}
}




[LISTING THREE]

#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 /* 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; /* time corrections */
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 */
0310 9A CLI CLI(); /* turn on interrupt */
FOREVER
{
0311 B6 C2 LDA $C2 if(sec==60) /* do clock things */
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 energy */
0330 20 DF BRA $0311 }
0332 81 RTS }
void __TIMER(void)
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)
0343 B6 C4 LDA $C4
0345 A1 0E CMP #$0E
0347 26 2D BNE $0376
{
0349 3F C4 CLR $C4 corr1=0;
034B 3C C5 INC $C5 if(++corr2==80)
034D B6 C5 LDA $C5
034F A1 50 CMP #$50
0351 26 1D BNE $0370
{
0353 3F C5 CLR $C5 corr2=0;
0355 3C C6 INC $C6 if(++corr3==4)
0357 B6 C6 LDA $C6
0359 A1 04 CMP #$04
035B 26 0F BNE $036C
{
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;
}
036E 20 04 BRA $0374 else
0370 A6 FF LDA #$FF count=(-1);
0372 B7 C3 STA $C3
}
0374 20 02 BRA $0378 else
0376 3F C3 CLR $C3 count=0;
}
0378 80 RTI }
07FE 03 00

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





[LISTING FOUR

#include "hc05c8.h"
#include "general.h"

int hrs, mts, sec; /* global variables */
long count=1000;

struct bothbytes /* 16 bit int structure */
{
int hi;
int lo;
};
union isboth /* and union */
{
long l;
struct bothbytes b;
};
union isboth time_comp_count;
registera ac;
void main(void)
{
int key;
TCR.OCIE = 1; /* enable output compare interrupt */
CLI(); /* enable all interrupts */
FOREVER
{
if(sec==60) /* do clock things each minute */
{
sec=0;
if(++mts==60)
{
mts=0;
if(++hrs==13)
hrs=1;
}
}
WAIT(); /* wait here to save the energy */
}
}
void __TIMER(void) /* time interrupt service routine */
{
/* the program gets here every millisecond */
time_comp_count.b.hi = TCHI;
ac =TSR; /* Clear the tof bit */
time_comp_count.b.lo = TCLO;
time_comp_count.l += 500; /* 500 counts per millisecond */
OCHI = time_comp_count.b.hi;
ac = TSR; /* Clear ocf bit */
OCLO = time_comp_count.b.lo;
if(--count)
return ;
else
{
sec++; /* here every second */
count=1000;/* reset count to 1 second */
}
}


  3 Responses to “Category : Files from Magazines
Archive   : DDJ8_91.ZIP
Filename : 68HC05.ASC

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/