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.

18f1320 ADCON0 question

Status
Not open for further replies.

ghostman11

Well-Known Member
i think pommie posted the following code

Code:
// Name : BLINK_1.BAS
Device = 18F1320
Clock = 4            // 4MHz clock
Include "junebug.bas"
Dim Count As Byte
Dim GO As ADCON0.1
OSCCON = $62         // select 4MHz internal clock
ADCON1 = %11110101   // digital I/O except RA1 & RA3
ADCON0 = %00000101   //A2D on and select AN1
ADCON2 = %00110101   //Left justify - Fosc/16
While True
    Count = 1
    While Count < 6
        GO = 1              //start conversion
        While(GO=1)         //wait for it to complete
        Wend   
        LED(Count)          // light LED(1..6) or none LED(0)
        DelayMS(ADRESh+10)  // delay in 1000s of a second
        Inc(Count)
    Wend   
    While Count > 1
        GO = 1              //start conversion
        While(GO=1)         //wait for it to complete
        Wend   
        LED(Count)          // light LED(1..6) or none LED(0)
        DelayMS(ADRESh+100)  // delay in 1000s of a second
        Dec(Count)
    Wend
Wend
End

wich blinks the leds on the june bug at a rate that corresponds to the VR1 on the june bug. the code works fine..however
i been trying to switch this to VR2.
according to the data sheet AN1 is 001, and 101 is AN5??
is not making much sense to me can anyone explain this??

VR2 according to the junebug diagram is on AN3 so how would i set this?

sorry if i havnt described what i want to know very well.
 
The channel is selected by the line ADCON0 = %00000101, the bits in red define the channel number and so they need to be 011 (3 in decimal) so it becomes ADCON0 = %00001101.

Is it making any sense yet?

Mike.
 
Last edited:
great one mike :D the datasheet is a bit confuseing :D whats the last 01 do??
its slowly sinking in :D finaly feel like i am getting a start was about ready to sling it across the room in frustration last night lol :p
 
If you look on page 155 of the datasheet, you will see that bit 0 (the last bit) turns the ADC on/off and bit 1 starts the conversion.

The frustration is understandable. You have jumped into the deep end by reading DS1820s and using the ADC etc. Most people start with flashing an LED.

Mike.
 
i have to get some more books! i know the web is full of info but i seem to take things on board better doing it the old fashioned way and sit by the fire reading a real book lol. i did the flashing led but its not enough :D i am realy getting into all this, i didnt think i would origanally i just wanted to learn enough to do a few projects i had in mind. now its turned into a thirst for knowledge thanks for all the help by the way
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top