Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Writing to 7-segment display from PIC16F628A

Status
Not open for further replies.

Alphadl

New Member
Hi,
I am new to PIC microcontrollers.
I am trying to write numbers 0-9 in a seven segment display(common cathode)through a PIC16F628.
I coded,compiled and downloaded the program.
But what i observed is that 'e' segment never glows.I checked the circuit and its proper.
I have connected RB0-a, RB1-b ...... RB6-g. So RB4 is never getting 'High'.
My C code is pasted below. What can be the reason?


I have few queries:
1) In some sample code i have seen changing the register bank for configuring the port and again changing it before writing to the port. Is it necessary? if so what is the reason.

2) Is there anything wrong in connecting MCLR (pin#4) directly to Vdd(pin#14).

3) At first the 7-segment display was connected directly to the port pins and the cathode was connected to GND through a 330 Ohm resistor. Then the Microcontroller was behaving in a strange way. Then i changed the circuit with 7 different resistors for each segment. After that it was okay. Now my doubt is,anyway i am connecting a resistor in series, then how can there be a difference between these two connections?


#include <pic.h>
#include <HTC.h>
__CONFIG(0x3FF0);

void delay(void);

void main(void) {
TRISB = 0x00;
while (1)
{
PORTB = 0x3F; // Equal to 0
delay();
PORTB = 0x06; // Equal to 1
delay();
PORTB = 0x5B; // Equal to 2
delay();
PORTB = 0x4F; // Equal to 3
delay();
PORTB = 0x66; // Equal to 4
delay();
PORTB = 0x6D; // Equal to 5
delay();
PORTB = 0x7D; // Equal to 6
delay();
PORTB = 0x07; // Equal to 7
delay();
PORTB = 0x7F; // Equal to 8
delay();
PORTB = 0x6F; // Equal to 9
delay();
}
}

void delay(void) {
unsigned int i,j,k;
for (i=0; i<100; i++)
{
for (j=0; j<1000; j++)
k=j; //just to waste one cycle
}
}
 
Hi
In your config fuses do you have LVP (Low Voltage Programming) enabled??

if you do then RB4 is disabled and can only be used for programming, try disabling it and see if you get any better results.
 
Hi Cobra1 and Gayan Soyza,
Thanks a lot for your valuable suggestions.
I made those changes and now its working fine.
Once again thanks for your support.
Regards
Bipin (Alphadl)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top