16LF1824 strange problem


Results 1 to 32 of 32

Threaded View

  1. #21
    Join Date
    Jan 2014
    Posts
    84


    Did you find this post helpful? Yes | No

    Default Re: 16LF1824 strange problem

    Something is strange. Now it work with the same variable in init and in main loops. Yesterday I tried a many time and don't worked.
    @ richard : thx for your suggestions
    Here is working code :

    Code:
    #CONFIG
            __CONFIG _CONFIG1, _FCMEN_OFF & _FOSC_INTOSC & _WDTE_OFF & _MCLRE_OFF & _CP_ON & _IESO_OFF & _BOREN_OFF & _PWRTE_OFF
            __CONFIG _CONFIG2, _PLLEN_OFF & _STVREN_OFF & _LVP_OFF
    #ENDCONFIG
    
    DEfine  OSC 4 
    OSCCON = %01101010   'sets the internal oscillator to 4Mhz
    
    
    
    ADCON0 = %00000000    
    ADCON1 = %00000000     
    FVRCON = %11000010     'turn fixed voltage reference on & set it to 2.048V (last two bits set the voltage ...01 =1.024V,10=2.048
    CM1CON0 = 0   ' COMPARATORS OFF
    CM1CON1 = 0
    CM2CON0 = 0   ' COMPARATORS OFF
    CM2CON1 = 0    
    CPSCON0 = 0   'CAPACTIVE SENSE MODULE OFF
    RCSTA.7  = 0   'SERIAL PORT OFF
    
    TRISA   = %00000000
    TRISC   = %00000100    
    ANSELA = %00000000
    ANSELC = %00000000
    
    OPTION_REG.7 = 0
    WPUA  =  %00000000
    
    PORTA = 0
    PORTC = 0 
    
    Symbol front  = PORTA.4
    
    
    x      var  byte
    varb   var  byte
    divf   var  byte
    
    x        = 0
    varb   = 0
    divf    = 0
    
    pause 100
    
    init:
    pulsin portc.2 , 1, varb
     if (varb < 140) or (varb > 160) then init
     pause 100
     pulsin portc.2 , 1, varb
     if (varb < 140) or (varb > 160) then init
     if (varb > 140) and (varb < 160) then goto beep
    goto init
    
    beep:      
    hpwm 1 , 10, 3000
        high front
        pause 80
        low front
        pause 200
    hpwm 1 , 5, 1200
        high front
        pause 80
        low front
        pause 200
    hpwm 1 , 10, 3000
        high front
        pause 80
        low front
     
    
    '************************************************************
    main:
    pulsin portc.2 , 1, varb
    hpwm 1 , x, 1954 
    
    '=======================miss signal=========================
    if varb < 50 then
         varb = 150
         x=0
         low front
    endif
    '============================================================
    
    '========================front===============================
    if varb> 160  then
            high front
        if varb > 190 then varb = 190
            divf=255*(varb-160)/30
        if x > 255 then x = 255
        if divf > 255 then divf = 255            
        if divf >x then x=x+2
        if divf <x then x=x-6
    endif
    '============================================================
    
    '==================== stay ==================================
    if varb < 160 and varb > 140 then
        low front
        x= 0 
    endif
    '=============================================================
    
    '==========================light==============================
    if varb < 140 and varb > 50 then
         high PORTA.0
    else
        low PORTA.0
    endif
    goto main
    end
    Last edited by midali; - 20th August 2014 at 15:06.

Similar Threads

  1. A strange problem
    By mombasa in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 25th January 2012, 22:08
  2. Very strange problem...
    By alanmcf in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th May 2011, 07:28
  3. strange serout2 problem
    By KaanInal in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 7th January 2010, 10:33
  4. Strange problem with PBP 2.50
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 16th October 2007, 21:45
  5. strange problem 12f675
    By peterdeco1 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th July 2007, 14:47

Members who have read this thread : 0

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