16F883 and Problems with HIGH statement


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2009
    Posts
    2

    Default 16F883 and Problems with HIGH statement

    I started with PIC programming two days ago. The project is to make a tachometer for my car. I am using the pulsin statement and that is (finally) working as expected. I will use about 10 LED's to indicate the RPM. 800 RPM=1 LED, 1300 RPM=2 LED 1800RPM=3 LED etc.
    The problem now is that when using the statement: HIGH PORTB.0 the port goes down again immidiately.. If I put a pause directly after it stays on however.
    Is this normal??
    My goal is that when the code enters the IF statement for say: 5000 RPM I want ALL the LED's "below" 5000RPM to be on.
    Here is a copy of my code. I have removed some of the IF statements for better readability.


    @ device pic16F883, INTRC_OSC_CLKOUT, BOD_OFF, PWRT_OFF, wdt_off, mclr_off, protect_off


    '************************************************* ******************************
    DEFINE OSC 8 'set OSC value to 8MHz for instructions PAUSE, PAUSEus and SOUND
    '************************************************* ******************************

    '************************************************* ******************************
    'VARIABLES declaration
    'IF VARIABLES USED FOUR COUNTER GO OVER 256, USE WORD INSTEAD

    puls_h VAR Word 'input high
    puls_l VAR Word 'input low
    rpm var word
    '************************************************* ******************************
    'Setting registers

    OSCCON = %01110001
    ANSEL = %00000000 'choose digital i/o, val = 0
    TRISA = %00000001 'set porta pins directions (1=input, high impedance)
    TRISB = %00000000
    PORTA = %00000000 'set port pins logic, A0 will be a default LOW with 100K WPD
    PORTB = %00000000 'set port pins logic
    '************************************************* ******************************

    PAUSE 1000 'let the power level stabilize if not already done

    start:

    PULSIN PORTA.0, 0, puls_l
    PULSIN PORTA.0, 1, puls_h
    rpm = puls_l+puls_h

    IF (rpm > 600 AND RPM < 2000) THEN
    HIGH PORTB.0
    'PAUSE 500 When I use this pause the LED will be lit 500ms here
    LOW PORTB.1 'Without the pause the LED's flash fast and very dim.
    LOW PORTB.2
    LOW PORTB.3
    GOTO START
    endif
    IF (rpm > 2000 AND RPM < 4000) THEN
    HIGH PORTB.0
    HIGH PORTB.1
    'PAUSE 500 When I use this pause the LED will be lit 500ms here
    LOW PORTB.2
    LOW PORTB.3
    GOTO START
    endif
    IF (rpm > 4000 AND RPM < 6000) THEN
    HIGH PORTB.0
    HIGH PORTB.1
    HIGH PORTB.2
    'pause 500 When I use this pause the LED will be lit 500ms here
    LOW PORTB.3
    GOTO START
    endif
    IF (rpm > 6000 AND RPM < 8000) THEN
    HIGH PORTB.0
    HIGH PORTB.1
    HIGH PORTB.2
    HIGH PORTB.3 'When this code is active, the LED on portb.3 is lit.
    GOTO START
    endif
    GOTO START
    END 'end of program
    Last edited by aaanekre; - 27th October 2009 at 04:14.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    The problem now is that when using the statement: HIGH PORTB.0 the port goes down again immidiately.. If I put a pause directly after it stays on however.
    Is this normal??
    Yes it is.

    The 16F88x devices have analog functions on PORTB.

    add this ...
    Code:
    ANSELH = 0
    DT

  3. #3
    Join Date
    Oct 2009
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Thank you

    Thank you for helping me out with that one. Pretty simple problem now after reading about the ANSELH in the datasheet though... But its nice to get some help when you are banging the head...
    I am learning new stuff all the time and I think the PIC processor is great. I work as a teacher in high school and we have been using Basic Stamp wich is a bit easier to work with but have limitations. (Especially the price !!) One of my students made code for a tachometer using BS2 and I promised him to port the program to a cheaper PIC processor. I managed to get the tachometer running now on a PIC16F628 that costs a fraction of the BS2. I hope my student will be pleased.
    Thanks again.

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