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
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.
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.
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