Hades logoHades applet banner
PIC16C84 microcontroller demonstration (nightrider)

applet icon

The image above shows a thumbnail of the interactive Java applet embedded into this page. Unfortunately, your browser is not Java-aware or Java is disabled in the browser preferences. To start the applet, please enable Java and reload this page. (You might have to restart the browser.)

Circuit Description

A first and very simple demonstration of our PIC 16C84 microcontroller simulation model. The program loaded into the microcontroller just drives a few LEDs connected to its port B outputs in 'nightrider' fashion. This design is also a very good start to play with a real PIC16C84 microcontroller on a prototyping bread-board. Just program the microcontroller with the walk.hex file, add some LEDs, and switch on the power!

If the applet seems to be running very slowly, you might want to switch-off glow-mode in the Hades editor, because the simulator performance will often be limited by the frequent repaint requests to the clock signal.

Use the popup-menu (popup, edit-component) to open the microcontroller user-interface and watch the program execution. You can also edit the data and program memories while the simulation is running. The following image shows a screenshot of the PIC microcontroller user-interface:

PIC 16C84 user interface

The right part of the window shows the program memory with addresses, raw memory data, and disassembled instructions. You can click the leftmost column to set and clear program breakpoints. The current intruction is highlighted in green color. The left part of the window shows (from top to bottom) the data memory, on-chip EEPROM memory, internal subroutine stack, and the current values of the four most important registers (work register, program-counter, status register, interrupt control). All special-function registers in the PIC architecture are directly memory-mapped into the data-memory. If you want to change the memory contents or a register value, just type-in new hex-values into the data memory.

However, note that the simulation runs very slowly while the PIC GUI window is open and enabled, because most of the processor time is spent redrawing the processor register and memory windows. Uncheck the 'update' checkbox to disable redrawing of the registers to watch the simulation at normal speed.

The speed of the nightrider animation depends on the wait loops in the PIC microcontroller program, whose limits were set during assembly. If the simulation runs too slow (or fast :-)), you can edit the assembly code and re-assemble, or open the microcontroller GUI and change the values of the wait loop initialization manually. The corresponding movlw C8 instructions are at program addresses 00F and 001 and load the value C8 first into the W register. You can change those instructions to something like movlw 10 to reduce the wait counter initialization value, which makes the animation much faster.

For reference, here is the original program:

;*******************************************************************
;                           walk.asm
;
; This code walks LEDs backwards and forwards on port b. 
; Couldn't be simpler.
;*******************************************************************

	LIST    P=16C84;f=inhx8m
	
_CP_OFF		equ	H'3FFF'			;code protect off
_PWRTE_ON	equ	H'3FFF' 		;Power on timer on
_WDT_OFF	equ	H'3FFB'			;watch dog timer off
_XT_OSC		equ	H'3FFD'			;crystal oscillator
__CONFIG       _CP_OFF & _PWRTE_ON & _WDT_OFF & _XT_OSC
						;configure programmer directive

w       equ     0	; register destination numbers.
f       equ     1	
same	equ	1

z       equ     2	; status flags
zero	equ	2
c	equ	0
carry	equ	0
	
count1  equ     0C      ; wait counter ls digit file register C
count2  equ	0D	; wait counter ms digit file register D
portb   equ     06      ; port b I/O register f6
porta	equ	05	; port a I/O register f5
status  equ     03      ; status register f3
;
;
;
	org     0	; origin
;
init   
	movlw   0
	tris    portb                   ; set portb as outputs
	movwf   portb                   ; set portb levels all low

start
        bsf	portb,0         	; set portb bit 0 high
	

rot_L	call 	wait			; wait for a bit
	bcf	status,c		; clear carry bit
	rlf	portb,same		; rotate left portb, store result portb
	btfss	portb,7			; skip next line if top bit set
	goto	rot_L

rot_R	call 	wait			; wait for a bit
	bcf	status,c		; clear carry bit
	rrf	portb,same		; rotate right portb, store in portb
	btfss	portb,0			; skip next line if bottom bit set
	goto	rot_R
	goto 	rot_L			; do it all again	

; ----------------------------
; wait subroutine 
; ----------------------------
wait    
	movlw   .200	        ; load count1 with decimal 200
	movwf   count1
d1	movlw   .200		; load count2 with decimal 200
	movwf   count2	
				; shorten these for the simulator
	
d2	decfsz  count2,same	; decrement and skip next line if zero
	goto 	d2		; if not zero		
	decfsz  count1		; decrement count1 if count2 is zero
	goto 	d1		; do inside loop again if count2 nz
	retlw 	00
; ----------------------------        

END

Print version | Run this demo in the Hades editor (via Java WebStart)
Usage | FAQ | About | License | Feedback | Tutorial (PDF) | Referenzkarte (PDF, in German)
Impressum http://tams-www.informatik.uni-hamburg.de/applets/hades/webdemos/72-pic/05-walk/walk.html