Code not working. Analog readings on 2 pins


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: Code not working. Analog readings on 2 pins

    Alain, here is the update. Updating to PBP3 didn't worked using MPLAB. But I copied the code to MicroCodeStudio. Compiled it and it compiled fine using PBP3 compiler. The result is the same:
    Code:
    ;-----------------PIC16F676---------------------------
    Include "modedefs.bas"
    DEFINE OSC 4       ' OSCCON defaults to 4MHz on reset
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50
    ;-------------CONFIGURATION FUSES SET HERE-------------------------
    
    
    @ __Config _XT_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _BODEN & _CP & _CPD
    
    
    '----------------------------------------
    DEFINE DEBUG_REG	PORTC
    DEFINE DEBUG_BIT	5
    DEFINE DEBUG_BAUD 2400
    DEFINE DEBUG_MODE 0
    
    
    '-------Analog Input--------------
    Poten		Var	PortA.1
    Ldr			Var	PortC.3
    '--------------------------------------
    
    
    Time		Var	Word
    Time1		Var	Word
    Counter	Var	Byte
    Ambient	Var	Word
    
    
    ;------REGISTERS SET --------
    PORTA=0
    PORTC=0
    TRISA = %000010
    TRISC = %001110
    OPTION_REG = 128
    PORTA=0
    PORTC=0
    CMCON=7
    ANSEL=%10000010
    ADCON1=%00110000
    ADCON0=%10000000
    '---------------------------------------
    
    
    
    
    	GoSub	LoadTime
    	Time1=Time
    	GoSub LoadLight
    	Counter=0
    
    
    Main:
    ; my code here
    Goto Main
    
    
    
    
    LoadTime:
    		ADCIN Poten,Time : Pause 10
    		DEBUG "TIME=",DEC Time,10
    Return
    
    
    LoadLight:
    		ADCIN Ldr,Ambient : Pause 10
    		DEBUG "AMBIENT=",DEC AMBIENT,10
    Return
    They both (Time & Ambient) are outputting as '0' on my screen. Seems the problem is something else.
    Both Time & Ambient pins are currently held high (5v)using 4.7k.
    ___________________
    WHY things get boring when they work just fine?

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: Code not working. Analog readings on 2 pins

    Alain, thanks for your inputs. Got it working finally
    ___________________
    WHY things get boring when they work just fine?

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts