Assembler
MC68HC11
1 decimal count output on PORTB
* Bootstrap Mode
PORTB   EQU  $1004

                ORG     $B600

START           ldaa    #$FF
		staa    PORTB
                clra

LOOP            inca
                cmpa    #10             ; T -> decimal
                blo     WRITE_PORTB
                clra
WRITE_PORTB     staa    PORTB

                ldx    #60000          ; delay time
next_x1         dex   
                cpx    #0   
                bne     next_x1

                BRA     LOOP
2 flashing lights left
* HC11 in Bootstrap Mode
PORTB   EQU  $1004

                ORG     $B600

START           ldaa    #$01
		staa    PORTB

LOOP            ldx    #60000          ; delay time
next_delay      dex   
                cpx    #0   
                bne     next_delay

                lsl     PORTB
                tst     PORTB
                bne     SHIFT_OKAY
                ldaa    #$01
		staa    PORTB
SHIFT_OKAY

                BRA     LOOP
3 flashing lights right
* Bootstrap Mode
PORTB   EQU  $1004

                ORG     $B600

START           ldaa    #$80
		staa    PORTB
               

LOOP            ldx    #60000          ; delay time
next_delay      dex   
                cpx    #0   
                bne     next_delay

                lsr     PORTB
                tst     PORTB
                bne     SHIFT_OKAY
                ldaa    #$80
		staa    PORTB
SHIFT_OKAY

                BRA     LOOP
4 flashing lights runs from left to right and back
PORTB   EQU  $1004

		ORG     $0
direction       RMB     1

                ORG     $B600

START           ldaa    #$01
		staa    PORTB
		clr 	direction
               
LOOP            ldx    #60000          ; delay time
next_delay      dex   
                cpx    #0   
                bne     next_delay

		tst     direction
		bne	GO_RIGHT
		lsl     PORTB
                tst     PORTB
                bne     SHIFT_OKAY
                ldaa    #$80
		staa	PORTB
                ldaa    #1
		staa    direction
                bra     SHIFT_OKAY

GO_RIGHT        lsr     PORTB
                tst     PORTB
                bne     SHIFT_OKAY
                ldaa    #$01
		staa    PORTB
		clr	direction
SHIFT_OKAY

                BRA     LOOP
5 Analog conversion from PE0 output on PORTB

PORTA   EQU $1000
PORTB   EQU $1004
ADCTL   EQU $1030
ADR1    EQU $1031
OPTION  EQU $1039


                ORG     $B600

START		LDAA 	#10011000B 	; enable ADC
		STAA 	OPTION

LOOP            LDAA	#0
		STAA	ADCTL          ; start conversion

                ldx    #$2000          ; delay time
next_delay      dex   
                cpx    #0   
                bne     next_delay

                ldaa    ADR1           ; read ADC value 
                staa    PORTB

		ldaa	PORTA		; blink
		eora	#$78
		staa	PORTA

                BRA     LOOP
6 Make analog conversion on PE1 and send byte over RS232
PORTA   EQU $1000
PORTB   EQU $1004
ADCTL   EQU $1030
ADR1    EQU $1031
OPTION  EQU $1039
SPCR    EQU $1028
BAUD    EQU $102B
SCCR1   EQU $102C
SCCR2   EQU $102D
SCSR    EQU $102E
SCDR    EQU $102F

                ORG     $B600

START		LDAA 	#%10011000 	;enable ADC
		STAA 	OPTION

		LDAA	#%00110000      ;    00110000 = 9600 BAUD
		STAA	BAUD            ;    00110011 = 1200 BAUD
		CLR 	SCCR1
		LDAA 	#$0C
		STAA 	SCCR2           ;RECEIVER & TRANS. ENABLED
		clr	SPCR

LOOP            LDAA	#1             ; Channel 1
		STAA	ADCTL          ; start conversion

                ldx    #$2000          ; delay time
next_delay      dex   
                cpx    #0   
                bne     next_delay

                ldaa    ADR1           ; read ADC value 
                staa    PORTB
		ldab	SCSR           ; read first Status
		staa	SCDR           ; save in TX Register

		ldaa	PORTA		; blink
		eora	#$78
		staa	PORTA

                BRA     LOOP
7 Make analog conversion on PE1 to control PWM value on PA6 and PA5
PORTA   EQU $1000
OC1M    EQU $100C
OC1D    EQU $100D
TOC1    EQU $1016
TOC2    EQU $1018
TOC3    EQU $101A
TOC4    EQU $101C
TOC5    EQU $101E
TCTL1   EQU $1020
TCTL2   EQU $1021
TMSK1   EQU $1022
TFLG1   EQU $1023
ADCTL   EQU $1030
ADR1    EQU $1031
OPTION  EQU $1039

BIT0    EQU 00000001B
BIT1    EQU 00000010B
BIT2    EQU 00000100B
BIT3    EQU 00001000B
BIT4    EQU 00010000B
BIT5    EQU 00100000B
BIT6    EQU 01000000B
BIT7    EQU 10000000B

******** interrupt vector for bootstrap mode **************
IRQTOC1		EQU	$100-33

                ORG $0
PWM             RMB 1

		ORG 	$B600

		LDAA 	#%10000000 	;enable ADC
		STAA 	OPTION


		LDAA	#$7E
		STAA	IRQTOC1
		LDX	#TOC1_INT
		STX	IRQTOC1+1

		LDAA	#%01010100      ; toggle PA6 PA5 PA4
		STAA	TCTL1

		LDAA    #01100000B
		STAA    OC1M		;PA6 PA5 under TOC1 control
		LDAA    #00100000B      ;PA6=0 PA5=1 if TOC1 interrupt
		STAA    OC1D

		LDAA	#BIT7		; enable TOC1 interrupt
		STAA	TMSK1

		CLI

LOOP            LDAA	#1             ; Channel 1
		STAA	ADCTL          ; start conversion

                ldx     #2000          ; delay time
next_delay      dex   
                cpx     #0   
                bne     next_delay

                ldaa    ADR1           ; read ADC value 
		staa    PWM
		cmpa    #20
		bhs	PWM_OKAY
		ldaa	#20
		staa	PWM
PWM_OKAY
		
		BRA	LOOP
*		=================

		ORG	$B740

TOC1_INT	LDAB    PWM
		CLRA
		LSLD
		ADDD	TOC1
                STD	TOC2
		STD     TOC3

		LDAA	TOC1
		ADDA	#2
		CLRB
		STD     TOC1     

		LDAA    PORTA     ; only control 
		EORA    #BIT3
		STAA    PORTA                

		LDAA	#BIT7     ;reset interrupt flag
		STAA	TFLG1

		RTI
7) PWM 3 phase output on PORTA
**** 3 PHASE PWM OUTPUT ****
pwm-sixp.gif

** The output frequency starts from 0Hz to 50Hz
** This program is tested on a HC11 board in extended mode
** eprom size 27C256
** if You change the start address from $8000 to $E000 eprom size 27C64
PORTA   EQU $0000
TCNT    EQU $000E
TOC1    EQU $0016
TOC2    EQU $0018
TOC3    EQU $001A
TOC4    EQU $001C
TOC5    EQU $001E
TCTL1   EQU $0020
TMSK1   EQU $0022
TFLG1   EQU $0023
OPTION  EQU $0039
INIT    EQU $003D

*----------------------------------------------------------------
		org   $0040
 
FREQ_PRESET	RMB	2	* 5000 => 50 Hz
FREQ_ACTUAL	RMB	2	* from 0 to 5000 => 0Hz to 50 Hz
V_MOT           RMB	1	* Voltage Motor 		
pwm		RMB	2       * temporary variable pwm3.inc
PTR_SINUS       RMB	4	* pointer for sinus table
PTR_ADD        	RMB	2	* pointer increase with this value
TEMP		RMB	2	* temporary variable

*----------------------------------------------------------------
*----------------------------------------------------------------

		org	$8000

START           clr     INIT+$1000      *  direct Adressing Mode
		sei
                clr     TMSK1

		LDAA    #10011011B      enable ADC,clock monitor,
		STAA    OPTION          and set COP timer delay
		TPA
                ORAA    #$80            disable STOP instruction
		TAP

		lds	#$FF
*--------------------------------
		ldx     #$40
clearram        clr     0,X
		inx
                cpx     #$0100
		blo     clearram
*---------------------------------------------
		ldaa	PORTA
		anda	#%11000111
		staa	PORTA
		ldaa    #%00010101      * Output Toggle bei Compares
		staa    TCTL1           * OC3, OC4 und OC5, Setzen bei OC2
		ldaa    #%10000000      * OC1 Interrupt freigeben
		staa    TMSK1           *

		ldd     #$FF69          * Output Compares initialisieren
		std     TOC1
		ldd     #$FF40
		std     TOC3
		std     TOC4
		std     TOC5
		ldd     #Sin000
		std     PTR_SINUS
*--------------------------------------------
                ldaa	#90
                staa	V_MOT
		ldd	#3000		  * 5000 => 50 Hz
                std	FREQ_PRESET
*		=============================
		ldaa    TCNT
		adda    #12
		staa    TOC1
		cli

		wai
*********************************************************************
*** BLOCK 1     7 x 128 µsec = 896 µsec
*********************************************************************
PWM3_LOOP       wai                   
		ldd	FREQ_ACTUAL
		addd	#1
		std	FREQ_ACTUAL
		cpd     FREQ_PRESET
		blt	RAMP_OK
		ldd	FREQ_PRESET
		std	FREQ_ACTUAL
RAMP_OK 
		wai                      

		ldd 	FREQ_ACTUAL
		LDX	#4200  		        
		IDIV
		STX	TEMP        		remainder in D

                wai 
                     
		LDX	#4200
		FDIV
   
                wai  

		XGDX
		TAB
		LDAA	TEMP+1
		STD	PTR_ADD

                   
    		wai                     
		wai              
		wai 
              
*********************************************************************
*** BLOCK 2     7 x 128 ęsec = 896 ęsec  UF_BERECHNUNG
*********************************************************************
		wai                         	

                wai				
		ldd	FREQ_ACTUAL
		cpd	#4200
                blo     div_okay
                wai  
                       	
                ldab	#255		* max. modulation
                bra     UF_OK
div_okay	ldx	#4200

		wai                         	
		fdiv
		xgdx
		tab

UF_OK           wai                         	
		ldx	#UF_TABLE
		abx
		ldab	X
                subb	#10
                bcc	save_V_MOT
                clrb
save_V_MOT	clrb
		stab	V_MOT

                wai                         	
 

*********************************************************************
*** BLOCK 3     7 x 128 µsec = 896 ęsec  TIMER usw.
*********************************************************************
		wai                         wai_0
                wai                         wai_1
                wai                         wai_2
                wai                         wai_3
                wai                         wai_4
                wai                         wai_5
                wai                         wai_6
  		jmp	PWM3_LOOP
*====================================================================
*====================================================================
***********************************************************************
****** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! *****
*Never make changes in this routines 
*EVERY CYCLE is calculated exactly
*
*						Bytes
INTERRUPT_OC1   LDAA	TOC3+1		*  3     2    IM RAM
		LDAB	TOC4+1		*  3     2
		NEGA			*  2     1
		NEGB			*  2     1
		STAA	TOC3+1		*  3     2
		STAB	TOC4+1		*  3     2
		NEG	TOC5+1		*  6     2
*---------------------------------------*---   22 cycles
		nop 	*  2
                nop
		nop
		nop
		nop
*-----------------------------------------------
		ldaa    TOC3+1         *  4
		LDY	PTR_SINUS	*  5
		LDX	PTR_SINUS	*  4
		CBA			*  2
		BCS	SETPWM_1	*  3
		CMPB	#222		*  2
		BCC	SETPWM_2	*  3

		LDD	PTR_SINUS+1	*  4
		ADDD	PTR_ADD		*  5
		STAB	PTR_SINUS+2	*  3

		LDAB	#186		*  2
		STAB	TFLG1		*  3

		BCS	*+3		*  3
		CMPA	#$10		*  2

		STAA	PTR_SINUS+1	*  3

		LDAB	V_MOT		*  3
		ABX			*  3
		LDAA	TOC1		*  3 
		INCA			*  2
		STAA	TOC1		*  3

		LDAB	0,y		*  5
		ADDB	0,x		*  4
		LSRB			*  2
		STD	pwm		*  4

		LDAB	62,y		*  5
		ADDB	62,x		*  4
		LSRB			*  2
		STD	TOC4		*  4

		LDAB	124,y		*  5
		ADDB	124,x		*  4
		LSRB			*  2
		LDX	pwm		*  4

		STD	TOC5		*  4
		STX	TOC3		*  4
		RTI 			* 12
*-------------------------------------------
SETPWM_1	cmpa	#222
		bcc	SETPWM_2
		ldd	PTR_SINUS+1
		addd	PTR_ADD
		stab	PTR_SINUS+2

		ldab	#186
		stab	TFLG1
		bcs	*+3
		cmpa	#$10
		staa	PTR_SINUS+1

		ldab	V_MOT		*  3
		abx          		*  3
		ldaa	TOC1
		inca			*  2
		staa	TOC1		*  3

		ldab	124,y		*  5
		addb	124,x		*  4
		lsrb			*  2
		std	pwm		*  3
		ldab	0,y		*  5
		addb	0,x		*  4
		lsrb			*  2
		std	TOC3		*  4
		ldab	62,y		*  5
		addb	62,x		*  4
		lsrb			*  2
		ldx	pwm		*  4
		std	TOC4		*  4
		stx	TOC5		*  4
		rti			* 12
*-------------------------------------------
SETPWM_2        ldd	PTR_SINUS+1		*  4
		addd	PTR_ADD		*  5
		stab	PTR_SINUS+2		*  3

		ldab	#186
                stab	TFLG1
		bcs	*+3
		cmpa	#$10
		staa	PTR_SINUS+1

		ldab	V_MOT
		abx
		ldaa	TOC1
		inca
		staa	TOC1
		ldab	62,y
		addb	62,x
		lsrb
		std	pwm
		ldab	124,y
		addb	124,x
		lsrb
		std	TOC5
		ldab	0,Y
		addb	0,X
		lsrb
		ldx	pwm
		std	TOC3
		stx	TOC4
		rti
*-----------------------------------------------------------------
*-----------------------------------------------------------------
		ORG	$F800	* The table must have address xx00
  		
Sin000	        fcb	064,067,071,074,078,081,084,087,090,093
		fcb	096,099,101,104,106,108,110,112,113,115
		fcb	116,118,119,119,120,121,121,122,122,122
		fcb	122,122,122,122,122,122,122,122,121,121
		fcb	121,121,121,120,120,120,120,120,120,120
		fcb	120,121,121,121,121,121,122,122,122,122
		fcb	122,122
Sin120		fcb	122,122,122,122,122,121,121,120,119,119
		fcb	118,116,115,113,112,110,108,106,104,101
		fcb	099,096,093,090,087,084,081,078,074,071
		fcb	067,064,061,057,054,050,047,044,041,038
		fcb	035,032,029,027,024,022,020,018,016,015
		fcb	013,012,010,009,009,008,007,007,006,006
		fcb	006,006
Sin240		fcb	006,006,006,006,006,006,006,007,007,007
		fcb	007,007,008,008,008,008,008,008,008,008
		fcb	007,007,007,007,007,006,006,006,006,006
		fcb	006,006,006,006,006,006,007,007,008,009
		fcb	009,010,012,013,015,016,018,020,022,024
		fcb	027,029,032,035,038,041,044,047,050,054
		fcb	057,061

Sin360		fcb	064,067,071,074,078,081,084,087,090,093
		fcb	096,099,101,104,106,108,110,112,113,115
		fcb	116,118,119,119,120,121,121,122,122,122
		fcb	122,122,122,122,122,122,122,122,121,121
		fcb	121,121,121,120,120,120,120,120,120,120
		fcb	120,121,121,121,121,121,122,122,122,122
		fcb	122,122
		fcb	122,122,122,122,122,121,121,120,119,119
		fcb	118,116,115,113,112,110,108,106,104,101
		fcb	099,096,093,090,087,084,081,078,074,071
		fcb	067,064,061,057,054,050,047,044,041,038
		fcb	035,032,029,027,024,022,020,018,016,015
		fcb	013,012,010,009,009,008,007,007,006,006
		fcb	006,006
		fcb	006,006,006,006,006,006,006,007,007,007
		fcb	007,007,008,008,008,008,008,008,008,008
		fcb	007,007,007,007,007,006,006,006,006,006
		fcb	006,006,006,006,006,006,007,007,008,009
		fcb	009,010,012,013,015,016,018,020,022,024
		fcb	027,029,032,035,038,041,044,047,050,054
		fcb	057,061

		fcb	064,067,071,074,078,081,084,087,090,093
		fcb	096,099,101,104,106,108,110,112,113,115
		fcb	116,118,119,119,120,121,121,122,122,122
		fcb	122,122,122,122,122,122,122,122,121,121
		fcb	121,121,121,120,120,120,120,120,120,120
		fcb	120,121,121,121,121,121,122,122,122,122
		fcb	122,122
*
		ORG	$FC00	* Table to calculate motor voltage

UF_TABLE	fcb	093,093,093,092,092,092,091,091,091,091	* 1
		fcb	090,090,090,090,089,089,089,089,088,088	* 2
		fcb	088,088,087,087,087,087,086,086,086,086	* 3
		fcb	085,085,085,085,084,084,084,084,083,083	* 4
		fcb	083,083,082,082,082,082,081,081,081,081	* 5
		fcb	080,080,080,080,079,079,079,079,078,078	* 6
		fcb	078,078,077,077,077,076,076,076,076,075	* 7
		fcb	075,075,075,074,074,074,074,073,073,073	* 8
		fcb	073,072,072,072,071,071,071,071,070,070	* 9
		fcb	070,070,069,069,069,068,068,068,068,067	*10
		fcb	067,067,067,066,066,066,065,065,065,065	*11
		fcb	064,064,064,063,063,063,063,062,062,062	*12
		fcb	061,061,061,061,060,060,060,059,059,059	*13
		fcb	058,058,058,058,057,057,057,056,056,056	*14
		fcb	055,055,055,054,054,054,054,053,053,053	*15
		fcb	052,052,052,051,051,051,050,050,050,049	*16
		fcb	049,049,048,048,048,047,047,046,046,046	*17
		fcb	045,045,045,044,044,044,043,043,042,042	*18
		fcb	042,041,041,040,040,040,039,039,038,038	*19
		fcb	038,037,037,036,036,035,035,035,034,034	*20
		fcb	033,033,032,032,031,031,030,030,029,029	*21
		fcb	028,028,027,026,026,025,025,024,023,023	*22
		fcb	022,021,021,020,019,018,017,016,015,014	*23
		fcb	013,012,011,009,007,004,000,000,000,000	*24
		fcb	000,000,000,000,000,000,000,000,000,000	*25
		fcb	000,000,000,000,000,000



		ORG $FFE8
		FDB INTERRUPT_OC1   

		ORG  $FFFE
		FDB  START
	
  1. sw-step.htm with this applications:
     PID-Drivecontrol with 68HC11
     STEPPER CONTROL
     68HC11 read encoder
     High accuracy RPM-measurement with 68HC11

  2. 68HC11 programms eproms 27C64 to 27C512

  3. FLASH AMD 29F010 with 68HC11
  4. SPI, External EEPROM 24C65 with 68HC11
  5. OUTPUT COMPARE - INPUT CAPTURE 68HC11

  6. index11.htm with this applications
     68HC11 Schematic in Bootstrap-Mode
     68HC11 Schematic in Expanded Mode
     68HC11 with CAN-BUS
     68HC11 and IEC-BUS
     ULTRASONIC EXAMPLE