Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Pic Assembly programming

  1. Nov 8, 2011 #1
    Hi. I'm learning how to program in assembly to PICs and I'm stuck quite a while in a problem trying to figure out how to read an input value. I've been googling a lot and it seems that my code it's fine but as I'm beginning to learn I would like to know if any of you guys could tell me if its really ok.

    Code (Text):

    #include <P16F688.inc>

    ORG     0x00
    goto    main

    main:
        banksel     TRISC
        movlw       B'00000100'
        movwf       TRISC
       
    loop:
        banksel     PORTC
        btfsc       PORTC, RC2
        call        blinkRed
       
        btfss       PORTC, RC2
        call        blinkGreen 
    goto    loop

    blinkRed:
        banksel     PORTC
        bsf         PORTC, 1
        bcf         PORTC, 0
        ;movlw      B'00000010'
        ;movwf      PORTC      
    return

    blinkGreen:
        banksel     PORTC
        bcf         PORTC, 1
        bsf         PORTC, 0
        ;movlw      B'00000001'
        ;movwf      PORTC  
    return

    end

     
    Thank you very much.
     
  2. jcsd
  3. Nov 8, 2011 #2

    chiro

    User Avatar
    Science Advisor

    Hey rsegecin and welcome to the forums.

    I'm not familiar with this kind of assembler, but is the information you are trying to read meant to be coming from a hardware port?
     
  4. Nov 9, 2011 #3
    Hi chiro thank your very much for the reply. I've just found out that if I left the code the way I mentioned in the post above the ports were configured by default as analog inputs therefore to get a discrete value 0, 1 wouldn't work as an analog input has to have some others configurations to work properly. So I just needed to set them as digitals IO.

    I'm posting the code for future reference to others:

    Code (Text):

    #include <P16F688.inc>

    ORG     0x00
    goto    main

    main:
        banksel     ANSEL
        movlw       B'00000000'
        movwf       ANSEL
           
        banksel     TRISC
        movlw       B'00000100'
        movwf       TRISC

    loop:
        banksel     PORTC

        btfsc       PORTC, 2
        call        blinkRed   

        btfss       PORTC, 2   
        call        blinkGreen
    goto    loop

    blinkRed:
        banksel     PORTC
        movlw       B'00000010'
        movwf       PORTC      
    return

    blinkGreen:
        banksel     PORTC
        movlw       B'00000001'
        movwf       PORTC  
    return

    end

     
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Pic Assembly programming
  1. Assembly Programming (Replies: 2)

  2. Programming a PIC (Replies: 21)

  3. PIC IO in assembly (Replies: 3)

Loading...