CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

About output_bit() & output_x() discussion

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
leevise



Joined: 05 Aug 2010
Posts: 89

View user's profile Send private message

About output_bit() & output_x() discussion
PostPosted: Wed Sep 01, 2010 12:50 am     Reply with quote

Hello guys, I have a question with PIC16f877a.
When I program the C code as follows:
Code:

#include "D:\PICprogram\12864LCD_20100901.h"
#include <16f877a.h>
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOCPD,NOWRT
                         
#use delay(CLOCK=20000000)
#use fast_io(B)

void init_lcd()
{
   set_tris_b(0x00);
   output_b(0x0f);
 }

void main()
{
   init_lcd();
   while(1);
}

My DEMO board PINS are defined as follows:
LED0_RB0-----PIN_B0
LED1_RB1-----PIN_B1
LED2_RB2-----PIN_B2
LED3_RB3-----PIN_B3


The LED1 & LED2 light, the other is not light, this why ?

I have the same question when I use OUTPUT_BIT() in the code as follows:
Code:

#include "D:\PICprogram\12864LCD_20100901.h"
#include <16f877a.h>
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOCPD,NOWRT
                         
#use delay(CLOCK=20000000)
#use fast_io(B)

void init_lcd()
{
   set_tris_b(0x00);
    output_bit(PIN_B2,1);
   output_bit(PIN_B7,1);
   output_bit(PIN_B6,1);
   output_bit(PIN_B5,1);
   output_bit(PIN_B4,1);
   output_bit(PIN_B3,1);
   output_bit(PIN_B2,1);
   output_bit(PIN_B1,1);
   output_bit(PIN_B0,1);
 }

void main()
{
   init_lcd();
   while(1);
}

I find the PIN_B7,PIN_B6 and PIN_B3 is not output HIGH bit. I know the B7--PGD, B6---PGC, B3---PGM, but how do I set them in order to let them work ok !


Last edited by leevise on Thu Sep 02, 2010 1:12 am; edited 1 time in total
leevise



Joined: 05 Aug 2010
Posts: 89

View user's profile Send private message

why ?
PostPosted: Wed Sep 01, 2010 7:10 pm     Reply with quote

I don't know if I went wrong in code, or the DEMO board is bad?
jbmiller



Joined: 07 Oct 2006
Posts: 73
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Sep 01, 2010 7:30 pm     Reply with quote

I/O pins can have multiple uses, so you have to disable those peripherals that are not being used.
Check with the datasheet to which are applicable for the PIC you're using and disable are required.
leevise



Joined: 05 Aug 2010
Posts: 89

View user's profile Send private message

I only use the I/O
PostPosted: Wed Sep 01, 2010 8:06 pm     Reply with quote

jbmiller wrote:
I/O pins can have multiple uses, so you have to disable those peripherals that are not being used.
Check with the datasheet to which are applicable for the PIC you're using and disable are required.


I know the PIN has multiple uses, but it works OK ago.
I don't open the multiple use PIN, because the Default State is closed, isn't it?
And I set the FUSES:
Code:

#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOCPD,NOWRT

I test the voltage of RB, I got the result:
PIN_B7=0V
PIN_B6=0V
PIN_B5=5V
PIN_B4=5V
PIN_B3=0.12V
PIN_B2=4.68V
PIN_B1=4.66V
PIN_B0=1.56V
leevise



Joined: 05 Aug 2010
Posts: 89

View user's profile Send private message

Very puzzle thing !!!!!i will crazy !!!!
PostPosted: Wed Sep 01, 2010 11:33 pm     Reply with quote

I check the RC and I find these things

in code define PIN ------match--------DEMO BOARD PIC PIN
PIN_C0---------------------------------- NOthing
PIN_C1----------------------------------NOthing
PIN_C2----------------------------------C0
PIN_C3----------------------------------C1
PIN_C4----------------------------------C2
PIN_C5----------------------------------C3
PIN_C6----------------------------------C4
PIN_C7----------------------------------C5


I mean the define PINs can't match actual PINs. When I use the "output_bit()"command, occur above thing.

But I use the "output_c(0xff)", the RC all output signal. I am very puzzled, I will go crazy !!
Pls so everyone tell me why this is ?

My test code as follow:
Code:
#include <16f877a.h>
#device icd=ture
#fuses HS,NOWDT,PUT,NOPROTECT
                             
#use delay(CLOCK=20000000)//When use the TMR0 ,not use the delay
#use fast_io(C)

void init_lcd()
{
    set_tris_c(0x00);
    //output_c(0x00);   //output_c(0xff);
    output_bit(PIN_C2,1);  // C0
   
   output_bit(PIN_C7,1);    //C5
   output_bit(PIN_C6,1);  //C4
  output_bit(PIN_C5,1);    //C3
   output_bit(PIN_C4,1);      //C2
   output_bit(PIN_C3,1);   //C1
   output_bit(PIN_C1,1);
   output_bit(PIN_C0,1); //
 }

void main()
{
   init_lcd();
   while(1);
}
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Sep 02, 2010 3:28 am     Reply with quote

Quote:
I don't open the multiple use PIN, because the Default State is closed, isn't it?
No. You have to check the datasheet for each pin. Too bad the PIC16F87xA datasheet is not very clear in this, the datasheets for newer processors have the default state listed in a table.
For example, at start up, all analog pins are activated. To use them for digital inputs you have to disable the analog function on these pins.
To play it safe it is best to add code at the startup of your program that disables all the units you don't use.

Quote:
#device icd=ture
Does this compile without errors? Please fix the typo as now you have undefined behaviour.

Which demo board are you using? Post the manufacturer and model number. Even better when you can post a link to the website and schematic.

Post your compiler version number.
leevise



Joined: 05 Aug 2010
Posts: 89

View user's profile Send private message

I use the Microchip demo board
PostPosted: Thu Sep 02, 2010 6:56 pm     Reply with quote

Good morning guys, I use the MICROCHIP demo board "PICDEM 2 PLUS DEMO BOARD "2002 version. The complier I use is the PCWHD 4.088.
I already know the reason about the PIN_B7, PIN_B6, PIN_B3 no output,
I need to disconnect debugger cable from the demo board. They work OK, but the demo RC don't match the define RC, I am not finding the reason. Does RC pin need set the analog ?


ckielstra wrote:
Quote:
I don't open the multiple use PIN, because the Default State is closed, isn't it?
No. You have to check the datasheet for each pin. Too bad the PIC16F87xA datasheet is not very clear in this, the datasheets for newer processors have the default state listed in a table.
For example, at start up, all analog pins are activated. To use them for digital inputs you have to disable the analog function on these pins.
To play it safe it is best to add code at the startup of your program that disables all the units you don't use.

Quote:
#device icd=ture
Does this compile without errors? Please fix the typo as now you have undefined behaviour.

Which demo board are you using? Post the manufacturer and model number. Even better when you can post a link to the website and schematic.

Post your compiler version number.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group