Set bits of Word problem


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Cool Rtfm ...

    Hi, Pdegior

    I saw something in the manual ....$ 4.17.14 ...

    Have a look to it ...

    Alain

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Freebie!!!

    Code:
    TRISA=255  ' Set all PORTA pins to Input
    
    dip var byte
    
    Start:
        dip=PORTA
        select case dip
            case 0
                '
                ' Code for PORTA=0
                '
            case 1
                '
                ' Code for PORTA=1
                '
            case 2
                '
                ' Code for PORTA=2
                '
            end select
        goto start
    And you're using a BYTE sized variable to do it.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Hi Pdegior. I tested this program with only part of PORTA and it works. Hope this helps.

    'CODE COMPILED FOR 16F818
    OSCCON = $60 'set int osc to 4mhz
    adcon1 = 7 ' set inputs to digital
    TRISA = %11111111 'ALL PORTA INPUTS
    TRISB = %00000000 'ALL PORTB OUTPUTS
    PORTB = 0 'ALL OUTPUTS LOW
    @ DEVICE MCLR_ON, INTRC_OSC, WDT_ON, LVP_OFF, BOD_ON, PWRT_ON, PROTECT_ON
    DIP VAR BYTE

    START:
    PORTB = 0 'off all leds
    LET DIP = 0 'clear the variable DIP


    LET DIP.BIT0 = 0
    IF PORTA.0 = 1 Then LET DIP.BIT0 = 1 'dip bits are 0 unless PORTA bit is high

    LET DIP.BIT1 = 0
    IF PORTA.1 = 1 Then LET DIP.BIT1 = 1

    LET DIP.BIT2 = 0
    IF PORTA.2 = 1 Then LET DIP.BIT2 = 1

    LET DIP.BIT3 = 0
    IF PORTA.3 = 1 Then LET DIP.BIT3 = 1

    IF DIP = 0 Then High PORTB.0 'light corresponding LED
    IF DIP = 1 Then High PORTB.1
    IF DIP = 2 Then High PORTB.2
    IF DIP = 3 Then High PORTB.3
    Pause 1000 'wait a second
    PORTB = 0 'off led
    GoTo START 'do it again

  4. #4
    Join Date
    Jul 2005
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Thanks,

    that seems to have done it. Still not too sure why the way I had it doesn't work but oh well.

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. 16f877A and tmr1 external crystal question
    By comwarrior in forum General
    Replies: 3
    Last Post: - 13th July 2009, 00:40
  3. Interruptus Frustratus
    By Byte_Butcher in forum General
    Replies: 16
    Last Post: - 17th April 2009, 20:36
  4. 16F628A - Stops if release power switch.
    By dene12 in forum General
    Replies: 16
    Last Post: - 14th February 2009, 07:57
  5. How to isolate 10 bits from word variable?
    By rcbandwidth123 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 14th April 2008, 20:18

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