- #1
El Moriana
- 33
- 0
Hi,
Here goes:
Problem
I'm having trouble getting my PIC18F45J10 to light up an LED.
I have a LED-res-ground connected to RC7 (pin 26).
My code is set to configure PORTC pins to be output and then set the RC7 bit.
Upon debugging, the following is shown:
TRISC=0x00
PORTC=0x80
RC7=0x00
It can be seen here that, though the RC7 bit in PORTC is set (shown by the '10000000' in PORTC), RC7 is not... my physical circuit is also devoid of any activity and my LED stays dark.
Quick Analysis of Problem
This is purely a code problem; the circuit has been checked and is working.
A major part of the problem is certainly because I am new to programming PIC18Fxxxx's. Also, I have never dealt with latches before. My guess is that my problem has to do with latches and how they affect the physical pin status. I have only a vague inkling of what the latches actually do.. as the I/O section of the datasheet mentions only that they are "useful" and that the most relevant threads on my problem I have found mention them and assume I already know all about them.
I was about to venture into the realm of vague google searching but I might as well also ask here: what are latches and why are they useful? (the latter is not always obvious)
I have provided my code below:
Code
I have also tried setting RC7 using
but read somewhere I should always write to latches and never the actual port.. in anycase both gave me the same result in the debugger.
Here goes:
Problem
I'm having trouble getting my PIC18F45J10 to light up an LED.
I have a LED-res-ground connected to RC7 (pin 26).
My code is set to configure PORTC pins to be output and then set the RC7 bit.
Upon debugging, the following is shown:
TRISC=0x00
PORTC=0x80
RC7=0x00
It can be seen here that, though the RC7 bit in PORTC is set (shown by the '10000000' in PORTC), RC7 is not... my physical circuit is also devoid of any activity and my LED stays dark.
Quick Analysis of Problem
This is purely a code problem; the circuit has been checked and is working.
A major part of the problem is certainly because I am new to programming PIC18Fxxxx's. Also, I have never dealt with latches before. My guess is that my problem has to do with latches and how they affect the physical pin status. I have only a vague inkling of what the latches actually do.. as the I/O section of the datasheet mentions only that they are "useful" and that the most relevant threads on my problem I have found mention them and assume I already know all about them.
I was about to venture into the realm of vague google searching but I might as well also ask here: what are latches and why are they useful? (the latter is not always obvious)
I have provided my code below:
Code
Code:
;Imports
LIST P=18F45J10 ;directive to define processor
#include <P18F45J10.INC> ;processor specific variable definitions
;Config Bits
CONFIG FOSC = HS ;select HS oscillator
;Start
ORG 0x0000 ;reset
goto Init ;go to initialisation
;Initialisation
Init:
clrf PORTC ;clear register
clrf TRISC ;set all pins to output
clrf LATC ;clear data latch
goto Main
;Main Code
Main:
BSF LATC, LATC7 ;run pin high
Loop:
goto Loop ;Infinite Loop
END
I have also tried setting RC7 using
Code:
BSF PORTC, RC7