TAMS / Java / Hades / applets: contents | previous | next | ||||
Hades Applets contents visual index introduction std_logic_1164 gatelevel circuits delay models flipflops adders and arithm... counters LFSR and selftest memories programmable logic state-machine editor misc. demos I/O and displays DCF-77 clock relays (switch-le... CMOS circuits (sw... RTLIB logic RTLIB registers Prima processor D*CORE MicroJava Pic16 cosimulation PIC16C84 dem... fast PIC16C8... interrupt-dr... on-chip timer EEPROM access EEPROM access RS-232 trans... software RS-232 software RS-... chronograph MIDI footswi... MIDI footswi... MIDI footswi... MIDI organ p... MIDI organ p... ultrasonic r... ultrasonic r... "Phrasendres... "mastermind"... Mips R3000 cosimu... Intel MCS4 (i4004) image processing ... [Sch04] Codeumsetzer [Sch04] Addierer [Sch04] Flipflops [Sch04] Schaltwerke [Sch04] RALU, Min... [Fer05] State-Mac... [Fer05] PIC16F84/... [Fer05] Miscellan... [Fer05] Femtojava FreeTTS | PIC16C84 interrupt-driven counter
Circuit Description
This applet demonstrates an interrupt-based counter
realized with the PIC16C84 microcontroller.
In the default settings, the clock generator for the PIC16C84
runs at 1 KHz only, in order to save host CPU time.
The second clock generator component is used to generate the
pulses we want to count. Naturally, you could use any other data source.
The microcontroller program is very simple.
It first initializes the counter register and enables interrupts
on port B0. Afterwards, it enters an endless loop that does nothing.
The interrupt routine in turn increments the counter variable,
outputs the lower 4 bits of the counter value to ports B7..B4,
re-enables interrupts, and returns:
TITLE "16-Bit-Zaehler: PIC16C84" SUBTITLE "Zaehlimpulse von RB0/INT" ;*********************************************************************** ; A simple interrupt-driven counter program. It counts rising-edge ; events on port B0 and outputs the lower 4 bits of the counter value ; on ports B7...B4. ; Note that the watchdog timer WDT needs to be disabled to run this ; program, because WDT interrupts are not handled. ;*********************************************************************** Processor 16C84 Radix DEC EXPAND include "p16c84.inc" _ResetVector set 0x00 _IntVector set 0x04 Zaehler set 0x20 ORG _ResetVector ; the program starts here call Init ; initialize ports, counter, and interrupts InfiniteLoop: goto InfiniteLoop ; idle loop ORG _IntVector ; interrupt-address goto Interrupt ; handle interrupt ;*********************************************************************** ; enable B3..B0 as inputs and B7..B4 as outputs. ; enable interrupts for RB0/INT and reset the counter variable. ;*********************************************************************** Init: bsf STATUS, RP0 ; select bank 1 movlw 0xC0 ; rising edge sensitive, no pullup for movwf OPTION ; RB0/INT-PIN movlw 0x10 ; only enable RB0/INT interrupt movwf INTCON ; INTCON is in both banks movlw 0x0F ; set B3..B0 as inputs, B7..B4 as outputs movwf TRISB ; move into the direction control register bcf STATUS, RP0 ; select bank 0 clrf Zaehler ; clear counter value retfie ; RETURN and enable interrupts ;*********************************************************************** ; very simple interrupt handler. ; We do not even need to save and restore the work register or status bits. ; Increment the counter and output the lower 4 bits on port B. ;*********************************************************************** Interrupt: incf Zaehler ; increment counter values swapf Zaehler,W ; swap nibbles of counter, result in W movwf PORTB ; write W to port B bsf STATUS, RP0 ; select bank 1 movlw 0x10 ; select RB0/INT interrupts only movwf INTCON ; move to interrupt control register bcf STATUS, RP0 ; select bank 0 retfie ; return from interrupt handler | |||
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.informatik.uni-hamburg.de/applets/hades/webdemos/72-pic/08-counter/count.html |