Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Need help for PIC16f84a count-up timer using a 7 segment

Status
Not open for further replies.

DMC69

Newbie level 3
Joined
May 23, 2010
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,317
PIC16f84a

hey guys.. i hope i'm posting in the right section... i got a problem... am trying to make a count-up timer using a 7 segment display with a decoder and PIC... with two push buttons RA0 as reset and RA1 as start... initial display is 00 and when i press start it starts counting up with a delay of .5s from 00-99... what i want is that when it reaches 99 it stays 99 until i press reset... my code only counts up and after it reaches 99 it immediately goes to 00... plase help... i've attached my code in my post and a schematic diagram... am using MPLAB IDE 8.50 and proteus 7.4 and also i'm using assembly

***********************************************
LIST P = 16f84A, F = INHX8M
INCLUDE <P16F84.INC>
__CONFIG _CP_OFF & _WDT_ON & _XT_OSC

digitctr1 equ 0ch
digitctr2 equ 0dh
delayctr equ 0eh

goto initPIC

delay movlw 07h
movwf delayctr
d1 Sleep
decfsz delayctr
goto d1
return

initPIC BSF STATUS, RP0
clrf TRISB
movlw 03h
movwf TRISA
movlw 0ah
movwf OPTION_REG
BCF STATUS, RP0

rst CLRF PORTB
clrf PORTA

startchk BTfss PORTA, 1
GOTO startchk

movlw 09h
movwf digitctr1

rstdgt movlw 09h
movwf digitctr2

inrdigit call delay
incf PORTB
DECFSZ digitctr2
goto inrdigit

call delay
movlw 0ah
addwf PORTB
movlw 0f0h
andwf PORTB

decfsz digitctr1
goto rstdgt

movlw 09h
movwf digitctr2

extra call delay
incf PORTB
DECFSZ digitctr2
goto extra
restart BTFSS PORTA, 0
goto restart

goto rst
END

********************************************
here's the design... my RB0-RB3 is the least significant and RB4-RB7 is the most significant

 

Hi,

Have quickly looked at your code, corrected two little things as detailed.
Also when using the Decfsz Filename, W or F - use the W or F after the filename to tell it where to place the result - good practice / makes things clearer.

To stop the count at 99, then you simply test the contents of your registers every loop to see if they are at 99. Several ways to do that - will let you decide.

When posting code enclose it in the Code tags so its easier to follow / use and post your actual .dsn so we can try running your code without having to create all the design again.

Assume you know you do not actually need those decoder chips, you can output from one port to two or more 7 segment displays by the use of multiplexing.
Plenty of examples on the web when you are ready to use it.
 

    DMC69

    Points: 2
    Helpful Answer Positive Rating
thanks for the correction dude.. i didn't notice that... can you give some examples on what you meant about checking the register if they are at 99??
 

Hi,

There are a couple of ways to do this with the 16F chips

Most rely on doing a maths/ logic instruction, the result of which is stored in certain Bits of the Status Register, namely the Zero Bit and the Carry Bit.

A typical way to test to see if Counter1 was equal to 9

Code:
	movlw .9 		; the number you are testing for    b'00001001'
	xorwf counter1  ; the file you are testing         b'00001001'
					    ; when both are equal the result = b'00000000'
				    	; a zero result causes the Z bit of the Status register to be SET to 1

	btfss STATUS,Z   ; is the Z bit set to 1  - the numbers are equal
	goto not on 	  ; does not =9
	goto is on 		; does =9


As you can see it is not a simple way to compare results , on the 18F chips with extra instructions available its a lot easier.

Also note that the above only tests if the numbers are equal.

Sometimes using the SUB / ADD instructions etc and the Carry flag you can test if a number is Greater than or Less than, which are often a safer way to test .

If you look at the 16F84A instructions section of the datasheet, you will see it lists what Status Bits are affected by the instructions.
 

ok ok.. thahnks man..i'll try this..... i have 1 more question.... in my code... my does it go directly form 99 to 00?
 

Hi,

Well trying to work out someone elses tight looping code is not that easy - being as you have not commented your code which makes it easy for others to follow, and as you will soon learn when you look back on your own code a few months later you will be saying, how the 'bleep' did I do that !


Have run your code in MPLABs Simualtor, you have to bypass your start switch and the delay loop, but as you can see, Port B is being increased, Digitctr2 is decreasing and Digitctr1 is the same.

EDIT - have just let the whole sequence run in the 'animate' mode and PORTB increments its hex value in decimal fashion until it reaches 99 then the program is looping round waiting for the restart key
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top