Problem with my 2nd PIC program...

MMcLaren

Joined Feb 14, 2010
861
Eric, I'm glad you're having fun. I've always enjoyed playing with LED projects. Here's a couple graphics of an old single chip Charlieplexed Clock/Calendar/Timer experiment;





Speaking of fun, I modified my version of the code (below) to support a second active lo switch on the RB4 pin (with external pull-up). Code in the main loop was modified for "up" and "down" switch functions.

May I suggest a simple exercise? Find out what changes are necessary in the code to eliminate the external pull-up resistors in favor of the internal pull-ups for the switches on RB7 and RB4.

BTW, with support for two switches in place, a minor code change would allow using a rotary encoder, which has A and B switches, in place of the two push button switches.

Food for thought...

Back to my homework... Regards, Mike
 

Attachments

Last edited:

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Eric,

Have you thought about adding a switch, one for "up" and one for "down"?
Ohh that would be so interresting...anyway will extend this problem to do different other stuff...thanks for the suggestion...will think about it and try implementing it...
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
1. If you were to use the gettim and getkey routines that I originally showed you in the other thread, you could eliminate the need to count out 16 ms in your interrupt routine to check the switch. Just check to see when the TC16ms bit is set. In the future, this could save you at least 1 register for every (simultaneous) time delay you require.

.
YES SIR!!! You are absolutely right...I still have to study your 'gettim' and 'getkek' coz I know and can see that it can help me do amazing stuff.
I'll try my best to understand it fully and use it in my future project...
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
2. Here's another one of my "nevers": Don't ever do something in an interrupt that can be done in normal code space just as effectively. I like to keep my interrupts as short as humanly possible. Interrupt, do something really fast, and get out.
You got an excellent point there! Although I was doing that BUT I kept on telling myself that I shouldn't put much stuff in the isr.

The display is a special case. If the MCU is responsible for multiplexing the display, and there is lots of other stuff going on, updating the display within an interrupt is usually the right approach. In the case of your (short) program, you could use the TC1ms flag in the main loop to trigger display updates. I've done it both ways.[/QUOTE]

Another reason why I MUST understand and use your 'gettim'

3. In every program I write (except the one I did for you), I always include a routine called 'CLRMEM' which sets all (non-special) file registers to 0 upon power on. This way I only need to initialize values that are not zero.[/QUOTE]

Wow that so cool...JOEYD, u got so many things you must show me them all...lolol

4. Get used to placing a NOP at address 0x00, before your goto init. You'll need this if you ever decide to use an ICD.[/QUOTE]

Ohk!! But what's an ICD!??

5. Understand that registers used by interrupts may change in value during execution of your main program. As your programs get larger, your logic may get confused if registers such as 'SWNEW' change (because an interrupt occurred). There is no problem with this particular program, I just want you to be aware now that you're delving into interrupts. If you go back to my original code, you'll see that I capture (static) copies of the (volatile) interrupt registers each pass of the main loop. I usually name "volatiles" (those that can change within in interrupt) differently than I name "statics" (those that do not change within interrupts). I usually preface it with an '_', i.e. _timer. This is a reminder to me that I cannot trust the value to be the same from one reading of it to the next.[/QUOTE]

Ohk! I'm taking that into consideration...

Learn to modularize functionality into smaller routines that will be easier to maintain and debug. You've got a stack. Use it.[/QUOTE]

That's one thang I told myself when I saw ur first code...I fell in love with that...that's the best way to solve design problem!!

Overall, good work! Be proud of yourself for the *very* fast progress you have made.[/QUOTE]

Thanks Joey
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Oh!!! I tried making several quotes at the same time but guess I didn't do it well...
Sorry about that...anybody to show me how to do it??

Thx
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Eric, I'm glad you're having fun. I've always enjoyed playing with LED projects. Here's a couple graphics of an old single chip Charlieplexed Clock/Calendar/Timer experiment

Speaking of fun, I modified my version of the code (below) to support a second active lo switch on the RB4 pin (with external pull-up). Code in the main loop was modified for "up" and "down" switch functions.

May I suggest a simple exercise? Find out what changes are necessary in the code to eliminate the external pull-up resistors in favor of the internal pull-ups for the switches on RB7 and RB4.

BTW, with support for two switches in place, a minor code change would allow using a rotary encoder, which has A and B switches, in place of the two push button switches.

Food for thought..

That's correct I'm having SO MUCH fun BUT time does not permit me to enjoy it all...thx for the homework I'll do it as soon as I can and get back to you......
 
Top