Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Problem with PIC digital input output

Status
Not open for further replies.

sahu

Member
I tried to use the below given code to PIC 16F72.
Code:
#include <htc.h>
#include <PIC16F72.h>
    __CONFIG(FOSC_HS & WDTE_OFF & PWRTE_OFF & CP_OFF & BOREN_ON);

#define _XTAL_FREQ 4000000
#define HI_CUT 208//adc=245*17/20    //250
#define OLD 100
#define LO_CUT 60


#define NORMAL_LED     RA5    //RB1
#define ERRORE_LED     RA4   
#define OP_LOAD_RELAY     RA3    //RB2

#define C_100    RB5
#define C_10    RB6
#define C_1        RB7
.
.
.
.
.

void main()
{
  TRISB = 0x01;
  TRISC = 0x00;
  TRISA = 0xC7; //RA0 to RA2 as adc & RA3 to RA5 as o\p
  GIE = 1;
  PEIE = 1;
  T0IF = 0;
  OPTION_REG = 0x07;
  T0IE = 1;
  TMR2IE = 1;
  TMR2IF = 0;
  TMR1IF = 0;
  TMR1IE = 1;
  T1CON = 0x34;
  INTF = 0;
  INTEDG = 0;
  INTE = 1;
  T0CS = 1;
  NORMAL_LED = 1;
  ERRORE_LED = 1;
  OP_LOAD_RELAY = 0;
  C_100 = 1;
  C_10 = 1;
  C_1 = 1;

  ADC_Init();
.
.
.
.
.
.
BUT RA3 & RA5 are not Work as output. Can anyone tell why?
where i has wrong ?
but when i use as below
#define NORMAL_LED RB1
#define ERRORE_LED RA4
#define OP_LOAD_RELAY RB2
work fine .
 
According to the ADCON1 register... That combo isn't possible...

The closest is ADCON1 = 0x04.. That gives AN0, AN1, AN3, and AN2 / 5 as digital... so you'll have to swap AN2 and AN3
now i'm using ADC_Init as below given code
Code:
void ADC_Init()
{
  ADCON0 = 0x81; //ADC Module Turned ON
  ADCON1 = 0x00;
}

char ADC_Read(unsigned char channel)
{
  if(channel > 7) //If Invalid channel selected
    return 0;     //Return 0

  ADCON0 &= 0xC7; //Clearing the Channel Selection Bits
  ADCON0 |= channel<<3; //Setting the required Bits
  __delay_ms(2); //Acquisition time to charge hold capacitor
  GO_nDONE = 1; //Initializes A/D Conversion
  while(GO_nDONE); //Wait for A/D Conversion to complete
  return (ADRES); //Returns Result
}
 
You can't have that combination!!!!!!

If ADCON1 = 000.. All PORTA will be analogue input.
If ADCON1 = 001.. All PORTA will be analogue input and RA3 will be Vref.
If ADCON1 = 010.. All PORTA will be analogue input.
If ADCON1 = 011 . All PORTA will be analogue input and RA3 will be Vref.
If ADCON1 = 100.. RA0, RA1 and RA3 will be analogue input RA2 and RA5 will be digital.
If ADCON1 = 101.. RA0 and RA1 will be analogue input and RA3 will be Vref.. RA2 and RA5 will be digital.
If ADCON1 = 111.. All PORTA digital.

These are the only combinations
 
You can't have that combination!!!!!!

If ADCON1 = 000.. All PORTA will be analogue input.
If ADCON1 = 001.. All PORTA will be analogue input and RA3 will be Vref.
If ADCON1 = 010.. All PORTA will be analogue input.
If ADCON1 = 011 . All PORTA will be analogue input and RA3 will be Vref.
If ADCON1 = 100.. RA0, RA1 and RA3 will be analogue input RA2 and RA5 will be digital.
If ADCON1 = 101.. RA0 and RA1 will be analogue input and RA3 will be Vref.. RA2 and RA5 will be digital.
If ADCON1 = 111.. All PORTA digital.

These are the only combinations
RA4 can't use as digital?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top