View previous topic :: View next topic |
Author |
Message |
el-3aba6i
Joined: 20 Sep 2018 Posts: 4
|
16f628a comparator configuration |
Posted: Fri May 03, 2019 11:20 pm |
|
|
I have one input changing in logic. When 5v input i want an interrupt to fire so that to reset a two seven segments with 4 bit decoders counter in port b.
Can anyone help me on configuring the comparator interrupt when input change to reset a counter and in the interrupt how to clear the flag so that it won't block on isr ?
I don't know how to match this code with the comparator mode. If anyone can give me comments on what each line does?
Code: |
#define A0_A3_A1_A2 0xfff04
#define A0_A2_A1_A2 0x7ff03
#define NC_NC_A1_A2 0x6ff05
#define NC_NC_NC_NC 0x0ff07
#define A0_VR_A1_VR 0x3ff02
#define A3_VR_A2_VR 0xcff0A
#define A0_A2_A1_A2_OUT_ON_A3_A4 0x7e706
#define A3_A2_A1_A2 0xeff09
#define CP1_INVERT 0x00010
#define CP2_INVERT 0x00020
|
Using ccs code and thanks. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri May 03, 2019 11:56 pm |
|
|
Quote: | #define A0_A2_A1_A2_OUT_ON_A3_A4 0x7e706 |
The constant consists of three bytes: 07 E7 06
1. CMCON is loaded with 0x06.
2. TRISA is bitwise OR'ed with 0x07.
This sets bits 0,1,2 = 1, which makes pins A0, A1, A2 into inputs.
3. TRISA is bitwise AND'ed with 0xE7.
This sets bits 3 and 4 = 0, which makes pins A3 and A4 into outputs. |
|
![](templates/subSilver/images/spacer.gif) |
el-3aba6i
Joined: 20 Sep 2018 Posts: 4
|
|
Posted: Sat May 04, 2019 12:01 am |
|
|
Thanks for good explaning.
I'm not using asm code but pic c compiler code.
The code i pasted was from .h pic file. I didn't find any reference explaining it in pic c compiler code directly, all i find is mplab codes.
What i need is the code to put in setup comparator() function and thanks. ;) |
|
![](templates/subSilver/images/spacer.gif) |
el-3aba6i
Joined: 20 Sep 2018 Posts: 4
|
|
Posted: Sat May 04, 2019 12:09 am |
|
|
This is the setup i have done after your reply but int won't fire.
Code: | setup_comparator(A0_A2_A1_A2_OUT_ON_A3_A4);
enable_interrupts(GLOBAL);
enable_interrupts(INT_COMP); |
|
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9177 Location: Greensville,Ontario
|
|
Posted: Sat May 04, 2019 5:18 am |
|
|
You need to show us your complete program !
Jay |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: 16f628a comparator configuration |
Posted: Sat May 04, 2019 4:08 pm |
|
|
el-3aba6i wrote: | I have one input changing in logic.
| Is this a push-button to ground, with a pull-up resistor on it ?
el-3aba6i wrote: |
When 5v input i want an interrupt to fire so that to reset a two seven
segments with 4 bit decoders counter in port b.
|
Why use the comparator to detect the input change ?
Why not make it easy and use the External Interrupt on Pin B0 ? |
|
![](templates/subSilver/images/spacer.gif) |
|