Myke's Home Page

Book CD-ROM Home

File Copying/Harddrive Setup

Development Tools

Experiments

Projects

Useful Code Snippets and Macros

Introduction to Electronics

Introduction to Programming

Datasheets

PCBs

Links

McGraw-Hill Professional Publishing

"TimeEnd" Experiment

As I indicated in the book's text, there is an awful lot of different reasons why a PICmicro may appear to be unresponsive. The "TimeEnd" is one of the more esoteric ones - The code should light an LED after TMR0 has overflowed. In the aplication code, you will see that TMR0 is polled continuously using the code:

Loop
  movf   TMR0, f		;  Does TMR0 Equal 00?  (1 msec Passed)
  btfss  STATUS, Z
   goto  Loop
              
and should light the LED when "TMR0" is equal to zero.

The experiment uses the circuit shown below:

The parts needed for this experiment are listed in the table:

Part Description Required for the YAP-II/EMU-II?
PICmicro® MCU PIC16F84-04/P
PIC16F877-04/P
In Socket
Vdd/Vss Decoupling Capacitor 0.1 uF (Any Type) No
_MCLR Pull Up Resistor 10K, 1/4 Watt No
4 MHz Ceramic Resonator Three Leaded Ceramic Resonator with Built in 27-33pF Capacitors No
RB0 LED Current Limiting Resistor 220W, 1/4 Watt No - "LED1" Used
RB0 LED Any Type No - "LED1" Used
Breadboard Any Type No
+5 Volt "Vcc" Power Supply Any Type No

Using a breadboard, the experiment is wired using the guide:

If the EMU-II or YAP-II is used, the experiment is wired as:

The source code listed below can be accessed from the CD-ROM by clicking Here.

 title  "TimeEnd - Loop While Waiting for TMR0 to End"
;
;  This Uses TMR0 with a 4x Prescaler to Provide a 1 msec
;   Delay.  The Access instruction will cause the Timer to 
;   Never Reach Zero
;
;
;  Hardware Notes:
;   PIC16F84 Running at 4 MHz
;   _MCLR is Pulled Up
;   PortB0 Pulled up and Connected to LED
;
;  Myke Predko
;  99.06.22
;
  LIST R=DEC
 ifdef __16F84
  INCLUDE "p16f84.inc"
 else
 ifdef __16F877
  INCLUDE "p16f877.inc"
 endif

;  Register Usage
 CBLOCK 0x020                   ;  Start Registers at End of the SFRs
 ENDC


 PAGE
 ifdef __16F84
 __CONFIG _CP_OFF & _WDT_OFF & _XT_OSC & _PWRTE_ON
 else
 __CONFIG _CP_OFF & _WDT_OFF & _XT_OSC & _PWRTE_ON & _DEBUG_OFF & _LVP_OFF & _BODEN_OFF
 endif
;  Mainline of TimeEnd

  org    0

  nop

  bsf    PORTB, 0		;  Turn RB0 off
  bsf    STATUS, RP0
  clrf   TRISB ^ 0x080
  movlw  0x0D1			;  Set TMR0 to Prescaler and 4x
  movwf  OPTION_REG ^ 0x080
  bcf    STATUS, RP0

  movlw  (1024 - 1000) / 4	;  Reset TMR0 to Wait 1 msec
  movwf  TMR0

Loop
  movf   TMR0, f		;  Does TMR0 Equal 00?  (1 msec Passed)
  btfss  STATUS, Z
   goto  Loop

  bcf    PORTB, 0		;  Turn RB0 ON

  goto   $ 			;  Loop Forever When Done


  end
              

This experiment shows that if TMR0 is to be polled, the following code should always be used:

Loop
  movf   TMR0, w		;  Does TMR0 Equal 00?  (1 msec Passed)
  btfss  STATUS, Z
   goto  Loop
              
to avoid the situation where the prescaler is always reset by the read/store movf TMR0, f instruction.

Click Here to look at the twenty third experiment - Decouple