Here I go showing just how little I know. I am making a 16F690 circuit that will monitor 4 inputs. When an input goes low it will light a green led. When an input goes high it will light a red led.
At this time I'm using port A for the input and ports B and C for the outputs.
(The actual pin assignments aren't cast in stone)
I don't know anything about writing any kind of code, so .
I initially created the code using FlowCode, and compiled it with Hi-Tech ANSI C. Next I ran it on PIC Simulator IDE. I works, for the most part. When RA3/MRCLR is is toggled high RB7 (green) goes out and RC0 (red)comes on. Problem is the red led blinks. I have the same issue with RA4 /OSC2
I think the reason is that RA3 is MRCLR. If so, is the cure to configure port A as INPUT?
I'd try it myself if I knew what to cut and paste into the code. Could someone spoon feed me the answer?
At this time I'm using port A for the input and ports B and C for the outputs.
(The actual pin assignments aren't cast in stone)
I don't know anything about writing any kind of code, so .
I initially created the code using FlowCode, and compiled it with Hi-Tech ANSI C. Next I ran it on PIC Simulator IDE. I works, for the most part. When RA3/MRCLR is is toggled high RB7 (green) goes out and RC0 (red)comes on. Problem is the red led blinks. I have the same issue with RA4 /OSC2
I think the reason is that RA3 is MRCLR. If so, is the cure to configure port A as INPUT?
I'd try it myself if I knew what to cut and paste into the code. Could someone spoon feed me the answer?
Rich (BB code):
#define MX_PIC
//Defines for microcontroller
#define P16F690
//Functions
#define MX_CLK_SPEED 19660800
#ifdef _BOOSTC
#include <system.h>
#endif
#ifdef HI_TECH_C
#include <pic.h>
#endif
//Configuration data
//__CONFIG(0x3ff4);
__CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT & UNPROTECT \
& BORDIS & IESODIS & FCMDIS);
//Internal functions
#include "C:\Program Files\Matrix Multimedia\Flowcode V4\FCD\internals.h"
//Macro function declarations
//Variable declarations
char FCV_INPUTA4;
char FCV_INPUTA1;
char FCV_INPUTA2;
char FCV_INPUTA3;
//Macro implementations
void main()
{
//Initialisation
// ansel = 1;
// anselh = 1;
ANSEL = 0x00;
ANSELH = 0x00;
//Interrupt initialisation code
option_reg = 0xC0;
//Loop
//Loop: While 1
while (1)
{
//Input
//Input: A4 -> inputA4
trisa = trisa | 0x10;
FCV_INPUTA4 = ((porta & 0x10) == 0x10);
//Decision
//Decision: inputA4=1?
if (FCV_INPUTA4==1)
{
//Output
//Output: 0 -> C0
trisc = trisc & 0xfe;
if (1)
portc = (portc & 0xfe) | 0x01;
else
portc = portc & 0xfe;
//Output
//Output: 1 -> B4
trisb = trisb & 0xef;
if (0)
portb = (portb & 0xef) | 0x10;
else
portb = portb & 0xef;
} else {
//Output
//Output: 1 -> C0
trisc = trisc & 0xfe;
if (0)
portc = (portc & 0xfe) | 0x01;
else
portc = portc & 0xfe;
//Output
//Output: 0 -> B4
trisb = trisb & 0xef;
if (1)
portb = (portb & 0xef) | 0x10;
else
portb = portb & 0xef;
}
//Input
//Input: A1 -> inputA1
trisa = trisa | 0x02;
FCV_INPUTA1 = ((porta & 0x02) == 0x02);
//Decision
//Decision: inputA1=1?
if (FCV_INPUTA1==1)
{
//Output
//Output: 0 -> C1
trisc = trisc & 0xfd;
if (1)
portc = (portc & 0xfd) | 0x02;
else
portc = portc & 0xfd;
//Output
//Output: 1 -> B5
trisb = trisb & 0xdf;
if (0)
portb = (portb & 0xdf) | 0x20;
else
portb = portb & 0xdf;
} else {
//Output
//Output: 1 -> C1
trisc = trisc & 0xfd;
if (0)
portc = (portc & 0xfd) | 0x02;
else
portc = portc & 0xfd;
//Output
//Output: 0 -> B5
trisb = trisb & 0xdf;
if (1)
portb = (portb & 0xdf) | 0x20;
else
portb = portb & 0xdf;
}
//Input
//Input: A2 -> inputA2
trisa = trisa | 0x04;
FCV_INPUTA2 = ((porta & 0x04) == 0x04);
//Decision
//Decision: inputA2=1?
if (FCV_INPUTA2==1)
{
//Output
//Output: 0 -> C3
trisc = trisc & 0xf7;
if (1)
portc = (portc & 0xf7) | 0x08;
else
portc = portc & 0xf7;
//Output
//Output: 1 -> B6
trisb = trisb & 0xbf;
if (0)
portb = (portb & 0xbf) | 0x40;
else
portb = portb & 0xbf;
} else {
//Output
//Output: 1 -> C3
trisc = trisc & 0xf7;
if (0)
portc = (portc & 0xf7) | 0x08;
else
portc = portc & 0xf7;
//Output
//Output: 0 -> B6
trisb = trisb & 0xbf;
if (1)
portb = (portb & 0xbf) | 0x40;
else
portb = portb & 0xbf;
}
//Input
//Input: A3 -> inputA3
trisa = trisa | 0x08;
FCV_INPUTA3 = ((porta & 0x08) == 0x08);
//Decision
//Decision: inputA3=1?
if (FCV_INPUTA3==1)
{
//Output
//Output: 0 -> C0
trisc = trisc & 0xfe;
if (1)
portc = (portc & 0xfe) | 0x01;
else
portc = portc & 0xfe;
//Output
//Output: 1 -> B7
trisb = trisb & 0x7f;
if (0)
portb = (portb & 0x7f) | 0x80;
else
portb = portb & 0x7f;
} else {
//Output
//Output: 1 -> C0
trisc = trisc & 0xfe;
if (0)
portc = (portc & 0xfe) | 0x01;
else
portc = portc & 0xfe;
//Output
//Output: 0 -> B7
trisb = trisb & 0x7f;
if (1)
portb = (portb & 0x7f) | 0x80;
else
portb = portb & 0x7f;
}
}
mainendloop: goto mainendloop;
}
void MX_INTERRUPT_MACRO(void)
{
}