How Do I Use The Analog Pins In Pic 16f877a With MikroBasic

Status
Not open for further replies.

Programmer.C

Junior Member level 1
Joined
May 6, 2006
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,414
How Do I Use The Analog Pins In Pic 16f877a With MikroBasicPro

I'hv Tried the code below to use pin AN2 but it does not work

I'm working with RS232 Normally & I'hv not face any problems
But i can't read any analog signal with this code

I hope any body write me some code for reading an analog signal for example from a normal Potentiometer


Code:
program Gen_Test


dim adc_rd as word
dim str_x as string [20]

        
main:

'   Main program

    ADCON1 = 0x00          ' Configure AN2 pin as analog
    TRISA  = 0xFF            ' PORTA is input

    UART1_Init(4800)         ' initialize UART module
    Delay_ms(100)

    UART1_Write_Text("Ok")              

 while TRUE


     adc_rd = ADC_Read(2)    ' get ADC value from 2nd channel
     WordToStr(adc_rd,str_x)
     UART1_Write_Text(str_x)              
     Delay_ms(5000)

 wend


end.
 

Hi,
At first, try to read ADC and show them on LEDs like:
Code:
program ADC_Test
dim ADC_Rd as word
main:
     TRISA = $FF 'PORTA assigned as input
     TRISB = 0 'PORTB assigned as output
     PORTB = 0
     while true
          ADC_Rd = ADC_Read(2) 'Read Channel 2
          PORTB = ADC_Rd >> 2 'Send 8 bit data to PORTB
     wend
end.
Try this and see. If it works, then the problem lies elsewhere.
Hope this helps.
Tahmid.
 

Re: How Do I Use The Analog Pins In Pic 16f877a With MikroBa

Thanks for ur reply but i have tried this before i send my problem & it's work properly.
I need to read an analog signal from Channel 2 (AN2) using the ADC module as i mentioned before.
I hope u help me to do that.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…