Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Help in PIC Program - 2 Hours to go!!!

Status
Not open for further replies.

Agent 009

New Member
I need some fast serious help:
Program to do counter: 00 - 99 and stop when user press button. Program for PIC16F628...
Thanks Folks...
 
Gonna need more info than this... Like how fast should it count? What pin is the button connected to? Is the button de-bounced? What langauage is the program to be written in?

anyway... heres a basic 'C' program you can use.

Code:
byte x = 0;
for( ; x < 99; x++ )
{
    if( button )
    {
        break;
    }
    delay_ms(100);
}
 
Agent 009 said:
10x Kybert 4 ur prompt response, but:
Language: assembly, for PIC
Input: any bit from port A

My tutorials have all you need!, ones to read switches, and one that already counts from 0-99 on two 7 segment LED's - all for the 628.
 
Yes Nigel... This post was just for a friend, not me... Anyway, thanks!
He tried, after initialization:

movlw 0x00
movwf count
start movf count,portb
call delay
btfsc porta,3 ; if porta bit 3 is the input switch
goto stop
INCFSZ count
goto start

stop goto stop

end

where delay is a convenient delay... Would this work?
 
Agent 009 said:
Yes Nigel... This post was just for a friend, not me... Anyway, thanks!
He tried, after initialization:

movlw 0x00
movwf count
start movf count,portb
call delay
btfsc porta,3 ; if porta bit 3 is the input switch
goto stop
INCFSZ count
goto start

stop goto stop

end

where delay is a convenient delay... Would this work?
HI, what is this start movf count,portb ???
That is not a valid syntax of MOVF instruction
 
Agent 009 said:
Nigel, I cld b my browser, but tutorial 10.1, which I need, is not showing up!!!

The code is in the ZIP file at the top of the screen, there's nothing much to say about the program, which is why it only has one line of description.
 
And you program counts from 0-255, not from 0-99, You need to add COMWF instruction to limit number od cycles. (I don't know if there is one for 16F though..)
 
Jay.slovak said:
And you program counts from 0-255, not from 0-99, You need to add COMWF instruction to limit number od cycles. (I don't know if there is one for 16F though..)

There isn't, but my tutorial 10.1 does the 0-99 count, the main part of the program looks like this:
Code:
Main
		call	Delay255
		call	Delay255
		call	Delay255
		call	Delay255
		incf	ones,	f
		movf	ones, 	w		;test first digit
		sublw	0x0A
		btfss	STATUS, Z
		goto	Main
		clrf	ones
		incf	tens,	f
		movf	tens, 	w		;test second digit
		sublw	0x0A
		btfss	STATUS, Z
		goto	Main
		clrf	tens
		goto	Main			;loop for ever
[quote]

It simply increments two GPR's called 'ones' and 'tens', and loops back to zero after 99 - the actual displaying is done by the interrupt driven multiplexing routine.[/quote]
 
if we wanna use the pic16F84 instead, what shall we do with the interrupt register :

PIR1, TMR2IF, T2CON, PIE1
 
nisrine said:
if we wanna use the pic16F84 instead, what shall we do with the interrupt register :

PIR1, TMR2IF, T2CON, PIE1

If you use a PIC that doesn't have TMR2, you would need to rewrite the routines, I use TMR2 because it's far better (and easier to use) than the older ones. Although in this particular case, just for multiplexing, no great accuracy is required.
 
nisrine said:
:'( do u have a program written that fits the 16F84?

No, I haven't used the 84 for years, I moved to the 628 when it replaced the 84.

But as I said, the only difference in the counter program is the seven segment timer interrupt routines, it would be fairly simple to alter it accordingly.

For that matter, does it need to have a display?, the non-working code posted earlier made no effort to have a display driven by the PIC.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top