Searching \ for '[pic]: Problem with PortB' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/ios.htm?key=port
Search entire site for: 'Problem with PortB'.

Exact match. Not showing close matches.
PICList Thread
'[pic]: Problem with PortB'
2005\11\28@194244 by Andre Abelian

flavicon
face
strange

Hi to all,

when I set break point on portB bit 4 other pins turn on too and
shift_left doesn't work
I worked on it whole day and I gave up. I appreciate if any one can see
what I
am doing wrong. I am not sure if what I put together is real SPI
interface what
I wanted to do is to make spi interface. here is partial code.
I am using 18f452 with mplab ccs plugin

thanks

Andre



#include <18F252.h>  
#device ADC=8
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)   //
#use rs232(baud=1200, xmit=PIN_C6, rcv=PIN_C7,errors)  //
#define MICROSOFT TRUE
#define MOUSE_SYSTEMS FALSE  
#DEFINE LEFT_BUTTON PIN_B6
#DEFINE RIGHT_BUTTON PIN_B7
#DEFINE X_CHANNEL 0
#DEFINE Y_CHANNEL 1
#define PS2_CLK_OUT   PIN_B4 //
#define PS2_DATA_OUT  PIN_B5 //
#define PS2_CLK_IN  PIN_B1 //
#define PS2_DATA_IN      PIN_B0 //
#define LED    PIN_C3



void ps2_out(BYTE data)
{
     BYTE i;
             
        output_low(PS2_CLK_OUT);  // start bit on
      for(i=1;i<=8;++i)
     {
     output_bit(PS2_DATA_OUT, shift_left(data,1,0));
     output_high(PS2_CLK_OUT);   //  <= I set break point here
     output_low(PS2_CLK_OUT);
     }
     output_low(PS2_DATA_OUT);
     delay_ms(11);
}

2005\11\28@203122 by peteHVAC

flavicon
face
Hello,
Not sure if I can help much but it looks like shift_left should be
output_bit(PS2_DATA_OUT, shift_left(&data,1,0));
data needs to be a structure or array shift needs the address of data &data
Not sure about the port. Single step the program and watch for changes?

I'm just starting with CCS too. If you post some more code maybe I can help.
If you need SPI you should use the built in stuff very easy + lots of
examples.

If your rewriting PICC\Examples\EX_MOUSE.C maybe you should get that working
first.

http://www.ccsinfo.com/forum/ is a good place to hang out.

A very good book is PICmicro MCU C by Nigel Gardner ISBN 0-9724181-0-5
Hope this helps.

Pete

{Original Message removed}

2005\11\28@212324 by Andre Abelian

flavicon
face
Pete,

thaks for your input yes that was the problem with shifting.
what is the purpose of &  ?

Andre



peteHVAC wrote:

{Quote hidden}

>{Original Message removed}

2005\11\28@212603 by William Chops Westfield

face picon face
On Nov 28, 2005, at 4:42 PM, Andre Abelian wrote:

>      output_bit(PS2_DATA_OUT, shift_left(data,1,0));
>

I'm not familiar with the specifics of CCS, but...

What is shift_left supposed to do, beyond "data = data<<1", and
are you sure it is appropriate here?

And does output_bit() output the low order bit, high order bit, or
boolean of its second argument?  (unless it's the high order bit,
which seems unlikely (not C-like), then this isn't going to do what
it probably needs to do for serial-like communications...)

Finally, though I guess you're not there yet, it seems to me that
this code is somewhat likely to execute too fast for reliable
communications with most PC-like PS2 devices/computers.  You'll
probably need a delay before toggling the clock bit...

BillW

2005\11\28@223238 by peteHVAC

flavicon
face
Andre,

& means "The address of"
It gives you the memory location of the variable data.
When you make portb all low you are writing 0b00000000 to address F81h(portb
on 18f452)

If you declare a pointer variable
int *a;
and a variable
int b=3;
and you then say
a=&b;
a will contain the address of b not the value of b.

Pete

{Original Message removed}

2005\11\29@013047 by Andre Abelian

flavicon
face

William,

thanks for your replay


William Chops Westfield wrote:

{Quote hidden}

it will shift bits out thru one of pic pin
if you do   data=data<<1 then you are shifting to left only
then you need to add more code to shift out thru the pin.

>
>
> And does output_bit() output the low order bit, high order bit, or
> boolean of its second argument?

output_bit()  // will specify single bit only high or low

> (unless it's the high order bit,
> which seems unlikely (not C-like), then this isn't going to do what
> it probably needs to do for serial-like communications...)
>
> Finally, though I guess you're not there yet, it seems to me that
> this code is somewhat likely to execute too fast for reliable
> communications with most PC-like PS2 devices/computers.  You'll
> probably need a delay before toggling the clock bit...
>
my spi routine is messed up. Since I am not there yet deffinetly needs
more work to be done.

thank you for your time

> BillW


Andre

2005\11\29@071625 by olin piclist

face picon face
Andre Abelian wrote:
> when I set break point on portB bit 4

I wasn't aware any tool let you set a breakpoint on a particular bit,
whatever that means.  Do you mean write to the bit?  Read from it?  Any
access?  Port pin externally changed?


******************************************************************
Embed Inc, Littleton Massachusetts, (978) 742-9014.  #1 PIC
consultant in 2004 program year.  http://www.embedinc.com/products

2005\11\29@092714 by Andre Abelian

flavicon
face
Olin Lathrop wrote:

All I mean is when I am setting break point on this line
instead of just setting bit 4 it sets other bits too.
that was the problem. I do not think there is a way to
set a break point on single bit.

Andre





{Quote hidden}

2005\11\29@105324 by Scott Dattalo

face
flavicon
face
On Tue, 2005-11-29 at 07:17 -0500, Olin Lathrop wrote:
> Andre Abelian wrote:
> > when I set break point on portB bit 4
>
> I wasn't aware any tool let you set a breakpoint on a particular bit,
> whatever that means.

Hi Olin,

I'm not sure to which tool Andre refers, but gpsim (and probably other 3rd
party simulators) can break "on a particular bit".

>  Do you mean write to the bit?  Read from it?  Any
> access?  Port pin externally changed?

gpsim can do all of these. For example,

Break if RB4 if a '1' is written to portb:

break w portb & (1<<4) == (1<<4)

Break if RB4 is read as a zero:
break r portb & (1<<4) == 0

Or if you want an assertion type break that checks portb while the code is
running at a particular address:

break e loop_start ( (portb & (1<<4)) == (1<<4))

This last one sets an execution break point at the label 'loop_start' and
will halt whenever the simulation reaches this address and RB4 is high.

Scott

2005\11\29@121652 by Spehro Pefhany

picon face
At 10:31 PM 11/28/2005 -0500, you wrote:

I'm not that familiar with CCS C (except to know that it is not very much
like the C language from doing a translation), but you should also consider
inserting a delay between where you set PS2_CLK_OUT high and set it low or
the strobe duration may not be long enough to work, depending on the
efficiency of code the compiler emits. Worst (or best) case it could emit
two succeeding bsf/bcf instructions that might not even reach the correct
logic levels with a 20MHz clock, let alone be long enough to meet the
requirements of whatever is connected to your interface. Data setup and
hold times (probably more the former) could also be an issue, so look at
that too.

Best regards,

Spehro Pefhany --"it's the network..."            "The Journey is the reward"
spam_OUTspeffTakeThisOuTspaminterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
->> Inexpensive test equipment & parts http://search.ebay.com/_W0QQsassZspeff


More... (looser matching)
- Last day of these posts
- In 2005 , 2006 only
- Today
- New search...