one switch to change led pattern 16f84a

Status
Not open for further replies.

arc6ft6

New Member
hi everyone,

i have a problem.
i need to make a program for 16f84a when power turned on,it will show led pattern 1(on portb). Then when switch(porta pin 0) is pressed, portb will change to pattern2 and when pressed again,change to pattern3,then when pressed again,go back to pattern1.
 
Last edited:
Again.. you can start with Nigel's tutorials... tutorial 2 is a good start... Link in my signature.... There is also a C version in my tutorials
 
thanks ian,
i have seen nigel's tutorial, but he uses multiple switch to change from one pattern to another.
i want to use only one switch (portA pin 0) and it will be able to change prom pattern to the next pattern.
hope you could help.
 
Upload tutorial 1.9 from Nigel's site.... Before the line...

.....incf count, w

Place your switch test.

....btfss PORTA, 0

Then it will increase ONLY when you press the button.... if the button press is too fast,
You will then have to jump to a debounce routine.
 
If you want it to inc 1 time each press you'll need a flag and delay or it will change so fast it never stops where you want.

If button =1 then delay 20ms then if button still 1 set flag Then test to see if button was released and flag set

You then inc by 1 your display and reset flag.
 
unsigned int count

void interrupt routine
if interrupt(
increment count
wait a little to reduce debounce errors

) remember to off flag

main
initializa i/o
set interrupt bor RB0
enable global interrupt

while 1 loop
while count ==1(pattern 1)
while count== 2(pattern 2)
while count ==3(pattern3)
while count ==4(count ==1)

i hope tou can finde your way if u are fameliar with c
 
Thanks for the replies.

Unfortunately, i still can't make it work.
I attached the my asm file.
Please help me with it.

(i'm not very familiar with C and i use MPLAB IDE)

Thanks again
 

Attachments

  • 16F84ATMPO.ASM
    8.1 KB · Views: 212
This doesn't look promising

Code:
    Start	clrf	count			;set counter register to zero
    Read	goto	Table			
    Check	btfss	PORTA,0
		goto	Read		
		call	Delay2
		btfsc	PORTA,0
		retlw	0x00		<------------ Return from a call.....What call.	
		incf	count,	w
		xorlw	d'3'			;check for last (3rd) entry
		btfsc	STATUS,	Z
		goto	Start			;if start from beginning
		incf	count,	f		;else do next
		goto	Read
 
Any suggestion?

You're welcome to take a peek at something I did awhile back for a 16F628A. It may be worth studying for ideas. If you get stuck, please feel free to ask questions. Caveat - I have not tested this code on a real circuit...

The first byte in each FX sequence table is the number of steps in the sequence. This is calculated automatically (as long as you follow the same format shown in the example tables). Each of the following entries in an FX table represents a "step" in the sequence. That is, each entry or "step" contains a <pattern> byte, which is written to PORTB, and an <interval> byte which gives you the duration for that step (in 10 msec increments).

You'll notice that the push button switch is sampled continuously at 10 msec intervals during sequencer operation so you won't miss a switch press. The switch state logic may not be very intuitive but, basically, it detects a "new press" state and ignores the "continually pressed" state and the "release" state. When a "new press" is detected the code simply goes to the next FX sequence.

Regards, Mike
 

Attachments

  • 16F628A LED Sequencer.asm
    11.5 KB · Views: 164
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…