PDA

View Full Version : Noobie programmer



noobie
- 27th April 2006, 09:35
Hi! I am currently a new programmer programming a PIC16C745 IC. Can any people out there take a look at my code and advice me what is wrong.I am trying to detect an input at RB0 and give an output and RB5. Thanks!

#include <p16c745.inc>

#define LED PORTB,5 ;
#define switch PORTB,0 ;


ORG 00H ;
BCF STATUS, RP1 ;
BCF STATUS, RP0 ;
CLRF PORTB ; Initialize PORTB by
; clearing output
; data latches
BSF STATUS, RP0 ; Select Bank 1
MOVLW 06H ; Configure all pins
MOVWF ADCON1 ; as digital inputs
MOVLW 0xCF ; Value used to
; initialize data
; direction
MOVWF TRISB ; Set RB<3:0> as inputs
; RB<5:4> as outputs
; TRISB<7:6> are always
; read as ’0’.
GOTO main ;
main BTFSS switch ;
GOTO $-1 ;
BSF LED ;
BTFSC switch ;
GOTO $-1 ;
BCF LED ;
GOTO main ;

end

paul borgmeier
- 27th April 2006, 13:33
One problem with your quest for a solution is that you have posted in a PicBasic language Forum and not an Assembly language Forum. Try posting your question here

http://forum.microchip.com/

However, everything looks fine to me with your code – it should work. When you repost in the microchip forum, make sure to describe what is not working. Does the chip just do nothing? Does your chip program without error? What is providing the highs and lows on PORTB.0? What configs did you set? Do you have a schematic to post? etc.

Good Luck,

Paul Borgmeier
Salt Lake City, Utah
USA

noobie
- 28th April 2006, 02:10
Just a manual switch at port B,0 that is providing a high then i expect port B,5 to output a high when port B,0 is detected high to light up a LED. Thanks for telling me the exact forum to post. If u know what's wrong for the logic of my program pls reply me. Thanks!

Darrel Taylor
- 28th April 2006, 02:36
noobie,

I think it's just a banking problem.

Before entering the Main loop, you change to bank1 and load ADCON1 and TRISB. Then in the loop you are testing and trying to set bits in PORTB, which is in bank0 or bank2.

Put a clrf STATUS before entering the loop and it should work better.
<br>

noobie
- 28th April 2006, 03:28
I tried it out but to no avail. Output RA4 still dun hav a high...

Darrel Taylor
- 28th April 2006, 03:37
RA4 ???

Your output was RB5.
<br>

noobie
- 28th April 2006, 03:46
Sorry i made a mistake... Should be RB5 do not hav a high output...

Darrel Taylor
- 28th April 2006, 04:01
Then, may I ask exactly where you put the line?

AND

Just a manual switch at port B,0 that is providing a high ...Does it have a pull-down resistor to provide a low when the switch is not pressed?
<br>

noobie
- 28th April 2006, 04:16
I did have a pull up resistor so that it is a low when the switch is not press.
I place the CLRF STATUS before GOTO main

Darrel Taylor
- 28th April 2006, 04:49
Then you're left with Paul's other questions ...
Does your chip program without error?
What configs did you set?Along with ...

Are you using a 6mhz crystal?
Is the oscillator config set to HS or H4? (16C745 doesn't have XT mode)
What size capacitors are on the crystal? (normally 22pf)
Is it a valid crystal, and is it actually oscillating?
Is there a pull-up resistor on MCLR?
Do you have 5V to VDD?
Are both VSS pins connected to ground?

Sorry for the basic questions but, it doesn't matter how good the program is, if the hardware isn't running.
<br>

noobie
- 28th April 2006, 05:03
Sorry Guess noobie fault... I didn't pluck in the oscillator... Embarrased that i made this kind of stupid fault...

Darrel Taylor
- 28th April 2006, 05:56
Not to worry, just chalk it up as something you won't do next time.

Eventually, you'll have made every possible mistake already, and you'll write Perfect bug free code. &nbsp; But, in the mean time, plan on having at least one of those "ooops" reactions in every project you do.

I still do. :)
<br>