I want to compare two voltages and sound the buzzer if referance voltage is higher than the other. However, when I change the voltage values on corresponding pins, nothing changes at the buzzer pin (it always sounds or nothing happens). As I investigate some example codes on the internet I saw that I should use some commands like ADRESH or ADRESL to compare the converted values by the internal ADC of the PIC I'm using. However I dunno how to modify my code. I think there's a problem with "IF PORTA.3 > PORTA.0 THEN..." part of my code. I think I can not compare the pins directly but I should compare the converted binary values. I dunno how to do it exactly. Another problem might be activating the corresponding pins AN0 and AN1. Could you please help me? Here is my code:
****************************************************************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2011 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 18.05.2011 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
@ DEVICE pic16F628a
@ DEVICE pic16F628a, WDT_on
@ DEVICE pic16F628a, PWRT_ON
@ DEVICE pic16F628a, PROTECT_OFF
@ DEVICE pic16F628a, MCLR_OFF
@ DEVICE pic16F628a, INTRC_OSC_NOCLKOUT
CMCON=7 ; Turn OFF the comparators, and use these pins as normal
; digital I/O-pins
VRCON.7=0 ; Disable voltage reference module
TRISA = %01111111
CMCON = %00000010
T1CON = %00000001 ; Enable Timer1 with a prescaler of 1:1(1microsec.)
PIE1.0=1 ; Enable Timer1 as peripheral interrupt source
PIR1.0=0 ; Clear Timer1 interrupt flag
INTCON =0 ; All interrupt are disable
BUZZER VAR PORTA.7
MAIN:
while 1=1
IF PORTA.3 > PORTA.0 THEN
HIGH BUZZER
else
low buzzer
endIF
wend
****************************************************************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2011 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 18.05.2011 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
@ DEVICE pic16F628a
@ DEVICE pic16F628a, WDT_on
@ DEVICE pic16F628a, PWRT_ON
@ DEVICE pic16F628a, PROTECT_OFF
@ DEVICE pic16F628a, MCLR_OFF
@ DEVICE pic16F628a, INTRC_OSC_NOCLKOUT
CMCON=7 ; Turn OFF the comparators, and use these pins as normal
; digital I/O-pins
VRCON.7=0 ; Disable voltage reference module
TRISA = %01111111
CMCON = %00000010
T1CON = %00000001 ; Enable Timer1 with a prescaler of 1:1(1microsec.)
PIE1.0=1 ; Enable Timer1 as peripheral interrupt source
PIR1.0=0 ; Clear Timer1 interrupt flag
INTCON =0 ; All interrupt are disable
BUZZER VAR PORTA.7
MAIN:
while 1=1
IF PORTA.3 > PORTA.0 THEN
HIGH BUZZER
else
low buzzer
endIF
wend