PIC16F84A countdown timer

Thread Starter

Aaron0000

Joined Jul 15, 2009
4
If I could get help with this I would greatly appreciate it. I'm using a PIC16F84A (I don't doubt its easier to use a different PIC for this project, but this is the PIC I am using).

Basically, I am using 4 digits. "seven-segment-LED"'s. They are common-cathode.

Two digits are for minutes and two are for seconds,obviously.

So I want to be able to have it countdown from any chosen time from 99 minutes . And I Do want to have zero's showing. for example if the count is set at 45 seconds, then the minutes show 00.

I am not a student. I have and am trying to learn electronics myself. I am a slow learner.

I've been working a while now and just seem to be stuck at writing the assembly code. (I think thats the correct term).

So if I am correct in what I know, then the first digit is connected to RA0, (by the common-cathode line), the tens of seconds digit is connected to RA1, the ones for the minutes digit is connected to the RA3 , and the tens of minutes digit is connected to the RA4.

And if I am not mistaken, when writing assembly , the digits from the RA0-RA3 would be "ones,tens,hundreds,thousandths."

I am going to have the segments connect to RBO-RB6.

I won't be using transistors, i just will have the common-cathode lines directly into the pin's.
Because I have not worked with transistors before.

Though I have ordered 4 "2N2222A NPN
General Purpose RF" from www.bitsbox.co.uk .

The common-cathode digits I am using are the "0.56" as shown here http://www.bitsbox.co.uk/optos.html

From what I understand, I can place a push button at pin 4.

yet am uncertain what to do for buttons.If one or two is needed.

I have ordered 3 different kinds of oscillators as well. and by the way, the PIC16F84A I'm using is the -04 , which I believe means the highest used is the 4MHz.

I have two 4MHz crystal oscillators , one is called "HC49/U style can." the other is "low profile can." and a third one I ordered is a "4.19 MHz Ceramic Resonator".

I am uncertain which one to use . (and how to connect them).

I will be using 6volts DC. obviously four AA batteries.

I'm using MPLAB the recent one. And I am using a JDM Programmer with winpic800.

I have MPLAB at this right now (which is what was there the moment I opened this project using project wizard) :

;**********************************************************************
; *
; This file is a basic code template for assembly code generation *
; on the PIC16F84A. This file contains the basic code *
; building blocks to build upon. *
; *
; Refer to the MPASM User's Guide for additional information on *
; features of the assembler (Document DS33014). *
; *
; Refer to the respective PIC data sheet for additional *
; information on the instruction set. *
; *
;**********************************************************************
; *
; Filename: xxx.asm *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
; *
;**********************************************************************
; *
; Files required: P16F84A.INC *
; *
; *
; *
;**********************************************************************
; *
; Notes: *
; *
; *
; *
; *
;**********************************************************************


list p=16F84A ; list directive to define processor
#include <p16F84a.inc> ; processor specific variable definitions

__CONFIG _CP_OFF & _WDT_ON & _PWRTE_ON & _RC_OSC

; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.

;***** VARIABLE DEFINITIONS
w_temp EQU 0x0C ; variable used for context saving
status_temp EQU 0x0D ; variable used for context saving

;**********************************************************************
RESET_VECTOR CODE 0x0000 ; processor reset vector
goto start ; go to beginning of program

ISR CODE 0x0004 ; interrupt vector location

Interrupt:

movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register

; Place ISR Here

movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt

MAIN_PROGRAM CODE

start:

; remaining code goes here

goto $

END ; directive 'end of program'


If anyone is willing to do so, will you write the assembly code I am suppose to place here? I would appreciate it very much.

Also, (if anyone does help), do I erase all that is above and replace it with the written code? and what do I set the other things to, such as watchdog timer, oscilator etc.

What matters most to me is that my timer works. but if it can also do a cool thing at the end of countdown like: once the timer digits reaches zero, have the LED's for each digit at the same time, turn on the segments and off, so it looks like the top part of the digit comes on, then the b segments, then the c, you know? as though the light is moving around for each digit...

So if anyone could, I would really appreciate it.

-Aaron
 

eblc1388

Joined Nov 28, 2008
1,542
I'm sorry to discourage you. If this is the first time you have ventured into PIC world, the chance of your project success is virtually zero. :(

If you really want to achieve you goal, follows this path:

1. flash an LED
2. flash an LED at two different speeds if a button is pressed
3. flash an LED with increasing/deceasing speed control by two buttons
4. display 0-9 on single 7-segment LED
5. display 0-9 on single 7-segment LED, values changes up/down with two push buttons
6. make a 0-9 continuous counter on a single 7-seg LED, counts up every second
7. learn LED multiplexing and build a 4-digit up counter
8. build a 4-digit minute/second down counter

9. Finally, a 4-digit minute/second down counter with buttons to preset/start/stop the counts.
 

Thread Starter

Aaron0000

Joined Jul 15, 2009
4
Thank you for the reply. and suggestion. i already know how to build multiplex, i just can't figure out those few things i mentioned and how to create the code. As I said, I'm a slow learner. I have been reading through books on how to program, for four months and still have yet to understand much. I chose this kind of multi-digit multiplex timer cause I am a big fan of sliders the t.v. show.
 

Thread Starter

Aaron0000

Joined Jul 15, 2009
4
Oh and don't worry, I won't be "discouraged", I haven't given up on electronics for twenty years since I started back at the age of ten, and I certainly won't give up now. It's just sometimes a nice helping hand helps teach . Much like a person looking at another fish. One may not know how to build that same fishing rod, yet if I look at one , I may build that one and re-build it, again and again, and then, everything else is a piece of cake...or fish. :)
 

rjenkins

Joined Nov 6, 2005
1,013
The only way to actually learn a subject is to work though it from the fundamentals and make your own mistakes.

I would say stick to assembly language, again it is the best way to learn.
If you want to progress from that, look at the C programming language.
(As a professional programmer, forget Basic on a PIC).

Have a look through this site for a nudge in the right direction:
http://www.piclist.com/techref/microchip/routines.htm
 
Top