PDA

View Full Version : PicBasicPro Code help!



michel
- 10th June 2008, 23:45
Hi!

I'm new to PIC programming....I have done projects with Basic Stamp 2...

Two codes question;

With a ex VAR WORD (ex=2343). How do I get the digit 2 with picbasic pro?
With basicstamp it's NIB 3. (starting from the right from 0).

Other question;

I have a 40 pin PIC (16f877) and wanna get PORTB (rb0,rb1,rb2 and rb3) to output and ascii number all together.How do I do it with picbasic pro?

With basic stamp here is te code, LOW and HIGH port can be used.

LEDs VAR OUTD ' LEDs on P12 - P15
LEDsDirs VAR DIRD ' DIRS control for LEDs
display VAR OUTC ' Transistors on P8 - P11
cntdisplay VAR DIRC ' DIRS control for Transistors

LEDs = 2 (pin 12 t0 15 will output 2)


Tank you....(don't forget beginner) ...

mister_e
- 11th June 2008, 00:02
Salut Michel,
NIB 3 should be DIG 3 in PBP, refer to section 4.17.7 of your manual


PORTB (rb0,rb1,rb2 and rb3) to output and ascii number all together.
TRISB=0 ' all PORTB i/o = output
'
'
'
'
PORTB=YourVariable ' use with care

Refer to section 10 for PIcBasic VS Stamp difference.

michel
- 11th June 2008, 00:14
Tanks for the first question....

But the second....portB has 8 pins rb0 to rb7 and I have to define the 4 pins (0 to 3) only to use for output my number. I have, imagine to dfive one variable with those 4 pins and than ....

Can i say ex = portB.low...let's say! and than ex = 2

Thanks again!

michel
- 14th June 2008, 15:43
Made my protoboard and finaly found the code for assinging port pins.





DEFINE OSC 4

TRISB = %00000000

x var byte
Leds var byte
Digs var byte

ENABLE DEBUG

main:


for x = 0 to 9
leds = x
Digs = x
GOSUB PORTSsegments
gosub PORTSdiggits
Pause 500 ' Delay for .5 seconds
leds = %0000
Digs = %0000
GOSUB PORTSsegments
gosub PORTSdiggits
Pause 500 ' Delay for .5 seconds
next x
Goto main ' Go back to loop and blink LED forever


PORTSsegments:

PortB.0 = leds.0 : PortB.1 = leds.1 : PortB.2 = leds.2 : PortB.3 = leds.3

return

PORTSdiggits:

PortB.4 = Digs.0 : PortB.5 = Digs.1 : PortB.6 = Digs.2 : PortB.7 = Digs.3

return

DISABLE DEBUG

End