Вопрос

I have a board with a PIC18LF26K22, and I'm a beginner with microcontroller programming. The RC0 (pin 11) of the PIC is connected to a LED.

As a starting excercise, I'd like to light up the LED. Since this is a very simple thing, I'd like to do it in assembly.

So, I do the following: set TRISC and ANSELC to make the pins of PORTC inputs / outputs (the RC0 is set as an output) and then in an infinite loop just send B'11111111' to PORTC and LATC.

I'm not sure what the difference is between PORTC and LATC but it seems that neither of them make this work.

INCLUDE "p18lf26k22.inc"

; Initialize
init
    ; Initialize port C
    CLRF PORTC
    CLRF LATC
    MOVLW B'01100111'
    MOVWF TRISC
    MOVLW B'00000000'
    MOVWF ANSELC

mainloop
    ; light up led on RC0
    MOVLW B'11111111'
    MOVWF PORTC
    MOVWF LATC
    GOTO mainloop

    END

The LED doesn't light up. Since I'm quite new to PICs, I guess I'm doing something wrong or am forgetting something. (Of course, this could be a soldering mistake, but it seems more likely that I'm simply missing an important point in the above code.)

Could you please tell me what I'm doing wrong?

EDIT

For the record, I also made a mistake in using pk2cmd improperly. (I was missing the -M flag.) Here's how to deploy to the PIC:

gpasm yourcode.asm
./pk2cmd -X -PPIC18LF26K22 -R -M -Fyourcode.hex -T
Это было полезно?

Решение

The least significant bit of TRISC indicates whether RC0 is an input or an output. In your code you are setting it to 1, which is an input. The mnemonic is 1 looks like an I (input) and 0 looks like an O (output).

Also with this type of problem you should check your hardware. You can easily eliminate "soldering problems". Do you have continuity in the right places? Do you see a change in voltage with a voltmeter when you think your driving the output? Does your LED work? Is the LED the right way around? Those tests are very quick and can avoid going down a more time consuming path.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top