PDA

View Full Version : Newbie question:



Izone
- 24th February 2006, 20:42
How can I recompile the PicBasic code found on this page;

http://www.rentron.com/PIC16F84.htm

With PBC?

I am getting errors due to the missing bs2defs.bas file.

Archilochus
- 25th February 2006, 00:25
Well, I don't know about the PBC issues, but to get around needing the "bs2defs.bas" file you should give the variables your own names (don't use the generic "b1", etc), and not use numbers for pins:

Instead of "high3" ; make pin 3 high

Write high PORTx.x ; x.x is port letter & pin number EX: PORTA.1

Izone
- 26th February 2006, 17:24
Thanks for your help, much appreciated.

Is it possible to use the SERIN command in PicBasic. but use a pin on port A as the input?

I have changed the code to this:

Symbol PORTA = 5
Symbol TRISA = $85
Symbol PORTB = 6
Symbol TRISB = $86
symbol relay = B0
symbol stat = B1
symbol serpin = porta.4
POKE TRISA,16 ' set porta.4 to input all others output
POKE TRISB,0 ' set output to all PORTB pins

poke porta, $00 'clear port A and B.
poke portb, $00




serin serpin, N2400, ("A"),relay ,B1
loop:
IF relay = 1 THEN outr1 ' if request is for relay#1 then goto relay#1 routine
IF relay = 2 THEN outr2
IF relay = 3 THEN outr3
IF relay = 4 THEN outr4
IF relay = 5 THEN outr5
IF relay = 6 THEN outr6
IF relay = 7 THEN outr7
IF relay = 8 THEN outr8
IF relay = 9 THEN outr9
IF relay = 10 THEN outr10
IF relay = 11 THEN outr11
IF relay = 12 THEN outr12
goto loop



outr1:
IF stat = 1 THEN high1 ' If status request is I/O pin#0 logic 1 [high]
LOW 0: GOTO loop ' then make I/O pin#0 high, else make it [low]

high1:
HIGH 0: GOTO loop ' Make I/O pin#0 logic 1 [high]

outr2:
IF stat = 1 THEN high2
LOW 1: GOTO loop

high2:
HIGH 1: GOTO loop

outr3:
IF stat = 1 THEN high3
LOW 2: GOTO loop

high3:
HIGH 2: GOTO loop

outr4:
IF stat = 1 THEN high4
LOW 3: GOTO loop

high4:
HIGH 3: GOTO loop

outr5:
IF stat = 1 THEN high5
LOW 4: GOTO loop

high5:
HIGH 4: GOTO loop

outr6:
IF stat = 1 THEN high6
LOW 5: GOTO loop

high6:
HIGH 5: GOTO loop

outr7:
IF stat = 1 THEN high7
LOW 6: GOTO loop

high7:
HIGH 6: GOTO loop

outr8:
IF stat = 1 THEN high8
LOW 7: GOTO loop

high8:
HIGH 7: GOTO loop

outr9:
IF stat = 1 THEN high9
poke portA, $00: GOTO loop

high9:
poke porta, $01: GOTO loop

outr10:
IF stat = 1 THEN high10
poke porta, $00: GOTO loop

high10:
poke porta, $02: GOTO loop

outr11:
IF stat = 1 THEN high11
poke porta, $00: GOTO loop

high11:
poke porta, $04: GOTO loop

outr12:
IF stat = 1 THEN high12
poke porta, $00: GOTO loop

high12:
poke porta, $08: GOTO loop