| View previous topic :: View next topic |
| Author |
Message |
Sam_40
Joined: 07 Jan 2015 Posts: 127
|
|
Posted: Sat Sep 05, 2015 1:00 pm |
|
|
PCM programmer and Ttelmah,
Thanks for the detail reply, That did clear a lot of confusion and also made it more simple!
After PCM programmer explain that RA6 and RA7 can both be set outputs (for my purpose). I can redesign my my project and use RA0-RA6 for the display multiplex option (I need seven outputs on the same ports RA0 to RA6), I will use the port B for the inputs.
Would you please elaborate on the sleep/wakeup with Interrupts!
Also is it better to do and how:
1- use just one Interrupt to wakeup the CPU, I can set the wakeup time for extended period to read the other inputs then the cpu go to sleep (or if it can stay awake as long as it is reading change of inputs even on non Interrupts pins)or:
2- I need 4 inputs, it also be better if I can leave pins 27-RB6/KBI2/PGC and 28-RB7/KBI3/PGD (so I do not have to worry about programming jumper pins). is it better to use 4 Interrupts?
How to time the wakeup time and how to put the CPU to sleep without affecting TIMER1? To put the CPU in deep sleep, is it by making a forever loop in main and if interrupt then wakeup or else count down then SLEEP(); ? Would you please provide a simple test source code to use the TIMER1 RTC and Interrupts?
Thanks, |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Sep 05, 2015 6:57 pm |
|
|
| Quote: | | is it better to use 4 Interrupts? |
Tell us what your project is all about, and we can decide this better.
| Quote: |
How to time the wakeup time and how to put the CPU to sleep without
affecting TIMER1 ? |
Timer1, when running with external crystal and capacitors, is independent
of the CPU. It runs by itself. It runs if the CPU is sleeping.
| Quote: |
Would you please provide a simple test source code to use the TIMER1
RTC and Interrupts? |
See the code in this thread, and also see the links in the thread.
http://www.ccsinfo.com/forum/viewtopic.php?t=46219
| Quote: | | To put the CPU in deep sleep, |
Deep Sleep mode is a feature of specific PICs. Your PIC (18F2685) does
not have it. Please don't use that term for your PIC. Some of the
18F and 24F "J series" PICs have Deep Sleep mode. |
|
 |
Sam_40
Joined: 07 Jan 2015 Posts: 127
|
|
Posted: Sat Sep 05, 2015 8:16 pm |
|
|
PCM programmer,
My apologies, I read a few articles hear and there about using "deep sleep" and I thought this would apply to all of the 18F.
My project is simply a RTC with 4 alarms. I did update my project code to leave port B for the input switches to set the time and test the alarm.
Thanks,
Last edited by Sam_40 on Sun Sep 06, 2015 8:38 pm; edited 1 time in total |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Sep 06, 2015 7:55 am |
|
|
| Quote: | 2- The display will only active after the interrupts from port B to display
the time so the user can update it. The display will turn off after 10
seconds from no inputs and stay off until next input interrupt. |
You have a one second timer. Use it.
1. Create a global int8 variable and initialize it to 0. In your code that
detects PortB interrupts, set the variable to 10. Anytime a PortB
interrupt occurs, it will be set to 10. Also, turn on the display at the
same time. This won't give you exactly a 10 second delay, because
the #int_timer1 interrupt is asynchronous to the PortB interrupts.
But you will get between a 10.0 and a 10.99 second delay.
You could call this variable 'counter' or 'display_on_counter', or
whatever you want.
2. Count down the variable in your #int_timer1 routine. The #int_timer1
routine is entered once per second. Thus, your variable counts down
once per second. Only decrement the variable if it's a positive number.
Check for this before decrementing it.
3. If the variable is decremented from 1 to 0, turn off the display. |
|
 |
Sam_40
Joined: 07 Jan 2015 Posts: 127
|
|
Posted: Sun Sep 06, 2015 8:21 am |
|
|
Easy enough, However I still need your help with:
1- Determine which input shall I use from Port-B for this?
2- Sample code to use Port-B interrupts for my need. I did read your link and others but I did not get the concept as I did not understand as there are no codes that read the port pins? As they say "a picture is worth a thousand words" and a sample test program code will clear this for me.
Thanks, |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Sep 06, 2015 8:58 am |
|
|
I think you want us to write code for you. You need to at least attempt
to do it yourself. |
|
 |
Sam_40
Joined: 07 Jan 2015 Posts: 127
|
|
Posted: Sun Sep 06, 2015 10:27 am |
|
|
| PCM programmer wrote: | I think you want us to write code for you. You need to at least attempt
to do it yourself. |
No sir, but I need your help so I can write my code by myself. You helped me last time and I did adapt you example and added to it to meet my requirement. Regardless if you help or not, I can't thank you enough for all of the information you had provided to me.
Best regards, |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Sep 06, 2015 11:14 am |
|
|
| Quote: | 1- Determine which input shall I use from Port-B for this?
|
Look at the PIC data sheet, near the end of the Overview section.
It lists which pins on PortB can be used for Interrupt-on-Change.
| Quote: | | 2- Sample code to use Port-B interrupts for my need. |
Look at the CCS example files folder. Search it for #int_rb.
You will see this result:
c:\program files\picc\examples\ex_pbutt.c
Or, use the CCS forum search page:
http://www.ccsinfo.com/forum/search.php
Search for: #int_rb
Author: pcm programmer
You will find many threads, probably with sample code. |
|
 |
|