Using as many internal peripherals as possible.


Results 1 to 12 of 12

Threaded View

  1. #2


    Did you find this post helpful? Yes | No

    Default Re: Using as many internal peripherals as possible.

    Even better, only 33 words.

    Code:
    #CONFIG
      __config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_ON & _FCMEN_ON
      __config _CONFIG2, _WRT_OFF & _PLLEN_ON & _STVREN_ON & _BORV_19 & _LVP_OFF
    #ENDCONFIG
     
    OSCCON =     %00110010 ; Clock 250kHz
    
    TRISA   =    %010000   ; RA4 input for battery measurement, rest output
    ANSELA  =    %0000     ; ADC Disable
    OPTION_REG = %10000111 ; Disable internal pull-ups, TMR0 On, prescaller to 256
    
    FVRCON  =    %10011000 ; Internal reference to 2048mV
    
    CM1CON0 =    %10100110 ; Comparator output to C1OUT, switch on LED if voltage is below ref. 2,048V
    CM1CON1 =    %00100001 ; C1IN1- pin is RA4, comparator voltage input, C1IN1+ positive input to FVR set to 2,048V
    
    LATA    =    %000010   ; init state of pin RA0 and RA1, LEDs connected to these port
    
    Main:
    
    if INTCON.2 = 1 then LATA = LATA ^ %000011 : INTCON.2 = 0 ; if TMR0 owerflow flip LEDs, then clear owerflow flag
    
    goto main
    I think, reached the limit of optimization.
    Last edited by louislouis; - 30th August 2023 at 14:26.

Similar Threads

  1. New cool PIC peripherals
    By HenrikOlsson in forum General
    Replies: 1
    Last Post: - 21st September 2016, 20:50
  2. Replies: 8
    Last Post: - 21st March 2015, 17:21
  3. Replies: 4
    Last Post: - 11th June 2014, 22:53
  4. Replies: 0
    Last Post: - 7th August 2008, 09:02
  5. Internal Oscillator
    By jhorsburgh in forum General
    Replies: 2
    Last Post: - 10th December 2007, 02:13

Members who have read this thread : 1

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