Very first use of PBP (newbie!)
Hi all,
I just got my first program working on PBP. I have bought lots of books but am waiting for them to arrive. I was just wondering why I had this problem getting the blink.bas example working.
Portb.0 doesn't work. I tried portb.1 by chance and it worked. As I understand it, there are all sorts of registers to set and I have got the datasheet for the PIC I am using (16F886) but for someone as new as me, the datasheet doesn't tell me why. I have got a lot to learn!
I thought High and Low caused pins to become outputs so I didn't need to do anthing special with registers.
I have done quite a bit of work with PICAXE and when I change the osc freq on PICAXE the pause command is affected. I tried changing the freq from 4 to 8 in this code example and expected the LED to blink twice as fast but it didn't. Is PBP cleverer or have I not actually doubled the clock freq. I am using the internal osc.
Can anybody lend me a small hand with getting started on understanding datasheets and this specific problem.
Thanks
Rich
Code:
define osc 8
led var Portb.0
led2 var Portb.1
loop: High led ' Turn on LED connected to PORTB.0
High led2 ' Turn on LED connected to PORTB.0
Pause 500 ' Delay for .5 seconds
Low led ' Turn off LED connected to PORTB.0
low led2
Pause 500 ' Delay for .5 seconds
Goto loop ' Go back to loop and blink LED forever
End
A few things are wrong here
Rich,
"define osc 8" Is NOT changing oscillator frequency, It's just telling PBP at which frequency the oscillator is running. And most important, all defines must be in UPPERCASE when using PBP. Not 100% sure if required, but I would also try writing PORTB.0 uppercase.
BobK is right too, try adding define TRISB = %00000000. I don't exactly remember why, but I had some problem a while ago using high and low without having defined the port as an output, (but PORTB.0=1 was working fine!)
Picaxe is fantastic to learn PIC, but is missing all details related with PIC registers. When you're programming with PBP you have to read and understand the datasheet of the chip you're using. Then you will be able enjoy PBP and use all the flexibility of you're PIC.
J-P