Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > using picc on a pic1f627

Reply
Thread Tools

using picc on a pic1f627

 
 
Andrew Smallshaw
Guest
Posts: n/a
 
      05-18-2012
[crosspost to c.a.e. as more appropriate group]

On 2012-05-17, Andre <(E-Mail Removed)> wrote:
> First, I am retired and doing all this just for fun and it's a
> looong time since I used C language
>
> I need to write 4 bits to PORTB without disturbing the others bit
> RB1, RB2 are ( will be ) used by the UART.
> If I Mask 4 bits like CC = CC & 0x0F the upper bits are set to 0 but
> still there?


By default the I/O ports all default to input mode until pins are
configured as outputs. I don't use C on the smaller PICs, but in
PIC assembler you'd do that by configuring the TRISB register (for
port B) so I would start by looking that up in your compiler
documentation (alternatively it may be down as TRISIO for historical
reasons).

Although I suspect that is your actual problem, there is another
potential issue to catch out the unwary. Regardless of whether
the pin in question is configured as an input or an output any
reads will always refer to the signal on the pin itself - if a
given pin is configured as an output and you write a 0 to it, if
external circuitry drives the pin high you'll get a 1 back when
you read the port.

Finally, you don't need to worry about treating the pins with
special peripherals on them with kid gloves - if the peripheral in
question is in use the peripheral will over-ride the corresponding
slot in PORTB - any changes to the value in PORTB have no effect.

--
Andrew Smallshaw
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Andre
Guest
Posts: n/a
 
      05-19-2012
Le 18/05/2012 18:34, Andre a écrit :
> Le 17/05/2012 10:32, Andre a écrit :
>> First, I am retired and doing all this just for fun and it's a
>> looong time since I used C language
>>
>> I need to write 4 bits to PORTB without disturbing the others bit
>> RB1, RB2 are ( will be ) used by the UART.
>> If I Mask 4 bits like CC = CC & 0x0F the upper bits are set to 0 but
>> still there?
>>
>> I think I could create a structure ( or a type ) with 4 bits such as
>> BCD { RB3
>> RB4
>> RB5
>> RB6
>> }
>>
>> But I keep trying, no luck ( so far )
>> Can someone give a hand??
>> Many thanks in advances
>> André

> FYI
>
> I found somthing, not perfect but OK for the moment
>
> unsigned char counter;
> #define bit_set(var,bitno) ((var) |= 1 << (bitno))
> #define bit_clr(var,bitno) ((var) &= ~(1 << (bitno)))
> #define testbit_on(data,bitno) ((data>>bitno)&0x01)
>
> while (1){
>
> if ( testbit_on(counter,3) ) { RB7 = 1; } else { RB7 = 0; }
> if ( testbit_on(counter,2) ) { RB6 = 1; } else { RB6 = 0; }
> if ( testbit_on(counter,1) ) { RB5 = 1; } else { RB5 = 0; }
> if ( testbit_on(counter,0) ) { RB4 = 1; } else { RB4 = 0; }
> _delay(10000);
> counter++;
> if ( counter == 10 ) { counter = 0; }
>
> .
> So that seems to work ( At lease with MPLab ;-//
> Many thanks
> André
>
> BTW: I will bring update on this if there is such interest.


Before anything else
I didn't invent it my self I found this on:
http://www.microchipc.com/HiTechCFAQ/
André
 
Reply With Quote
 
 
 
 
Thad Smith
Guest
Posts: n/a
 
      05-24-2012
On 5/18/2012 3:42 PM, Andrew Smallshaw wrote:
> [crosspost to c.a.e. as more appropriate group]
>
> On 2012-05-17, Andre<(E-Mail Removed)> wrote:
>> First, I am retired and doing all this just for fun and it's a
>> looong time since I used C language
>>
>> I need to write 4 bits to PORTB without disturbing the others bit
>> RB1, RB2 are ( will be ) used by the UART.
>> If I Mask 4 bits like CC = CC& 0x0F the upper bits are set to 0 but
>> still there?

>
> By default the I/O ports all default to input mode until pins are
> configured as outputs. I don't use C on the smaller PICs, but in
> PIC assembler you'd do that by configuring the TRISB register (for
> port B) so I would start by looking that up in your compiler
> documentation (alternatively it may be down as TRISIO for historical
> reasons).
>
> Although I suspect that is your actual problem, there is another
> potential issue to catch out the unwary. Regardless of whether
> the pin in question is configured as an input or an output any
> reads will always refer to the signal on the pin itself - if a
> given pin is configured as an output and you write a 0 to it, if
> external circuitry drives the pin high you'll get a 1 back when
> you read the port.


That's true. The correct way is to modify the LATB, rather than PORTB, to avoid
this problem.

> Finally, you don't need to worry about treating the pins with
> special peripherals on them with kid gloves - if the peripheral in
> question is in use the peripheral will over-ride the corresponding
> slot in PORTB - any changes to the value in PORTB have no effect.


An interesting note on this: I was getting a spurious output character on the
TXD line when the RXD line was sampling the input character in autobaud sampling
mode on a PIC16F1938. It turns out that the PIC was disabling the transmit
circuit for the duration of the sample period and the corresponding output latch
(for when the pin wasn't configured as TXD) had a zero bit, causing an
8-bit-time low pulse. The fix? Set the port bit to 1.

--
Thad
 
Reply With Quote
 
Wolfgang Mahringer
Guest
Posts: n/a
 
      05-25-2012
Hi,

Am 24.05.2012 05:22, schrieb Thad Smith:
> That's true. The correct way is to modify the LATB, rather than PORTB,
> to avoid this problem.


Unfortunately, there is no such thing like a "LATB" register on a
16F627...

If the OP really needs to know the latch value, he needs to keep a
copy of it in a file register.

Cheers,
Wolfgang

--
From-address is Spam trap
Use: wolfgang (dot) mahringer (at) sbg (dot) at
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error page using the Application_Error void dosnt work when using DIV for a please wait message s_erez@hotmail.com ASP .Net 2 12-24-2004 12:11 PM
Are bit-variables in PICC a good idea Andras Tantos C Programming 3 01-12-2004 03:18 PM
no code in webform using vs.net, but in webform using notepad timmso ASP .Net 1 12-12-2003 04:30 PM
Using GetOleDbSchemaTable to get SQL Server Field Description - using pete ASP .Net 1 08-29-2003 10:50 AM
Re: MVP? Index error on nested element using System.xml but NOT using msxml??? William F. Robertson, Jr. ASP .Net 1 06-25-2003 08:08 PM



Advertisments