Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Pic16f84a with pickit2 clone - led flasher

Status
Not open for further replies.

mailus

Full Member level 4
Joined
Mar 6, 2012
Messages
234
Helped
7
Reputation
16
Reaction score
7
Trophy points
1,308
Location
-
Activity points
2,706
i am trying my first project in PIC16f84A LED flasher. it doesn't flash in simulation it's ok.why?
my programmer is also good condition.


TO CHECK MY PROGRAMMER I USED THIS CODE
Code:
void main() 
{
 trisb=0x00;trisa=0x00;
 portb=0x00;porta=0x00;
 do {
     portb=~portb;
     delay_ms(5);
    }while(1);
}
IT'S WORKING..

MY PROBLEM IN THESE CODE
PORT B FLASH:
Code:
void main()
{
trisa=0x00;
trisb=0x00;
porta=0x00;
portb=0x00;
do
{
 portb=0xff;
 delay_ms(30);
 portb=0x00;
 delay_ms(50);
 }while(1);
}

MY HEX CODE FOR PORTB FLASH:
Code:
:020000001528C1
:0C00060083120D088A000C08820008001C
:1000120003208A110A128000840A8C0A03198D0AAD
:08002200C003031D09280800BA
:10002A00831685018601831285018601FF308600C9
:10003A002730CC00F530CD00CD0B2128CC0B212860
:10004A0086014130CC00EE30CD00CD0B2A28CC0BF6
:08005A002A2800001B283028B1
:02400E00F33F7E
:00000001FF
 
Last edited:

portb=0xff;
delay_ms(30);
porta=0x00;
delay_ms(50);
}while(1);

you are just making portb high, and clearing porta??? it should be portb=0 instead of porta=0;
 

sorry, while uploading i typed these codes this is my mistake...i edited the post...
 

16f84-flashing-led.png


Note: The LED current limiter resistor (1k) is not ideal it just lets you see the led (you don't need maximum current to see it) - Replace the 1k with a 220 if you want brighter output.


MikroC code:

Code:
//////////////////////////////////////////////////////////////////////
// Start here for PIC16F84 led flash
//
void main() {
unsigned short pa=0;
unsigned int i;


  PORTA = 0;
  TRISA = 0; // o/p   - sets analogue pins to digital output

  TRISB = 0;
  PORTB = 0;

  while(1) {

     pa=~pa;
     if (pa) {
        setBit(PORTB,3);
     } else {
        resBit(PORTB,3);
     }
     Delay_ms(100);
  } ; // infinite while loop
}

First of all the ports are initialized using TRISA, TRISB which set up the direction of pins for each port - in common with all the other PIC Micros you can change the port direction at any time using a TRIS keyword (which is just another register location).

Setting a bit in the TRIS register to zero sets the pin direction to an output. Here all bits are zero for TRISA and TRISB so all PORTA and PORTB bits are set as outputs. Then PORTA and PORTB are initialized to logic level zero.

As you can see main() is a very simple it alternately sets and resets bit 3 of PORTB

Try changing the delay time in the delay_ms statements to a smaller or larger value, re-compile and re-program the chip to see the effect.

https://www.best-microcontroller-projects.com/pic16f84.html
 

anything wrong in my code....
 

anything wrong in my code....
i had the same problem when i used 16f84 for the first time
check the watch dog timer i dont know how to reset it in C but it was my problem that time it was making random flasher time
 

problem identified.......
I changed my compiler version few days ago. I programmed some programs in that compiler.now I try these copies in new compiler that only problem....
now I changed everything to new compiler versions. my problem solved....
 

congrat. by the by would you please help to do the same thing for porta?...actually i want to know how a led will turn on by PA4 pin.
 

congrat. by the by would you please help to do the same thing for porta?...actually i want to know how a led will turn on by PA4 pin.

you need pull up resistor to vcc.because the RA4 pin is open drain output.hoose a pull up resistor...refer datasheet for more info
 

congrat. by the by would you please help to do the same thing for porta?...actually i want to know how a led will turn on by PA4 pin.

Make the pin an output pin by writing 0 to TRISA4.

Now you have to keep in mind that RA4 is open-drain. So, it can only sink current but cannot source current. So, for controlling LED, you can connect the LED in series with a resistor between RA4 and VDD and send 0 to RA4 to turn the LED on and send 0 to turn it off. Or you could connect a pull-up and connect the LED between RA4 and ground. This diagram should make things clear:

4858974200_1353737433.png


Hope this helps.
Tahmid.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top