Hi there, hoping you could help me with this little project of mine, so I\'m pro
ID: 2291275 • Letter: H
Question
Hi there, hoping you could help me with this little project of mine, so I'm programming a microcontroller (PIC12F683) using BASIC LANGUAGE on microcodestudio software
I NEED this PIC to work as a voltage comparator(ports AN0, and AN1 are the ports that can be activatated as such comparators).
this is what I currently have(the code is not 100% correct, I really need to fix this coding, I have my doubts on CMCON and VRCON)
Basic Code:
ASM_CONFIG_MCLRE_OFF; MCLR to VDD
P var byte: S var byte; Declaring Variables
V1 VAR BYTE: V2 var byte; Declaring Variables
VRCON.bit=1; For controlling 1 bit
TRISIO=%111000; GP0,GP1,GP2 pins are set as outputs, and rest as inputs
ANSEL=%000111; AN0, AN1,AN2 are set as analog inputs and rest as outputs
CMCON0=%00000011;
CMCON1=%00000011;
OSCTUNE=0: OSCCON=%01100101; Internal Oscillator set to 4 MHZ
DEFINE ADC_BITS 8; A/D converter set to 8 bits
DEFINE ADC_CLOCK 3; clock source
DEFINE SAMPLEUS 50; wait 50uS after adquisition time of 20uS
RPT:GPIO=0; Clear Port
pause 50; Pause 50 mS
adcin 0, V1; READ AN0
adcin 1, V2; READ AN1
IF V1>V2 then goto PRADO;
IF V1<V2 then goto SOMOZA;
PRADO:for P=1 TO 2;
GPIO.0=0;
PAUSE 50;
GPIO.0=1;
PAUSE 50;
NEXT P=1;
goto RPT;
SOMOZA:FOR s=1 TO 2;
GPIO.1=0;
PAUSE 50;
GPIO.1=1;
NEXT S=1;
pause 50;
GOTO RPT;
END
Explanation / Answer
ASM_CONFIG_MCLRE_OFF; MCLR to VDD
P var byte: S var byte; Declaring Variables
V1 VAR BYTE: V2 var byte; Declaring Variables
VRCON.bit=1; For controlling 1 bit
TRISIO=%111000; GP0,GP1,GP2 pins are set as outputs, and rest as inputs
ANSEL=%000111; AN0, AN1,AN2 are set as analog inputs and rest as outputs
CMCON0=%00000011;
CMCON1=%00000011;
OSCTUNE=0: OSCCON=%01100101; Internal Oscillator set to 4 MHZ
DEFINE ADC_BITS 8; A/D converter set to 8 bits
DEFINE ADC_CLOCK 3; clock source
DEFINE SAMPLEUS 50; wait 50uS after adquisition time of 20uS
RPT:GPIO=0; Clear Port
pause 50; Pause 50 mS
adcin 0, V1; READ AN0
adcin 1, V2; READ AN1
IF V1>V2 then goto PRADO;
IF V1<V2 then goto SOMOZA;
PRADO:for P=1 TO 2;
GPIO.0=0;
PAUSE 50;
GPIO.0=1;
PAUSE 50;
NEXT P=1;
goto RPT;
SOMOZA:FOR s=1 TO 2;
GPIO.1=0;
PAUSE 50;
GPIO.1=1;
NEXT S=1;
pause 50;
GOTO RPT;
END
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.