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.

ADC on Junebug

Status
Not open for further replies.

MrDEB

Well-Known Member
For test purposes I am trying to get Junebug to run an ADC code snippet but Juney won't coperate.
My end usage is to use a CDS or photo-transistor to detect day/ night which will enable several LEDs running a PWM code.
Got the PWM working but getting the ADC to work?
using VR1 (connected to RA1 as my input and outputting to A0
have A6 low so A0 can light
Code:
Include "ADC.bas"                   // Include the ADC.bas library  you had this  / Include "ADC.bas" didn't need the backslash 
 
Dim LED0 As PORTA.0                  // Declare the LED pin
//Dim LED1 As PORTB.1
Dim LED2 As PORTA.6
Dim result As Word 
Function Get_ADC_Sample() As Word   // Function to grab the ADC sample
 
   result = ADC.Read(1)             // Grab an ADC sample from channel 0
  result =result * 2              // Scale the answer up by a factor of 2
 
End Function
 
 
OSCCON = %01110110                 // Setup the internal OSC for 8Mhz
 
Input(PORTA.1)  // Make AN1 an inputconnected to VR1 on junebug
 PORTA.6=0
 //result =0     // clears Aresults 
//While True                         // Create an infinate loop
//If Aresult > 128 Then 
  // High (LED0)
//EndIf
 //Wend
 
while True                         // Create an infinite loop
If Get_ADC_Sample > 128 Then
   High (LED0)
EndIf
Wend
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top