• PicŪ Basic


  • PIC18F1320 - Using ADC - 10 bits

    PIC18F1320 to transmit data read by AN0 to PC at 115K,8N1 using the on chip EUSART


    Device 18F1320 ' Produce code for a 18F1320
    ' Config file
    ' Using 10Mhz Crystal - set PLL x 4 (40Mhz internal clock)
    ' MCLR disabled
    '
    XTAL = 40 ' 40 Mhz Int Osc
    WATCHDOG = OFF '
    '
    '
    '
    'Baud Rate setup
    Declare HSERIAL_BAUD 115200 ' 115200 baud
    Declare HSERIAL_RCSTA %10010000 ' Sets the respective PICmicro hardware register RCSTA
    Declare HSERIAL_TXSTA %00100100 ' Sets the respective PICmicro hardware register TXSTA
    Declare HSERIAL_CLEAR On ' Clear the overflow error bit before commencing a read
    '
    '
    '
    ' ADC Setup
    '-------------
    Declare ADIN_STIME 150 ' Settling time 150uS
    ADCON0 = %00000001 ' Chan Select AN0
    ADCON1 = %11111110 ' AN0 Analogue
    ADCON2 = %10111110 ' Right justified, 20TAD, Fosc/64
    '
    ' Declare variables
    '---------------------
    Dim ADCVALUE As Word ' ADC reading
    '
    'Setup Ports
    '-------------
    TRISA = %00000011 ' Set up IO PortA
    TRISB = %11111101 ' Set up IO PortB
    '
    '
    '
    ReadADC:
    ADCVALUE = ADIn 0 ' Read ADC Chan 0
    HSerOut [DEC4 ADCVALUE, ","] ' Send
    GoTo ReadADC ' Loop for ever
    '
    '
    End
    This article was originally published in forum thread: PIC18F1320 - Using ADC - 10 bits started by Dick Barton View original post
  • Recent Activity

    teo-16018

    Microsoft security essentials blues

    Thread Starter: shantanu@india

    Hi, A strange thing happened just now.My Windows 7 Micrsoft Sercurity Essentials suddenly gave a warning that prplus.exe(Compiler) is a potential...

    teo Today, 19:23 Go to last post
    pic-ignorant-1162

    Proton Runtime Error

    Thread Starter: Paulcc

    I have proton running well on my laptop, but after installing it on my desktop, I get the following runtime error: "Runtime Error 217 at 000709FC" I...

    pic-ignorant Yesterday, 22:11 Go to last post
    David Barker-251

    UMC bootloader 18F46K22

    Thread Starter: shunt010

    Hi all. I am trying to build a UMC bootloader file for the 18F46K22, and it doesn't appear to work. It returns (in the error log) Error ...

    David Barker Today, 11:20 Go to last post
    barak-1433

    SPI mssp

    Thread Starter: picprotonguy

    Just ordered Digital to Analog IC MCP4822 with SPI interface and immediately opened proton manual. I'm very disappointed, it looks like Proton...

    barak Today, 16:06 Go to last post