Jump to content

Problem With Port A Of Pic16f876


Recommended Posts

hi..this is my first post in here..i hope there is somebody will help me..

 

i have create a program to blink led all port in PIC16F876...i get this code from winpic website and try to test using soureboost with led plugin..

 

then i'm stuck here when all port seems ok except for port A..

 

RA4,RA6 & RA7 is not produce any output..

 

i have questions.

1. what is means by #pragma DATA 0x2007, 0x3FF9 // XT,!CP,!WDT,!PWRT,BODEN,LPV,!CPD,WRT,!DEBUGGER

2.does this line of code affect the PORT A as ADC?

3.initially all pins in port A did not produce any output,then when I put adcon1 RA0,RA1,RA2,RA3&RA5 produce output..is there need to configure adon1?

 

for your ref, here is my code..

 

 

/*

 

6/24/03

Copyright Spark Fun Electronics 2003©

 

Classic Blinking Test Routine for the 40 Pin PIC16F876

 

 

Flashes all pins on PIC - 3.6864MHz operations

*/

 

#include <system.h>

 

#ifdef _BOOSTC

//Define device config block

#pragma DATA 0x2007, 0x3FF9 // XT,!CP,!WDT,!PWRT,BODEN,LPV,!CPD,WRT,!DEBUGGER

 

#else

 

//Define device config block

asm

{

list p=PIC16F876

__config H'3FF9' ;XT,!CP,!WDT,!PWRT,BODEN,LPV,!CPD,WRT,!DEBUGGER

}

 

#endif

 

//////////////////////////////////////////////

// Main program entry

//////////////////////////////////////////////

 

void main()

{

 

//Disable all interrupts

clear_bit( intcon, GIE ); //disable interrupts

 

//Init ports

//A, B, C, D and E port initialization

 

trisb = 0; //All pins configured for output

trisc = 0; //All pins configured for input

 

 

portb = 0;

portc = 0;

 

//Turn Port A to Digital Outputs

set_bit(adcon1, ADFM); //

clear_bit(adcon1, PCFG0); //

set_bit(adcon1, PCFG1); //

set_bit(adcon1, PCFG2); //

clear_bit(adcon1, PCFG3);

trisa = 0; //All pins configured for output

porta = 0;

 

while(1) {

porta = 255;

portb = 255;

portc = 255;

delay_ms(100);

porta = 0;

portb = 0;

portc = 0;

delay_ms(100);}}

 

//General short delay

 

void delay_ms(unsigned char t);

 

 

 

thanks,

 

Regards..

madie (M'sia)

Link to post
Share on other sites
    6/24/03

    Copyright Spark Fun Electronics 2003©

 

Classic Blinking Test Routine for the 40 Pin PIC16F876

   

   

Flashes all pins on PIC - 3.6864MHz operations

*/

 

 

Hi,

As far as i know PIC16F876 is a 28 pin chip.

To see your leds work on porta make adcon1=7; ie. set it to digital mode.

I would suggest you to take a look at the thread "pic micro programming in BoostC for beginners".

Regards

Raghunathan.

Link to post
Share on other sites
1. what is means by  #pragma DATA 0x2007, 0x3FF9 // XT,!CP,!WDT,!PWRT,BODEN,LPV,!CPD,WRT,!DEBUGGER

2.does this line of code affect the PORT A as ADC?

3.initially all pins in port A did not produce any output,then when I put adcon1 RA0,RA1,RA2,RA3&RA5 produce output..is there need to configure adon1?

 

XT = Temperature Compensated Crystal

!CP = No comparators

!WDT = No Watchdog Timer

!PWRT = ... No Power on reset?

BODEN = BrownOut Detect

LPV = Low Voltage Programming

!CPD = No clear power down detect ?

WRT = Write Protect

!DEBUGGER = No Debugger

 

adon enables/disables AD in the adcon register

No, your pragma line did not affect the adcon register, and yes you need to disable AD

if you want to use it as a regular IO port.

Link to post
Share on other sites
i have create a program to blink led all port in PIC16F876...i get this code from winpic website and try to test using soureboost with led plugin..

 

then i'm stuck here when all port seems ok except for port A..

 

RA4,RA6 & RA7 is not produce any output..

You have a few of issue to deal with:

 

First there is a bug in the SourceBoost simulator: Port A Fails In Simulator

 

Second the PIC16F87x does not implement bits 6 and 7 for port A.

 

Third port A bit 4 is an "open drain" output. In your real hardware this output will need a pull up resistor before you can see a "high" output.

 

Forth there is a comparator function block that can force some of port A pins into analog mode. Be sure to use the statement "cmcon = 0x07;" to turn off the comparator and assign the port A pins to digital I/O.

 

Use the Microchip MPLAB IDE and simulator to get a better idea of how you code should work.

Link to post
Share on other sites
Forth there is a comparator function block that can force some of port A pins into analog mode. Be sure to use the statement "cmcon = 0x07;" to turn off the comparator and assign the port A pins to digital I/O.

 

 

Hi cac001,

PIC16F876 has got both adc and comparator connected to porta. The cmcon register is by default sets to off or 7 on POR. So on power-on reset (POR) porta gets configured as analog input for the adc. In order to change it to digital you should config adcon1 to 7.

Regards

Raghunathan

Link to post
Share on other sites
1. what is means by  #pragma DATA 0x2007, 0x3FF9 // XT,!CP,!WDT,!PWRT,BODEN,LPV,!CPD,WRT,!DEBUGGER

2.does this line of code affect the PORT A as ADC?

3.initially all pins in port A did not produce any output,then when I put adcon1 RA0,RA1,RA2,RA3&RA5 produce output..is there need to configure adon1?

 

XT = Temperature Compensated Crystal

!CP = No comparators

!WDT = No Watchdog Timer

!PWRT = ... No Power on reset?

BODEN = BrownOut Detect

LPV = Low Voltage Programming

!CPD = No clear power down detect ?

WRT = Write Protect

!DEBUGGER = No Debugger

 

adon enables/disables AD in the adcon register

No, your pragma line did not affect the adcon register, and yes you need to disable AD

if you want to use it as a regular IO port.

 

i think:

!CP = disable Code Protect

XT = use crystal oscillator instead of RC, internal osc, etc

**for the rest look at the WINPIC's device config tab

 

That pragma line is use by your WINPIC to configure the device config before uploading the hex file on your microcontroller

Link to post
Share on other sites

ra68gi,

 

Sorry I was not clear enough. You are correct, though madie is already setting adcon1 to 0x06, just doing it one bit at a time. If you believe the datasheet then setting adcon1 to 0x06 or 0x07 will assign all of port A to digital I/O.

 

Setting cmcon to 0x07 is just to make sure that nothing else could have configured port A bits to analog I/O.

 

To be completely sure every thing is configured set bit 5 of the option register to 0. When this bit is 1 then port A bit 4 is the clock source for timer 0.

 

Remember that port A bit 4 is an open drain output and needs a pull up to go high on the real hardware.

 

CAC.

Link to post
Share on other sites

thanks all my friends..yuo help me a lots..i thinks cac001 was correct..there is a bug in the SourceBoost simulator (beetle bugs :P )..RA4 will never blink using sourceboost simulator...but it will when using real hardware..

 

thanks averybody..

Link to post
Share on other sites

madie,

 

RA4 will never blink using sourceboost simulator...but it will when using real hardware..

This is not a bug, on the PIC16F876A RA4 is open drain, that means the pin can only go low. The LEDs in the LED block in the simulation needs the pins to be taken to 5V for the LEDs to illuminate, which can't be done with an open drain output.

 

Regards

Dave

Link to post
Share on other sites

Dave,

This is not a bug, on the PIC16F876A RA4 is open drain, that means the pin can only go low. The LEDs in the LED block in the simulation needs the pins to be taken to 5V for the LEDs to illuminate, which can't be done with an open drain output.

While this is true for all PICs where RA4 is an open drain output.

 

The simulator seems to treat all PIC16F parts as if RA4 is an open drain.

 

RA4 is not an open drain output on the PIC16F688 and PIC16F917, there are possible others as well.

 

Another issue with the simulator is that it will read back a non-zero value for a port bit even when the bit is configured as an analog input.

 

For example, with a PIC16F688 configure port A for analog I/O then set bit 0, then set bit 1. The port A register show the value 3 using SourceBoost sim but MPLAB shows the value zero.

 

We could catch a few more configuration issues if the simulator paid attention to the analog enable bits.

 

cac.

Edited by cac001
Link to post
Share on other sites
madie,

 

RA4 will never blink using sourceboost simulator...but it will when using real hardware..

This is not a bug, on the PIC16F876A RA4 is open drain, that means the pin can only go low. The LEDs in the LED block in the simulation needs the pins to be taken to 5V for the LEDs to illuminate, which can't be done with an open drain output.

 

Regards

Dave

 

yes...i know RA4 is open drain...ofcourse 5V source is needed for hardware..but it is same for this simulation? i'm just thinking this simulation is configured both (open drain and open source).lol..

 

anyway..thanks..i solve my pboblem..and my hardware now work fine.. :D:D

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...