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.

I\p & o\p setting

Status
Not open for further replies.

sahu

Member
right now i am facing some problem about i\p , o\p & adc setting .use 16f676.
Code:
TRISA0_bit = 1            '   input
  TRISC = 0x00              ' Set PORTc as output
  CMCON  = CMCON or 0x07    ' turn off comparators
  ADCON1 = ADCON1 or 0x00   ' Set AN0 channel pin as analog

description....
AN0 channel (RA0) ' adc input
TRISC = 0x00 ' Set PORTc as output for relay , led & bzr
CMCON = CMCON or 0x07 ' turn off comparators
ADCON1 = ADCON1 or 0x00 ' Set only AN0 channel (RA0) pin as analog
porta.1 & porta.2 = Set PORTA as output for relay , led & bzr
porta.4 & porta.5 = Set PORTA as input for digital (means logic hi \ low)
ref volt is vdd (5v)
pl clear me where i wrong ?
 
CMCON =0x07 is right but you need to set this to make the ADC work right

REGISTER 7-3: ANSEL — ANALOG SELECT REGISTER (ADRESS: 91h) (PIC16F676 ONLY)
R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1
ANS7 ANS6 ANS5 ANS4 ANS3 ANS2 ANS1 ANS0
bit 7 bit 0
bit 7-0: ANS<7:0>: Analog Select between analog or digital function on pins AN<7:0>, respectively.
1 = Analog input. Pin is assigned as analog input.(1)
0 = Digital I/O. Pin is assigned to port or special function.
Note 1: Setting a pin to an analog input automatically disables the digital input circuitry,
weak pull-ups, and interrupt-on-change if available. The corresponding TRIS bit
must be set to Input mode in order to allow external control of the voltage on the pin.
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ’1’ = Bit is set ’0’ = Bit is cleared x = Bit is unknown
 
Status
Not open for further replies.

Latest threads

Back
Top