View previous topic :: View next topic |
Author |
Message |
zamzam23
Joined: 25 Aug 2010 Posts: 47
|
PIC16F18323 with pinc_c1 input |
Posted: Mon Dec 25, 2023 11:45 pm |
|
|
Hi,
I want to use pin_c1 as an input with dac function actived, but I couldn't.
Pin_c0 can use as an input, it works but C1 couldn't.
when I remove dac codes, pin_c1 can be input.
Can you say me why?
Thanks.
Here is my bacis code:
Code: |
#ignore_warnings 203
#include "Library/16F18323.h"
#fuses HS,NOBROWNOUT,NOLVP,PUT,NOCPD,NOPROTECT,WDT
#use delay(crystal=20MHz, clock=20Mhz)
#include "Library/stdlib.h"
#include "Library/math.h"
#use standard_io(a)
#use standard_io(c)
//DO
#define led_pic pin_c2
//DI
#define buton1 input(pin_c0)
#define buton2 input(pin_c1)
//GENERAL
#define ON output_high
#define OFF output_low
#define flash(){ON(led_pic);delay_ms(500);OFF(led_pic);delay_ms(500);}
#use delay(clock=20M)
void main ( )
{
setup_spi(SPI_DISABLED);
setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);
setup_clc1(CLC_DISABLED);
setup_clc2(CLC_DISABLED);
setup_dsm(DSM_DISABLED);
setup_adc(ADC_OFF);
//dac codes
setup_adc_ports(sAN0 | DAC_CHANNEL);
setup_dac(DAC_OUTPUT | DAC_VSS_VDD);
dac_write(10);
while(1)
{
if(input(pin_c0)) flash();
if(input(pin_c1)) flash();
}
} |
|
|
|
zamzam23
Joined: 25 Aug 2010 Posts: 47
|
|
Posted: Tue Dec 26, 2023 12:13 am |
|
|
I solved.
I used dac codes like this.
Code: |
setup_dac(DAC_OUTPUT | DAC_VSS_VDD);
set_analog_pins(PIN_A0);
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Tue Dec 26, 2023 10:11 am |
|
|
Well done.
The reason it didn't work, was you were using the define for the wrong thing...
You have to make sure you only use the defines where the are intended.
The DMA_CHANNEL define is to allow you to set the DMA as an input to the
ADC. So just as the FVR can be read by the ADC, so can the DMA. Doesn't
setup the pin as an analog output....
The define is for use in the set_adc_channel function, not in the ports
function. |
|
|
|