Reader Experiments

This page is dedicated to Reader Feedback in the form of experiments and ideas. 
The first program was sent in by Miroslav Kostecki of elabtronics (  the designers of Icon Assembler. 
I asked him for a program that incremented the 7-segment display. I expected a program similar to Experiment 4: Counting on the 7-segment display.  I actually asked for a program in Icon Assembler so I could compare the ease of understanding the Icon Assembler approach. I received the Icon program and loaded it into Icon Assembler but it was so over-the-top that I closed the program and realised it was not for me. 
The Icon program was spread over 3 pages and was filled with circles and triangles and half-finished words that made the concept 10 times more complex than the hand-assembly approach I am advocating. 
I don't mind if someone comes up with something that makes writing a program easier and more understandable, but to add to the complexity by 1,000% and attempt to hood-wink me with the suggestion that the new approach is the way to go, I think not. 
However, here's the first readers program. Copy it, put it into a text editor, burn it into a PIC chip, and put it in the PIC LAB-1 project. 
This program serves as a very good example of how other people work and think. Miroslav Kostecki is a brilliant programmer and operates at a very high level of thought. Even a simple program such as the one below uses a higher level of thought than we have provided in our set of experiments, and is more complex than expected.  
But this is very important. When you see a combination of reasoning from different minds, you can combine the common points and see how to tackle a specific problem from different stand-points. 
The first thing you will notice is the layout. 
It is different to our recommended format and the inclusion of the interrupt vector adds to the complexity. The interrupt instructions are not functional as the interrupt has not been set up, and maybe this program is left-over from a larger example.
All programs naturally starts at address "000" where it sees the instruction GOTO 5. The instruction ORG 0, does not have to be included as the assembler naturally starts programming at this address. This causes the micro to jump over the instruction GOTO Interrupt, at location 4, and operate on the instruction __CONFIG 0Bh, at address 5.  This configuration turns off the watchdog timer, invokes the external RC oscillator mode, and turns on code-protect.
The instruction: MOVLW  B'10000000'   OPTION    puts the value 80h into the OPTION register to disable the pull-ups on port B. This feature only applies when any of port B lines are INPUT, and does not apply to this program - another unnecessary instruction. 
The programmer has used the TRIS operation to determine which lines of each port will be input or output. 
The micro then continues directly to Start, where it clears the count file (file 12h) and then goes to Main1.
The output port is initially cleared and so the program starts with a blank display. 
The program basically consists of two loops. The "button not pressed" loop is in dloop, where the last value placed in file 06 will appear on the screen. The "button pressed" loop is Main1 and this includes CALL display
If the button is NOT pressed, the micro carries out the first and third instructions of Main1 and then goes to dloop where it carries out the first and second instructions, in a continuous loop. The screen will display the last value placed in file 06.
When the button is pressed, the first instruction
in dloop gets the micro out of the loop and back to Main1, where the micro goes to display. The instruction incf count,f in display increments the "jump value" for the table, performs a SUB and  looks in the STATUS file to see if the zero flag has been set. If this flag is SET, the 'end of table' has been reached and the jump value is zeroed. 
A display value is obtained from the table and passed to port B for outputting to the display. This action is repeated and the display is changed very rapidly to produce a "figure-8." 
As soon as the button is released, the micro goes to the above-mentioned routine with the last display-value appearing on the 7-segment display. 
This is not what I requested and the program should be called RANDOM NUMBER or DICE
By changing the values in the table to include only the numbers 1 to 6, and limiting the jump value to 6, a DICE program can be produced.  
GOTO $ is also not used (it is a BASIC language instruction meaning GOTO String Data) and is only included to confuse you. All these misleading instructions from a pioneer of a program designed to help beginners understand programming!  If someone can convince me that Icon Assembler is easier to understand than hand-assembly, I will offer a $10,000 prize! 
My challenge to Icon Assembly is a program similar to Expt1 test  but with lines of code that can be changed on the screen. It can have circles and triangles to make the program colourful and fancy but really only needs each instruction to be taken from a library and dragged into place. This concept will make a superb assembly program where you can see the whole program at a glance and the endless page allows you to scroll down the whole program.
The 7-segment program supplied by elabtronics is already 3 pages long in Icon Assembly and trying to follow the flow of the program is absolutely impossible. 
The program below is already more complex than our layout, so you can imagine adding 1,000% more complexity to this is going to make it an Archimedean entanglement! 

			;Project: Button increments 7-seg
LIST p=16C84,r=DEC	; Put assembler into PIC16C84 mode.
			; r=DEC means decimal numbers are
			; assumed if 'B' or 'h' not specified
     			;include ""

   ;**************Declare Variables************************
   	count		equ	12
	x		equ	13      
   ;**************Initialise interrupt subroutine**********
     	goto 5
	ORG 4
	goto interrupt
	ORG 5     
  ;**************Initialise Ports*************************
   	__CONFIG  0Bh
    	MOVLW	B'10000000'
	MOVLW	B'00011111'
	MOVLW	B'00000000'
	TRIS	6  

  ;**************Start Of Main Program********************
  Start		; Button Increments a Seven Segment Display
		; PORTA,0 is connected to the button
		; PORTB to display, format=gfedcba0

	clrf	count	;count  =  0
 Main1	btfsc	5,0	;If PORTA Bit 0 OFF Skip Next
	call	display
	call	Delay
	goto	Main1
	goto	$	;Safety Caching Loop


	retfie		;Interrupt    

 dloop	btfss	5,0	;If PORTA Bit 0 ON Skip Next
	goto	dloop
	decfsz	x,f	;x  =  x -1 , Skip Next If Zero
	goto	dloop
	return		;Return

	incf	count,f		;count  =  count + 1
	movlw	0Ah		;w  =  10
	subwf	count,w		;w  =  count - w
	btfsc	3,2		;If STATUS Bit2 OFF Skip Next
	clrf	count		;count  =  0
	movf	count,w		;w  =  count
	call	table
	movwf	6		;PORTB  =  w
	return			;Return  

table	addwf	2,f		;PCL  =  PCL + w
	retlw	H'3F'		;w = H'3F'
	retlw	H'06'		;w = H'06'
	retlw	H'5B'		;w = H'5B'
	retlw	H'4F'		;w = H'4F'
	retlw	H'66'		;w = H'66'
	retlw	H'6D'		;w = H'6D'
	retlw	H'7D'		;w = H'7D'
	retlw	H'07'		;w = H'07'
	retlw	H'7F'		;w = H'7F'
	retlw	H'6F'		;w = H'6F' 

		;Reader 2.asm
             		 ;Project: To come
 List P = 16F84
 #include <>






BSF 03,5
BCF 03,5

GOTO Delay
GOTO Delay

GOTO Delay2

BTFSS 05,0
BSF 06,0
CALL Delay
CALL Delay
BCF 1F,1
BSF 1F,2
BCF 06,0
BSF 1F,1
BSF 1F,0
BCF 1F,0
BCF 1F,2

CALL Delay2
other instructions
other instructions
BCF 1F,0

;This is the start of memory for the program.
;Go to Bank 1
;Make all port B output
;Load W with 0000 0001
;Make RA0 input
;Go to Bank 0 - the program memory area.
;Clear the button-press file
;Blank the display

;Create approx 250mS delay

;Create 1mS debounce delay

;Test the push button
;Button not pressed
;Test end-of-flash flag

;First pass?
;Test first-press flag
;First press
;Button has been pressed twice. Illuminate LED
;Keep LED on
;Keep LED on
;Clear second-push flag bit
;Set end-of-flash flag
;Turn LED off

;Set the first-press flag
;Set button pass flag bit

;Clear button pass flag bit
;Clear end-of-flash flag

;Carry out other instructions

;Clear first-push flag bit

;Tells assembler end of program